]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/strconv.cpp
Fix for decoding of utf-16 surrogates. Also remove #include that's not needed
[wxWidgets.git] / src / common / strconv.cpp
index e40f0f39f70b9ccadc36cebad1fe543b804f2114..4741650e156b640c5b4712b60576c49b351f0991 100644 (file)
@@ -55,9 +55,6 @@
 #include <ctype.h>
 #include <string.h>
 #include <stdlib.h>
-#ifdef HAVE_LANGINFO_H
-  #include <langinfo.h>
-#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,29 +357,12 @@ 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
@@ -429,7 +409,7 @@ wxConvBrokenFileNames::WC2MB(char *outputBuf,
     return m_conv->WC2MB( outputBuf, psz, outputSize );
 }
 
-#endif // __WXGTK20__
+#endif
 
 // ----------------------------------------------------------------------------
 // UTF-7
@@ -585,7 +565,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;
         }
@@ -755,9 +735,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;
@@ -808,9 +788,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;
@@ -2764,10 +2744,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 +2753,6 @@ WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvCurrent = &wxConvLibcObj;
 WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvFileName = &
 #ifdef __WXOSX__
                                     wxConvUTF8Obj;
-#elif __WXGTK20__
-                                    wxConvBrokenFileNamesObj;
 #else
                                     wxConvLibcObj;
 #endif