From: Vadim Zeitlin Date: Thu, 22 Sep 2005 12:36:17 +0000 (+0000) Subject: try all known UCS-[24] synonyms in wxMBConv_iconv, this should fix this class on... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/74a7eb0bf6ccefe6f377f70ccab1613056107ec4 try all known UCS-[24] synonyms in wxMBConv_iconv, this should fix this class on IRIX (where UCS-4 is supported but neither UCS-4[LB]E nor UCS4, which were the only ones we tested, are not) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35644 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index ed4d3d889e..bb08007cf4 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -57,10 +57,6 @@ #define wxHAVE_WIN32_MB2WC #endif // __WIN32__ but !__WXMICROWIN__ -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - #ifdef __SALFORDC__ #include #endif @@ -86,35 +82,6 @@ #define TRACE_STRCONV _T("strconv") -// ---------------------------------------------------------------------------- -// macros -// ---------------------------------------------------------------------------- - -#define BSWAP_UCS4(str, len) { unsigned _c; for (_c=0; _c", ms_wcNeedsSwap); + wxT("iconv wchar_t charset is \"%s\"%s"), + ms_wcCharsetName.empty() ? "" + : ms_wcCharsetName.c_str(), + ms_wcNeedsSwap ? _T(" (needs swap)") + : _T("")); } else // we already have ms_wcCharsetName { - m2w = iconv_open(ms_wcCharsetName, cname); + m2w = iconv_open(ms_wcCharsetName.ToAscii(), cname); } - // NB: don't ever pass NULL to iconv_open(), it may crash! - if ( ms_wcCharsetName ) + if ( ms_wcCharsetName.empty() ) { - w2m = iconv_open( cname, ms_wcCharsetName); + w2m = ICONV_T_INVALID; } else { - w2m = (iconv_t)-1; + w2m = iconv_open(cname, ms_wcCharsetName.ToAscii()); + if ( w2m == ICONV_T_INVALID ) + { + wxLogTrace(TRACE_STRCONV, + wxT("\"%s\" -> \"%s\" works but not the converse!?"), + ms_wcCharsetName.c_str(), cname); + } } } wxMBConv_iconv::~wxMBConv_iconv() { - if ( m2w != (iconv_t)-1 ) + if ( m2w != ICONV_T_INVALID ) iconv_close(m2w); - if ( w2m != (iconv_t)-1 ) + if ( w2m != ICONV_T_INVALID ) iconv_close(w2m); } @@ -1489,7 +1488,8 @@ size_t wxMBConv_iconv::MB2WC(wchar_t *buf, const char *psz, size_t n) const if (ms_wcNeedsSwap) { // convert to native endianness - WC_BSWAP(buf /* _not_ bufPtr */, res) + for ( unsigned n = 0; n < res; n++ ) + buf[n] = WC_BSWAP(buf[n]); } // NB: iconv was given only strlen(psz) characters on input, and so @@ -1542,13 +1542,13 @@ size_t wxMBConv_iconv::WC2MB(char *buf, const wchar_t *psz, size_t n) const if (ms_wcNeedsSwap) { // need to copy to temp buffer to switch endianness - // this absolutely doesn't rock! - // (no, doing WC_BSWAP twice on the original buffer won't help, as it + // (doing WC_BSWAP twice on the original buffer won't help, as it // could be in read-only memory, or be accessed in some other thread) - tmpbuf=(wchar_t*)malloc((inbuf+1)*SIZEOF_WCHAR_T); - memcpy(tmpbuf,psz,(inbuf+1)*SIZEOF_WCHAR_T); - WC_BSWAP(tmpbuf, inbuf) - psz=tmpbuf; + tmpbuf = (wchar_t *)malloc(inbuf + SIZEOF_WCHAR_T); + for ( size_t n = 0; n < inbuf; n++ ) + tmpbuf[n] = WC_BSWAP(psz[n]); + tmpbuf[inbuf] = L'\0'; + psz = tmpbuf; } if (buf)