]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/strconv.cpp
Fix for using std streams when std:: conflicts with ::
[wxWidgets.git] / src / common / strconv.cpp
index 4741650e156b640c5b4712b60576c49b351f0991..9df03b339f385a1892154d6ef082932e9ab7b7f3 100644 (file)
@@ -369,26 +369,28 @@ wxConvBrokenFileNames::wxConvBrokenFileNames()
 
     // (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);
         }
     }
 }
@@ -645,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
         {
@@ -782,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]) )