X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f7e98dee7eb8747ddd0b912600bcad1191818733..3b01b1fe4cb656f39290bf7f3891667855abe601:/src/common/strconv.cpp?ds=sidebyside diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index e0e0def4da..83c06de9c6 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -1,12 +1,14 @@ ///////////////////////////////////////////////////////////////////////////// // Name: strconv.cpp // Purpose: Unicode conversion classes -// Author: Ove Kaaven, Robert Roebling, Vadim Zeitlin, Vaclav Slavik +// Author: Ove Kaaven, Robert Roebling, Vadim Zeitlin, Vaclav Slavik, +// Ryan Norton, Fredrik Roubert (UTF7) // Modified by: // Created: 29/01/98 // RCS-ID: $Id$ // Copyright: (c) 1999 Ove Kaaven, Robert Roebling, Vaclav Slavik // (c) 2000-2003 Vadim Zeitlin +// (c) 2004 Ryan Norton, Fredrik Roubert // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -168,7 +170,7 @@ static size_t decode_utf16(const wxUint16* input, wxUint32& output) wxMBConv::~wxMBConv() { - // nothing to do here + // nothing to do here (necessary for Darwin linking probably) } const wxWCharBuffer wxMBConv::cMB2WC(const char *psz) const @@ -228,34 +230,210 @@ size_t wxMBConvLibc::WC2MB(char *buf, const wchar_t *psz, size_t n) const { return wxWC2MB(buf, psz, n); } - // ---------------------------------------------------------------------------- -// UTF-7 +// UTF-7 // ---------------------------------------------------------------------------- -#if 0 -static char utf7_setD[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789'(),-./:?"; -static char utf7_setO[]="!\"#$%&*;<=>@[]^_`{|}"; -static char utf7_setB[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789+/"; -#endif +// Implementation (C) 2004 Fredrik Roubert + +// +// BASE64 decoding table +// +static const unsigned char utf7unb64[] = +{ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f, + 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, + 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, + 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, + 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, + 0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff +}; -// TODO: write actual implementations of UTF-7 here -size_t wxMBConvUTF7::MB2WC(wchar_t * WXUNUSED(buf), - const char * WXUNUSED(psz), - size_t WXUNUSED(n)) const +size_t wxMBConvUTF7::MB2WC(wchar_t *buf, const char *psz, size_t n) const { - return 0; + + size_t len = 0; + + while (*psz && ((!buf) || (len < n))) + { + unsigned char cc = *psz++; + if (cc != '+') + { + // plain ASCII char + if (buf) + *buf++ = cc; + len++; + } + else if (*psz == '-') + { + // encoded plus sign + if (buf) + *buf++ = cc; + len++; + psz++; + } + else + { + // BASE64 encoded string + bool lsb; + unsigned char c; + unsigned int d, l; + for (lsb = false, d = 0, l = 0; + (cc = utf7unb64[(unsigned char)*psz]) != 0xff; psz++) + { + d <<= 6; + d += cc; + for (l += 6; l >= 8; lsb = !lsb) + { + c = (d >> (l -= 8)) % 256; + if (lsb) + { + if (buf) + *buf++ |= c; + len ++; + } + else + if (buf) + *buf = c << 8; + } + } + if (*psz == '-') + psz++; + } + } + if (buf && (len < n)) + *buf = 0; + return len; } -size_t wxMBConvUTF7::WC2MB(char * WXUNUSED(buf), - const wchar_t * WXUNUSED(psz), - size_t WXUNUSED(n)) const +// +// BASE64 encoding table +// +static const unsigned char utf7enb64[] = { - return 0; + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', + 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', + 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', + '4', '5', '6', '7', '8', '9', '+', '/' +}; + +// +// UTF-7 encoding table +// +// 0 - Set D (directly encoded characters) +// 1 - Set O (optional direct characters) +// 2 - whitespace characters (optional) +// 3 - special characters +// +static const unsigned char utf7encode[128] = +{ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 3, 3, 2, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 3, 0, 0, 0, 3, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 3, 3 +}; + +size_t wxMBConvUTF7::WC2MB(char *buf, const wchar_t +*psz, size_t n) const +{ + + + size_t len = 0; + + while (*psz && ((!buf) || (len < n))) + { + wchar_t cc = *psz++; + if (cc < 0x80 && utf7encode[cc] < 1) + { + // plain ASCII char + if (buf) + *buf++ = (char)cc; + len++; + } +#ifndef WC_UTF16 + else if (cc > 0xffff) + { + // no surrogate pair generation (yet?) + return (size_t)-1; + } +#endif + else + { + if (buf) + *buf++ = '+'; + len++; + if (cc != '+') + { + // BASE64 encode string + unsigned int lsb, d, l; + for (d = 0, l = 0;; psz++) + { + for (lsb = 0; lsb < 2; lsb ++) + { + d <<= 8; + d += lsb ? cc & 0xff : (cc & 0xff00) >> 8; + + for (l += 8; l >= 6; ) + { + l -= 6; + if (buf) + *buf++ = utf7enb64[(d >> l) % 64]; + len++; + } + } + cc = *psz; + if (!(cc) || (cc < 0x80 && utf7encode[cc] < 1)) + break; + } + if (l != 0) + { + if (buf) + *buf++ = utf7enb64[((d % 16) << (6 - l)) % 64]; + len++; + } + } + if (buf) + *buf++ = '-'; + len++; + } + } + if (buf && (len < n)) + *buf = 0; + return len; } // ---------------------------------------------------------------------------- @@ -1292,7 +1470,7 @@ private: #if defined(__WXCOCOA__) -// RN: There is no UTF-32 support in either Core Foundation or +// RN: There is no UTF-32 support in either Core Foundation or // Cocoa. Strangely enough, internally Core Foundation uses // UTF 32 internally quite a bit - its just not public (yet). @@ -1300,139 +1478,139 @@ private: #include CFStringEncoding wxCFStringEncFromFontEnc(wxFontEncoding encoding) -{ - CFStringEncoding enc = 0 ; - if ( encoding == wxFONTENCODING_DEFAULT ) - { +{ + CFStringEncoding enc = 0 ; + if ( encoding == wxFONTENCODING_DEFAULT ) + { #if wxUSE_GUI - encoding = wxFont::GetDefaultEncoding() ; + encoding = wxFont::GetDefaultEncoding() ; #else - encoding = wxLocale::GetSystemEncoding() ; + encoding = wxLocale::GetSystemEncoding() ; #endif - } - else switch( encoding) - { - case wxFONTENCODING_ISO8859_1 : - enc = kCFStringEncodingISOLatin1 ; - break ; - case wxFONTENCODING_ISO8859_2 : - enc = kCFStringEncodingISOLatin2; - break ; - case wxFONTENCODING_ISO8859_3 : - enc = kCFStringEncodingISOLatin3 ; - break ; - case wxFONTENCODING_ISO8859_4 : - enc = kCFStringEncodingISOLatin4; - break ; - case wxFONTENCODING_ISO8859_5 : - enc = kCFStringEncodingISOLatinCyrillic; - break ; - case wxFONTENCODING_ISO8859_6 : - enc = kCFStringEncodingISOLatinArabic; - break ; - case wxFONTENCODING_ISO8859_7 : - enc = kCFStringEncodingISOLatinGreek; - break ; - case wxFONTENCODING_ISO8859_8 : - enc = kCFStringEncodingISOLatinHebrew; - break ; - case wxFONTENCODING_ISO8859_9 : - enc = kCFStringEncodingISOLatin5; - break ; - case wxFONTENCODING_ISO8859_10 : - enc = kCFStringEncodingISOLatin6; - break ; - case wxFONTENCODING_ISO8859_11 : - enc = kCFStringEncodingISOLatinThai; - break ; - case wxFONTENCODING_ISO8859_13 : - enc = kCFStringEncodingISOLatin7; - break ; - case wxFONTENCODING_ISO8859_14 : - enc = kCFStringEncodingISOLatin8; - break ; - case wxFONTENCODING_ISO8859_15 : - enc = kCFStringEncodingISOLatin9; - break ; - - case wxFONTENCODING_KOI8 : - enc = kCFStringEncodingKOI8_R; - break ; - case wxFONTENCODING_ALTERNATIVE : // MS-DOS CP866 - enc = kCFStringEncodingDOSRussian; - break ; - -// case wxFONTENCODING_BULGARIAN : -// enc = ; -// break ; - - case wxFONTENCODING_CP437 : - enc =kCFStringEncodingDOSLatinUS ; - break ; - case wxFONTENCODING_CP850 : - enc = kCFStringEncodingDOSLatin1; - break ; - case wxFONTENCODING_CP852 : - enc = kCFStringEncodingDOSLatin2; - break ; - case wxFONTENCODING_CP855 : - enc = kCFStringEncodingDOSCyrillic; - break ; - case wxFONTENCODING_CP866 : - enc =kCFStringEncodingDOSRussian ; - break ; - case wxFONTENCODING_CP874 : - enc = kCFStringEncodingDOSThai; - break ; - case wxFONTENCODING_CP932 : - enc = kCFStringEncodingDOSJapanese; - break ; - case wxFONTENCODING_CP936 : - enc =kCFStringEncodingDOSChineseSimplif ; - break ; - case wxFONTENCODING_CP949 : - enc = kCFStringEncodingDOSKorean; - break ; - case wxFONTENCODING_CP950 : - enc = kCFStringEncodingDOSChineseTrad; - break ; - - case wxFONTENCODING_CP1250 : - enc = kCFStringEncodingWindowsLatin2; - break ; - case wxFONTENCODING_CP1251 : - enc =kCFStringEncodingWindowsCyrillic ; - break ; - case wxFONTENCODING_CP1252 : - enc =kCFStringEncodingWindowsLatin1 ; - break ; - case wxFONTENCODING_CP1253 : - enc = kCFStringEncodingWindowsGreek; - break ; - case wxFONTENCODING_CP1254 : - enc = kCFStringEncodingWindowsLatin5; - break ; - case wxFONTENCODING_CP1255 : - enc =kCFStringEncodingWindowsHebrew ; - break ; - case wxFONTENCODING_CP1256 : - enc =kCFStringEncodingWindowsArabic ; - break ; - case wxFONTENCODING_CP1257 : - enc = kCFStringEncodingWindowsBalticRim; - break ; - case wxFONTENCODING_UTF7 : - enc = kCFStringEncodingNonLossyASCII ; - break ; - case wxFONTENCODING_UTF8 : - enc = kCFStringEncodingUTF8 ; - break ; - case wxFONTENCODING_EUC_JP : - enc = kCFStringEncodingEUC_JP; - break ; - case wxFONTENCODING_UTF16 : + } + else switch( encoding) + { + case wxFONTENCODING_ISO8859_1 : + enc = kCFStringEncodingISOLatin1 ; + break ; + case wxFONTENCODING_ISO8859_2 : + enc = kCFStringEncodingISOLatin2; + break ; + case wxFONTENCODING_ISO8859_3 : + enc = kCFStringEncodingISOLatin3 ; + break ; + case wxFONTENCODING_ISO8859_4 : + enc = kCFStringEncodingISOLatin4; + break ; + case wxFONTENCODING_ISO8859_5 : + enc = kCFStringEncodingISOLatinCyrillic; + break ; + case wxFONTENCODING_ISO8859_6 : + enc = kCFStringEncodingISOLatinArabic; + break ; + case wxFONTENCODING_ISO8859_7 : + enc = kCFStringEncodingISOLatinGreek; + break ; + case wxFONTENCODING_ISO8859_8 : + enc = kCFStringEncodingISOLatinHebrew; + break ; + case wxFONTENCODING_ISO8859_9 : + enc = kCFStringEncodingISOLatin5; + break ; + case wxFONTENCODING_ISO8859_10 : + enc = kCFStringEncodingISOLatin6; + break ; + case wxFONTENCODING_ISO8859_11 : + enc = kCFStringEncodingISOLatinThai; + break ; + case wxFONTENCODING_ISO8859_13 : + enc = kCFStringEncodingISOLatin7; + break ; + case wxFONTENCODING_ISO8859_14 : + enc = kCFStringEncodingISOLatin8; + break ; + case wxFONTENCODING_ISO8859_15 : + enc = kCFStringEncodingISOLatin9; + break ; + + case wxFONTENCODING_KOI8 : + enc = kCFStringEncodingKOI8_R; + break ; + case wxFONTENCODING_ALTERNATIVE : // MS-DOS CP866 + enc = kCFStringEncodingDOSRussian; + break ; + +// case wxFONTENCODING_BULGARIAN : +// enc = ; +// break ; + + case wxFONTENCODING_CP437 : + enc =kCFStringEncodingDOSLatinUS ; + break ; + case wxFONTENCODING_CP850 : + enc = kCFStringEncodingDOSLatin1; + break ; + case wxFONTENCODING_CP852 : + enc = kCFStringEncodingDOSLatin2; + break ; + case wxFONTENCODING_CP855 : + enc = kCFStringEncodingDOSCyrillic; + break ; + case wxFONTENCODING_CP866 : + enc =kCFStringEncodingDOSRussian ; + break ; + case wxFONTENCODING_CP874 : + enc = kCFStringEncodingDOSThai; + break ; + case wxFONTENCODING_CP932 : + enc = kCFStringEncodingDOSJapanese; + break ; + case wxFONTENCODING_CP936 : + enc =kCFStringEncodingDOSChineseSimplif ; + break ; + case wxFONTENCODING_CP949 : + enc = kCFStringEncodingDOSKorean; + break ; + case wxFONTENCODING_CP950 : + enc = kCFStringEncodingDOSChineseTrad; + break ; + + case wxFONTENCODING_CP1250 : + enc = kCFStringEncodingWindowsLatin2; + break ; + case wxFONTENCODING_CP1251 : + enc =kCFStringEncodingWindowsCyrillic ; + break ; + case wxFONTENCODING_CP1252 : + enc =kCFStringEncodingWindowsLatin1 ; + break ; + case wxFONTENCODING_CP1253 : + enc = kCFStringEncodingWindowsGreek; + break ; + case wxFONTENCODING_CP1254 : + enc = kCFStringEncodingWindowsLatin5; + break ; + case wxFONTENCODING_CP1255 : + enc =kCFStringEncodingWindowsHebrew ; + break ; + case wxFONTENCODING_CP1256 : + enc =kCFStringEncodingWindowsArabic ; + break ; + case wxFONTENCODING_CP1257 : + enc = kCFStringEncodingWindowsBalticRim; + break ; + case wxFONTENCODING_UTF7 : + enc = kCFStringEncodingNonLossyASCII ; + break ; + case wxFONTENCODING_UTF8 : + enc = kCFStringEncodingUTF8 ; + break ; + case wxFONTENCODING_EUC_JP : + enc = kCFStringEncodingEUC_JP; + break ; + case wxFONTENCODING_UTF16 : enc = kCFStringEncodingUnicode ; - break ; + break ; case wxFONTENCODING_MACROMAN : enc = kCFStringEncodingMacRoman ; break ; @@ -1550,128 +1728,128 @@ CFStringEncoding wxCFStringEncFromFontEnc(wxFontEncoding encoding) case wxFONTENCODING_MACGAELIC : enc = kCFStringEncodingMacGaelic ; break ; -// case wxFONTENCODING_MACKEYBOARD : -// enc = kCFStringEncodingMacKeyboardGlyphs ; -// break ; - default : - // because gcc is picky - break ; - } ; - return enc ; +// case wxFONTENCODING_MACKEYBOARD : +// enc = kCFStringEncodingMacKeyboardGlyphs ; +// break ; + default : + // because gcc is picky + break ; + } ; + return enc ; } wxFontEncoding wxFontEncFromCFStringEnc(CFStringEncoding encoding) -{ - wxFontEncoding enc = wxFONTENCODING_DEFAULT ; - - switch( encoding) - { - case kCFStringEncodingISOLatin1 : - enc = wxFONTENCODING_ISO8859_1 ; - break ; - case kCFStringEncodingISOLatin2 : - enc = wxFONTENCODING_ISO8859_2; - break ; - case kCFStringEncodingISOLatin3 : - enc = wxFONTENCODING_ISO8859_3 ; - break ; - case kCFStringEncodingISOLatin4 : - enc = wxFONTENCODING_ISO8859_4; - break ; - case kCFStringEncodingISOLatinCyrillic : - enc = wxFONTENCODING_ISO8859_5; - break ; - case kCFStringEncodingISOLatinArabic : - enc = wxFONTENCODING_ISO8859_6; - break ; - case kCFStringEncodingISOLatinGreek : - enc = wxFONTENCODING_ISO8859_7; - break ; - case kCFStringEncodingISOLatinHebrew : - enc = wxFONTENCODING_ISO8859_8; - break ; - case kCFStringEncodingISOLatin5 : - enc = wxFONTENCODING_ISO8859_9; - break ; - case kCFStringEncodingISOLatin6 : - enc = wxFONTENCODING_ISO8859_10; - break ; - case kCFStringEncodingISOLatin7 : - enc = wxFONTENCODING_ISO8859_13; - break ; - case kCFStringEncodingISOLatin8 : - enc = wxFONTENCODING_ISO8859_14; - break ; - case kCFStringEncodingISOLatin9 : - enc =wxFONTENCODING_ISO8859_15 ; - break ; - - case kCFStringEncodingKOI8_R : - enc = wxFONTENCODING_KOI8; - break ; - -// case : -// enc = wxFONTENCODING_BULGARIAN; -// break ; - - case kCFStringEncodingDOSLatinUS : - enc = wxFONTENCODING_CP437; - break ; - case kCFStringEncodingDOSLatin1 : - enc = wxFONTENCODING_CP850; - break ; - case kCFStringEncodingDOSLatin2 : - enc =wxFONTENCODING_CP852 ; - break ; - case kCFStringEncodingDOSCyrillic : - enc = wxFONTENCODING_CP855; - break ; - case kCFStringEncodingDOSRussian : - enc = wxFONTENCODING_CP866; - break ; - case kCFStringEncodingDOSThai : - enc =wxFONTENCODING_CP874 ; - break ; - case kCFStringEncodingDOSJapanese : - enc = wxFONTENCODING_CP932; - break ; - case kCFStringEncodingDOSChineseSimplif : - enc = wxFONTENCODING_CP936; - break ; - case kCFStringEncodingDOSKorean : - enc = wxFONTENCODING_CP949; - break ; - case kCFStringEncodingDOSChineseTrad : - enc = wxFONTENCODING_CP950; - break ; - - case kCFStringEncodingWindowsLatin2 : - enc = wxFONTENCODING_CP1250; - break ; - case kCFStringEncodingWindowsCyrillic : - enc = wxFONTENCODING_CP1251; - break ; - case kCFStringEncodingWindowsLatin1 : - enc = wxFONTENCODING_CP1252; - break ; - case kCFStringEncodingWindowsGreek : - enc = wxFONTENCODING_CP1253; - break ; - case kCFStringEncodingWindowsLatin5 : - enc = wxFONTENCODING_CP1254; - break ; - case kCFStringEncodingWindowsHebrew : - enc = wxFONTENCODING_CP1255; - break ; - case kCFStringEncodingWindowsArabic : - enc = wxFONTENCODING_CP1256; - break ; - case kCFStringEncodingWindowsBalticRim : - enc =wxFONTENCODING_CP1257 ; - break ; - case kCFStringEncodingEUC_JP : - enc = wxFONTENCODING_EUC_JP; - break ; +{ + wxFontEncoding enc = wxFONTENCODING_DEFAULT ; + + switch( encoding) + { + case kCFStringEncodingISOLatin1 : + enc = wxFONTENCODING_ISO8859_1 ; + break ; + case kCFStringEncodingISOLatin2 : + enc = wxFONTENCODING_ISO8859_2; + break ; + case kCFStringEncodingISOLatin3 : + enc = wxFONTENCODING_ISO8859_3 ; + break ; + case kCFStringEncodingISOLatin4 : + enc = wxFONTENCODING_ISO8859_4; + break ; + case kCFStringEncodingISOLatinCyrillic : + enc = wxFONTENCODING_ISO8859_5; + break ; + case kCFStringEncodingISOLatinArabic : + enc = wxFONTENCODING_ISO8859_6; + break ; + case kCFStringEncodingISOLatinGreek : + enc = wxFONTENCODING_ISO8859_7; + break ; + case kCFStringEncodingISOLatinHebrew : + enc = wxFONTENCODING_ISO8859_8; + break ; + case kCFStringEncodingISOLatin5 : + enc = wxFONTENCODING_ISO8859_9; + break ; + case kCFStringEncodingISOLatin6 : + enc = wxFONTENCODING_ISO8859_10; + break ; + case kCFStringEncodingISOLatin7 : + enc = wxFONTENCODING_ISO8859_13; + break ; + case kCFStringEncodingISOLatin8 : + enc = wxFONTENCODING_ISO8859_14; + break ; + case kCFStringEncodingISOLatin9 : + enc =wxFONTENCODING_ISO8859_15 ; + break ; + + case kCFStringEncodingKOI8_R : + enc = wxFONTENCODING_KOI8; + break ; + +// case : +// enc = wxFONTENCODING_BULGARIAN; +// break ; + + case kCFStringEncodingDOSLatinUS : + enc = wxFONTENCODING_CP437; + break ; + case kCFStringEncodingDOSLatin1 : + enc = wxFONTENCODING_CP850; + break ; + case kCFStringEncodingDOSLatin2 : + enc =wxFONTENCODING_CP852 ; + break ; + case kCFStringEncodingDOSCyrillic : + enc = wxFONTENCODING_CP855; + break ; + case kCFStringEncodingDOSRussian : + enc = wxFONTENCODING_CP866; + break ; + case kCFStringEncodingDOSThai : + enc =wxFONTENCODING_CP874 ; + break ; + case kCFStringEncodingDOSJapanese : + enc = wxFONTENCODING_CP932; + break ; + case kCFStringEncodingDOSChineseSimplif : + enc = wxFONTENCODING_CP936; + break ; + case kCFStringEncodingDOSKorean : + enc = wxFONTENCODING_CP949; + break ; + case kCFStringEncodingDOSChineseTrad : + enc = wxFONTENCODING_CP950; + break ; + + case kCFStringEncodingWindowsLatin2 : + enc = wxFONTENCODING_CP1250; + break ; + case kCFStringEncodingWindowsCyrillic : + enc = wxFONTENCODING_CP1251; + break ; + case kCFStringEncodingWindowsLatin1 : + enc = wxFONTENCODING_CP1252; + break ; + case kCFStringEncodingWindowsGreek : + enc = wxFONTENCODING_CP1253; + break ; + case kCFStringEncodingWindowsLatin5 : + enc = wxFONTENCODING_CP1254; + break ; + case kCFStringEncodingWindowsHebrew : + enc = wxFONTENCODING_CP1255; + break ; + case kCFStringEncodingWindowsArabic : + enc = wxFONTENCODING_CP1256; + break ; + case kCFStringEncodingWindowsBalticRim : + enc =wxFONTENCODING_CP1257 ; + break ; + case kCFStringEncodingEUC_JP : + enc = wxFONTENCODING_EUC_JP; + break ; case kCFStringEncodingUnicode : enc = wxFONTENCODING_UTF16; break; @@ -1794,9 +1972,9 @@ wxFontEncoding wxFontEncFromCFStringEnc(CFStringEncoding encoding) break ; // case kCFStringEncodingMacKeyboardGlyphs : // enc = wxFONTENCODING_MACKEYBOARD ; -// break ; - } ; - return enc ; +// break ; + } ; + return enc ; } class wxMBConv_cocoa : public wxMBConv @@ -1830,13 +2008,13 @@ public: size_t MB2WC(wchar_t * szOut, const char * szUnConv, size_t nOutSize) const { wxASSERT(szUnConv); - + size_t nBufSize = strlen(szUnConv) + 1; size_t nRealOutSize; - UniChar* szUniCharBuffer = (UniChar*) szOut; - wchar_t* szConvBuffer = szOut; - + UniChar* szUniCharBuffer = (UniChar*) szOut; + wchar_t* szConvBuffer = szOut; + if (szConvBuffer == NULL && nOutSize != 0) { szConvBuffer = new wchar_t[nOutSize] ; @@ -1847,18 +2025,18 @@ public: #endif CFDataRef theData = CFDataCreateWithBytesNoCopy ( - NULL, //allocator - (const UInt8*)szUnConv, + NULL, //allocator + (const UInt8*)szUnConv, nBufSize - 1, - NULL //deallocator - ); + NULL //deallocator + ); wxASSERT(theData); CFStringRef theString = CFStringCreateFromExternalRepresentation ( NULL, theData, - m_char_encoding + m_char_encoding ); wxASSERT(theString); @@ -1869,16 +2047,16 @@ public: CFRelease(theString); return nRealOutSize - 1; } - + CFRange theRange = { 0, CFStringGetLength(theString) }; - + CFStringGetCharacters(theString, theRange, szUniCharBuffer); - - + + nRealOutSize = (CFStringGetLength(theString) + 1); - + CFRelease(theString); - + szUniCharBuffer[nRealOutSize-1] = '\0' ; #if SIZEOF_WCHAR_T == 4 @@ -1898,11 +2076,11 @@ public: size_t nRealOutSize; char* szBuffer = szOut; UniChar* szUniBuffer = (UniChar*) szUnConv; - + if (szOut == NULL) { // worst case - nRealOutSize = ((nBufSize - 1) << 1)+1 ; + nRealOutSize = wxString::WorstEncodingCase(nBufSize - 1, *this)+1 ; szBuffer = new char[ nRealOutSize ] ; } else @@ -1923,9 +2101,9 @@ public: nBufSize, NULL //deallocator ); - + wxASSERT(theString); - + //Note that CER puts a BOM when converting to unicode //so we may want to check and use getchars instead in that case CFDataRef theData = CFStringCreateExternalRepresentation( @@ -1938,9 +2116,9 @@ public: if(!theData) return (size_t)-1; - + CFRelease(theString); - + nRealOutSize = CFDataGetLength(theData); if ( szOut == NULL ) @@ -1955,12 +2133,12 @@ public: CFRelease(theData); return nRealOutSize - 1; } - + CFRange theRange = {0, CFDataGetLength(theData) }; CFDataGetBytes(theData, theRange, (UInt8*) szBuffer); - - CFRelease(theData); - + + CFRelease(theData); + //TODO: This gets flagged as a non-malloced address by the debugger... //#if SIZEOF_WCHAR_T == 4 // delete[] szUniBuffer; @@ -1969,9 +2147,9 @@ public: } bool IsOk() const - { + { //TODO: check for invalid en/de/coding - return true; + return true; } private: @@ -2079,7 +2257,7 @@ public: if (buf == NULL) { // worst case - n = byteInLen * 2 ; + n = wxString::WorstEncodingCase(byteInLen / SIZEOF_WCHAR_T, *this) + SIZEOF_WCHAR_T; tbuf = (char*) malloc( n ) ; }