// conversion to/from UTF-8:
#if wxUSE_UNICODE_UTF8
- static wxString FromUTF8(const char *utf8)
+ static wxString FromUTF8Unchecked(const char *utf8)
{
if ( !utf8 )
return wxEmptyString;
wxASSERT( wxStringOperations::IsValidUtf8String(utf8) );
return FromImpl(wxStringImpl(utf8));
}
- static wxString FromUTF8(const char *utf8, size_t len)
+ static wxString FromUTF8Unchecked(const char *utf8, size_t len)
{
if ( !utf8 )
return wxEmptyString;
if ( len == npos )
- return FromUTF8(utf8);
+ return FromUTF8Unchecked(utf8);
wxASSERT( wxStringOperations::IsValidUtf8String(utf8, len) );
return FromImpl(wxStringImpl(utf8, len));
}
+
+ static wxString FromUTF8(const char *utf8)
+ {
+ if ( !utf8 || !wxStringOperations::IsValidUtf8String(utf8) )
+ return "";
+
+ return FromImpl(wxStringImpl(utf8));
+ }
+ static wxString FromUTF8(const char *utf8, size_t len)
+ {
+ if ( len == npos )
+ return FromUTF8(utf8);
+
+ if ( !utf8 || !wxStringOperations::IsValidUtf8String(utf8, len) )
+ return "";
+
+ return FromImpl(wxStringImpl(utf8, len));
+ }
+
const char* utf8_str() const { return wx_str(); }
const char* ToUTF8() const { return wx_str(); }
// internal UTF-8 representation
size_t utf8_length() const { return m_impl.length(); }
#elif wxUSE_UNICODE_WCHAR
- static wxString FromUTF8(const char *utf8)
- { return wxString(utf8, wxMBConvUTF8()); }
- static wxString FromUTF8(const char *utf8, size_t len)
+ static wxString FromUTF8(const char *utf8, size_t len = npos)
{ return wxString(utf8, wxMBConvUTF8(), len); }
+ static wxString FromUTF8Unchecked(const char *utf8, size_t len = npos)
+ {
+ const wxString s(utf8, wxMBConvUTF8(), len);
+ wxASSERT_MSG( !utf8 || !*utf8 || !s.empty(),
+ "string must be valid UTF-8" );
+ return s;
+ }
const wxCharBuffer utf8_str() const { return mb_str(wxMBConvUTF8()); }
const wxCharBuffer ToUTF8() const { return utf8_str(); }
#else // ANSI
{ return wxString(wxMBConvUTF8().cMB2WC(utf8)); }
static wxString FromUTF8(const char *utf8, size_t len)
{
- size_t wlen;
- wxWCharBuffer buf(wxMBConvUTF8().cMB2WC(utf8, len == npos ? wxNO_LEN : len, &wlen));
- return wxString(buf.data(), wlen);
+ size_t wlen;
+ wxWCharBuffer buf(wxMBConvUTF8().cMB2WC(utf8, len == npos ? wxNO_LEN : len, &wlen));
+ return wxString(buf.data(), wlen);
+ }
+ static wxString FromUTF8Unchecked(const char *utf8, size_t len = npos)
+ {
+ size_t wlen;
+ wxWCharBuffer buf(wxMBConvUTF8().cMB2WC(utf8,
+ len == npos ? wxNO_LEN : len,
+ &wlen));
+ wxASSERT_MSG( !utf8 || !*utf8 || wlen,
+ "string must be valid UTF-8" );
+
+ return wxString(buf.data(), wlen);
}
const wxCharBuffer utf8_str() const
{ return wxMBConvUTF8().cWC2MB(wc_str()); }
const wxWX2MBbuf mbc_str() const { return mb_str(*wxConvCurrent); }
#if wxUSE_UNICODE_WCHAR
- const wxChar* wc_str() const { return wx_str(); }
+ const wchar_t* wc_str() const { return wx_str(); }
#elif wxUSE_UNICODE_UTF8
const wxWCharBuffer wc_str() const;
#endif
const wxChar* mb_str() const { return wx_str(); }
// for compatibility with wxUSE_UNICODE version
- const wxChar* mb_str(const wxMBConv& WXUNUSED(conv)) const { return wx_str(); }
+ const char* mb_str(const wxMBConv& WXUNUSED(conv)) const { return wx_str(); }
const wxWX2MBbuf mbc_str() const { return mb_str(); }
const wxCharBuffer fn_str() const { return wxConvFile.cWC2WX( wc_str( wxConvLibc ) ); }
#endif // Unicode/ANSI
+#if wxUSE_UNICODE_UTF8
+ const wxWCharBuffer t_str() const { return wc_str(); }
+#elif wxUSE_UNICODE_WCHAR
+ const wchar_t* t_str() const { return wx_str(); }
+#else
+ const char* t_str() const { return wx_str(); }
+#endif
+
+
// overloaded assignment
// from another wxString
wxString& operator=(const wxString& stringSrc)
len = lenWanted - 1;
}
- wxTmemcpy(m_buf.data(), buf, len + 1);
+ memcpy(m_buf.data(), buf, (len + 1)*sizeof(CharType));
}
//else: conversion failed, this can happen when trying to get Unicode
// string contents into a char string