Update of /cvsroot/mahogany/M/src/util
In directory usw-pr-cvs1:/tmp/cvs-serv15681/src/util
Modified Files:
strutil.cpp
Log Message:
repackaged Nerijus' changes in a cleaner way
Index: strutil.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/util/strutil.cpp,v
retrieving revision 1.101
retrieving revision 1.102
diff -b -u -2 -r1.101 -r1.102
--- strutil.cpp 15 Apr 2002 22:49:03 -0000 1.101
+++ strutil.cpp 16 Apr 2002 19:15:34 -0000 1.102
@@ -38,6 +38,13 @@
#include <wx/textfile.h> // just for strutil_enforceNativeCRLF()
+#include <wx/fontenc.h>
#include <wx/regex.h>
+#include "Mcclient.h"
+extern "C"
+{
+ #include "utf8.h" // for utf8_text_utf7()
+}
+
// ----------------------------------------------------------------------------
// options we use here
@@ -1418,2 +1425,62 @@
return TRUE;
}
+
+// convert a string in UTF-8 or 7 into the string in the current encoding: of
+// course, this doesn't work in general as Unicode is not representable as an 8
+// bit charset but it works in some common cases and is better than no UTF-8
+// support at all
+//
+// FIXME this won't be needed when full Unicode support is available
+wxFontEncoding
+ConvertUnicodeToSystem(wxString *strUtf, wxFontEncoding enc)
+{
+ CHECK( strUtf, wxFONTENCODING_SYSTEM,
+ "NULL string in ConvertUnicodeToSystem" );
+
+ if ( !strUtf->empty() )
+ {
+ if ( enc == wxFONTENCODING_UTF7 )
+ {
+ // wxWindows does not support UTF-7 yet, so we first convert
+ // UTF-7 to UTF-8 using c-client function and then convert
+ // UTF-8 to current environment's encoding.
+ SIZEDTEXT text7, text8;
+ text7.data = (unsigned char *) strUtf->c_str();
+ text7.size = strUtf->Length();
+
+ // cclient doesn't use the table parameter in utf8_text_utf7
+ // function but still has it (for future extensions? or just
+ // because other conversion functions have it?)
+ utf8_text_utf7 ( &text7, &text8, NULL /* table */ );
+
+ strUtf->clear();
+ for ( unsigned long k = 0; k < text8.size; k++ )
+ {
+ *strUtf << wxChar(text8.data[k]);
+ }
+ }
+ else
+ {
+ ASSERT_MSG( enc == wxFONTENCODING_UTF8, "unknown Unicode enocding" );
+ }
+
+ wxString str(strUtf->wc_str(wxConvUTF8), wxConvLocal);
+ if ( str.empty() )
+ {
+ // conversion failed - use original text (and display incorrectly,
+ // unfortunately)
+ wxLogDebug("conversion from UTF-8 to default encoding failed");
+ }
+ else
+ {
+ *strUtf = str;
+ }
+ }
+
+#if wxUSE_INTL
+ return wxLocale::GetSystemEncoding();
+#else // !wxUSE_INTL
+ return wxFONTENCODING_ISO8859_1;
+#endif // wxUSE_INTL/!wxUSE_INTL
+}
+
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates