Add overloads of wxString::FromUTF8/FromUTF8Unchecked taking a std::string
See #17461.
This commit is contained in:
@@ -1611,6 +1611,24 @@ public:
|
|||||||
return FromImpl(wxStringImpl(utf8, len));
|
return FromImpl(wxStringImpl(utf8, len));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if wxUSE_STD_STRING
|
||||||
|
static wxString FromUTF8Unchecked(const std::string& utf8)
|
||||||
|
{
|
||||||
|
wxASSERT( wxStringOperations::IsValidUtf8String(utf8.c_str(), utf8.length()) );
|
||||||
|
/*
|
||||||
|
Note that, under wxUSE_UNICODE_UTF8 and wxUSE_STD_STRING, wxStringImpl can be
|
||||||
|
initialized with a std::string whether wxUSE_STL_BASED_WXSTRING is 1 or not.
|
||||||
|
*/
|
||||||
|
return FromImpl(utf8);
|
||||||
|
}
|
||||||
|
static wxString FromUTF8(const std::string& utf8)
|
||||||
|
{
|
||||||
|
if ( utf8.empty() || !wxStringOperations::IsValidUtf8String(utf8.c_str(), utf8.length()) )
|
||||||
|
return wxString();
|
||||||
|
return FromImpl(utf8);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
const wxScopedCharBuffer utf8_str() const
|
const wxScopedCharBuffer utf8_str() const
|
||||||
{ return wxCharBuffer::CreateNonOwned(m_impl.c_str(), m_impl.length()); }
|
{ return wxCharBuffer::CreateNonOwned(m_impl.c_str(), m_impl.length()); }
|
||||||
|
|
||||||
@@ -1627,6 +1645,12 @@ public:
|
|||||||
"string must be valid UTF-8" );
|
"string must be valid UTF-8" );
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
#if wxUSE_STD_STRING
|
||||||
|
static wxString FromUTF8(const std::string& utf8)
|
||||||
|
{ return FromUTF8(utf8.c_str(), utf8.length()); }
|
||||||
|
static wxString FromUTF8Unchecked(const std::string& utf8)
|
||||||
|
{ return FromUTF8Unchecked(utf8.c_str(), utf8.length()); }
|
||||||
|
#endif
|
||||||
const wxScopedCharBuffer utf8_str() const { return mb_str(wxMBConvUTF8()); }
|
const wxScopedCharBuffer utf8_str() const { return mb_str(wxMBConvUTF8()); }
|
||||||
#else // ANSI
|
#else // ANSI
|
||||||
static wxString FromUTF8(const char *utf8)
|
static wxString FromUTF8(const char *utf8)
|
||||||
@@ -1654,6 +1678,12 @@ public:
|
|||||||
|
|
||||||
return wxString(buf.data(), wlen);
|
return wxString(buf.data(), wlen);
|
||||||
}
|
}
|
||||||
|
#if wxUSE_STD_STRING
|
||||||
|
static wxString FromUTF8(const std::string& utf8)
|
||||||
|
{ return FromUTF8(utf8.c_str(), utf8.length()); }
|
||||||
|
static wxString FromUTF8Unchecked(const std::string& utf8)
|
||||||
|
{ return FromUTF8Unchecked(utf8.c_str(), utf8.length()); }
|
||||||
|
#endif
|
||||||
const wxScopedCharBuffer utf8_str() const
|
const wxScopedCharBuffer utf8_str() const
|
||||||
{ return wxMBConvUTF8().cWC2MB(wc_str()); }
|
{ return wxMBConvUTF8().cWC2MB(wc_str()); }
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1824,10 +1824,14 @@ public:
|
|||||||
alternative to this function called FromUTF8Unchecked() which, unlike
|
alternative to this function called FromUTF8Unchecked() which, unlike
|
||||||
this one, doesn't check that the input string is valid.
|
this one, doesn't check that the input string is valid.
|
||||||
|
|
||||||
|
The overload taking @c std::string is only available starting with
|
||||||
|
wxWidgets 3.1.1.
|
||||||
|
|
||||||
@since 2.8.4
|
@since 2.8.4
|
||||||
*/
|
*/
|
||||||
static wxString FromUTF8(const char* s);
|
static wxString FromUTF8(const char* s);
|
||||||
static wxString FromUTF8(const char* s, size_t len);
|
static wxString FromUTF8(const char* s, size_t len);
|
||||||
|
static wxString FromUTF8(const std::string& s);
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
//@{
|
//@{
|
||||||
@@ -1844,10 +1848,14 @@ public:
|
|||||||
string to this function will result in creating a corrupted wxString
|
string to this function will result in creating a corrupted wxString
|
||||||
and all the subsequent operations on it will be undefined.
|
and all the subsequent operations on it will be undefined.
|
||||||
|
|
||||||
|
The overload taking @c std::string is only available starting with
|
||||||
|
wxWidgets 3.1.1.
|
||||||
|
|
||||||
@since 2.8.9
|
@since 2.8.9
|
||||||
*/
|
*/
|
||||||
static wxString FromUTF8Unchecked(const char* s);
|
static wxString FromUTF8Unchecked(const char* s);
|
||||||
static wxString FromUTF8Unchecked(const char* s, size_t len);
|
static wxString FromUTF8Unchecked(const char* s, size_t len);
|
||||||
|
static wxString FromUTF8Unchecked(const std::string& s);
|
||||||
//@}
|
//@}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user