X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3698ae71952311f7f0dc4594e0f666e07cc0a103..4b524c27cceda99907dec63f9224270ed5dd617d:/src/common/strconv.cpp?ds=sidebyside diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index db0147d6bc..a43f43550f 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -360,50 +360,60 @@ size_t wxMBConvLibc::WC2MB(char *buf, const wchar_t *psz, size_t n) const return wxWC2MB(buf, psz, n); } +#ifdef __UNIX__ + // ---------------------------------------------------------------------------- -// wxConvBrokenFileNames is made for GTK2 in Unicode mode when -// files are accidentally written in an encoding which is not -// the system encoding. Typically, the system encoding will be -// UTF8 but there might be files stored in ISO8859-1 on disk. +// wxConvBrokenFileNames // ---------------------------------------------------------------------------- -class wxConvBrokenFileNames: public wxMBConvLibc +wxConvBrokenFileNames::wxConvBrokenFileNames() { -public: - wxConvBrokenFileNames() : m_utf8conv(wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL) { } - virtual size_t MB2WC(wchar_t *outputBuf, const char *psz, size_t outputSize) const; - virtual size_t WC2MB(char *outputBuf, const wchar_t *psz, size_t outputSize) const; - inline bool UseUTF8() const; -private: - wxMBConvUTF8 m_utf8conv; -}; + // decide which conversion to use for the file names -bool wxConvBrokenFileNames::UseUTF8() const -{ -#if defined HAVE_LANGINFO_H && defined CODESET - char *codeset = nl_langinfo(CODESET); - return strcmp(codeset, "UTF-8") == 0; -#else - return false; -#endif + // (1) this variable exists for the sole purpose of specifying the encoding + // of the filenames for GTK+ programs, so use it if it is set + const wxChar *encName = wxGetenv(_T("G_FILENAME_ENCODING")); + if ( encName ) + { + m_conv = new wxCSConv(encName); + } + else // no G_FILENAME_ENCODING + { + // (2) if a non default locale is set, assume that the user wants his + // filenames in this locale too + switch ( wxLocale::GetSystemEncoding() ) + { + default: + m_conv = new wxMBConvLibc; + break; + + // (3) finally use UTF-8 by default + case wxFONTENCODING_SYSTEM: + case wxFONTENCODING_UTF8: + m_conv = new wxMBConvUTF8(wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL); + break; + } + } } -size_t wxConvBrokenFileNames::MB2WC(wchar_t *outputBuf, const char *psz, size_t outputSize) const +size_t +wxConvBrokenFileNames::MB2WC(wchar_t *outputBuf, + const char *psz, + size_t outputSize) const { - if (UseUTF8()) - return m_utf8conv.MB2WC( outputBuf, psz, outputSize ); - else - return wxMBConvLibc::MB2WC( outputBuf, psz, outputSize ); + return m_conv->MB2WC( outputBuf, psz, outputSize ); } -size_t wxConvBrokenFileNames::WC2MB(char *outputBuf, const wchar_t *psz, size_t outputSize) const +size_t +wxConvBrokenFileNames::WC2MB(char *outputBuf, + const wchar_t *psz, + size_t outputSize) const { - if (UseUTF8()) - return m_utf8conv.WC2MB( outputBuf, psz, outputSize ); - else - return wxMBConvLibc::WC2MB( outputBuf, psz, outputSize ); + return m_conv->WC2MB( outputBuf, psz, outputSize ); } +#endif + // ---------------------------------------------------------------------------- // UTF-7 // ---------------------------------------------------------------------------- @@ -558,7 +568,7 @@ size_t wxMBConvUTF7::WC2MB(char *buf, const wchar_t *psz, size_t n) const } #ifndef WC_UTF16 else if (((wxUint32)cc) > 0xffff) - { + { // no surrogate pair generation (yet?) return (size_t)-1; } @@ -728,9 +738,9 @@ size_t wxMBConvUTF8::MB2WC(wchar_t *buf, const char *psz, size_t n) const { unsigned char n = *opsz; *buf++ = L'\\'; - *buf++ = L'0' + n / 0100; - *buf++ = L'0' + (n % 0100) / 010; - *buf++ = L'0' + n % 010; + *buf++ = (wchar_t)( L'0' + n / 0100 ); + *buf++ = (wchar_t)( L'0' + (n % 0100) / 010 ); + *buf++ = (wchar_t)( L'0' + n % 010 ); } opsz++; len += 4; @@ -781,9 +791,9 @@ size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const { if (buf) { - *buf++ = (char) (psz[0] - L'0')*0100 + - (psz[1] - L'0')*010 + - (psz[2] - L'0'); + *buf++ = (char) ((psz[0] - L'0')*0100 + + (psz[1] - L'0')*010 + + (psz[2] - L'0')); } psz += 3; @@ -2736,7 +2746,6 @@ static wxCSConv wxConvLocalObj(wxFONTENCODING_SYSTEM); static wxCSConv wxConvISO8859_1Obj(wxFONTENCODING_ISO8859_1); static wxMBConvUTF7 wxConvUTF7Obj; static wxMBConvUTF8 wxConvUTF8Obj; -static wxConvBrokenFileNames wxConvBrokenFileNamesObj; WXDLLIMPEXP_DATA_BASE(wxMBConv&) wxConvLibc = wxConvLibcObj; WXDLLIMPEXP_DATA_BASE(wxCSConv&) wxConvLocal = wxConvLocalObj; @@ -2747,8 +2756,6 @@ WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvCurrent = &wxConvLibcObj; WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvFileName = & #ifdef __WXOSX__ wxConvUTF8Obj; -#elif __WXGTK20__ - wxConvBrokenFileNamesObj; #else wxConvLibcObj; #endif