Add wxString::ToStdString() and ToStdWstring().

These trivial helper functions are available in all builds (provided that
wxUSE_STD_STRING is not explicitly set to non-default 0 value) unlike implicit
conversions to std::[w]string which are only available when wxUSE_STL==1.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63938 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-04-11 11:08:49 +00:00
parent 13f0c85aa4
commit e3ab69523b
4 changed files with 70 additions and 10 deletions

View File

@@ -181,11 +181,15 @@ public:
/**
Constructs a string from @a str using the using the current locale encoding
to convert it to Unicode (wxConvLibc).
@see ToStdString()
*/
wxString(const std::string& str);
/**
Constructs a string from @a str.
@see ToStdWstring()
*/
wxString(const std::wstring& str);
@@ -509,6 +513,36 @@ public:
*/
const wxCharBuffer ToAscii() const;
/**
Return the string as an std::string in current locale encoding.
Note that if the conversion of (Unicode) string contents to the current
locale fails, the return string will be empty. Be sure to check for
this to avoid silent data loss.
Instead of using this function it's also possible to write
@code
std::string s;
wxString wxs;
...
s = std::string(wxs);
@endcode
but using ToStdString() may make the code more clear.
@since 2.9.1
*/
std::string ToStdString() const;
/**
Return the string as an std::wstring.
Unlike ToStdString(), there is no danger of data loss when using this
function.
@since 2.9.1
*/
std::wstring ToStdWstring() const;
/**
Same as utf8_str().
*/