Reimplement wxSafeConvertXXX() functions using wxWhateverWorksConv

These functions were almost but not quite identical to it:
wxSafeConvertMB2WX() tried the current locale encoding before UTF-8 while
wxConvWhateverWorks tries UTF-8 first and then the current locale encoding.

The latter behaviour is more correct as valid UTF-8 could be misinterpreted as
some legacy multibyte encoding otherwise, so get rid of this difference and
just forward these functions to wxConvWhateverWorks.
This commit is contained in:
Vadim Zeitlin 2016-02-19 02:57:20 +01:00
parent 8eac125e86
commit 956edbb309
2 changed files with 8 additions and 35 deletions

View File

@ -687,12 +687,15 @@ extern WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvUI;
// function which would crash if we passed NULL to it), so these functions
// always return a valid pointer if their argument is non-NULL
// this function safety is achieved by trying wxConvLibc first, wxConvUTF8
// next if it fails and, finally, wxConvISO8859_1 which always succeeds
extern WXDLLIMPEXP_BASE wxWCharBuffer wxSafeConvertMB2WX(const char *s);
inline wxWCharBuffer wxSafeConvertMB2WX(const char *s)
{
return wxConvWhateverWorks.cMB2WC(s);
}
// this function uses wxConvLibc and wxConvUTF8 if it fails
extern WXDLLIMPEXP_BASE wxCharBuffer wxSafeConvertWX2MB(const wchar_t *ws);
inline wxCharBuffer wxSafeConvertWX2MB(const wchar_t *ws)
{
return wxConvWhateverWorks.cWC2MB(ws);
}
#else // ANSI
// no conversions to do
#define wxConvertWX2MB(s) (s)

View File

@ -3320,36 +3320,6 @@ wxWhateverWorksConv::FromWChar(char *dst, size_t dstLen,
return rc;
}
#if wxUSE_UNICODE
wxWCharBuffer wxSafeConvertMB2WX(const char *s)
{
if ( !s )
return wxWCharBuffer();
wxWCharBuffer wbuf(wxConvLibc.cMB2WX(s));
if ( !wbuf )
wbuf = wxConvUTF8.cMB2WX(s);
if ( !wbuf )
wbuf = wxConvISO8859_1.cMB2WX(s);
return wbuf;
}
wxCharBuffer wxSafeConvertWX2MB(const wchar_t *ws)
{
if ( !ws )
return wxCharBuffer();
wxCharBuffer buf(wxConvLibc.cWX2MB(ws));
if ( !buf )
buf = wxConvUTF8.cWX2MB(ws);
return buf;
}
#endif // wxUSE_UNICODE
// ----------------------------------------------------------------------------
// globals
// ----------------------------------------------------------------------------