/////////////////////////////////////////////////////////////////////////////
-// Name: strconv.cpp
+// Name: src/common/strconv.cpp
// Purpose: Unicode conversion classes
// Author: Ove Kaaven, Robert Roebling, Vadim Zeitlin, Vaclav Slavik,
// Ryan Norton, Fredrik Roubert (UTF7)
#define TRACE_STRCONV _T("strconv")
+#if SIZEOF_WCHAR_T == 2
+ #define WC_UTF16
+#endif
+
// ============================================================================
// implementation
// ============================================================================
{
// BASE64 encode string
unsigned int lsb, d, l;
- for (d = 0, l = 0;; psz++)
+ for (d = 0, l = 0; /*nothing*/; psz++)
{
for (lsb = 0; lsb < 2; lsb ++)
{
}
#else // !WC_UTF16
if (buf)
- *buf++ = res;
+ *buf++ = (wchar_t)res;
len++;
#endif // WC_UTF16/!WC_UTF16
}
len += pa;
#else
if (buf)
- *buf++ = wxUnicodePUA + (unsigned char)*opsz;
+ *buf++ = (wchar_t)(wxUnicodePUA + (unsigned char)*opsz);
opsz++;
len++;
#endif
return pa;
if (buf)
- *buf++ = cc;
+ *buf++ = (wchar_t)cc;
len++;
psz += pa * sizeof(wxUint16);
}
return pa;
if (buf)
- *buf++ = cc;
+ *buf++ = (wchar_t)cc;
len++;
psz += pa * sizeof(wxUint16);
while (*(wxUint32*)psz && (!buf || len < n))
{
if (buf)
- *buf++ = *(wxUint32*)psz;
+ *buf++ = (wchar_t)(*(wxUint32*)psz);
len++;
psz += sizeof(wxUint32);
}
// check for charset that represents wchar_t:
if ( ms_wcCharsetName.empty() )
{
+ wxLogTrace(TRACE_STRCONV, _T("Looking for wide char codeset:"));
+
#if wxUSE_FONTMAP
const wxChar **names = wxFontMapperBase::GetAllEncodingNames(WC_ENC);
#else // !wxUSE_FONTMAP
};
#endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
- for ( ; *names; ++names )
+ for ( ; *names && ms_wcCharsetName.empty(); ++names )
{
const wxString nameCS(*names);
nameXE += _T("LE");
#endif
+ wxLogTrace(TRACE_STRCONV, _T(" trying charset \"%s\""),
+ nameXE.c_str());
+
m2w = iconv_open(nameXE.ToAscii(), cname);
if ( m2w == ICONV_T_INVALID )
{
// try charset w/o bytesex info (e.g. "UCS4")
+ wxLogTrace(TRACE_STRCONV, _T(" trying charset \"%s\""),
+ nameCS.c_str());
m2w = iconv_open(nameCS.ToAscii(), cname);
// and check for bytesex ourselves:
if (ICONV_FAILED(cres, inbuf))
{
- //VS: it is ok if iconv fails, hence trace only
wxLogTrace(TRACE_STRCONV, wxT("iconv failed: %s"), wxSysErrorMsg(wxSysErrorCode()));
return (size_t)-1;
}
SetName(charset);
}
+#if wxUSE_FONTMAP
+ m_encoding = wxFontMapperBase::GetEncodingFromName(charset);
+#else
m_encoding = wxFONTENCODING_SYSTEM;
+#endif
}
wxCSConv::wxCSConv(wxFontEncoding encoding)
// check for the special case of ASCII or ISO8859-1 charset: as we have
// special knowledge of it anyhow, we don't need to create a special
// conversion object
- if ( m_encoding == wxFONTENCODING_ISO8859_1 )
+ if ( m_encoding == wxFONTENCODING_ISO8859_1 ||
+ m_encoding == wxFONTENCODING_DEFAULT )
{
// don't convert at all
return NULL;
wxConvUTF8;
#endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T
-
-