diff --git a/include/wx/string.h b/include/wx/string.h index c23586e314..eca035c5f9 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -1611,6 +1611,24 @@ public: 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 { return wxCharBuffer::CreateNonOwned(m_impl.c_str(), m_impl.length()); } @@ -1627,6 +1645,12 @@ public: "string must be valid UTF-8" ); 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()); } #else // ANSI static wxString FromUTF8(const char *utf8) @@ -1654,6 +1678,12 @@ public: 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 { return wxMBConvUTF8().cWC2MB(wc_str()); } #endif diff --git a/interface/wx/string.h b/interface/wx/string.h index 0b12290ab9..2bba347512 100644 --- a/interface/wx/string.h +++ b/interface/wx/string.h @@ -1824,10 +1824,14 @@ public: alternative to this function called FromUTF8Unchecked() which, unlike 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 */ static wxString FromUTF8(const char* s); 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 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 */ static wxString FromUTF8Unchecked(const char* s); static wxString FromUTF8Unchecked(const char* s, size_t len); + static wxString FromUTF8Unchecked(const std::string& s); //@} };