size_t wxMBConvUTF7::MB2WC(wchar_t *buf, const char *psz, size_t n) const
{
-
size_t len = 0;
while (*psz && ((!buf) || (len < n)))
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 3, 3
};
-size_t wxMBConvUTF7::WC2MB(char *buf, const wchar_t
-*psz, size_t n) const
+size_t wxMBConvUTF7::WC2MB(char *buf, const wchar_t *psz, size_t n) const
{
// and break the library itself, e.g. wxTextInputStream::NextChar()
// wouldn't work if reading an incomplete MB char didn't result in an
// error
+ //
+ // note however that using MB_ERR_INVALID_CHARS with CP_UTF7 results in
+ // an error (tested under Windows Server 2003) and apparently it is
+ // done on purpose, i.e. the function accepts any input in this case
+ // and although I'd prefer to return error on ill-formed output, our
+ // own wxMBConvUTF7 doesn't detect errors (e.g. lone "+" which is
+ // explicitly ill-formed according to RFC 2152) neither so we don't
+ // even have any fallback here...
+ int flags = m_CodePage == CP_UTF7 ? 0 : MB_ERR_INVALID_CHARS;
+
const size_t len = ::MultiByteToWideChar
(
m_CodePage, // code page
- MB_ERR_INVALID_CHARS, // flags: fall on error
+ flags, // flags: fall on error
psz, // input string
-1, // its length (NUL-terminated)
buf, // output string
Init(CFStringGetSystemEncoding()) ;
}
+#if wxUSE_FONTMAP
wxMBConv_mac(const wxChar* name)
{
Init( wxMacGetSystemEncFromFontEnc(wxFontMapper::Get()->CharsetToEncoding(name, false) ) ) ;
}
+#endif
wxMBConv_mac(wxFontEncoding encoding)
{
{
size_t inbuf = strlen(psz);
if (buf)
- m2w.Convert(psz,buf);
+ {
+ if (!m2w.Convert(psz,buf))
+ return (size_t)-1;
+ }
return inbuf;
}
{
const size_t inbuf = wxWcslen(psz);
if (buf)
- w2m.Convert(psz,buf);
+ {
+ if (!w2m.Convert(psz,buf))
+ return (size_t)-1;
+ }
return inbuf;
}
if ( m_name || ( m_encoding < wxFONTENCODING_UTF16BE ) )
{
+#if wxUSE_FONTMAP
wxMBConv_mac *conv = m_name ? new wxMBConv_mac(m_name)
: new wxMBConv_mac(m_encoding);
+#else
+ wxMBConv_mac *conv = new wxMBConv_mac(m_encoding);
+#endif
if ( conv->IsOk() )
return conv;