-// ----------------------------------------------------------------------------
-// the function creating the wxCharacterSet for the specified charset on the
-// current system, trying all possibilities
-//
-// it uses the name if it is given or encoding if name == NULL
-// ----------------------------------------------------------------------------
-
-static wxCharacterSet *
-wxGetCharacterSet(const wxChar *name, wxFontEncoding encoding)
-{
- // check for the special case of ASCII charset
- if ( (!name && encoding == wxFONTENCODING_DEFAULT)
-#if wxUSE_FONTMAP
- || (name && wxFontMapper::Get()->
- CharsetToEncoding(name) == wxFONTENCODING_DEFAULT)
-#endif // wxUSE_FONTMAP
- )
- {
- // don't convert at all
- return NULL;
- }
-
- wxCharacterSet *cset = NULL;
-
- if (name)
- {
- if((wxStricmp(name, wxT("UTF8")) == 0) ||
- (wxStricmp(name, wxT("UTF-8")) == 0) ||
- encoding == wxFONTENCODING_UTF8 )
- {
- cset = new ID_CharSet(&wxConvUTF8);
- }
- else if((wxStricmp(name, wxT("UTF16")) == 0) ||
- (wxStricmp(name, wxT("UTF-16")) == 0) ||
- encoding == wxFONTENCODING_UTF16 )
- {
-#ifdef WORDS_BIGENDIAN
- cset = new ID_CharSet(&wxConvUTF16BE);
-#else
- cset = new ID_CharSet(&wxConvUTF16LE);
-#endif
- }
- else if((wxStricmp(name, wxT("UTF16BE")) == 0) ||
- (wxStricmp(name, wxT("UTF-16BE")) == 0) ||
- encoding == wxFONTENCODING_UTF16BE )
- {
- cset = new ID_CharSet(&wxConvUTF16BE);
- }
- else if((wxStricmp(name, wxT("UTF16LE")) == 0) ||
- (wxStricmp(name, wxT("UTF-16LE")) == 0) ||
- encoding == wxFONTENCODING_UTF16LE )
- {
- cset = new ID_CharSet(&wxConvUTF16LE);
- }
- else if((wxStricmp(name, wxT("UTF32")) == 0) ||
- (wxStricmp(name, wxT("UTF-32")) == 0) ||
- (wxStricmp(name, wxT("UCS4")) == 0) ||
- (wxStricmp(name, wxT("UCS-4")) == 0) ||
- encoding == wxFONTENCODING_UTF32 )
- {
-#ifdef WORDS_BIGENDIAN
- cset = new ID_CharSet(&wxConvUTF32BE);
-#else
- cset = new ID_CharSet(&wxConvUTF32LE);
-#endif
- }
- else if((wxStricmp(name, wxT("UTF32BE")) == 0) ||
- (wxStricmp(name, wxT("UTF-32BE")) == 0) ||
- (wxStricmp(name, wxT("UCS4BE")) == 0) ||
- (wxStricmp(name, wxT("UCS-4BE")) == 0) ||
- encoding == wxFONTENCODING_UTF32BE )
- {
- cset = new ID_CharSet(&wxConvUTF32BE);
- }
- else if((wxStricmp(name, wxT("UTF32LE")) == 0) ||
- (wxStricmp(name, wxT("UTF-32LE")) == 0) ||
- (wxStricmp(name, wxT("UCS4LE")) == 0) ||
- (wxStricmp(name, wxT("UCS-4LE")) == 0) ||
- encoding == wxFONTENCODING_UTF32 )
- {
- cset = new ID_CharSet(&wxConvUTF32LE);
- }
-#ifdef HAVE_ICONV
- else
- {
- cset = new IC_CharSet(name);
- }
-#endif // HAVE_ICONV
- }
-
- // it can only be NULL in this case
-#ifndef HAVE_ICONV
- if ( cset )
-#endif // !HAVE_ICONV
- {
- if ( cset->usable() )
- return cset;
-
- delete cset;
- cset = NULL;
- }
-
-#if defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
- cset = name ? new CP_CharSet(name) : new CP_CharSet(encoding);
- if ( cset->usable() )
- return cset;
-
- delete cset;
- cset = NULL;
-#endif // defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
-
-#if wxUSE_FONTMAP
- cset = name ? new EC_CharSet(name) : new EC_CharSet(encoding);
- if ( cset->usable() )
- return cset;
-
- delete cset;
- cset = NULL;
-#endif // wxUSE_FONTMAP
-
- wxLogError(_("Cannot convert from encoding '%s'!"),
- name ? name
- :
-#if wxUSE_FONTMAP
- wxFontMapper::GetEncodingDescription(encoding).c_str()
-#else // !wxUSE_FONTMAP
- wxString::Format(_T("%s"), encoding).c_str()
-#endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
- );
-
- return NULL;
-}
-