X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b2c13097deb7736a86a278c02d0b3f7cd9873750..3d70763cd84bc4d8f3060a8188b1d5dd37cbe37b:/src/common/strconv.cpp?ds=inline diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index e502652057..9df03b339f 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -55,9 +55,6 @@ #include #include #include -#ifdef HAVE_LANGINFO_H - #include -#endif #if defined(__WIN32__) && !defined(__WXMICROWIN__) #define wxHAVE_WIN32_MB2WC @@ -155,7 +152,7 @@ static size_t decode_utf16(const wxUint16* input, wxUint32& output) output = *input; return 1; } - else if ((input[1]<0xdc00) || (input[1]>=0xdfff)) + else if ((input[1]<0xdc00) || (input[1]>0xdfff)) { output = *input; return (size_t)-1; @@ -360,55 +357,40 @@ size_t wxMBConvLibc::WC2MB(char *buf, const wchar_t *psz, size_t n) const return wxWC2MB(buf, psz, n); } -#ifdef __WXGTK20__ +#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 wxMBConv -{ -public: - wxConvBrokenFileNames(); - virtual ~wxConvBrokenFileNames() { delete m_conv; } - - 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; - -private: - // the conversion object we forward to - wxMBConv *m_conv; -}; - wxConvBrokenFileNames::wxConvBrokenFileNames() { // decide which conversion to use for the file names // (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 ) + wxString encName(wxGetenv(_T("G_FILENAME_ENCODING"))); + encName.MakeUpper(); + if ( !encName.empty() && encName != _T("UTF-8") && encName != _T("UTF8") ) { m_conv = new wxCSConv(encName); } else // no G_FILENAME_ENCODING { + if ( encName.empty() ) + encName = wxLocale::GetSystemEncodingName().Upper(); + // (2) if a non default locale is set, assume that the user wants his // filenames in this locale too - switch ( wxLocale::GetSystemEncoding() ) + if ( !encName.empty() && encName != _T("UTF-8") && encName != _T("UTF8") ) + { + wxSetEnv(_T("G_FILENAME_ENCODING"), encName); + m_conv = new wxMBConvLibc; + } + else { - 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; + m_conv = new wxMBConvUTF8(wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL); } } } @@ -429,7 +411,7 @@ wxConvBrokenFileNames::WC2MB(char *outputBuf, return m_conv->WC2MB( outputBuf, psz, outputSize ); } -#endif // __WXGTK20__ +#endif // ---------------------------------------------------------------------------- // UTF-7 @@ -665,6 +647,15 @@ size_t wxMBConvUTF8::MB2WC(wchar_t *buf, const char *psz, size_t n) const if (buf) *buf++ = cc; len++; + + // escape the escape character for octal escapes + if ((m_options & MAP_INVALID_UTF8_TO_OCTAL) + && cc == '\\' && (!buf || len < n)) + { + if (buf) + *buf++ = cc; + len++; + } } else { @@ -802,6 +793,14 @@ size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const *buf++ = (char)(cc - wxUnicodePUA); len++; } + else if ( (m_options & MAP_INVALID_UTF8_TO_OCTAL) + && cc == L'\\' && psz[0] == L'\\' ) + { + if (buf) + *buf++ = (char)cc; + psz++; + len++; + } else if ( (m_options & MAP_INVALID_UTF8_TO_OCTAL) && cc == L'\\' && isoctal(psz[0]) && isoctal(psz[1]) && isoctal(psz[2]) ) @@ -2764,10 +2763,6 @@ static wxCSConv wxConvISO8859_1Obj(wxFONTENCODING_ISO8859_1); static wxMBConvUTF7 wxConvUTF7Obj; static wxMBConvUTF8 wxConvUTF8Obj; -#ifdef __WXGTK20__ - static wxConvBrokenFileNames wxConvBrokenFileNamesObj; -#endif - WXDLLIMPEXP_DATA_BASE(wxMBConv&) wxConvLibc = wxConvLibcObj; WXDLLIMPEXP_DATA_BASE(wxCSConv&) wxConvLocal = wxConvLocalObj; WXDLLIMPEXP_DATA_BASE(wxCSConv&) wxConvISO8859_1 = wxConvISO8859_1Obj; @@ -2777,8 +2772,6 @@ WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvCurrent = &wxConvLibcObj; WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvFileName = & #ifdef __WXOSX__ wxConvUTF8Obj; -#elif __WXGTK20__ - wxConvBrokenFileNamesObj; #else wxConvLibcObj; #endif