Add wxWhateverWorksConv and use it for file names under Unix
This ensures that we can create output files with Unicode names even when they're not representable in the current locale encoding, notably when the current locale has never been changed and is still the default "C" one, not supporting anything else other than 7 bit ASCII. Credits for the new class name go to Woody Allen.
This commit is contained in:
@@ -543,6 +543,39 @@ private:
|
||||
wxMBConv *m_convReal;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxWhateverWorksConv: use whatever encoding works for the input
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLIMPEXP_BASE wxWhateverWorksConv : public wxMBConv
|
||||
{
|
||||
public:
|
||||
wxWhateverWorksConv()
|
||||
{
|
||||
}
|
||||
|
||||
// Try to interpret the string as UTF-8, if it fails fall back to the
|
||||
// current locale encoding (wxConvLibc) and if this fails as well,
|
||||
// interpret it as wxConvISO8859_1 (which is used because it never fails
|
||||
// and this conversion is used when we really, really must produce
|
||||
// something on output).
|
||||
virtual size_t
|
||||
ToWChar(wchar_t *dst, size_t dstLen,
|
||||
const char *src, size_t srcLen = wxNO_LEN) const wxOVERRIDE;
|
||||
|
||||
// Try to encode the string using the current locale encoding (wxConvLibc)
|
||||
// and fall back to UTF-8 (which never fails) if it doesn't work. Note that
|
||||
// we never use wxConvISO8859_1 here as we prefer to fall back on UTF-8
|
||||
// even for the strings containing only code points representable in 8869-1.
|
||||
virtual size_t
|
||||
FromWChar(char *dst, size_t dstLen,
|
||||
const wchar_t *src, size_t srcLen = wxNO_LEN) const wxOVERRIDE;
|
||||
|
||||
virtual wxMBConv *Clone() const wxOVERRIDE
|
||||
{
|
||||
return new wxWhateverWorksConv();
|
||||
}
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// declare predefined conversion objects
|
||||
@@ -578,6 +611,12 @@ WX_DECLARE_GLOBAL_CONV(wxMBConvStrictUTF8, wxConvUTF8)
|
||||
WX_DECLARE_GLOBAL_CONV(wxMBConvUTF7, wxConvUTF7)
|
||||
#define wxConvUTF7 wxGet_wxConvUTF7()
|
||||
|
||||
// conversion used when we may not afford to lose data when outputting Unicode
|
||||
// strings (should be avoid in the other direction as it can misinterpret the
|
||||
// input encoding)
|
||||
WX_DECLARE_GLOBAL_CONV(wxWhateverWorksConv, wxConvWhateverWorks)
|
||||
#define wxConvWhateverWorks wxGet_wxConvWhateverWorks()
|
||||
|
||||
// conversion used for the file names on the systems where they're not Unicode
|
||||
// (basically anything except Windows)
|
||||
//
|
||||
|
Reference in New Issue
Block a user