X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/373658eb493827a9a68a79eeaaab1dbfc69a206b..277f2e527e33de039146ab94358ffec9c98f6112:/src/common/strconv.cpp diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index 5f069277de..bdb210d538 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -42,6 +42,7 @@ #include #include +#include "wx/module.h" #include "wx/strconv.h" // ---------------------------------------------------------------------------- @@ -58,6 +59,24 @@ WXDLLEXPORT_DATA(wxMBConv *) wxConvCurrent = &wxConvLibc; +class wxStrConvModule: public wxModule +{ +public: + wxStrConvModule() : wxModule() { } + virtual bool OnInit() { return TRUE; } + virtual void OnExit() + { +#if wxUSE_WCHAR_T + wxConvLocal.Clear(); +#endif + } + + DECLARE_DYNAMIC_CLASS(wxStrConvModule) +}; + +IMPLEMENT_DYNAMIC_CLASS(wxStrConvModule, wxModule) + + // ---------------------------------------------------------------------------- // headers // ---------------------------------------------------------------------------- @@ -124,7 +143,7 @@ static size_t encode_utf16(wxUint32 input, wchar_t *output) { if (input<=0xffff) { - if (output) *output++ = input; + if (output) *output++ = (wchar_t) input; return 1; } else if (input>=0x110000) @@ -135,8 +154,8 @@ static size_t encode_utf16(wxUint32 input, wchar_t *output) { if (output) { - *output++ = (input >> 10)+0xd7c0; - *output++ = (input&0x3ff)+0xdc00; + *output++ = (wchar_t) ((input >> 10)+0xd7c0); + *output++ = (wchar_t) ((input&0x3ff)+0xdc00); } return 2; } @@ -389,7 +408,7 @@ size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const { // plain ASCII char if (buf) - *buf++ = cc; + *buf++ = (char) cc; len++; } @@ -398,9 +417,9 @@ size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const len += cnt + 1; if (buf) { - *buf++ = (-128 >> cnt) | ((cc >> (cnt * 6)) & (0x3f >> cnt)); + *buf++ = (char) ((-128 >> cnt) | ((cc >> (cnt * 6)) & (0x3f >> cnt))); while (cnt--) - *buf++ = 0x80 | ((cc >> (cnt * 6)) & 0x3f); + *buf++ = (char) (0x80 | ((cc >> (cnt * 6)) & 0x3f)); } } } @@ -772,13 +791,13 @@ public: enc(wxFONTENCODING_SYSTEM) { if (name) - enc = wxTheFontMapper->CharsetToEncoding(name, FALSE); + enc = wxFontMapper::Get()->CharsetToEncoding(name, FALSE); m_ok = m2w.Init(enc, wxFONTENCODING_UNICODE) && w2m.Init(wxFONTENCODING_UNICODE, enc); } - size_t MB2WC(wchar_t *buf, const char *psz, size_t n) + size_t MB2WC(wchar_t *buf, const char *psz, size_t WXUNUSED(n)) { size_t inbuf = strlen(psz); if (buf) @@ -786,7 +805,7 @@ public: return inbuf; } - size_t WC2MB(char *buf, const wchar_t *psz, size_t n) + size_t WC2MB(char *buf, const wchar_t *psz, size_t WXUNUSED(n)) { #if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) ) \ || ( defined(__MWERKS__) && defined(__WXMSW__) ) @@ -821,7 +840,7 @@ static wxCharacterSet *wxGetCharacterSet(const wxChar *name) { // check for the special case of ASCII charset #if wxUSE_FONTMAP - if ( wxTheFontMapper->CharsetToEncoding(name) == wxFONTENCODING_DEFAULT ) + if ( wxFontMapper::Get()->CharsetToEncoding(name) == wxFONTENCODING_DEFAULT ) #else // wxUSE_FONTMAP if ( !name ) #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP @@ -898,8 +917,31 @@ wxCSConv::wxCSConv(const wxChar *charset) wxCSConv::~wxCSConv() { - free(m_name); - delete m_cset; + Clear(); +} + +wxCSConv::wxCSConv(const wxCSConv& conv) + : wxMBConv() +{ + Clear(); + SetName(conv.m_name); +} + +wxCSConv& wxCSConv::operator=(const wxCSConv& conv) +{ + Clear(); + SetName(conv.m_name); + return *this; +} + +void wxCSConv::Clear() +{ + if (m_name) + free(m_name); + if (m_cset) + delete m_cset; + m_name = NULL; + m_cset = NULL; } void wxCSConv::SetName(const wxChar *charset)