inline ~wxCStrData();
- // methods defined inline below must be declared inline or mingw32 3.4.5
- // warns about "<symbol> defined locally after being referenced with
- // dllimport linkage"
-#if wxUSE_UNICODE_WCHAR
- inline
-#endif
- const wchar_t* AsWChar() const;
+ // AsWChar() and AsChar() can't be defined here as they use wxString and so
+ // must come after it and because of this won't be inlined when called from
+ // wxString methods (without a lot of work to extract these wxString methods
+ // from inside the class itself). But we still define them being inline
+ // below to let compiler inline them from elsewhere. And because of this we
+ // must declare them as inline here because otherwise some compilers give
+ // warnings about them, e.g. mingw32 3.4.5 warns about "<symbol> defined
+ // locally after being referenced with dllimport linkage" while IRIX
+ // mipsPro 7.4 warns about "function declared inline after being called".
+ inline const wchar_t* AsWChar() const;
operator const wchar_t*() const { return AsWChar(); }
-#if !wxUSE_UNICODE || wxUSE_UTF8_LOCALE_ONLY
- inline
-#endif
- const char* AsChar() const;
+ inline const char* AsChar() const;
const unsigned char* AsUnsignedChar() const
{ return (const unsigned char *) AsChar(); }
operator const char*() const { return AsChar(); }
// Unlike ctor from std::string, we provide conversion to std::string only
// if wxUSE_STL and not merely wxUSE_STD_STRING (which is on by default),
- // because it conflicts with operator const char/wchar_t*:
-#if wxUSE_STL
+ // because it conflicts with operator const char/wchar_t* but we still
+ // provide explicit conversions to std::[w]string for convenience in any case
+#if wxUSE_STD_STRING
+ // We can avoid a copy if we already use this string type internally,
+ // otherwise we create a copy on the fly:
#if wxUSE_UNICODE_WCHAR && wxUSE_STL_BASED_WXSTRING
- // wxStringImpl is std::string in the encoding we want
- operator const wxStdWideString&() const { return m_impl; }
+ #define wxStringToStdWstringRetType const wxStdWideString&
+ const wxStdWideString& ToStdWstring() const { return m_impl; }
#else
// wxStringImpl is either not std::string or needs conversion
- operator wxStdWideString() const
+ #define wxStringToStdWstringRetType wxStdWideString
+ wxStdWideString ToStdWstring() const
{
wxScopedWCharBuffer buf(wc_str());
return wxStdWideString(buf.data(), buf.length());
#if (!wxUSE_UNICODE || wxUSE_UTF8_LOCALE_ONLY) && wxUSE_STL_BASED_WXSTRING
// wxStringImpl is std::string in the encoding we want
- operator const std::string&() const { return m_impl; }
+ #define wxStringToStdStringRetType const std::string&
+ const std::string& ToStdString() const { return m_impl; }
#else
// wxStringImpl is either not std::string or needs conversion
- operator std::string() const
+ #define wxStringToStdStringRetType std::string
+ std::string ToStdString() const
{
wxScopedCharBuffer buf(mb_str());
return std::string(buf.data(), buf.length());
}
#endif
+
+#if wxUSE_STL
+ // In wxUSE_STL case we also provide implicit conversions as there is no
+ // ambiguity with the const char/wchar_t* ones as they are disabled in this
+ // build (for consistency with std::basic_string<>)
+ operator wxStringToStdStringRetType() const { return ToStdString(); }
+ operator wxStringToStdWstringRetType() const { return ToStdWstring(); }
#endif // wxUSE_STL
+#undef wxStringToStdStringRetType
+#undef wxStringToStdWstringRetType
+
+#endif // wxUSE_STD_STRING
+
wxString Clone() const
{
// make a deep copy of the string, i.e. the returned string will have
// insert a long long if they exist and aren't longs
wxString& operator<<(wxLongLong_t ll)
{
- const wxChar *fmt = wxT("%") wxLongLongFmtSpec wxT("d");
- return (*this) << Format(fmt, ll);
+ return (*this) << Format("%" wxLongLongFmtSpec "d", ll);
}
// insert an unsigned long long
wxString& operator<<(wxULongLong_t ull)
{
- const wxChar *fmt = wxT("%") wxLongLongFmtSpec wxT("u");
- return (*this) << Format(fmt , ull);
+ return (*this) << Format("%" wxLongLongFmtSpec "u" , ull);
}
#endif // wxLongLong_t && !wxLongLongIsLong
// insert a float into string
// convert to a double
bool ToDouble(double *val) const;
-#if wxUSE_XLOCALE
// conversions to numbers using C locale
// convert to a signed integer
bool ToCLong(long *val, int base = 10) const;
bool ToCULong(unsigned long *val, int base = 10) const;
// convert to a double
bool ToCDouble(double *val) const;
-#endif
-
+
+ // create a string representing the given floating point number
+ // in the current locale
+ static wxString FromDouble(double val)
+ { return wxString::Format(wxS("%g"), val); }
+ // in C locale
+ static wxString FromCDouble(double val);
+
#ifndef wxNEEDS_WXSTRING_PRINTF_MIXIN
// formatted input/output
// as sprintf(), returns the number of characters written or < 0 on error