[Aptitude-svn-commit] r3579 - in branches/aptitude-0.3/aptitude: . src/vscreen
Daniel Burrows
dburrows@costa.debian.org
Sun Jul 3 16:00:14 UTC 2005
Author: dburrows
Date: Sun Jul 3 16:00:11 2005
New Revision: 3579
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/vscreen/transcode.cc
branches/aptitude-0.3/aptitude/src/vscreen/transcode.h
Log:
Add transcoding directly from character buffers.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Sun Jul 3 16:00:11 2005
@@ -1,3 +1,10 @@
+2005-07-03 Daniel Burrows <dburrows@debian.org>
+
+ * src/vscreen/transcode.cc, src/vscreen/transcode.h:
+
+ Add transcode-with-punted-errors variants that read directly
+ from a character buffer.
+
2005-07-02 Daniel Burrows <dburrows@debian.org>
* src/generic/aptitude_resolver.h:
Modified: branches/aptitude-0.3/aptitude/src/vscreen/transcode.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/transcode.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/transcode.cc Sun Jul 3 16:00:11 2005
@@ -184,6 +184,23 @@
}
}
+std::wstring transcode(const char *s,
+ const char *encoding,
+ std::wstring (*errf)(int error,
+ const std::wstring &partial,
+ const std::string &input))
+{
+ std::wstring rval;
+ if(transcode(s, rval, encoding))
+ return rval;
+ else
+ {
+ if(errf == NULL)
+ errf=transcode_mbtow_err;
+ return errf(errno, rval, s);
+ }
+}
+
bool transcode(const wchar_t *s,
string &out,
const char *encoding)
@@ -233,3 +250,20 @@
return errf(errno, rval, s);
}
}
+
+std::string transcode(const wchar_t *s,
+ const char *encoding,
+ std::string (*errf)(int error,
+ const std::string &partial,
+ const std::wstring &input))
+{
+ std::string rval;
+ if(transcode(s, rval, encoding))
+ return rval;
+ else
+ {
+ if(errf == NULL)
+ errf=transcode_wtomb_err;
+ return errf(errno, rval, s);
+ }
+}
Modified: branches/aptitude-0.3/aptitude/src/vscreen/transcode.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/transcode.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/transcode.h Sun Jul 3 16:00:11 2005
@@ -71,6 +71,24 @@
const std::wstring &partial,
const std::string &input)=NULL);
+/** Convenience function to convert a multibyte encoding to wide
+ * characters, where the caller doesn't need to directly handle
+ * errors. This is a wrapper around iconv.
+ *
+ * \param s the string to decode
+ *
+ * \param encoding the encoding of s; if \b null or unspecified, the
+ * value of LC_CTYPE is used.
+ *
+ * \param errf the error handler, or \b null to use the default
+ * handler (transcode_mbtow_err).
+ */
+std::wstring transcode(const char *s,
+ const char *encoding=NULL,
+ std::wstring (*errf)(int error,
+ const std::wstring &partial,
+ const std::string &input)=NULL);
+
// Note: would it be saner to express errors via exceptions?
/** Convenience function to convert the native wide character encoding
@@ -124,4 +142,22 @@
const std::string &partial,
const std::wstring &input)=NULL);
+/** Convenience function to convert a multibyte encoding to wide
+ * characters, where the caller doesn't need to directly handle
+ * errors. This is a wrapper around iconv.
+ *
+ * \param s the string to decode
+ *
+ * \param encoding the encoding of s; if \b null or unspecified, the
+ * value of LC_CTYPE is used.
+ *
+ * \param errf the error handler, or \b null to use the default
+ * handler (transcode_mbtow_err).
+ */
+std::string transcode(const wchar_t *s,
+ const char *encoding=NULL,
+ std::string (*errf)(int error,
+ const std::string &partial,
+ const std::wstring &input)=NULL);
+
#endif // TRANSCODE_H
More information about the Aptitude-svn-commit
mailing list