Update of /cvsroot/mahogany/M/src/util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31646/src/util
Modified Files:
strutil.cpp
Log Message:
use wxConvUTF7 for recent wx; unfortunately had to duplicate code a bit
Index: strutil.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/util/strutil.cpp,v
retrieving revision 1.138
retrieving revision 1.139
diff -b -u -2 -r1.138 -r1.139
--- strutil.cpp 16 Dec 2004 18:29:34 -0000 1.138
+++ strutil.cpp 22 Mar 2005 01:42:08 -0000 1.139
@@ -42,6 +42,5 @@
extern "C"
{
- #include "utf8.h" // for utf8_text_utf7()
-
+ #include "utf8.h" // for utf8_text_utf7() and arrays below
// arrays used by GuessUnicodeCharset()
#include "charset/iso_8859.c"
@@ -1478,6 +1477,5 @@
//
// FIXME this won't be needed when full Unicode support is available
-wxFontEncoding
-ConvertUTFToMB(wxString *strUtf, wxFontEncoding enc)
+wxFontEncoding ConvertUTFToMB(wxString *strUtf, wxFontEncoding enc)
{
CHECK( strUtf, wxFONTENCODING_SYSTEM, _T("NULL string in ConvertUTFToMB") );
@@ -1485,7 +1483,7 @@
if ( !strUtf->empty() )
{
- // first convert to UTF-8
if ( enc == wxFONTENCODING_UTF7 )
{
+#if !wxCHECK_VERSION(2, 5, 4)
// wxWindows does not support UTF-7 yet, so we first convert
// UTF-7 to UTF-8 using c-client function and then convert
@@ -1503,10 +1501,65 @@
*strUtf << wxChar(text8.data[k]);
}
+
+ return ConvertUTF8ToMB(strUtf);
+#else // wx >= 2.5.4
+
+ // try to determine which multibyte encoding is best suited for this
+ // Unicode string
+ wxWCharBuffer wbuf(strUtf->wc_str(wxConvUTF7));
+ if ( !wbuf )
+ {
+ // invalid UTF-7 data, leave it as is
+ enc = wxFONTENCODING_SYSTEM;
+ }
+ else // try to find a multibyte encoding we can show this in
+ {
+ enc = GuessUnicodeCharset(wbuf);
+
+ // finally convert to multibyte
+ wxString str;
+ if ( enc == wxFONTENCODING_SYSTEM )
+ {
+ str = wxString(wbuf);
+ }
+ else
+ {
+ wxCSConv conv(enc);
+ str = wxString(wbuf, conv);
+ }
+ if ( str.empty() )
+ {
+ // conversion failed - use original text (and display
incorrectly,
+ // unfortunately)
+ wxLogDebug(_T("conversion from UTF-7 to default encoding
failed"));
+ }
+ else
+ {
+ *strUtf = str;
+ }
+ }
+#endif // 2.5.4
}
else
{
ASSERT_MSG( enc == wxFONTENCODING_UTF8, _T("unknown Unicode
encoding") );
+ return ConvertUTF8ToMB(strUtf);
+ }
+ }
+ else // doesn't really matter what we return from here
+ {
+ enc = wxFONTENCODING_SYSTEM;
}
+ return enc;
+}
+
+wxFontEncoding ConvertUTF8ToMB(wxString *strUtf)
+{
+ wxFontEncoding enc;
+ CHECK( strUtf, wxFONTENCODING_SYSTEM, _T("NULL string in ConvertUTF8ToMB")
);
+
+ if ( !strUtf->empty() )
+ {
// try to determine which multibyte encoding is best suited for this
// Unicode string
@@ -1566,3 +1619,2 @@
return 0;
}
-
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates