Add wxString ctor from wxScopedCharBuffer and wxMBConv

This is more convenient and less error prone than using the existing
ctor taking char pointer and length as the buffer contains both.

Also add the corresponding assign() overload for consistency.

See #16490.
This commit is contained in:
Vadim Zeitlin
2017-12-06 03:38:39 +01:00
parent 6e678e3a85
commit 140d6fea88

View File

@@ -1162,6 +1162,9 @@ public:
wxString(const wxScopedWCharBuffer& buf) wxString(const wxScopedWCharBuffer& buf)
{ assign(buf.data(), buf.length()); } { assign(buf.data(), buf.length()); }
wxString(const wxScopedCharBuffer& buf, const wxMBConv& conv)
{ assign(buf, conv); }
// NB: this version uses m_impl.c_str() to force making a copy of the // NB: this version uses m_impl.c_str() to force making a copy of the
// string, so that "wxString(str.c_str())" idiom for passing strings // string, so that "wxString(str.c_str())" idiom for passing strings
// between threads works // between threads works
@@ -2539,6 +2542,13 @@ public:
{ return assign(str.AsString()); } { return assign(str.AsString()); }
wxString& assign(const wxScopedCharBuffer& str) wxString& assign(const wxScopedCharBuffer& str)
{ return assign(str.data(), str.length()); } { return assign(str.data(), str.length()); }
wxString& assign(const wxScopedCharBuffer& buf, const wxMBConv& conv)
{
SubstrBufFromMB str(ImplStr(buf.data(), buf.length(), conv));
m_impl.assign(str.data, str.len);
return *this;
}
wxString& assign(const wxScopedWCharBuffer& str) wxString& assign(const wxScopedWCharBuffer& str)
{ return assign(str.data(), str.length()); } { return assign(str.data(), str.length()); }
wxString& assign(const wxCStrData& str, size_t len) wxString& assign(const wxCStrData& str, size_t len)