From caf45e24c042754b1abd63b1fea4f3f9f158f1db Mon Sep 17 00:00:00 2001 From: Ove Kaaven Date: Sat, 25 Mar 2000 23:01:29 +0000 Subject: [PATCH] Trashed old wxCSConv loader code. Replaced with code that uses wxTheFontMapper->CharsetToEncoding and wxEncodingConverter for now (trying to do something more major would probably be too big for WX_2_2_BRANCH, this can be reimplemented in a better way later). Untested but compiles fine and ought to work. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@6937 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/strconv.cpp | 161 +++++++---------------------------------- 1 file changed, 26 insertions(+), 135 deletions(-) diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index d2b1144af8..307eff37a7 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -249,122 +249,34 @@ size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const // specified character set // ---------------------------------------------------------------------------- -#ifndef WX_PRECOMP - #include "wx/dynarray.h" - #include "wx/filefn.h" - #include "wx/textfile.h" - #include "wx/tokenzr.h" - #include "wx/utils.h" -#endif +WXDLLEXPORT_DATA(wxCSConv) wxConvLocal((const wxChar *)NULL); + +#include "wx/encconv.h" +#include "wx/fontmap.h" class wxCharacterSet { public: - wxArrayString names; - wchar_t *data; + // temporarily just use wxEncodingConverter stuff, + // so that it works while a better implementation is built + wxFontEncoding enc; + wxEncodingConverter m2w, w2m; + wxCharacterSet(wxFontEncoding e) : enc(e) + { + m2w.Init(enc, wxFONTENCODING_UNICODE); + w2m.Init(wxFONTENCODING_UNICODE, enc); + } }; -WX_DECLARE_OBJARRAY(wxCharacterSet, wxCSArray); -#include "wx/arrimpl.cpp" -WX_DEFINE_OBJARRAY(wxCSArray); - -static wxCSArray wxCharsets; - -static void wxLoadCharacterSets(void) +static wxCharacterSet *wxGetCharacterSet(const wxChar *name) { - static bool already_loaded = FALSE; - - if (already_loaded) return; - - already_loaded = TRUE; -#if defined(__UNIX__) && wxUSE_TEXTFILE - // search through files in /usr/share/i18n/charmaps - wxString fname; - for (fname = ::wxFindFirstFile(wxT("/usr/share/i18n/charmaps/*")); - !fname.IsEmpty(); - fname = ::wxFindNextFile()) { - wxTextFile cmap(fname); - if (cmap.Open()) { - wxCharacterSet *cset = new wxCharacterSet; - wxString comchar,escchar; - bool in_charset = FALSE; - - // wxFprintf(stderr,wxT("Loaded: %s\n"),fname.c_str()); - - wxString line; - for (line = cmap.GetFirstLine(); - !cmap.Eof(); - line = cmap.GetNextLine()) { - // wxFprintf(stderr,wxT("line contents: %s\n"),line.c_str()); - wxStringTokenizer token(line); - wxString cmd = token.GetNextToken(); - if (cmd == comchar) { - if (token.GetNextToken() == wxT("alias")) - cset->names.Add(token.GetNextToken()); - } - else if (cmd == wxT("")) - cset->names.Add(token.GetNextToken()); - else if (cmd == wxT("")) - comchar = token.GetNextToken(); - else if (cmd == wxT("")) - escchar = token.GetNextToken(); - else if (cmd == wxT("")) { - delete cset; - cset = (wxCharacterSet *) NULL; - break; // we don't support multibyte charsets ourselves (yet) - } - else if (cmd == wxT("CHARMAP")) { - cset->data = (wchar_t *)calloc(256, sizeof(wchar_t)); - in_charset = TRUE; - } - else if (cmd == wxT("END")) { - if (token.GetNextToken() == wxT("CHARMAP")) - in_charset = FALSE; - } - else if (in_charset) { - // format: /x00 NULL (NUL) - // /x41 LATIN CAPITAL LETTER A - wxString hex = token.GetNextToken(); - // skip whitespace (why doesn't wxStringTokenizer do this?) - while (wxIsEmpty(hex) && token.HasMoreTokens()) hex = token.GetNextToken(); - wxString uni = token.GetNextToken(); - // skip whitespace again - while (wxIsEmpty(uni) && token.HasMoreTokens()) uni = token.GetNextToken(); - if ((hex.Len() > 2) && (wxString(hex.GetChar(0)) == escchar) && (hex.GetChar(1) == wxT('x')) && - (uni.Left(2) == wxT("=0) { - unsigned long uni1 = ::wxHexToDec(uni.Mid(2,2)); - unsigned long uni2 = ::wxHexToDec(uni.Mid(4,2)); - cset->data[pos] = (uni1 << 16) | uni2; - // wxFprintf(stderr,wxT("char %02x mapped to %04x (%c)\n"),pos,cset->data[pos],cset->data[pos]); - } - } - } - } - if (cset) { - cset->names.Shrink(); - wxCharsets.Add(cset); - } - } - } -#endif - wxCharsets.Shrink(); + wxFontEncoding enc = name ? wxTheFontMapper->CharsetToEncoding(name, FALSE) + : wxFONTENCODING_SYSTEM; + wxCharacterSet *cset = (enc != wxFONTENCODING_SYSTEM) ? new wxCharacterSet(enc) + : (wxCharacterSet *)NULL; + return cset; } -static wxCharacterSet *wxFindCharacterSet(const wxChar *charset) -{ - if (!charset) return (wxCharacterSet *)NULL; - wxLoadCharacterSets(); - for (size_t n=0; n4) { - if (wxString(charset,4) == wxT("8859")) { - codeset << wxT("8859-"); - if (*charset == wxT('-')) charset++; - } - } - } - codeset << charset; - codeset.MakeUpper(); - m_name = wxStrdup(codeset.c_str()); + m_name = wxStrdup(charset); m_deferred = TRUE; -#endif } } @@ -410,12 +305,13 @@ void wxCSConv::LoadNow() if (m_deferred) { if (!m_name) { #ifdef __UNIX__ - wxChar *lang = wxGetenv(wxT("LANG")); + wxChar *lang = wxGetenv(wxT("LC_ALL")); + if (!lang) lang = wxGetenv(wxT("LANG")); wxChar *dot = lang ? wxStrchr(lang, wxT('.')) : (wxChar *)NULL; if (dot) SetName(dot+1); #endif } - m_cset = wxFindCharacterSet(m_name); + m_cset = wxGetCharacterSet(m_name); m_deferred = FALSE; } } @@ -425,8 +321,7 @@ size_t wxCSConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const ((wxCSConv *)this)->LoadNow(); // discard constness if (buf) { if (m_cset) { - for (size_t c=0; cdata[(unsigned char)(psz[c])]; + m_cset->m2w.Convert(psz, buf); } else { // latin-1 (direct) for (size_t c=0; cLoadNow(); // discard constness if (buf) { if (m_cset) { - for (size_t c=0; cdata[n] != psz[c]); n++); - buf[c] = (n>0xff) ? '?' : n; - } + m_cset->w2m.Convert(psz, buf); } else { // latin-1 (direct) for (size_t c=0; c