+public:
+ long CodePage;
+};
+#endif
+
+class EC_CharSet : public wxCharacterSet
+{
+public:
+ // temporarily just use wxEncodingConverter stuff,
+ // so that it works while a better implementation is built
+ EC_CharSet(const wxChar*name) : wxCharacterSet(name),
+ enc(wxFONTENCODING_SYSTEM)
+ {
+ if (name)
+ enc = wxTheFontMapper->CharsetToEncoding(name, FALSE);
+ m2w.Init(enc, wxFONTENCODING_UNICODE);
+ w2m.Init(wxFONTENCODING_UNICODE, enc);
+ }
+
+ size_t MB2WC(wchar_t *buf, const char *psz, size_t n)
+ {
+ size_t inbuf = strlen(psz);
+ if (buf)
+ m2w.Convert(psz,buf);
+ return inbuf;
+ }
+
+ size_t WC2MB(char *buf, const wchar_t *psz, size_t n)
+ {
+#if defined(__BORLANDC__) && (__BORLANDC__ > 0x530)
+ size_t inbuf = std::wcslen(psz);
+#else
+ size_t inbuf = ::wcslen(psz);
+#endif
+ if (buf)
+ w2m.Convert(psz,buf);
+
+ return inbuf;
+ }
+
+ bool usable()
+ { return (enc!=wxFONTENCODING_SYSTEM) && (enc!=wxFONTENCODING_DEFAULT); }
+
+public:
+ wxFontEncoding enc;
+ wxEncodingConverter m2w, w2m;
+};
+
+static wxCharacterSet *wxGetCharacterSet(const wxChar *name)
+{
+ wxCharacterSet *cset = NULL;
+ if (name)
+ {
+ if (wxStricmp(name, wxT("UTF8")) == 0 || wxStricmp(name, wxT("UTF-8")) == 0)
+ {
+ cset = new ID_CharSet(name, &wxConvUTF8);
+ }
+ else
+ {
+#ifdef HAVE_ICONV_H
+ cset = new IC_CharSet(name); // may not take NULL
+#endif
+ }
+ }
+
+ if (cset && cset->usable()) return cset;
+ if (cset) delete cset;
+ cset = NULL;
+#ifdef __WIN32__
+ cset = new CP_CharSet(name); // may take NULL
+ if (cset->usable()) return cset;
+#endif
+ if (cset) delete cset;
+ cset = new EC_CharSet(name);
+ if (cset->usable()) return cset;
+ delete cset;
+ wxLogError(_("Unknown encoding '%s'!"), name);
+ return NULL;
+}