// Purpose: interface of wxStringBuffer, wxString
// Author: wxWidgets team
// RCS-ID: $Id$
-// Licence: wxWindows license
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
/**
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);
@see wxString::From8BitData()
*/
- const char* To8BitData() const;
-
- /**
- @overload
- */
- const wxCharBuffer To8BitData() const;
+ const wxScopedCharBuffer To8BitData() const;
/**
Converts the string to an ASCII, 7-bit string in the form of
*/
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().
*/
Note that if @c wxUSE_PRINTF_POS_PARAMS is set to 1, then this function supports
Unix98-style positional parameters:
+ @code
+ wxString str;
+
+ str.Printf(wxT("%d %d %d"), 1, 2, 3);
+ // str now contains "1 2 3"
+
+ str.Printf(wxT("%2$d %3$d %1$d"), 1, 2, 3);
+ // str now contains "2 3 1"
+ @endcode
+
@note This function will use a safe version of @e vsprintf() (usually called
@e vsnprintf()) whenever available to always allocate the buffer of correct
size. Unfortunately, this function is not available on all platforms and the
static wxString FromAscii(char c);
//@}
+ /**
+ Returns a string with the textual representation of the number in C
+ locale.
+
+ Unlike FromDouble() the string returned by this function always uses
+ the period character as decimal separator, independently of the current
+ locale.
+
+ @since 2.9.1
+
+ @see ToCDouble()
+ */
+ static wxString FromCDouble(double val);
+
+ /**
+ Returns a string with the textual representation of the number.
+
+ This is a simple wrapper for @code wxString::Format("%g", val)
+ @endcode.
+
+ Notice that the string returned by this function uses the decimal
+ separator appropriate for the current locale, e.g. @c "," and not a
+ period in French locale. Use FromCDouble() if this is unwanted.
+
+ @since 2.9.1
+
+ @see ToDouble()
+ */
+ static wxString FromDouble(double val);
+
//@{
/**
Converts C string encoded in UTF-8 to wxString.