X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cdb14ecbe7fdf65f6c2dfd4b98526feb7813ddf9..1d7ea62e9e91bf5717feafb361e89ac8c7d32913:/src/common/strconv.cpp diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index 4741650e15..45af589a8b 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -270,9 +270,9 @@ const wxWCharBuffer wxMBConv::cMB2WC(const char *szString, size_t nStringLen, si } //Increment to next (sub)string - //Note that we have to use strlen here instead of nLen - //here because XX2XX gives us the size of the output buffer, - //not neccessarly the length of the string + //Note that we have to use strlen instead of nLen here + //because XX2XX gives us the size of the output buffer, + //which is not necessarily the length of the string szPos += strlen(szPos) + 1; } @@ -332,9 +332,9 @@ const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *szString, size_t nStringLen, } //Increment to next (sub)string - //Note that we have to use wxWcslen here instead of nLen - //here because XX2XX gives us the size of the output buffer, - //not neccessarly the length of the string + //Note that we have to use wxWcslen instead of nLen here + //because XX2XX gives us the size of the output buffer, + //which is not necessarily the length of the string szPos += wxWcslen(szPos) + 1; } @@ -363,34 +363,13 @@ size_t wxMBConvLibc::WC2MB(char *buf, const wchar_t *psz, size_t n) const // wxConvBrokenFileNames // ---------------------------------------------------------------------------- -wxConvBrokenFileNames::wxConvBrokenFileNames() +wxConvBrokenFileNames::wxConvBrokenFileNames(const wxChar *charset) { - // 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 ) - { - 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; - } - } + if ( !charset || wxStricmp(charset, _T("UTF-8")) == 0 + || wxStricmp(charset, _T("UTF8")) == 0 ) + m_conv = new wxMBConvUTF8(wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL); + else + m_conv = new wxCSConv(charset); } size_t @@ -645,6 +624,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 { @@ -782,6 +770,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]) )