[Aptitude-svn-commit] r3466 - in branches/aptitude-0.3/aptitude: . src/vscreen
Daniel Burrows
dburrows@costa.debian.org
Sun, 26 Jun 2005 17:31:33 +0000
Author: dburrows
Date: Sun Jun 26 17:31:29 2005
New Revision: 3466
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/vscreen/transcode.h
Log:
Add an interface (not yet implemented) for transcoding strings without reporting
errors to the caller (errors can be handled indirectly, though).
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Sun Jun 26 17:31:29 2005
@@ -1,5 +1,10 @@
2005-06-26 Daniel Burrows <dburrows@debian.org>
+ * src/vscreen/transcode.h:
+
+ Add a kinder, gentler transcoding interface for when error
+ detection isn't important.
+
* src/vscreen/vs_editline.cc, src/vscreen/vs_editline.h:
Convert the public interface of the line-editor to wide
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 Jun 26 17:31:29 2005
@@ -44,6 +44,33 @@
return transcode(s.c_str(), out, encoding);
}
+/** The error handler for converting multibyte strings to wide
+ * strings: it is passed a partially-decoded string and the error
+ * code, and its return value becomes the return value of the
+ * function. The default handler just returns "partial".
+ */
+extern std::wstring (*transcode_mbtow_err)(int error,
+ const std::wstring &partial,
+ const std::string &input);
+
+/** 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 std::string &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
@@ -69,4 +96,32 @@
return transcode(s.c_str(), out, encoding);
}
+
+/** The error handler for converting multibyte strings to wide
+ * strings: it is passed a partially-decoded string and the error
+ * code, and its return value becomes the return value of the
+ * function. The default handler just returns "partial".
+ */
+extern std::wstring (*transcode_wtomb_err)(int error,
+ const std::wstring &partial,
+ const std::string &input);
+
+/** 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 std::wstring &s,
+ const char *encoding=NULL,
+ std::string (*errf)(int error,
+ const std::wstring &partial,
+ const std::string &input)=NULL);
+
#endif // TRANSCODE_H