X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/65e508482777277c429b8c522e1ff8050ff5cdc7..9ac71bef070f553f4ecef2c549dba33b10422f06:/src/common/strconv.cpp diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index d613e6174a..235194fe46 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -66,7 +66,9 @@ public: virtual bool OnInit() { return TRUE; } virtual void OnExit() { - wxConvLocal.Clear(); +#if wxUSE_WCHAR_T + wxConvLocal.Clear(); +#endif } DECLARE_DYNAMIC_CLASS(wxStrConvModule) @@ -184,61 +186,69 @@ static size_t decode_utf16(const wchar_t* input, wxUint32& output) // wxMBConv // ---------------------------------------------------------------------------- +#define IGNORE_LIBC 0 + size_t wxMBConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const { +#if IGNORE_LIBC + if (buf) + { + for (size_t i = 0; i < strlen( psz )+1; i++) + buf[i] = (wchar_t) psz[i]; + return strlen( psz ); + } + else + { + return strlen( psz ); + } +#else return wxMB2WC(buf, psz, n); +#endif } size_t wxMBConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const { +#if IGNORE_LIBC + if (buf) + { + for (size_t i = 0; i < wxStrlen( psz )+1; i++) + buf[i] = (char) psz[i]; + return wxStrlen( psz ); + } + else + { + return wxStrlen( psz ); + } +#else return wxWC2MB(buf, psz, n); +#endif } const wxWCharBuffer wxMBConv::cMB2WC(const char *psz) const { if (psz) { - size_t nLen = MB2WC((wchar_t *) NULL, psz, 0); + size_t nLen = MB2WC((wchar_t *) NULL, psz, 0); // return value excludes /0 if (nLen == (size_t)-1) return wxWCharBuffer((wchar_t *) NULL); - wxWCharBuffer buf(nLen); - MB2WC((wchar_t *)(const wchar_t *) buf, psz, nLen); + wxWCharBuffer buf(nLen); // this allocates nLen1+ + MB2WC((wchar_t *)(const wchar_t *) buf, psz, nLen+1); return buf; } else return wxWCharBuffer((wchar_t *) NULL); } -const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *psz) const -{ - if (psz) - { - size_t nLen = WC2MB((char *) NULL, psz, 0); - if (nLen == (size_t)-1) - return wxCharBuffer((char *) NULL); - wxCharBuffer buf(nLen); - WC2MB((char *)(const char *) buf, psz, nLen); - return buf; - } - else - return wxCharBuffer((char *) NULL); -} - -// ---------------------------------------------------------------------------- -// standard file conversion -// ---------------------------------------------------------------------------- - -WXDLLEXPORT_DATA(wxMBConvFile) wxConvFile; - -// just use the libc conversion for now -size_t wxMBConvFile::MB2WC(wchar_t *buf, const char *psz, size_t n) const -{ - return wxMB2WC(buf, psz, n); -} - -size_t wxMBConvFile::WC2MB(char *buf, const wchar_t *psz, size_t n) const +const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *pwz) const { - return wxWC2MB(buf, psz, n); + // return value excludes NUL + size_t nLen = pwz ? WC2MB((char *) NULL, pwz, 0) : (size_t)-1; + if (nLen == (size_t)-1) + return wxCharBuffer((const char *)NULL); + + wxCharBuffer buf(nLen); // this allocates nLen+1 + WC2MB((char *)(const char *) buf, pwz, nLen+1); + return buf; } // ---------------------------------------------------------------------------- @@ -423,6 +433,7 @@ size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const } if (buf && (lenCharsetToEncoding(name, FALSE); + enc = wxFontMapper::Get()->CharsetToEncoding(name, FALSE); m_ok = m2w.Init(enc, wxFONTENCODING_UNICODE) && w2m.Init(wxFONTENCODING_UNICODE, enc); @@ -838,7 +866,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 @@ -918,6 +946,20 @@ wxCSConv::~wxCSConv() 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) @@ -945,7 +987,9 @@ void wxCSConv::LoadNow() { wxString name = wxLocale::GetSystemEncodingName(); if ( !name.empty() ) + { SetName(name); + } } // wxGetCharacterSet() complains about NULL name