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
This commit is contained in:
Vadim Zeitlin
2007-09-15 00:16:58 +00:00
parent e20d1329b5
commit d16d0917e4
2 changed files with 17 additions and 12 deletions

View File

@@ -290,8 +290,11 @@ public:
}; };
wxMBConvUTF8(int options = MAP_INVALID_UTF8_NOT) : m_options(options) { } 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); } virtual wxMBConv *Clone() const { return new wxMBConvUTF8(m_options); }

View File

@@ -983,14 +983,15 @@ wxMBConvStrictUTF8::FromWChar(char *dst, size_t dstLen,
return wxCONV_FAILED; 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 ) if ( m_options == MAP_INVALID_UTF8_NOT )
return wxMBConvStrictUTF8::MB2WC(buf, psz, n); return wxMBConvStrictUTF8::ToWChar(buf, n, psz, srcLen);
size_t len = 0; size_t len = 0;
while (*psz && ((!buf) || (len < n))) while ((srcLen == wxNO_LEN ? *psz : srcLen--) && ((!buf) || (len < n)))
{ {
const char *opsz = psz; const char *opsz = psz;
bool invalid = false; 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; *buf = 0;
return len; return len + 1;
} }
static inline bool isoctal(wchar_t wch) 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'; 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 ) if ( m_options == MAP_INVALID_UTF8_NOT )
return wxMBConvStrictUTF8::WC2MB(buf, psz, n); return wxMBConvStrictUTF8::FromWChar(buf, n, psz, srcLen);
size_t len = 0; size_t len = 0;
while (*psz && ((!buf) || (len < n))) while ((srcLen == wxNO_LEN ? *psz : srcLen--) && ((!buf) || (len < n)))
{ {
wxUint32 cc; 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; *buf = 0;
return len; return len + 1;
} }
// ============================================================================ // ============================================================================