// 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()); }
// convert to upper case in place, return the string itself
wxString& MakeUpper();
// convert to upper case, return the copy of the string
- // Here's something to remember: BC++ doesn't like returns in inlines.
- wxString Upper() const ;
+ wxString Upper() const { return wxString(*this).MakeUpper(); }
// convert to lower case in place, return the string itself
wxString& MakeLower();
// convert to lower case, return the copy of the string
- wxString Lower() const ;
+ wxString Lower() const { return wxString(*this).MakeLower(); }
+ // convert the first character to the upper case and the rest to the
+ // lower one, return the modified string itself
+ wxString& MakeCapitalized();
+ // convert the first character to the upper case and the rest to the
+ // lower one, return the copy of the string
+ wxString Capitalize() const { return wxString(*this).MakeCapitalized(); }
// trimming/padding whitespace (either side) and truncating
// remove spaces from left or from right (default) side