Merge branch 'mbconv-len-fix'

Return buffers of correct length from wxMBConv::cWC2MB() and cMB2WC().
This commit is contained in:
Vadim Zeitlin
2017-11-04 14:20:15 +01:00
4 changed files with 102 additions and 76 deletions

View File

@@ -71,11 +71,19 @@ public:
const wchar_t *src, size_t srcLen = wxNO_LEN) const;
// Convenience functions for translating NUL-terminated strings: returns
// the buffer containing the converted string or NULL pointer if the
// Convenience functions for translating NUL-terminated strings: return
// the buffer containing the converted string or empty buffer if the
// conversion failed.
const wxWCharBuffer cMB2WC(const char *in) const;
const wxCharBuffer cWC2MB(const wchar_t *in) const;
wxWCharBuffer cMB2WC(const char *in) const
{ return DoConvertMB2WC(in, wxNO_LEN); }
wxCharBuffer cWC2MB(const wchar_t *in) const
{ return DoConvertWC2MB(in, wxNO_LEN); }
wxWCharBuffer cMB2WC(const wxScopedCharBuffer& in) const
{ return DoConvertMB2WC(in, in.length()); }
wxCharBuffer cWC2MB(const wxScopedWCharBuffer& in) const
{ return DoConvertWC2MB(in, in.length()); }
// Convenience functions for converting strings which may contain embedded
// NULs and don't have to be NUL-terminated.
@@ -92,28 +100,22 @@ public:
// number of characters converted, whether the last one of them was NUL or
// not. But if inLen == wxNO_LEN then outLen doesn't account for the last
// NUL even though it is present.
const wxWCharBuffer
wxWCharBuffer
cMB2WC(const char *in, size_t inLen, size_t *outLen) const;
const wxCharBuffer
wxCharBuffer
cWC2MB(const wchar_t *in, size_t inLen, size_t *outLen) const;
// And yet more convenience functions for converting the entire buffers:
// these are the simplest and least error-prone as you never need to bother
// with lengths/sizes directly.
const wxWCharBuffer cMB2WC(const wxScopedCharBuffer& in) const;
const wxCharBuffer cWC2MB(const wxScopedWCharBuffer& in) const;
// convenience functions for converting MB or WC to/from wxWin default
#if wxUSE_UNICODE
const wxWCharBuffer cMB2WX(const char *psz) const { return cMB2WC(psz); }
const wxCharBuffer cWX2MB(const wchar_t *psz) const { return cWC2MB(psz); }
wxWCharBuffer cMB2WX(const char *psz) const { return cMB2WC(psz); }
wxCharBuffer cWX2MB(const wchar_t *psz) const { return cWC2MB(psz); }
const wchar_t* cWC2WX(const wchar_t *psz) const { return psz; }
const wchar_t* cWX2WC(const wchar_t *psz) const { return psz; }
#else // ANSI
const char* cMB2WX(const char *psz) const { return psz; }
const char* cWX2MB(const char *psz) const { return psz; }
const wxCharBuffer cWC2WX(const wchar_t *psz) const { return cWC2MB(psz); }
const wxWCharBuffer cWX2WC(const char *psz) const { return cMB2WC(psz); }
wxCharBuffer cWC2WX(const wchar_t *psz) const { return cWC2MB(psz); }
wxWCharBuffer cWX2WC(const char *psz) const { return cMB2WC(psz); }
#endif // Unicode/ANSI
// this function is used in the implementation of cMB2WC() to distinguish
@@ -162,7 +164,12 @@ public:
virtual wxMBConv *Clone() const = 0;
// virtual dtor for any base class
virtual ~wxMBConv();
virtual ~wxMBConv() { }
private:
// Common part of single argument cWC2MB() and cMB2WC() overloads above.
wxCharBuffer DoConvertWC2MB(const wchar_t* pwz, size_t srcLen) const;
wxWCharBuffer DoConvertMB2WC(const char* psz, size_t srcLen) const;
};
// ----------------------------------------------------------------------------