]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/strconv.cpp
\
[wxWidgets.git] / src / common / strconv.cpp
index bcb1a76a3aa2967cc201792014e9ceac9d38af6d..f13005cb373963954ffb3d47d16244583246b2fd 100644 (file)
@@ -111,7 +111,8 @@ static size_t encode_utf16(wxUint32 input, wxUint16 *output)
 {
     if (input<=0xffff)
     {
-        if (output) *output++ = (wxUint16) input;
+        if (output)
+            *output = (wxUint16) input;
         return 1;
     }
     else if (input>=0x110000)
@@ -123,7 +124,7 @@ static size_t encode_utf16(wxUint32 input, wxUint16 *output)
         if (output)
         {
             *output++ = (wxUint16) ((input >> 10)+0xd7c0);
-            *output++ = (wxUint16) ((input&0x3ff)+0xdc00);
+            *output = (wxUint16) ((input&0x3ff)+0xdc00);
         }
         return 2;
     }
@@ -1137,9 +1138,10 @@ public:
                                 buf ? n : 0     // size of output buffer
                              );
 
-        // note that it returns # of written chars for buf != NULL and *size*
-        // of the needed buffer for buf == NULL
-        return len ? (buf ? len : len - 1) : (size_t)-1;
+        // note that it returns count of written chars for buf != NULL and size
+        // of the needed buffer for buf == NULL so in either case the length of
+        // the string (which never includes the terminating NUL) is one less
+        return len ? len - 1 : (size_t)-1;
     }
 
     size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const
@@ -1156,8 +1158,8 @@ public:
                                 NULL            // [out] was it used?
                              );
 
-        // see the comment above!
-        return len ? (buf ? len : len - 1) : (size_t)-1;
+        // see the comment above for the reason of "len - 1"
+        return len ? len - 1 : (size_t)-1;
     }
 
     bool IsOk() const
@@ -1247,37 +1249,21 @@ void wxCSConv::Init()
     m_deferred = true;
 }
 
-// find a valid value for the encoding
-void wxCSConv::SetEncoding()
-{
-#if wxUSE_INTL
-    m_encoding = wxLocale::GetSystemEncoding();
-#else
-    m_encoding = wxFONTENCODING_SYSTEM;
-#endif
-}
-
 wxCSConv::wxCSConv(const wxChar *charset)
 {
     Init();
 
     if ( charset )
     {
-        // not used
-        m_encoding = wxFONTENCODING_SYSTEM;
-
         SetName(charset);
     }
-    else // no charset specified
-    {
-        SetEncoding();
-    }
+
+    m_encoding = wxFONTENCODING_SYSTEM;
 }
 
 wxCSConv::wxCSConv(wxFontEncoding encoding)
 {
-    if ( encoding == wxFONTENCODING_MAX ||
-            encoding == wxFONTENCODING_DEFAULT )
+    if ( encoding == wxFONTENCODING_MAX || encoding == wxFONTENCODING_DEFAULT )
     {
         wxFAIL_MSG( _T("invalid encoding value in wxCSConv ctor") );
 
@@ -1286,14 +1272,7 @@ wxCSConv::wxCSConv(wxFontEncoding encoding)
 
     Init();
 
-    if ( encoding == wxFONTENCODING_SYSTEM )
-    {
-        SetEncoding();
-    }
-    else // have valid encoding, use it
-    {
-        m_encoding = encoding;
-    }
+    m_encoding = encoding;
 }
 
 wxCSConv::~wxCSConv()
@@ -1411,18 +1390,12 @@ wxMBConv *wxCSConv::DoCreate() const
         case wxFONTENCODING_UTF8:
              return new wxMBConvUTF8;
 
-        case wxFONTENCODING_UTF16:
-             return new wxMBConvUTF16;
-
         case wxFONTENCODING_UTF16BE:
              return new wxMBConvUTF16BE;
 
         case wxFONTENCODING_UTF16LE:
              return new wxMBConvUTF16LE;
 
-        case wxFONTENCODING_UTF32:
-             return new wxMBConvUTF32;
-
         case wxFONTENCODING_UTF32BE:
              return new wxMBConvUTF32BE;
 
@@ -1464,6 +1437,16 @@ void wxCSConv::CreateConvIfNeeded() const
     if ( m_deferred )
     {
         wxCSConv *self = (wxCSConv *)this; // const_cast
+
+#if wxUSE_INTL
+        // if we don't have neither the name nor the encoding, use the default
+        // encoding for this system
+        if ( !m_name && m_encoding == wxFONTENCODING_SYSTEM )
+        {
+            self->m_encoding = wxLocale::GetSystemEncoding();
+        }
+#endif // wxUSE_INTL
+
         self->m_convReal = DoCreate();
         self->m_deferred = false;
     }