From d16d0917e40c083349e2a98a405433ade3e6f2c4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 15 Sep 2007 00:16:58 +0000 Subject: [PATCH] fix wxMBConvUTF8::cMB2WC/cWC2MB() broken by the introduction of wxMBConvStrictUTF8: as it overrides From/ToWChar(), wxMBConvUTF8 needs to do it (instead of deprecated MB2WC/WC2MB) as well git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48699 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/strconv.h | 7 +++++-- src/common/strconv.cpp | 22 ++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/include/wx/strconv.h b/include/wx/strconv.h index 1edf4f5082..96dc8d8a70 100644 --- a/include/wx/strconv.h +++ b/include/wx/strconv.h @@ -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); } diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index 97de5848f8..b74c577e2b 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -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; } // ============================================================================ -- 2.45.2