diff --git a/include/wx/strconv.h b/include/wx/strconv.h index 1aa5f97550..a4a18e5e43 100644 --- a/include/wx/strconv.h +++ b/include/wx/strconv.h @@ -500,8 +500,6 @@ public: 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 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 GetMBNulLen() const; #if wxUSE_UNICODE_UTF8 diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index 507bf1307b..b6c3ca3545 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -3151,7 +3151,19 @@ size_t wxCSConv::ToWChar(wchar_t *dst, size_t dstLen, return m_convReal->ToWChar(dst, dstLen, src, srcLen); // latin-1 (direct) - return wxMBConv::ToWChar(dst, dstLen, src, srcLen); + if ( srcLen == wxNO_LEN ) + srcLen = strlen(src) + 1; // take trailing NUL too + + if ( dst ) + { + if ( dstLen < srcLen ) + return wxCONV_FAILED; + + for ( size_t n = 0; n < srcLen; n++ ) + dst[n] = (unsigned char)(src[n]); + } + + return srcLen; } size_t wxCSConv::FromWChar(char *dst, size_t dstLen, @@ -3163,57 +3175,33 @@ size_t wxCSConv::FromWChar(char *dst, size_t dstLen, return m_convReal->FromWChar(dst, dstLen, src, srcLen); // latin-1 (direct) - return wxMBConv::FromWChar(dst, dstLen, src, srcLen); -} + if ( srcLen == wxNO_LEN ) + srcLen = wxWcslen(src) + 1; -size_t wxCSConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const -{ - CreateConvIfNeeded(); - - if (m_convReal) - return m_convReal->MB2WC(buf, psz, n); - - // latin-1 (direct) - size_t len = strlen(psz); - - if (buf) + if ( dst ) { - for (size_t c = 0; c <= len; c++) - buf[c] = (unsigned char)(psz[c]); - } + if ( dstLen < srcLen ) + return wxCONV_FAILED; - return len; -} - -size_t wxCSConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const -{ - CreateConvIfNeeded(); - - if (m_convReal) - return m_convReal->WC2MB(buf, psz, n); - - // latin-1 (direct) - const size_t len = wxWcslen(psz); - if (buf) - { - for (size_t c = 0; c <= len; c++) + for ( size_t n = 0; n < srcLen; n++ ) { - if (psz[c] > 0xFF) + if ( src[n] > 0xFF ) return wxCONV_FAILED; - buf[c] = (char)psz[c]; + dst[n] = (char)src[n]; } + } - else + else // still need to check the input validity { - for (size_t c = 0; c <= len; c++) + for ( size_t n = 0; n < srcLen; n++ ) { - if (psz[c] > 0xFF) + if ( src[n] > 0xFF ) return wxCONV_FAILED; } } - return len; + return srcLen; } size_t wxCSConv::GetMBNulLen() const