]> git.saurik.com Git - wxWidgets.git/commitdiff
fix wxMBConvUTF8::cMB2WC/cWC2MB() broken by the introduction of wxMBConvStrictUTF8...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 15 Sep 2007 00:16:58 +0000 (00:16 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 15 Sep 2007 00:16:58 +0000 (00:16 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48699 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/strconv.h
src/common/strconv.cpp

index 1edf4f5082c7af2cc1bea6139feb0440ca5410bb..96dc8d8a70b1511ab7b1dee9a78f43f94f55f139 100644 (file)
@@ -290,8 +290,11 @@ public:
     };
 
     wxMBConvUTF8(int options = MAP_INVALID_UTF8_NOT) : m_options(options) { }
-    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;
+
+    virtual size_t ToWChar(wchar_t *dst, size_t dstLen,
+                           const char *src, size_t srcLen = wxNO_LEN) const;
+    virtual size_t FromWChar(char *dst, size_t dstLen,
+                             const wchar_t *src, size_t srcLen = wxNO_LEN) const;
 
     virtual wxMBConv *Clone() const { return new wxMBConvUTF8(m_options); }
 
index 97de5848f898463c896078374db0abc2ea0e654a..b74c577e2bf266740f176f8b9c5d3b42e11eb27c 100644 (file)
@@ -983,14 +983,15 @@ wxMBConvStrictUTF8::FromWChar(char *dst, size_t dstLen,
     return wxCONV_FAILED;
 }
 
-size_t wxMBConvUTF8::MB2WC(wchar_t *buf, const char *psz, size_t n) const
+size_t wxMBConvUTF8::ToWChar(wchar_t *buf, size_t n,
+                             const char *psz, size_t srcLen) const
 {
     if ( m_options == MAP_INVALID_UTF8_NOT )
-        return wxMBConvStrictUTF8::MB2WC(buf, psz, n);
+        return wxMBConvStrictUTF8::ToWChar(buf, n, psz, srcLen);
 
     size_t len = 0;
 
-    while (*psz && ((!buf) || (len < n)))
+    while ((srcLen == wxNO_LEN ? *psz : srcLen--) && ((!buf) || (len < n)))
     {
         const char *opsz = psz;
         bool invalid = false;
@@ -1124,10 +1125,10 @@ size_t wxMBConvUTF8::MB2WC(wchar_t *buf, const char *psz, size_t n) const
         }
     }
 
-    if (buf && (len < n))
+    if (srcLen == wxNO_LEN && buf && (len < n))
         *buf = 0;
 
-    return len;
+    return len + 1;
 }
 
 static inline bool isoctal(wchar_t wch)
@@ -1135,14 +1136,15 @@ static inline bool isoctal(wchar_t wch)
     return L'0' <= wch && wch <= L'7';
 }
 
-size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const
+size_t wxMBConvUTF8::FromWChar(char *buf, size_t n,
+                               const wchar_t *psz, size_t srcLen) const
 {
     if ( m_options == MAP_INVALID_UTF8_NOT )
-        return wxMBConvStrictUTF8::WC2MB(buf, psz, n);
+        return wxMBConvStrictUTF8::FromWChar(buf, n, psz, srcLen);
 
     size_t len = 0;
 
-    while (*psz && ((!buf) || (len < n)))
+    while ((srcLen == wxNO_LEN ? *psz : srcLen--) && ((!buf) || (len < n)))
     {
         wxUint32 cc;
 
@@ -1210,10 +1212,10 @@ size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const
         }
     }
 
-    if (buf && (len < n))
+    if (srcLen == wxNO_LEN && buf && (len < n))
         *buf = 0;
 
-    return len;
+    return len + 1;
 }
 
 // ============================================================================