git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45664
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
if (!ascii)
return wxEmptyString;
if (!ascii)
return wxEmptyString;
- size_t len = strlen( ascii );
+ size_t len = strlen(ascii);
wxString res;
if ( len )
{
wxString res;
if ( len )
{
- wxStringBuffer buf(res, len);
-
- wchar_t *dest = buf;
+ wxImplStringBuffer buf(res, len);
+ wxStringCharType *dest = buf;
- if ( (*dest++ = (wchar_t)(unsigned char)*ascii++) == L'\0' )
- break;
+ unsigned char c = (unsigned char)*ascii++;
+ wxASSERT_MSG( c < 0x80,
+ _T("Non-ASCII value passed to FromAscii().") );
+
+ *dest++ = (wchar_t)c;
+
+ if ( c == '\0' )
+ break;
{
// What do we do with '\0' ?
{
// What do we do with '\0' ?
- wxString res;
- res += (wchar_t)(unsigned char) ascii;
+ unsigned char c = (unsigned char)ascii;
+ wxASSERT_MSG( c < 0x80, _T("Non-ASCII value passed to FromAscii().") );
+
+ // NB: the cast to wchar_t causes interpretation of 'ascii' as Latin1 value
+ return wxString(wxUniChar((wchar_t)c));
}
const wxCharBuffer wxString::ToAscii() const
{
// this will allocate enough space for the terminating NUL too
wxCharBuffer buffer(length());
}
const wxCharBuffer wxString::ToAscii() const
{
// this will allocate enough space for the terminating NUL too
wxCharBuffer buffer(length());
char *dest = buffer.data();
char *dest = buffer.data();
- const wchar_t *pwc = c_str();
- for ( ;; )
+ for ( const_iterator i = begin(); i != end(); ++i )
- *dest++ = (char)(*pwc > SCHAR_MAX ? wxT('_') : *pwc);
+ wxUniChar c(*i);
+ // FIXME-UTF8: unify substituted char ('_') with wxUniChar ('?')
+ *dest++ = c.IsAscii() ? (char)c : '_';
// the output string can't have embedded NULs anyhow, so we can safely
// stop at first of them even if we do have any
// the output string can't have embedded NULs anyhow, so we can safely
// stop at first of them even if we do have any
break;
}
return buffer;
}
break;
}
return buffer;
}
// extract string of length nCount starting at nFirst
wxString wxString::Mid(size_t nFirst, size_t nCount) const
// extract string of length nCount starting at nFirst
wxString wxString::Mid(size_t nFirst, size_t nCount) const