diff --git a/include/wx/any.h b/include/wx/any.h index 4883214b46..7fb297956c 100644 --- a/include/wx/any.h +++ b/include/wx/any.h @@ -504,8 +504,10 @@ extern WXDLLIMPEXP_BASE bool wxAnyConvertString(const wxString& value, wxAnyValueBuffer& dst); WX_ANY_DEFINE_CONVERTIBLE_TYPE_BASE(wxString, wxString, wxAnyConvertString) +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING WX_ANY_DEFINE_CONVERTIBLE_TYPE(const char*, ConstCharPtr, wxAnyConvertString, wxString) +#endif WX_ANY_DEFINE_CONVERTIBLE_TYPE(const wchar_t*, ConstWchar_tPtr, wxAnyConvertString, wxString) @@ -757,11 +759,13 @@ public: } // These two constructors are needed to deal with string literals +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxAny(const char* value) { m_type = wxAnyValueTypeImpl::sm_instance.get(); wxAnyValueTypeImpl::SetValue(value, m_buffer); } +#endif wxAny(const wchar_t* value) { m_type = wxAnyValueTypeImpl::sm_instance.get(); @@ -865,11 +869,13 @@ public: #endif // These two operators are needed to deal with string literals +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxAny& operator=(const char* value) { Assign(value); return *this; } +#endif wxAny& operator=(const wchar_t* value) { Assign(value); @@ -888,8 +894,10 @@ public: return value == value2; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING bool operator==(const char* value) const { return (*this) == wxString(value); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING bool operator==(const wchar_t* value) const { return (*this) == wxString(value); } @@ -1017,6 +1025,13 @@ public: #endif private: +#ifdef wxNO_IMPLICIT_WXSTRING_ENCODING + wxAny(const char*); // Disabled + wxAny& operator=(const char *&value); // Disabled + wxAny& operator=(const char value[]); // Disabled + wxAny& operator==(const char *value); // Disabled +#endif + // Assignment functions void AssignAny(const wxAny& any) { diff --git a/include/wx/anystr.h b/include/wx/anystr.h index 082d83f151..3f2fec3613 100644 --- a/include/wx/anystr.h +++ b/include/wx/anystr.h @@ -65,6 +65,7 @@ public: bool operator!() const { return !((bool)*this); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING // and these are the conversions operator which allow to assign the result // of FuncReturningAnyStrPtr() to either char* or wxChar* (i.e. wchar_t*) operator const char *() const @@ -94,6 +95,7 @@ public: return p; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING operator const wchar_t *() const { diff --git a/include/wx/artprov.h b/include/wx/artprov.h index 29e0c71b26..81681522ba 100644 --- a/include/wx/artprov.h +++ b/include/wx/artprov.h @@ -27,8 +27,8 @@ class wxArtProviderModule; typedef wxString wxArtClient; typedef wxString wxArtID; -#define wxART_MAKE_CLIENT_ID_FROM_STR(id) ((id) + "_C") -#define wxART_MAKE_CLIENT_ID(id) (#id "_C") +#define wxART_MAKE_CLIENT_ID_FROM_STR(id) ((id) + wxASCII_STR("_C")) +#define wxART_MAKE_CLIENT_ID(id) wxASCII_STR(#id "_C") #define wxART_MAKE_ART_ID_FROM_STR(id) (id) #define wxART_MAKE_ART_ID(id) (#id) diff --git a/include/wx/catch_cppunit.h b/include/wx/catch_cppunit.h index 66e660b158..652367c7e6 100644 --- a/include/wx/catch_cppunit.h +++ b/include/wx/catch_cppunit.h @@ -90,7 +90,7 @@ namespace Catch { #if wxUSE_UNICODE if ( !iswprint(*i) ) - s += wxString::Format("\\u%04X", *i).ToStdString(); + s += wxString::Format(wxASCII_STR("\\u%04X"), *i).ToAscii(); else #endif // wxUSE_UNICODE s += *i; @@ -278,10 +278,10 @@ inline std::string wxGetCurrentTestName() // Use this macro to assert with the given formatted message (it should contain // the format string and arguments in a separate pair of parentheses) #define WX_ASSERT_MESSAGE(msg, cond) \ - CPPUNIT_ASSERT_MESSAGE(std::string(wxString::Format msg .mb_str()), (cond)) + CPPUNIT_ASSERT_MESSAGE(std::string(wxString::Format msg .mb_str(wxConvLibc)), (cond)) #define WX_ASSERT_EQUAL_MESSAGE(msg, expected, actual) \ - CPPUNIT_ASSERT_EQUAL_MESSAGE(std::string(wxString::Format msg .mb_str()), \ + CPPUNIT_ASSERT_EQUAL_MESSAGE(std::string(wxString::Format msg .mb_str(wxConvLibc)), \ (expected), (actual)) #endif // _WX_CATCH_CPPUNIT_H_ diff --git a/include/wx/colour.h b/include/wx/colour.h index 87253462b5..4e9e0a1854 100644 --- a/include/wx/colour.h +++ b/include/wx/colour.h @@ -20,6 +20,12 @@ class WXDLLIMPEXP_FWD_CORE wxColour; // // It avoids the need to repeat these lines across all colour.h files, since // Set() is a virtual function and thus cannot be called by wxColourBase ctors +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING +#define wxWXCOLOUR_CTOR_FROM_CHAR \ + wxColour(const char *colourName) { Init(); Set(colourName); } +#else // wxNO_IMPLICIT_WXSTRING_ENCODING +#define wxWXCOLOUR_CTOR_FROM_CHAR +#endif #define DEFINE_STD_WXCOLOUR_CONSTRUCTORS \ wxColour() { Init(); } \ wxColour(ChannelType red, \ @@ -29,7 +35,7 @@ class WXDLLIMPEXP_FWD_CORE wxColour; { Init(); Set(red, green, blue, alpha); } \ wxColour(unsigned long colRGB) { Init(); Set(colRGB ); } \ wxColour(const wxString& colourName) { Init(); Set(colourName); } \ - wxColour(const char *colourName) { Init(); Set(colourName); } \ + wxWXCOLOUR_CTOR_FROM_CHAR \ wxColour(const wchar_t *colourName) { Init(); Set(colourName); } diff --git a/include/wx/confbase.h b/include/wx/confbase.h index 7188f50790..db98d725e3 100644 --- a/include/wx/confbase.h +++ b/include/wx/confbase.h @@ -225,8 +225,10 @@ public: // we have to provide a separate version for C strings as otherwise the // template Read() would be used +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString Read(const wxString& key, const char* defVal) const { return Read(key, wxString(defVal)); } +#endif wxString Read(const wxString& key, const wchar_t* defVal) const { return Read(key, wxString(defVal)); } @@ -268,10 +270,12 @@ public: // we have to provide a separate version for C strings as otherwise they // would be converted to bool and not to wxString as expected! +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING bool Write(const wxString& key, const char *value) { return Write(key, wxString(value)); } bool Write(const wxString& key, const unsigned char *value) { return Write(key, wxString(value)); } +#endif bool Write(const wxString& key, const wchar_t *value) { return Write(key, wxString(value)); } diff --git a/include/wx/gtk/dataform.h b/include/wx/gtk/dataform.h index 5df97d8b85..9389a99765 100644 --- a/include/wx/gtk/dataform.h +++ b/include/wx/gtk/dataform.h @@ -24,7 +24,9 @@ public: // we have to provide all the overloads to allow using strings instead of // data formats (as a lot of existing code does) wxDataFormat( const wxString& id ) { InitFromString(id); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxDataFormat( const char *id ) { InitFromString(id); } +#endif wxDataFormat( const wchar_t *id ) { InitFromString(id); } wxDataFormat( const wxCStrData& id ) { InitFromString(id); } diff --git a/include/wx/list.h b/include/wx/list.h index ee55b58e9c..866e2fb2bc 100644 --- a/include/wx/list.h +++ b/include/wx/list.h @@ -338,8 +338,10 @@ public: { m_key.integer = i; } wxListKey(const wxString& s) : m_keyType(wxKEY_STRING) { m_key.string = new wxString(s); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxListKey(const char *s) : m_keyType(wxKEY_STRING) { m_key.string = new wxString(s); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxListKey(const wchar_t *s) : m_keyType(wxKEY_STRING) { m_key.string = new wxString(s); } diff --git a/include/wx/mimetype.h b/include/wx/mimetype.h index 0ee1952911..efa807d7bf 100644 --- a/include/wx/mimetype.h +++ b/include/wx/mimetype.h @@ -138,11 +138,15 @@ public: // Do not use, it's used by the ctor only. struct CtorString { +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING CtorString(const char *str) : m_str(str) {} +#endif CtorString(const wchar_t *str) : m_str(str) {} CtorString(const wxString& str) : m_str(str) {} CtorString(const wxCStrData& str) : m_str(str) {} +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING CtorString(const wxScopedCharBuffer& str) : m_str(str) {} +#endif CtorString(const wxScopedWCharBuffer& str) : m_str(str) {} operator const wxString*() const { return &m_str; } diff --git a/include/wx/msgdlg.h b/include/wx/msgdlg.h index 28e53d320b..ede4038654 100644 --- a/include/wx/msgdlg.h +++ b/include/wx/msgdlg.h @@ -45,10 +45,12 @@ public: { } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING ButtonLabel(const char *label) : m_label(label), m_stockId(wxID_NONE) { } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING ButtonLabel(const wchar_t *label) : m_label(label), m_stockId(wxID_NONE) diff --git a/include/wx/strconv.h b/include/wx/strconv.h index 8474876500..c1b070d36a 100644 --- a/include/wx/strconv.h +++ b/include/wx/strconv.h @@ -719,5 +719,19 @@ extern WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvUI; #define wxSafeConvertWX2MB(s) (s) #endif // Unicode/ANSI +// Macro that indicates the default encoding for converting C strings +// to wxString. It provides a default value for a const wxMBConv& +// parameter (i.e. wxConvLibc) unless wxNO_IMPLICIT_WXSTRING_ENCODING +// is defined. +// +// Intended use: +// wxString(const char *data, ..., +// const wxMBConv &conv wxSTRING_DEFAULT_CONV_ARG); +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING +#define wxSTRING_DEFAULT_CONV_ARG = wxConvLibc +#else +#define wxSTRING_DEFAULT_CONV_ARG +#endif + #endif // _WX_STRCONV_H_ diff --git a/include/wx/string.h b/include/wx/string.h index fe6394dbe5..aaa46e6af4 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -90,6 +90,9 @@ namespace wxPrivate // macros // --------------------------------------------------------------------------- +// Shorthand for instantiating ASCII strings +#define wxASCII_STR(s) wxString::FromAscii(s) + // These macros are not used by wxWidgets itself any longer and are only // preserved for compatibility with the user code that might be still using // them. Do _not_ use them in the new code, just use const_cast<> instead. @@ -143,7 +146,9 @@ private: public: // Ctor constructs the object from char literal; they are needed to make // operator?: compile and they intentionally take char*, not const char* +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline wxCStrData(char *buf); +#endif inline wxCStrData(wchar_t *buf); inline wxCStrData(const wxCStrData& data); @@ -161,6 +166,7 @@ public: inline const wchar_t* AsWChar() const; operator const wchar_t*() const { return AsWChar(); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline const char* AsChar() const; const unsigned char* AsUnsignedChar() const { return (const unsigned char *) AsChar(); } @@ -174,6 +180,7 @@ public: { return wxScopedCharBuffer::CreateNonOwned(AsChar()); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING const wxScopedWCharBuffer AsWCharBuf() const { @@ -300,9 +307,16 @@ private: // these methods are not implemented - there is _no_ conversion from int to // string, you're doing something wrong if the compiler wants to call it! // - // try `s << i' or `s.Printf("%d", i)' instead + // try `s << i' or `s.Printf(wxASCII_STR("%d"), i)' instead wxString(int); +#ifdef wxNO_IMPLICIT_WXSTRING_ENCODING + // These constructors are disabled because the encoding must be explicit + explicit wxString(const char *psz); + explicit wxString(const char *psz, size_t nLength); + explicit wxString(const unsigned char *psz); + explicit wxString(const unsigned char *psz, size_t nLength); +#endif // buffer for holding temporary substring when using any of the methods // that take (char*,size_t) or (wchar_t*,size_t) arguments: @@ -358,22 +372,24 @@ private: static const SubstrBufFromWC ImplStr(const wchar_t* str, size_t n) { return SubstrBufFromWC(str, (str && n == npos) ? wxWcslen(str) : n); } static wxScopedWCharBuffer ImplStr(const char* str, - const wxMBConv& conv = wxConvLibc) + const wxMBConv& conv wxSTRING_DEFAULT_CONV_ARG) { return ConvertStr(str, npos, conv).data; } static SubstrBufFromMB ImplStr(const char* str, size_t n, - const wxMBConv& conv = wxConvLibc) + const wxMBConv& conv wxSTRING_DEFAULT_CONV_ARG) { return ConvertStr(str, n, conv); } #else static const char* ImplStr(const char* str, - const wxMBConv& WXUNUSED(conv) = wxConvLibc) + const wxMBConv& WXUNUSED(conv) wxSTRING_DEFAULT_CONV_ARG) { return str ? str : ""; } static const SubstrBufFromMB ImplStr(const char* str, size_t n, - const wxMBConv& WXUNUSED(conv) = wxConvLibc) + const wxMBConv& WXUNUSED(conv) wxSTRING_DEFAULT_CONV_ARG) { return SubstrBufFromMB(str, (str && n == npos) ? wxStrlen(str) : n); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING static wxScopedCharBuffer ImplStr(const wchar_t* str) { return ConvertStr(str, npos, wxConvLibc).data; } static SubstrBufFromWC ImplStr(const wchar_t* str, size_t n) { return ConvertStr(str, n, wxConvLibc); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING #endif // translates position index in wxString to/from index in underlying @@ -396,10 +412,10 @@ private: #else // wxUSE_UNICODE_UTF8 static wxScopedCharBuffer ImplStr(const char* str, - const wxMBConv& conv = wxConvLibc) + const wxMBConv& conv wxSTRING_DEFAULT_CONV_ARG) { return ConvertStr(str, npos, conv).data; } static SubstrBufFromMB ImplStr(const char* str, size_t n, - const wxMBConv& conv = wxConvLibc) + const wxMBConv& conv wxSTRING_DEFAULT_CONV_ARG) { return ConvertStr(str, n, conv); } static wxScopedCharBuffer ImplStr(const wchar_t* str) @@ -1128,13 +1144,17 @@ public: wxString(size_t nRepeat, wchar_t ch) { assign(nRepeat, ch); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING // ctors from char* strings: wxString(const char *psz) : m_impl(ImplStr(psz)) {} +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString(const char *psz, const wxMBConv& conv) : m_impl(ImplStr(psz, conv)) {} +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString(const char *psz, size_t nLength) { assign(psz, nLength); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString(const char *psz, const wxMBConv& conv, size_t nLength) { SubstrBufFromMB str(ImplStr(psz, nLength, conv)); @@ -1142,12 +1162,16 @@ public: } // and unsigned char*: +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString(const unsigned char *psz) : m_impl(ImplStr((const char*)psz)) {} +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString(const unsigned char *psz, const wxMBConv& conv) : m_impl(ImplStr((const char*)psz, conv)) {} +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString(const unsigned char *psz, size_t nLength) { assign((const char*)psz, nLength); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString(const unsigned char *psz, const wxMBConv& conv, size_t nLength) { SubstrBufFromMB str(ImplStr((const char*)psz, nLength, conv)); @@ -1164,8 +1188,10 @@ public: wxString(const wchar_t *pwz, const wxMBConv& WXUNUSED(conv), size_t nLength) { assign(pwz, nLength); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString(const wxScopedCharBuffer& buf) { assign(buf.data(), buf.length()); } +#endif wxString(const wxScopedWCharBuffer& buf) { assign(buf.data(), buf.length()); } @@ -1214,6 +1240,7 @@ public: { assign(str.c_str(), str.length()); } #endif +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING #if !wxUSE_UNICODE // ANSI build // FIXME-UTF8: do this in UTF8 build #if wxUSE_UTF8_LOCALE_ONLY, too wxString(const std::string& str) : m_impl(str) {} @@ -1221,6 +1248,7 @@ public: wxString(const std::string& str) { assign(str.c_str(), str.length()); } #endif +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING #endif // wxUSE_STD_STRING // Also always provide explicit conversions to std::[w]string in any case, @@ -1261,7 +1289,7 @@ public: #else // wxStringImpl is either not std::string or needs conversion #define wxStringToStdStringRetType std::string - std::string ToStdString(const wxMBConv& conv = wxConvLibc) const + std::string ToStdString(const wxMBConv& conv wxSTRING_DEFAULT_CONV_ARG) const { wxScopedCharBuffer buf(mb_str(conv)); return std::string(buf.data(), buf.length()); @@ -1553,7 +1581,7 @@ public: // conversion to *non-const* multibyte or widestring buffer; modifying // returned buffer won't affect the string, these methods are only useful // for passing values to const-incorrect functions - wxWritableCharBuffer char_str(const wxMBConv& conv = wxConvLibc) const + wxWritableCharBuffer char_str(const wxMBConv& conv wxSTRING_DEFAULT_CONV_ARG) const { return mb_str(conv); } wxWritableWCharBuffer wchar_str() const { return wc_str(); } @@ -1767,7 +1795,7 @@ public: return AsCharBuf(conv); } #else // !wxUSE_UTF8_LOCALE_ONLY - const wxScopedCharBuffer mb_str(const wxMBConv& conv = wxConvLibc) const + const wxScopedCharBuffer mb_str(const wxMBConv& conv wxSTRING_DEFAULT_CONV_ARG) const { return AsCharBuf(conv); } @@ -1799,11 +1827,13 @@ public: const wxWX2MBbuf mbc_str() const { return mb_str(); } - const wxScopedWCharBuffer wc_str(const wxMBConv& conv = wxConvLibc) const + const wxScopedWCharBuffer wc_str(const wxMBConv& conv wxSTRING_DEFAULT_CONV_ARG) const { return AsWCharBuf(conv); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING const wxScopedCharBuffer fn_str() const { return wxConvFile.cWC2WX( wc_str( wxConvLibc ) ); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING #endif // Unicode/ANSI #if wxUSE_UNICODE_UTF8 @@ -1855,6 +1885,7 @@ public: // from a C string - STL probably will crash on NULL, // so we need to compensate in that case #if wxUSE_STL_BASED_WXSTRING +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& operator=(const char *psz) { wxSTRING_INVALIDATE_CACHE(); @@ -1866,6 +1897,7 @@ public: return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& operator=(const wchar_t *pwz) { @@ -1879,6 +1911,7 @@ public: return *this; } #else // !wxUSE_STL_BASED_WXSTRING +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& operator=(const char *psz) { wxSTRING_INVALIDATE_CACHE(); @@ -1887,6 +1920,7 @@ public: return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& operator=(const wchar_t *pwz) { @@ -1898,15 +1932,19 @@ public: } #endif // wxUSE_STL_BASED_WXSTRING/!wxUSE_STL_BASED_WXSTRING +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& operator=(const unsigned char *psz) { return operator=((const char*)psz); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING // from wxScopedWCharBuffer wxString& operator=(const wxScopedWCharBuffer& s) { return assign(s); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING // from wxScopedCharBuffer wxString& operator=(const wxScopedCharBuffer& s) { return assign(s); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING // string concatenation // in place concatenation @@ -1927,8 +1965,10 @@ public: return *this; } // string += C string +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& operator<<(const char *psz) { append(psz); return *this; } +#endif wxString& operator<<(const wchar_t *pwz) { append(pwz); return *this; } wxString& operator<<(const wxCStrData& psz) @@ -1943,8 +1983,10 @@ public: // string += buffer (i.e. from wxGetString) wxString& operator<<(const wxScopedWCharBuffer& s) { return append(s); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& operator<<(const wxScopedCharBuffer& s) { return append(s); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING // string += C string wxString& Append(const wxString& s) @@ -1956,24 +1998,32 @@ public: append(s); return *this; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& Append(const char* psz) { append(psz); return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& Append(const wchar_t* pwz) { append(pwz); return *this; } wxString& Append(const wxCStrData& psz) { append(psz); return *this; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& Append(const wxScopedCharBuffer& psz) { append(psz); return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& Append(const wxScopedWCharBuffer& psz) { append(psz); return *this; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& Append(const char* psz, size_t nLen) { append(psz, nLen); return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& Append(const wchar_t* pwz, size_t nLen) { append(pwz, nLen); return *this; } wxString& Append(const wxCStrData& psz, size_t nLen) { append(psz, nLen); return *this; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& Append(const wxScopedCharBuffer& psz, size_t nLen) { append(psz, nLen); return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& Append(const wxScopedWCharBuffer& psz, size_t nLen) { append(psz, nLen); return *this; } // append count copies of given character @@ -2001,13 +2051,17 @@ public: // char with a string friend wxString WXDLLIMPEXP_BASE operator+(wxUniChar ch, const wxString& string); // string with C string +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string, const char *psz); +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING friend wxString WXDLLIMPEXP_BASE operator+(const wxString& string, const wchar_t *pwz); // C string with string +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING friend wxString WXDLLIMPEXP_BASE operator+(const char *psz, const wxString& string); +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING friend wxString WXDLLIMPEXP_BASE operator+(const wchar_t *pwz, const wxString& string); @@ -2028,12 +2082,12 @@ public: // insert a long long if they exist and aren't longs wxString& operator<<(wxLongLong_t ll) { - return (*this) << Format("%" wxLongLongFmtSpec "d", ll); + return (*this) << Format(wxASCII_STR("%" wxLongLongFmtSpec "d"), ll); } // insert an unsigned long long wxString& operator<<(wxULongLong_t ull) { - return (*this) << Format("%" wxLongLongFmtSpec "u" , ull); + return (*this) << Format(wxASCII_STR("%" wxLongLongFmtSpec "u") , ull); } #endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG // insert a float into string @@ -2045,16 +2099,20 @@ public: // string comparison // case-sensitive comparison (returns a value < 0, = 0 or > 0) +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING int Cmp(const char *psz) const { return compare(psz); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING int Cmp(const wchar_t *pwz) const { return compare(pwz); } int Cmp(const wxString& s) const { return compare(s); } int Cmp(const wxCStrData& s) const { return compare(s); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING int Cmp(const wxScopedCharBuffer& s) const { return compare(s); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING int Cmp(const wxScopedWCharBuffer& s) const { return compare(s); } // same as Cmp() but not case-sensitive @@ -2071,15 +2129,19 @@ public: #endif return (compareWithCase ? Cmp(str) : CmpNoCase(str)) == 0; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING bool IsSameAs(const char *str, bool compareWithCase = true) const { return (compareWithCase ? Cmp(str) : CmpNoCase(str)) == 0; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING bool IsSameAs(const wchar_t *str, bool compareWithCase = true) const { return (compareWithCase ? Cmp(str) : CmpNoCase(str)) == 0; } bool IsSameAs(const wxCStrData& str, bool compareWithCase = true) const { return IsSameAs(str.AsString(), compareWithCase); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING bool IsSameAs(const wxScopedCharBuffer& str, bool compareWithCase = true) const { return IsSameAs(str.data(), compareWithCase); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING bool IsSameAs(const wxScopedWCharBuffer& str, bool compareWithCase = true) const { return IsSameAs(str.data(), compareWithCase); } // comparison with a single character: returns true if equal @@ -2176,11 +2238,13 @@ public: const size_type idx = find(sub); return (idx == npos) ? wxNOT_FOUND : (int)idx; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING int Find(const char *sub) const // like strstr { const size_type idx = find(sub); return (idx == npos) ? wxNOT_FOUND : (int)idx; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING int Find(const wchar_t *sub) const // like strstr { const size_type idx = find(sub); @@ -2189,8 +2253,10 @@ public: int Find(const wxCStrData& sub) const { return Find(sub.AsString()); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING int Find(const wxScopedCharBuffer& sub) const { return Find(sub.data()); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING int Find(const wxScopedWCharBuffer& sub) const { return Find(sub.data()); } @@ -2335,11 +2401,13 @@ public: #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER // the 2 overloads below are for compatibility with the existing code using // pointers instead of iterators +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString(const char *first, const char *last) { SubstrBufFromMB str(ImplStr(first, last - first)); m_impl.assign(str.data, str.len); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString(const wchar_t *first, const wchar_t *last) { SubstrBufFromWC str(ImplStr(first, last - first)); @@ -2376,6 +2444,7 @@ public: } // append first n (or all if n == npos) characters of sz +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& append(const char *sz) { wxSTRING_INVALIDATE_CACHED_LENGTH(); @@ -2383,6 +2452,7 @@ public: m_impl.append(ImplStr(sz)); return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& append(const wchar_t *sz) { @@ -2392,6 +2462,7 @@ public: return *this; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& append(const char *sz, size_t n) { wxSTRING_INVALIDATE_CACHED_LENGTH(); @@ -2400,6 +2471,7 @@ public: m_impl.append(str.data, str.len); return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& append(const wchar_t *sz, size_t n) { wxSTRING_UPDATE_CACHED_LENGTH(n); @@ -2411,14 +2483,18 @@ public: wxString& append(const wxCStrData& str) { return append(str.AsString()); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& append(const wxScopedCharBuffer& str) { return append(str.data(), str.length()); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& append(const wxScopedWCharBuffer& str) { return append(str.data(), str.length()); } wxString& append(const wxCStrData& str, size_t n) { return append(str.AsString(), 0, n); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& append(const wxScopedCharBuffer& str, size_t n) { return append(str.data(), n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& append(const wxScopedWCharBuffer& str, size_t n) { return append(str.data(), n); } @@ -2459,8 +2535,10 @@ public: return *this; } #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& append(const char *first, const char *last) { return append(first, last - first); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& append(const wchar_t *first, const wchar_t *last) { return append(first, last - first); } wxString& append(const wxCStrData& first, const wxCStrData& last) @@ -2513,6 +2591,7 @@ public: } // same as `= first n (or all if n == npos) characters of sz' +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& assign(const char *sz) { wxSTRING_INVALIDATE_CACHE(); @@ -2521,6 +2600,7 @@ public: return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& assign(const wchar_t *sz) { @@ -2531,6 +2611,7 @@ public: return *this; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& assign(const char *sz, size_t n) { wxSTRING_INVALIDATE_CACHE(); @@ -2540,6 +2621,7 @@ public: return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& assign(const wchar_t *sz, size_t n) { @@ -2553,8 +2635,10 @@ public: wxString& assign(const wxCStrData& str) { return assign(str.AsString()); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& assign(const wxScopedCharBuffer& str) { return assign(str.data(), str.length()); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& assign(const wxScopedCharBuffer& buf, const wxMBConv& conv) { SubstrBufFromMB str(ImplStr(buf.data(), buf.length(), conv)); @@ -2566,8 +2650,10 @@ public: { return assign(str.data(), str.length()); } wxString& assign(const wxCStrData& str, size_t len) { return assign(str.AsString(), len); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& assign(const wxScopedCharBuffer& str, size_t len) { return assign(str.data(), len); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& assign(const wxScopedWCharBuffer& str, size_t len) { return assign(str.data(), len); } @@ -2603,8 +2689,10 @@ public: return *this; } #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& assign(const char *first, const char *last) { return assign(first, last - first); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& assign(const wchar_t *first, const wchar_t *last) { return assign(first, last - first); } wxString& assign(const wxCStrData& first, const wxCStrData& last) @@ -2613,12 +2701,16 @@ public: // string comparison int compare(const wxString& str) const; +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING int compare(const char* sz) const; +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING int compare(const wchar_t* sz) const; int compare(const wxCStrData& str) const { return compare(str.AsString()); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING int compare(const wxScopedCharBuffer& str) const { return compare(str.data()); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING int compare(const wxScopedWCharBuffer& str) const { return compare(str.data()); } // comparison with a substring @@ -2627,8 +2719,10 @@ public: int compare(size_t nStart, size_t nLen, const wxString& str, size_t nStart2, size_t nLen2) const; // substring comparison with first nCount characters of sz +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING int compare(size_t nStart, size_t nLen, const char* sz, size_t nCount = npos) const; +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING int compare(size_t nStart, size_t nLen, const wchar_t* sz, size_t nCount = npos) const; @@ -2648,6 +2742,7 @@ public: } // insert first n (or all if n == npos) characters of sz +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& insert(size_t nPos, const char *sz) { wxSTRING_INVALIDATE_CACHE(); @@ -2656,6 +2751,7 @@ public: return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& insert(size_t nPos, const wchar_t *sz) { @@ -2664,6 +2760,7 @@ public: m_impl.insert(PosToImpl(nPos), ImplStr(sz)); return *this; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& insert(size_t nPos, const char *sz, size_t n) { wxSTRING_UPDATE_CACHED_LENGTH(n); @@ -2673,6 +2770,7 @@ public: return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& insert(size_t nPos, const wchar_t *sz, size_t n) { @@ -2719,8 +2817,10 @@ public: } #if WXWIN_COMPATIBILITY_STRING_PTR_AS_ITER +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING void insert(iterator it, const char *first, const char *last) { insert(it - begin(), first, last - first); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING void insert(iterator it, const wchar_t *first, const wchar_t *last) { insert(it - begin(), first, last - first); } void insert(iterator it, const wxCStrData& first, const wxCStrData& last) @@ -2772,6 +2872,7 @@ public: } // replaces the substring of length nLen starting at nStart +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& replace(size_t nStart, size_t nLen, const char* sz) { wxSTRING_INVALIDATE_CACHE(); @@ -2782,6 +2883,7 @@ public: return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& replace(size_t nStart, size_t nLen, const wchar_t* sz) { @@ -2840,6 +2942,7 @@ public: } // replaces the substring with first nCount chars of sz +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& replace(size_t nStart, size_t nLen, const char* sz, size_t nCount) { @@ -2854,6 +2957,7 @@ public: return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& replace(size_t nStart, size_t nLen, const wchar_t* sz, size_t nCount) @@ -2882,6 +2986,7 @@ public: return *this; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& replace(iterator first, iterator last, const char* s) { wxSTRING_INVALIDATE_CACHE(); @@ -2890,6 +2995,7 @@ public: return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& replace(iterator first, iterator last, const wchar_t* s) { @@ -2900,6 +3006,7 @@ public: return *this; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& replace(iterator first, iterator last, const char* s, size_type n) { wxSTRING_INVALIDATE_CACHE(); @@ -2909,6 +3016,7 @@ public: return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& replace(iterator first, iterator last, const wchar_t* s, size_type n) { @@ -2952,9 +3060,11 @@ public: return *this; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& replace(iterator first, iterator last, const char *first1, const char *last1) { replace(first, last, first1, last1 - first1); return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& replace(iterator first, iterator last, const wchar_t *first1, const wchar_t *last1) { replace(first, last, first1, last1 - first1); return *this; } @@ -2978,18 +3088,22 @@ public: { return PosFromImpl(m_impl.find(str.m_impl, PosToImpl(nStart))); } // find first n characters of sz +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find(const char* sz, size_t nStart = 0, size_t n = npos) const { SubstrBufFromMB str(ImplStr(sz, n)); return PosFromImpl(m_impl.find(str.data, PosToImpl(nStart), str.len)); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find(const wchar_t* sz, size_t nStart = 0, size_t n = npos) const { SubstrBufFromWC str(ImplStr(sz, n)); return PosFromImpl(m_impl.find(str.data, PosToImpl(nStart), str.len)); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find(const wxScopedCharBuffer& s, size_t nStart = 0, size_t n = npos) const { return find(s.data(), nStart, n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find(const wxScopedWCharBuffer& s, size_t nStart = 0, size_t n = npos) const { return find(s.data(), nStart, n); } size_t find(const wxCStrData& s, size_t nStart = 0, size_t n = npos) const @@ -3021,18 +3135,22 @@ public: { return PosFromImpl(m_impl.rfind(str.m_impl, PosToImpl(nStart))); } // as find, but from the end +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t rfind(const char* sz, size_t nStart = npos, size_t n = npos) const { SubstrBufFromMB str(ImplStr(sz, n)); return PosFromImpl(m_impl.rfind(str.data, PosToImpl(nStart), str.len)); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t rfind(const wchar_t* sz, size_t nStart = npos, size_t n = npos) const { SubstrBufFromWC str(ImplStr(sz, n)); return PosFromImpl(m_impl.rfind(str.data, PosToImpl(nStart), str.len)); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t rfind(const wxScopedCharBuffer& s, size_t nStart = npos, size_t n = npos) const { return rfind(s.data(), nStart, n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t rfind(const wxScopedWCharBuffer& s, size_t nStart = npos, size_t n = npos) const { return rfind(s.data(), nStart, n); } size_t rfind(const wxCStrData& s, size_t nStart = npos, size_t n = npos) const @@ -3063,12 +3181,16 @@ public: // should we care? Probably not. size_t find_first_of(const wxString& str, size_t nStart = 0) const { return m_impl.find_first_of(str.m_impl, nStart); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_of(const char* sz, size_t nStart = 0) const { return m_impl.find_first_of(ImplStr(sz), nStart); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_of(const wchar_t* sz, size_t nStart = 0) const { return m_impl.find_first_of(ImplStr(sz), nStart); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_of(const char* sz, size_t nStart, size_t n) const { return m_impl.find_first_of(ImplStr(sz), nStart, n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_of(const wchar_t* sz, size_t nStart, size_t n) const { return m_impl.find_first_of(ImplStr(sz), nStart, n); } size_t find_first_of(wxUniChar c, size_t nStart = 0) const @@ -3076,12 +3198,16 @@ public: size_t find_last_of(const wxString& str, size_t nStart = npos) const { return m_impl.find_last_of(str.m_impl, nStart); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_of(const char* sz, size_t nStart = npos) const { return m_impl.find_last_of(ImplStr(sz), nStart); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_of(const wchar_t* sz, size_t nStart = npos) const { return m_impl.find_last_of(ImplStr(sz), nStart); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_of(const char* sz, size_t nStart, size_t n) const { return m_impl.find_last_of(ImplStr(sz), nStart, n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_of(const wchar_t* sz, size_t nStart, size_t n) const { return m_impl.find_last_of(ImplStr(sz), nStart, n); } size_t find_last_of(wxUniChar c, size_t nStart = npos) const @@ -3089,12 +3215,16 @@ public: size_t find_first_not_of(const wxString& str, size_t nStart = 0) const { return m_impl.find_first_not_of(str.m_impl, nStart); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_not_of(const char* sz, size_t nStart = 0) const { return m_impl.find_first_not_of(ImplStr(sz), nStart); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_not_of(const wchar_t* sz, size_t nStart = 0) const { return m_impl.find_first_not_of(ImplStr(sz), nStart); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_not_of(const char* sz, size_t nStart, size_t n) const { return m_impl.find_first_not_of(ImplStr(sz), nStart, n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_not_of(const wchar_t* sz, size_t nStart, size_t n) const { return m_impl.find_first_not_of(ImplStr(sz), nStart, n); } size_t find_first_not_of(wxUniChar c, size_t nStart = 0) const @@ -3102,12 +3232,16 @@ public: size_t find_last_not_of(const wxString& str, size_t nStart = npos) const { return m_impl.find_last_not_of(str.m_impl, nStart); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_not_of(const char* sz, size_t nStart = npos) const { return m_impl.find_last_not_of(ImplStr(sz), nStart); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_not_of(const wchar_t* sz, size_t nStart = npos) const { return m_impl.find_last_not_of(ImplStr(sz), nStart); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_not_of(const char* sz, size_t nStart, size_t n) const { return m_impl.find_last_not_of(ImplStr(sz), nStart, n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_not_of(const wchar_t* sz, size_t nStart, size_t n) const { return m_impl.find_last_not_of(ImplStr(sz), nStart, n); } size_t find_last_not_of(wxUniChar c, size_t nStart = npos) const @@ -3124,9 +3258,13 @@ public: { return find_first_of(str.mb_str(), nStart); } #endif // same as above +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_of(const char* sz, size_t nStart = 0) const; +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_of(const wchar_t* sz, size_t nStart = 0) const; +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_of(const char* sz, size_t nStart, size_t n) const; +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_of(const wchar_t* sz, size_t nStart, size_t n) const; // same as find(char, size_t) size_t find_first_of(wxUniChar c, size_t nStart = 0) const @@ -3139,9 +3277,13 @@ public: { return find_last_of(str.mb_str(), nStart); } #endif // same as above +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_of (const char* sz, size_t nStart = npos) const; +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_of (const wchar_t* sz, size_t nStart = npos) const; +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_of(const char* sz, size_t nStart, size_t n) const; +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_of(const wchar_t* sz, size_t nStart, size_t n) const; // same as above size_t find_last_of(wxUniChar c, size_t nStart = npos) const @@ -3157,9 +3299,13 @@ public: { return find_first_not_of(str.mb_str(), nStart); } #endif // same as above +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_not_of(const char* sz, size_t nStart = 0) const; +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_not_of(const wchar_t* sz, size_t nStart = 0) const; +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_not_of(const char* sz, size_t nStart, size_t n) const; +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_not_of(const wchar_t* sz, size_t nStart, size_t n) const; // same as above size_t find_first_not_of(wxUniChar ch, size_t nStart = 0) const; @@ -3171,9 +3317,13 @@ public: { return find_last_not_of(str.mb_str(), nStart); } #endif // same as above +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_not_of(const char* sz, size_t nStart = npos) const; +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_not_of(const wchar_t* sz, size_t nStart = npos) const; +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_not_of(const char* sz, size_t nStart, size_t n) const; +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_not_of(const wchar_t* sz, size_t nStart, size_t n) const; // same as above size_t find_last_not_of(wxUniChar ch, size_t nStart = npos) const; @@ -3217,53 +3367,69 @@ public: // and additional overloads for the versions taking strings: size_t find_first_of(const wxCStrData& sz, size_t nStart = 0) const { return find_first_of(sz.AsString(), nStart); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_of(const wxScopedCharBuffer& sz, size_t nStart = 0) const { return find_first_of(sz.data(), nStart); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_of(const wxScopedWCharBuffer& sz, size_t nStart = 0) const { return find_first_of(sz.data(), nStart); } size_t find_first_of(const wxCStrData& sz, size_t nStart, size_t n) const { return find_first_of(sz.AsWChar(), nStart, n); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_of(const wxScopedCharBuffer& sz, size_t nStart, size_t n) const { return find_first_of(sz.data(), nStart, n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_of(const wxScopedWCharBuffer& sz, size_t nStart, size_t n) const { return find_first_of(sz.data(), nStart, n); } size_t find_last_of(const wxCStrData& sz, size_t nStart = 0) const { return find_last_of(sz.AsString(), nStart); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_of(const wxScopedCharBuffer& sz, size_t nStart = 0) const { return find_last_of(sz.data(), nStart); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_of(const wxScopedWCharBuffer& sz, size_t nStart = 0) const { return find_last_of(sz.data(), nStart); } size_t find_last_of(const wxCStrData& sz, size_t nStart, size_t n) const { return find_last_of(sz.AsWChar(), nStart, n); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_of(const wxScopedCharBuffer& sz, size_t nStart, size_t n) const { return find_last_of(sz.data(), nStart, n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_of(const wxScopedWCharBuffer& sz, size_t nStart, size_t n) const { return find_last_of(sz.data(), nStart, n); } size_t find_first_not_of(const wxCStrData& sz, size_t nStart = 0) const { return find_first_not_of(sz.AsString(), nStart); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_not_of(const wxScopedCharBuffer& sz, size_t nStart = 0) const { return find_first_not_of(sz.data(), nStart); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_not_of(const wxScopedWCharBuffer& sz, size_t nStart = 0) const { return find_first_not_of(sz.data(), nStart); } size_t find_first_not_of(const wxCStrData& sz, size_t nStart, size_t n) const { return find_first_not_of(sz.AsWChar(), nStart, n); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_not_of(const wxScopedCharBuffer& sz, size_t nStart, size_t n) const { return find_first_not_of(sz.data(), nStart, n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_first_not_of(const wxScopedWCharBuffer& sz, size_t nStart, size_t n) const { return find_first_not_of(sz.data(), nStart, n); } size_t find_last_not_of(const wxCStrData& sz, size_t nStart = 0) const { return find_last_not_of(sz.AsString(), nStart); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_not_of(const wxScopedCharBuffer& sz, size_t nStart = 0) const { return find_last_not_of(sz.data(), nStart); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_not_of(const wxScopedWCharBuffer& sz, size_t nStart = 0) const { return find_last_not_of(sz.data(), nStart); } size_t find_last_not_of(const wxCStrData& sz, size_t nStart, size_t n) const { return find_last_not_of(sz.AsWChar(), nStart, n); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_not_of(const wxScopedCharBuffer& sz, size_t nStart, size_t n) const { return find_last_not_of(sz.data(), nStart, n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING size_t find_last_not_of(const wxScopedWCharBuffer& sz, size_t nStart, size_t n) const { return find_last_not_of(sz.data(), nStart, n); } @@ -3290,6 +3456,7 @@ public: return *this; } // string += C string +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& operator+=(const char *psz) { wxSTRING_INVALIDATE_CACHED_LENGTH(); @@ -3297,6 +3464,7 @@ public: m_impl += ImplStr(psz); return *this; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& operator+=(const wchar_t *pwz) { wxSTRING_INVALIDATE_CACHED_LENGTH(); @@ -3311,8 +3479,10 @@ public: m_impl += s.AsString().m_impl; return *this; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString& operator+=(const wxScopedCharBuffer& s) { return append(s); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString& operator+=(const wxScopedWCharBuffer& s) { return append(s); } // string += char @@ -3524,9 +3694,13 @@ inline wxString::const_reverse_iterator operator+(ptrdiff_t n, wxString::const_r // here as friend ones are not injected in the enclosing namespace and without // them the code fails to compile with conforming compilers such as xlC or g++4 wxString WXDLLIMPEXP_BASE operator+(const wxString& string1, const wxString& string2); +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString WXDLLIMPEXP_BASE operator+(const wxString& string, const char *psz); +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString WXDLLIMPEXP_BASE operator+(const wxString& string, const wchar_t *pwz); +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxString WXDLLIMPEXP_BASE operator+(const char *psz, const wxString& string); +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxString WXDLLIMPEXP_BASE operator+(const wchar_t *pwz, const wxString& string); wxString WXDLLIMPEXP_BASE operator+(const wxString& string, wxUniChar ch); @@ -3562,7 +3736,7 @@ struct wxStringAsBufHelper { static wxScopedCharBuffer Get(const wxString& s, size_t *len) { - wxScopedCharBuffer buf(s.mb_str()); + wxScopedCharBuffer buf(s.mb_str(wxConvUTF8)); if ( len ) *len = buf ? strlen(buf) : 0; return buf; @@ -3869,7 +4043,9 @@ public: #define wxCMP_WXCHAR_STRING(p, s, op) 0 op s.Cmp(p) wxDEFINE_ALL_COMPARISONS(const wchar_t *, const wxString&, wxCMP_WXCHAR_STRING) +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxDEFINE_ALL_COMPARISONS(const char *, const wxString&, wxCMP_WXCHAR_STRING) +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING #undef wxCMP_WXCHAR_STRING @@ -3904,6 +4080,7 @@ inline bool operator!=(const wxString& s1, const wxScopedWCharBuffer& s2) inline bool operator!=(const wxScopedWCharBuffer& s1, const wxString& s2) { return (s2.Cmp((const wchar_t *)s1) != 0); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline bool operator==(const wxString& s1, const wxScopedCharBuffer& s2) { return (s1.Cmp((const char *)s2) == 0); } inline bool operator==(const wxScopedCharBuffer& s1, const wxString& s2) @@ -3912,16 +4089,19 @@ inline bool operator!=(const wxString& s1, const wxScopedCharBuffer& s2) { return (s1.Cmp((const char *)s2) != 0); } inline bool operator!=(const wxScopedCharBuffer& s1, const wxString& s2) { return (s2.Cmp((const char *)s1) != 0); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline wxString operator+(const wxString& string, const wxScopedWCharBuffer& buf) { return string + (const wchar_t *)buf; } inline wxString operator+(const wxScopedWCharBuffer& buf, const wxString& string) { return (const wchar_t *)buf + string; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline wxString operator+(const wxString& string, const wxScopedCharBuffer& buf) { return string + (const char *)buf; } inline wxString operator+(const wxScopedCharBuffer& buf, const wxString& string) { return (const char *)buf + string; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING // comparison with char inline bool operator==(const wxUniChar& c, const wxString& s) { return s.IsSameAs(c); } @@ -3980,7 +4160,9 @@ inline bool wxString::iterator::operator>=(const const_iterator& i) const #define wxCMP_WCHAR_CSTRDATA(p, s, op) p op s.AsWChar() wxDEFINE_ALL_COMPARISONS(const wchar_t *, const wxCStrData&, wxCMP_WCHAR_CSTRDATA) +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxDEFINE_ALL_COMPARISONS(const char *, const wxCStrData&, wxCMP_CHAR_CSTRDATA) +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING #undef wxCMP_CHAR_CSTRDATA #undef wxCMP_WCHAR_CSTRDATA @@ -4029,7 +4211,9 @@ namespace std WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxString&); WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxCStrData&); +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxScopedCharBuffer&); +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxScopedWCharBuffer&); #if wxUSE_UNICODE && defined(HAVE_WOSTREAM) @@ -4046,8 +4230,10 @@ WXDLLIMPEXP_BASE wxSTD wostream& operator<<(wxSTD wostream&, const wxScopedWChar // wxCStrData implementation // --------------------------------------------------------------------------- +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline wxCStrData::wxCStrData(char *buf) : m_str(new wxString(buf)), m_offset(0), m_owned(true) {} +#endif inline wxCStrData::wxCStrData(wchar_t *buf) : m_str(new wxString(buf)), m_offset(0), m_owned(true) {} @@ -4100,6 +4286,7 @@ inline const wchar_t* wxCStrData::AsWChar() const return p + m_offset; } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline const char* wxCStrData::AsChar() const { #if wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY @@ -4112,6 +4299,7 @@ inline const char* wxCStrData::AsChar() const return p + m_offset; } +#endif inline wxString wxCStrData::AsString() const { @@ -4149,12 +4337,14 @@ inline wxUniChar wxCStrData::operator[](size_t n) const // more wxCStrData operators // ---------------------------------------------------------------------------- +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING // we need to define those to allow "size_t pos = p - s.c_str()" where p is // some pointer into the string inline size_t operator-(const char *p, const wxCStrData& cs) { return p - cs.AsChar(); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline size_t operator-(const wchar_t *p, const wxCStrData& cs) { @@ -4165,11 +4355,13 @@ inline size_t operator-(const wchar_t *p, const wxCStrData& cs) // implementation of wx[W]CharBuffer inline methods using wxCStrData // ---------------------------------------------------------------------------- +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING // FIXME-UTF8: move this to buffer.h inline wxCharBuffer::wxCharBuffer(const wxCStrData& cstr) : wxCharTypeBufferBase(cstr.AsCharBuf()) { } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline wxWCharBuffer::wxWCharBuffer(const wxCStrData& cstr) : wxCharTypeBufferBase(cstr.AsWCharBuf()) diff --git a/include/wx/strvararg.h b/include/wx/strvararg.h index 82cb94536f..3a363a3dee 100644 --- a/include/wx/strvararg.h +++ b/include/wx/strvararg.h @@ -133,16 +133,20 @@ class WXDLLIMPEXP_FWD_BASE wxString; class WXDLLIMPEXP_BASE wxFormatString { public: +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxFormatString(const char *str) : m_char(wxScopedCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {} +#endif wxFormatString(const wchar_t *str) : m_wchar(wxScopedWCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {} wxFormatString(const wxString& str) : m_str(&str), m_cstr(NULL) {} wxFormatString(const wxCStrData& str) : m_str(NULL), m_cstr(&str) {} +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxFormatString(const wxScopedCharBuffer& str) : m_char(str), m_str(NULL), m_cstr(NULL) {} +#endif wxFormatString(const wxScopedWCharBuffer& str) : m_wchar(str), m_str(NULL), m_cstr(NULL) {} @@ -201,7 +205,7 @@ public: // to other InputAsXXX() methods wxString InputAsString() const; -#if !wxUSE_UNICODE_WCHAR +#if !wxUSE_UNICODE_WCHAR && !defined wxNO_IMPLICIT_WXSTRING_ENCODING operator const char*() const { return const_cast(this)->AsChar(); } private: @@ -212,7 +216,7 @@ private: const char* InputAsChar(); const char* AsChar(); wxScopedCharBuffer m_convertedChar; -#endif // !wxUSE_UNICODE_WCHAR +#endif // !wxUSE_UNICODE_WCHAR && !defined wx_NO_IMPLICIT_WXSTRING_ENCODING #if wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY public: @@ -284,7 +288,12 @@ struct wxFormatStringArgumentFinder template<> struct wxFormatStringArgumentFinder - : public wxFormatStringArgumentFinder {}; + : public wxFormatStringArgumentFinder { +#ifdef wxNO_IMPLICIT_WXSTRING_ENCODING +private: + wxFormatStringArgumentFinder(); // Disabled +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING +}; template<> struct wxFormatStringArgumentFinder @@ -292,7 +301,12 @@ struct wxFormatStringArgumentFinder template<> struct wxFormatStringArgumentFinder - : public wxFormatStringArgumentFinder {}; + : public wxFormatStringArgumentFinder { +#ifdef wxNO_IMPLICIT_WXSTRING_ENCODING +private: + wxFormatStringArgumentFinder(); // Disabled +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING +}; template<> struct wxFormatStringArgumentFinder @@ -387,6 +401,13 @@ struct wxFormatStringSpecifier enum { value = arg }; \ }; +#define wxDISABLED_FORMAT_STRING_SPECIFIER(T) \ + template<> struct wxFormatStringSpecifier \ + { \ + private: \ + wxFormatStringSpecifier(); /* Disabled */ \ + }; + wxFORMAT_STRING_SPECIFIER(bool, wxFormatString::Arg_Int) wxFORMAT_STRING_SPECIFIER(int, wxFormatString::Arg_Int) wxFORMAT_STRING_SPECIFIER(unsigned int, wxFormatString::Arg_Int) @@ -406,18 +427,27 @@ wxFORMAT_STRING_SPECIFIER(long double, wxFormatString::Arg_LongDouble) wxFORMAT_STRING_SPECIFIER(wchar_t, wxFormatString::Arg_Char | wxFormatString::Arg_Int) #endif -#if !wxUSE_UNICODE +#if !wxUSE_UNICODE && !defined wxNO_IMPLICIT_WXSTRING_ENCODING wxFORMAT_STRING_SPECIFIER(char, wxFormatString::Arg_Char | wxFormatString::Arg_Int) wxFORMAT_STRING_SPECIFIER(signed char, wxFormatString::Arg_Char | wxFormatString::Arg_Int) wxFORMAT_STRING_SPECIFIER(unsigned char, wxFormatString::Arg_Char | wxFormatString::Arg_Int) #endif +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxFORMAT_STRING_SPECIFIER(char*, wxFormatString::Arg_String) wxFORMAT_STRING_SPECIFIER(unsigned char*, wxFormatString::Arg_String) wxFORMAT_STRING_SPECIFIER(signed char*, wxFormatString::Arg_String) wxFORMAT_STRING_SPECIFIER(const char*, wxFormatString::Arg_String) wxFORMAT_STRING_SPECIFIER(const unsigned char*, wxFormatString::Arg_String) wxFORMAT_STRING_SPECIFIER(const signed char*, wxFormatString::Arg_String) +#else // wxNO_IMPLICIT_WXSTRING_ENCODING +wxDISABLED_FORMAT_STRING_SPECIFIER(char*) +wxDISABLED_FORMAT_STRING_SPECIFIER(unsigned char*) +wxDISABLED_FORMAT_STRING_SPECIFIER(signed char*) +wxDISABLED_FORMAT_STRING_SPECIFIER(const char*) +wxDISABLED_FORMAT_STRING_SPECIFIER(const unsigned char*) +wxDISABLED_FORMAT_STRING_SPECIFIER(const signed char*) +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxFORMAT_STRING_SPECIFIER(wchar_t*, wxFormatString::Arg_String) wxFORMAT_STRING_SPECIFIER(const wchar_t*, wxFormatString::Arg_String) @@ -430,6 +460,7 @@ wxFORMAT_STRING_SPECIFIER(std::nullptr_t, wxFormatString::Arg_Pointer) #endif #undef wxFORMAT_STRING_SPECIFIER +#undef wxDISABLED_FORMAT_STRING_SPECIFIER // Converts an argument passed to wxPrint etc. into standard form expected, @@ -571,6 +602,7 @@ struct WXDLLIMPEXP_BASE wxArgNormalizerWchar // char* for wchar_t Unicode build or UTF8): #if wxUSE_UNICODE_WCHAR +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING template<> struct wxArgNormalizerWchar : public wxArgNormalizerWithBuffer @@ -579,6 +611,7 @@ struct wxArgNormalizerWchar const wxFormatString *fmt, unsigned index) : wxArgNormalizerWithBuffer(wxConvLibc.cMB2WC(s), fmt, index) {} }; +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING #elif wxUSE_UNICODE_UTF8 @@ -591,6 +624,7 @@ struct wxArgNormalizerUtf8 : wxArgNormalizerWithBuffer(wxConvUTF8.cWC2MB(s), fmt, index) {} }; +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING template<> struct wxArgNormalizerUtf8 : public wxArgNormalizerWithBuffer @@ -616,9 +650,10 @@ struct wxArgNormalizerUtf8 } } }; +#endif // UTF-8 build needs conversion to wchar_t* too: -#if !wxUSE_UTF8_LOCALE_ONLY +#if !wxUSE_UTF8_LOCALE_ONLY && !defined wxNO_IMPLICIT_WXSTRING_ENCODING template<> struct wxArgNormalizerWchar : public wxArgNormalizerWithBuffer @@ -627,10 +662,11 @@ struct wxArgNormalizerWchar const wxFormatString *fmt, unsigned index) : wxArgNormalizerWithBuffer(wxConvLibc.cMB2WC(s), fmt, index) {} }; -#endif // !wxUSE_UTF8_LOCALE_ONLY +#endif // !wxUSE_UTF8_LOCALE_ONLY && !defined wxNO_IMPLICIT_WXSTRING_ENCODING #else // ANSI - FIXME-UTF8 +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING template<> struct wxArgNormalizerWchar : public wxArgNormalizerWithBuffer @@ -639,10 +675,56 @@ struct wxArgNormalizerWchar const wxFormatString *fmt, unsigned index) : wxArgNormalizerWithBuffer(wxConvLibc.cWC2MB(s), fmt, index) {} }; +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING #endif // wxUSE_UNICODE_WCHAR/wxUSE_UNICODE_UTF8/ANSI +#ifdef wxNO_IMPLICIT_WXSTRING_ENCODING +// wxArgNormalizer specializations that cannot be instanced +template<> +struct wxArgNormalizer { +private: + wxArgNormalizer(const char*, const wxFormatString *, + unsigned); + const char *get() const; +}; +template<> +struct wxArgNormalizer { +private: + wxArgNormalizer(const char*, const wxFormatString *, unsigned); + char *get() const; +}; +template<> +struct wxArgNormalizer { +private: + wxArgNormalizer(const std::string&, + const wxFormatString *, unsigned); + std::string get() const; +}; +template<> +struct wxArgNormalizer { +private: + wxArgNormalizer(std::string&, + const wxFormatString *, unsigned); + std::string get() const; +}; +template<> +struct wxArgNormalizer { +private: + wxArgNormalizer(wxCharBuffer&, + const wxFormatString *, unsigned); + std::string get() const; +}; +template<> +struct wxArgNormalizer { +private: + wxArgNormalizer(wxScopedCharBuffer&, + const wxFormatString *, unsigned); + std::string get() const; +}; +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING + // this macro is used to implement specialization that are exactly same as // some other specialization, i.e. to "forward" the implementation (e.g. for // T=wxString and T=const wxString&). Note that the ctor takes BaseT argument, @@ -675,16 +757,22 @@ WX_ARG_NORMALIZER_FORWARD(wxString, const wxString&); WX_ARG_NORMALIZER_FORWARD(wxCStrData, const wxCStrData&); // versions for passing non-const pointers: +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING WX_ARG_NORMALIZER_FORWARD(char*, const char*); +#endif WX_ARG_NORMALIZER_FORWARD(wchar_t*, const wchar_t*); // versions for passing wx[W]CharBuffer: +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING WX_ARG_NORMALIZER_FORWARD(wxScopedCharBuffer, const char*); WX_ARG_NORMALIZER_FORWARD(const wxScopedCharBuffer&, const char*); +#endif WX_ARG_NORMALIZER_FORWARD(wxScopedWCharBuffer, const wchar_t*); WX_ARG_NORMALIZER_FORWARD(const wxScopedWCharBuffer&, const wchar_t*); +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING WX_ARG_NORMALIZER_FORWARD(wxCharBuffer, const char*); WX_ARG_NORMALIZER_FORWARD(const wxCharBuffer&, const char*); +#endif WX_ARG_NORMALIZER_FORWARD(wxWCharBuffer, const wchar_t*); WX_ARG_NORMALIZER_FORWARD(const wxWCharBuffer&, const wchar_t*); @@ -694,6 +782,7 @@ WX_ARG_NORMALIZER_FORWARD(const wxWCharBuffer&, const wchar_t*); #include "wx/stringimpl.h" #if !wxUSE_UTF8_LOCALE_ONLY +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING template<> struct wxArgNormalizerWchar : public wxArgNormalizerWchar @@ -702,6 +791,7 @@ struct wxArgNormalizerWchar const wxFormatString *fmt, unsigned index) : wxArgNormalizerWchar(s.c_str(), fmt, index) {} }; +#endif // NO_IMPLICIT_WXSTRING_ENCODING template<> struct wxArgNormalizerWchar @@ -714,6 +804,7 @@ struct wxArgNormalizerWchar #endif // !wxUSE_UTF8_LOCALE_ONLY #if wxUSE_UNICODE_UTF8 +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING template<> struct wxArgNormalizerUtf8 : public wxArgNormalizerUtf8 @@ -722,6 +813,7 @@ struct wxArgNormalizerUtf8 const wxFormatString *fmt, unsigned index) : wxArgNormalizerUtf8(s.c_str(), fmt, index) {} }; +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING template<> struct wxArgNormalizerUtf8 @@ -733,7 +825,9 @@ struct wxArgNormalizerUtf8 }; #endif // wxUSE_UNICODE_UTF8 +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING WX_ARG_NORMALIZER_FORWARD(std::string, const std::string&); +#endif WX_ARG_NORMALIZER_FORWARD(wxStdWideString, const wxStdWideString&); #endif // wxUSE_STD_STRING diff --git a/include/wx/variant.h b/include/wx/variant.h index 734d7f0dce..442dcd443a 100644 --- a/include/wx/variant.h +++ b/include/wx/variant.h @@ -216,8 +216,10 @@ public: wxVariant& operator=(const wxString& value); // these overloads are necessary to prevent the compiler from using bool // version instead of wxString one: +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxVariant& operator=(const char* value) { return *this = wxString(value); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxVariant& operator=(const wchar_t* value) { return *this = wxString(value); } wxVariant& operator=(const wxCStrData& value) @@ -230,6 +232,7 @@ public: wxString GetString() const; #if wxUSE_STD_STRING +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING wxVariant(const std::string& val, const wxString& name = wxEmptyString); bool operator==(const std::string& value) const { return operator==(wxString(value)); } @@ -238,6 +241,7 @@ public: wxVariant& operator=(const std::string& value) { return operator=(wxString(value)); } operator std::string() const { return (operator wxString()).ToStdString(); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING wxVariant(const wxStdWideString& val, const wxString& name = wxEmptyString); bool operator==(const wxStdWideString& value) const diff --git a/include/wx/wxcrt.h b/include/wx/wxcrt.h index 68f9fa85fc..6cf08f4fde 100644 --- a/include/wx/wxcrt.h +++ b/include/wx/wxcrt.h @@ -149,10 +149,12 @@ inline char* wxTmemset(char* szOut, char cIn, size_t len) WXDLLIMPEXP_BASE char* wxSetlocale(int category, const char *locale); inline char* wxSetlocale(int category, const wxScopedCharBuffer& locale) { return wxSetlocale(category, locale.data()); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline char* wxSetlocale(int category, const wxString& locale) { return wxSetlocale(category, locale.mb_str()); } inline char* wxSetlocale(int category, const wxCStrData& locale) { return wxSetlocale(category, locale.AsCharBuf()); } +#endif // ---------------------------------------------------------------------------- // string functions @@ -202,17 +204,21 @@ inline size_t wxStrnlen(const wchar_t *str, size_t maxlen) // inline wchar_t* wxStrdup(const wchar_t *s) { return wxStrdupW(s); } inline char* wxStrdup(const wxScopedCharBuffer& s) { return wxStrdup(s.data()); } inline wchar_t* wxStrdup(const wxScopedWCharBuffer& s) { return wxStrdup(s.data()); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline char* wxStrdup(const wxString& s) { return wxStrdup(s.mb_str()); } inline char* wxStrdup(const wxCStrData& s) { return wxStrdup(s.AsCharBuf()); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrcpy(char *dest, const char *src) { return wxCRT_StrcpyA(dest, src); } inline wchar_t *wxStrcpy(wchar_t *dest, const wchar_t *src) { return wxCRT_StrcpyW(dest, src); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrcpy(char *dest, const wxString& src) { return wxCRT_StrcpyA(dest, src.mb_str()); } inline char *wxStrcpy(char *dest, const wxCStrData& src) { return wxCRT_StrcpyA(dest, src.AsCharBuf()); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrcpy(char *dest, const wxScopedCharBuffer& src) { return wxCRT_StrcpyA(dest, src.data()); } inline wchar_t *wxStrcpy(wchar_t *dest, const wxString& src) @@ -221,19 +227,23 @@ inline wchar_t *wxStrcpy(wchar_t *dest, const wxCStrData& src) { return wxCRT_StrcpyW(dest, src.AsWCharBuf()); } inline wchar_t *wxStrcpy(wchar_t *dest, const wxScopedWCharBuffer& src) { return wxCRT_StrcpyW(dest, src.data()); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrcpy(char *dest, const wchar_t *src) { return wxCRT_StrcpyA(dest, wxConvLibc.cWC2MB(src)); } inline wchar_t *wxStrcpy(wchar_t *dest, const char *src) { return wxCRT_StrcpyW(dest, wxConvLibc.cMB2WC(src)); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrncpy(char *dest, const char *src, size_t n) { return wxCRT_StrncpyA(dest, src, n); } inline wchar_t *wxStrncpy(wchar_t *dest, const wchar_t *src, size_t n) { return wxCRT_StrncpyW(dest, src, n); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrncpy(char *dest, const wxString& src, size_t n) { return wxCRT_StrncpyA(dest, src.mb_str(), n); } inline char *wxStrncpy(char *dest, const wxCStrData& src, size_t n) { return wxCRT_StrncpyA(dest, src.AsCharBuf(), n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrncpy(char *dest, const wxScopedCharBuffer& src, size_t n) { return wxCRT_StrncpyA(dest, src.data(), n); } inline wchar_t *wxStrncpy(wchar_t *dest, const wxString& src, size_t n) @@ -242,10 +252,12 @@ inline wchar_t *wxStrncpy(wchar_t *dest, const wxCStrData& src, size_t n) { return wxCRT_StrncpyW(dest, src.AsWCharBuf(), n); } inline wchar_t *wxStrncpy(wchar_t *dest, const wxScopedWCharBuffer& src, size_t n) { return wxCRT_StrncpyW(dest, src.data(), n); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrncpy(char *dest, const wchar_t *src, size_t n) { return wxCRT_StrncpyA(dest, wxConvLibc.cWC2MB(src), n); } inline wchar_t *wxStrncpy(wchar_t *dest, const char *src, size_t n) { return wxCRT_StrncpyW(dest, wxConvLibc.cMB2WC(src), n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING // this is a function new in 2.9 so we don't care about backwards compatibility and // so don't need to support wchar_t/char overloads @@ -281,10 +293,12 @@ inline char *wxStrcat(char *dest, const char *src) { return wxCRT_StrcatA(dest, src); } inline wchar_t *wxStrcat(wchar_t *dest, const wchar_t *src) { return wxCRT_StrcatW(dest, src); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrcat(char *dest, const wxString& src) { return wxCRT_StrcatA(dest, src.mb_str()); } inline char *wxStrcat(char *dest, const wxCStrData& src) { return wxCRT_StrcatA(dest, src.AsCharBuf()); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrcat(char *dest, const wxScopedCharBuffer& src) { return wxCRT_StrcatA(dest, src.data()); } inline wchar_t *wxStrcat(wchar_t *dest, const wxString& src) @@ -293,19 +307,23 @@ inline wchar_t *wxStrcat(wchar_t *dest, const wxCStrData& src) { return wxCRT_StrcatW(dest, src.AsWCharBuf()); } inline wchar_t *wxStrcat(wchar_t *dest, const wxScopedWCharBuffer& src) { return wxCRT_StrcatW(dest, src.data()); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrcat(char *dest, const wchar_t *src) { return wxCRT_StrcatA(dest, wxConvLibc.cWC2MB(src)); } inline wchar_t *wxStrcat(wchar_t *dest, const char *src) { return wxCRT_StrcatW(dest, wxConvLibc.cMB2WC(src)); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrncat(char *dest, const char *src, size_t n) { return wxCRT_StrncatA(dest, src, n); } inline wchar_t *wxStrncat(wchar_t *dest, const wchar_t *src, size_t n) { return wxCRT_StrncatW(dest, src, n); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrncat(char *dest, const wxString& src, size_t n) { return wxCRT_StrncatA(dest, src.mb_str(), n); } inline char *wxStrncat(char *dest, const wxCStrData& src, size_t n) { return wxCRT_StrncatA(dest, src.AsCharBuf(), n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrncat(char *dest, const wxScopedCharBuffer& src, size_t n) { return wxCRT_StrncatA(dest, src.data(), n); } inline wchar_t *wxStrncat(wchar_t *dest, const wxString& src, size_t n) @@ -314,10 +332,12 @@ inline wchar_t *wxStrncat(wchar_t *dest, const wxCStrData& src, size_t n) { return wxCRT_StrncatW(dest, src.AsWCharBuf(), n); } inline wchar_t *wxStrncat(wchar_t *dest, const wxScopedWCharBuffer& src, size_t n) { return wxCRT_StrncatW(dest, src.data(), n); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrncat(char *dest, const wchar_t *src, size_t n) { return wxCRT_StrncatA(dest, wxConvLibc.cWC2MB(src), n); } inline wchar_t *wxStrncat(wchar_t *dest, const char *src, size_t n) { return wxCRT_StrncatW(dest, wxConvLibc.cMB2WC(src), n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING #define WX_STR_DECL(name, T1, T2) name(T1 s1, T2 s2) @@ -333,6 +353,7 @@ inline wchar_t *wxStrncat(wchar_t *dest, const char *src, size_t n) // forString - function to call when the *first* argument is wxString; // the second argument can be any string type, so this is // typically a template +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING #define WX_STR_FUNC_NO_INVERT(rettype, name, crtA, crtW, forString) \ inline rettype WX_STR_DECL(name, const char *, const char *) \ { return WX_STR_CALL(crtA, s1, s2); } \ @@ -395,9 +416,48 @@ inline wchar_t *wxStrncat(wchar_t *dest, const char *src, size_t n) { return WX_STR_CALL(forString, s1.AsString(), s2); } \ inline rettype WX_STR_DECL(name, const wxCStrData&, const wxCStrData&) \ { return WX_STR_CALL(forString, s1.AsString(), s2); } +#else // wxNO_IMPLICIT_WXSTRING_ENCODING +#define WX_STR_FUNC_NO_INVERT(rettype, name, crtA, crtW, forString) \ + inline rettype WX_STR_DECL(name, const char *, const char *) \ + { return WX_STR_CALL(crtA, s1, s2); } \ + \ + inline rettype WX_STR_DECL(name, const wchar_t *, const wchar_t *) \ + { return WX_STR_CALL(crtW, s1, s2); } \ + inline rettype WX_STR_DECL(name, const wchar_t *, const wxScopedWCharBuffer&) \ + { return WX_STR_CALL(crtW, s1, s2.data()); } \ + \ + inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const char *) \ + { return WX_STR_CALL(crtA, s1.data(), s2); } \ + inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wxScopedCharBuffer&)\ + { return WX_STR_CALL(crtA, s1.data(), s2.data()); } \ + \ + inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wchar_t *) \ + { return WX_STR_CALL(crtW, s1.data(), s2); } \ + inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxScopedWCharBuffer&) \ + { return WX_STR_CALL(crtW, s1.data(), s2.data()); } \ + \ + inline rettype WX_STR_DECL(name, const wxString&, const wchar_t*) \ + { return WX_STR_CALL(forString, s1, s2); } \ + inline rettype WX_STR_DECL(name, const wxString&, const wxScopedWCharBuffer&) \ + { return WX_STR_CALL(forString, s1, s2); } \ + inline rettype WX_STR_DECL(name, const wxString&, const wxString&) \ + { return WX_STR_CALL(forString, s1, s2); } \ + inline rettype WX_STR_DECL(name, const wxString&, const wxCStrData&) \ + { return WX_STR_CALL(forString, s1, s2); } \ + \ + inline rettype WX_STR_DECL(name, const wxCStrData&, const wchar_t*) \ + { return WX_STR_CALL(forString, s1.AsString(), s2); } \ + inline rettype WX_STR_DECL(name, const wxCStrData&, const wxScopedWCharBuffer&) \ + { return WX_STR_CALL(forString, s1.AsString(), s2); } \ + inline rettype WX_STR_DECL(name, const wxCStrData&, const wxString&) \ + { return WX_STR_CALL(forString, s1.AsString(), s2); } \ + inline rettype WX_STR_DECL(name, const wxCStrData&, const wxCStrData&) \ + { return WX_STR_CALL(forString, s1.AsString(), s2); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING // This defines strcmp-like function, i.e. one returning the result of // comparison; see WX_STR_FUNC_NO_INVERT for explanation of the arguments +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING #define WX_STRCMP_FUNC(name, crtA, crtW, forString) \ WX_STR_FUNC_NO_INVERT(int, name, crtA, crtW, forString) \ \ @@ -420,11 +480,26 @@ inline wchar_t *wxStrncat(wchar_t *dest, const char *src, size_t n) { return -WX_STR_CALL(forString, s2.AsString(), s1.data()); } \ inline int WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxString&) \ { return -WX_STR_CALL(forString, s2, s1.data()); } +#else // wxNO_IMPLICIT_WXSTRING_ENCODING +#define WX_STRCMP_FUNC(name, crtA, crtW, forString) \ + WX_STR_FUNC_NO_INVERT(int, name, crtA, crtW, forString) \ + \ + inline int WX_STR_DECL(name, const wchar_t *, const wxCStrData&) \ + { return -WX_STR_CALL(forString, s2.AsString(), s1); } \ + inline int WX_STR_DECL(name, const wchar_t *, const wxString&) \ + { return -WX_STR_CALL(forString, s2, s1); } \ + \ + inline int WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxCStrData&) \ + { return -WX_STR_CALL(forString, s2.AsString(), s1.data()); } \ + inline int WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxString&) \ + { return -WX_STR_CALL(forString, s2, s1.data()); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING // This defines a string function that is *not* strcmp-like, i.e. doesn't // return the result of comparison and so if the second argument is a string, // it has to be converted to char* or wchar_t* +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING #define WX_STR_FUNC(rettype, name, crtA, crtW, forString) \ WX_STR_FUNC_NO_INVERT(rettype, name, crtA, crtW, forString) \ \ @@ -447,6 +522,20 @@ inline wchar_t *wxStrncat(wchar_t *dest, const char *src, size_t n) { return WX_STR_CALL(crtW, s1.data(), s2.AsWCharBuf()); } \ inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxString&) \ { return WX_STR_CALL(crtW, s1.data(), s2.wc_str()); } +#else // wxNO_IMPLICIT_WXSTRING_ENCODING +#define WX_STR_FUNC(rettype, name, crtA, crtW, forString) \ + WX_STR_FUNC_NO_INVERT(rettype, name, crtA, crtW, forString) \ + \ + inline rettype WX_STR_DECL(name, const wchar_t *, const wxCStrData&) \ + { return WX_STR_CALL(crtW, s1, s2.AsWCharBuf()); } \ + inline rettype WX_STR_DECL(name, const wchar_t *, const wxString&) \ + { return WX_STR_CALL(crtW, s1, s2.wc_str()); } \ + \ + inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxCStrData&) \ + { return WX_STR_CALL(crtW, s1.data(), s2.AsWCharBuf()); } \ + inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxString&) \ + { return WX_STR_CALL(crtW, s1.data(), s2.wc_str()); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING template inline int wxStrcmp_String(const wxString& s1, const T& s2) @@ -526,12 +615,16 @@ inline size_t wxStrxfrm(wchar_t *dest, const wchar_t *src, size_t n) template inline size_t wxStrxfrm(T *dest, const wxScopedCharTypeBuffer& src, size_t n) { return wxStrxfrm(dest, src.data(), n); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline size_t wxStrxfrm(char *dest, const wxString& src, size_t n) { return wxCRT_StrxfrmA(dest, src.mb_str(), n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline size_t wxStrxfrm(wchar_t *dest, const wxString& src, size_t n) { return wxCRT_StrxfrmW(dest, src.wc_str(), n); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline size_t wxStrxfrm(char *dest, const wxCStrData& src, size_t n) { return wxCRT_StrxfrmA(dest, src.AsCharBuf(), n); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline size_t wxStrxfrm(wchar_t *dest, const wxCStrData& src, size_t n) { return wxCRT_StrxfrmW(dest, src.AsWCharBuf(), n); } @@ -544,12 +637,16 @@ inline wchar_t *wxStrtok(wchar_t *str, const wchar_t *delim, wchar_t **saveptr) template inline T *wxStrtok(T *str, const wxScopedCharTypeBuffer& delim, T **saveptr) { return wxStrtok(str, delim.data(), saveptr); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrtok(char *str, const wxCStrData& delim, char **saveptr) { return wxCRT_StrtokA(str, delim.AsCharBuf(), saveptr); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline wchar_t *wxStrtok(wchar_t *str, const wxCStrData& delim, wchar_t **saveptr) { return wxCRT_StrtokW(str, delim.AsWCharBuf(), saveptr); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline char *wxStrtok(char *str, const wxString& delim, char **saveptr) { return wxCRT_StrtokA(str, delim.mb_str(), saveptr); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline wchar_t *wxStrtok(wchar_t *str, const wxString& delim, wchar_t **saveptr) { return wxCRT_StrtokW(str, delim.wc_str(), saveptr); } @@ -557,23 +654,29 @@ inline const char *wxStrstr(const char *haystack, const char *needle) { return wxCRT_StrstrA(haystack, needle); } inline const wchar_t *wxStrstr(const wchar_t *haystack, const wchar_t *needle) { return wxCRT_StrstrW(haystack, needle); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline const char *wxStrstr(const char *haystack, const wxString& needle) { return wxCRT_StrstrA(haystack, needle.mb_str()); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline const wchar_t *wxStrstr(const wchar_t *haystack, const wxString& needle) { return wxCRT_StrstrW(haystack, needle.wc_str()); } // these functions return char* pointer into the non-temporary conversion buffer // used by c_str()'s implicit conversion to char*, for ANSI build compatibility +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline const char *wxStrstr(const wxString& haystack, const wxString& needle) { return wxCRT_StrstrA(haystack.c_str(), needle.mb_str()); } inline const char *wxStrstr(const wxCStrData& haystack, const wxString& needle) { return wxCRT_StrstrA(haystack, needle.mb_str()); } inline const char *wxStrstr(const wxCStrData& haystack, const wxCStrData& needle) { return wxCRT_StrstrA(haystack, needle.AsCharBuf()); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING // if 'needle' is char/wchar_t, then the same is probably wanted as return value +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline const char *wxStrstr(const wxString& haystack, const char *needle) { return wxCRT_StrstrA(haystack.c_str(), needle); } inline const char *wxStrstr(const wxCStrData& haystack, const char *needle) { return wxCRT_StrstrA(haystack, needle); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline const wchar_t *wxStrstr(const wxString& haystack, const wchar_t *needle) { return wxCRT_StrstrW(haystack.c_str(), needle); } inline const wchar_t *wxStrstr(const wxCStrData& haystack, const wchar_t *needle) @@ -623,6 +726,7 @@ inline const T* wxStrrchr(const wxScopedCharTypeBuffer& s, const wxUniCharRef { return wxStrrchr(s.data(), (T)c); } // these functions return char* pointer into the non-temporary conversion buffer // used by c_str()'s implicit conversion to char*, for ANSI build compatibility +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline const char* wxStrchr(const wxString& s, char c) { return wxCRT_StrchrA((const char*)s.c_str(), c); } inline const char* wxStrrchr(const wxString& s, char c) @@ -639,10 +743,12 @@ inline const char* wxStrchr(const wxString& s, const wxUniCharRef& uc) { char c; return uc.GetAsChar(&c) ? wxCRT_StrchrA(s.c_str(), c) : NULL; } inline const char* wxStrrchr(const wxString& s, const wxUniCharRef& uc) { char c; return uc.GetAsChar(&c) ? wxCRT_StrrchrA(s.c_str(), c) : NULL; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline const wchar_t* wxStrchr(const wxString& s, wchar_t c) { return wxCRT_StrchrW((const wchar_t*)s.c_str(), c); } inline const wchar_t* wxStrrchr(const wxString& s, wchar_t c) { return wxCRT_StrrchrW((const wchar_t*)s.c_str(), c); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline const char* wxStrchr(const wxCStrData& s, char c) { return wxCRT_StrchrA(s.AsChar(), c); } inline const char* wxStrrchr(const wxCStrData& s, char c) @@ -659,6 +765,7 @@ inline const char* wxStrchr(const wxCStrData& s, const wxUniCharRef& uc) { char c; return uc.GetAsChar(&c) ? wxCRT_StrchrA(s, c) : NULL; } inline const char* wxStrrchr(const wxCStrData& s, const wxUniCharRef& uc) { char c; return uc.GetAsChar(&c) ? wxCRT_StrrchrA(s, c) : NULL; } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline const wchar_t* wxStrchr(const wxCStrData& s, wchar_t c) { return wxCRT_StrchrW(s.AsWChar(), c); } inline const wchar_t* wxStrrchr(const wxCStrData& s, wchar_t c) @@ -668,30 +775,38 @@ inline const char *wxStrpbrk(const char *s, const char *accept) { return wxCRT_StrpbrkA(s, accept); } inline const wchar_t *wxStrpbrk(const wchar_t *s, const wchar_t *accept) { return wxCRT_StrpbrkW(s, accept); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline const char *wxStrpbrk(const char *s, const wxString& accept) { return wxCRT_StrpbrkA(s, accept.mb_str()); } inline const char *wxStrpbrk(const char *s, const wxCStrData& accept) { return wxCRT_StrpbrkA(s, accept.AsCharBuf()); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline const wchar_t *wxStrpbrk(const wchar_t *s, const wxString& accept) { return wxCRT_StrpbrkW(s, accept.wc_str()); } inline const wchar_t *wxStrpbrk(const wchar_t *s, const wxCStrData& accept) { return wxCRT_StrpbrkW(s, accept.AsWCharBuf()); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline const char *wxStrpbrk(const wxString& s, const wxString& accept) { return wxCRT_StrpbrkA(s.c_str(), accept.mb_str()); } inline const char *wxStrpbrk(const wxString& s, const char *accept) { return wxCRT_StrpbrkA(s.c_str(), accept); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline const wchar_t *wxStrpbrk(const wxString& s, const wchar_t *accept) { return wxCRT_StrpbrkW(s.wc_str(), accept); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline const char *wxStrpbrk(const wxString& s, const wxCStrData& accept) { return wxCRT_StrpbrkA(s.c_str(), accept.AsCharBuf()); } inline const char *wxStrpbrk(const wxCStrData& s, const wxString& accept) { return wxCRT_StrpbrkA(s.AsChar(), accept.mb_str()); } inline const char *wxStrpbrk(const wxCStrData& s, const char *accept) { return wxCRT_StrpbrkA(s.AsChar(), accept); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline const wchar_t *wxStrpbrk(const wxCStrData& s, const wchar_t *accept) { return wxCRT_StrpbrkW(s.AsWChar(), accept); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline const char *wxStrpbrk(const wxCStrData& s, const wxCStrData& accept) { return wxCRT_StrpbrkA(s.AsChar(), accept.AsCharBuf()); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING template inline const T *wxStrpbrk(const S& s, const wxScopedCharTypeBuffer& accept) { return wxStrpbrk(s, accept.data()); } @@ -771,24 +886,29 @@ inline int wxUngetc(int c, FILE *stream) { return wxCRT_UngetcA(c, stream); } // ---------------------------------------------------------------------------- // stdlib.h functions +// +// We only use wxConvLibc here because if the string is non-ASCII, +// then it's fine for the conversion to yield empty string, as atoi() +// will return 0 for it, which is the correct thing to do in this +// case. // ---------------------------------------------------------------------------- #ifdef wxCRT_AtoiW inline int wxAtoi(const wxString& str) { return wxCRT_AtoiW(str.wc_str()); } #else -inline int wxAtoi(const wxString& str) { return wxCRT_AtoiA(str.mb_str()); } +inline int wxAtoi(const wxString& str) { return wxCRT_AtoiA(str.mb_str(wxConvLibc)); } #endif #ifdef wxCRT_AtolW inline long wxAtol(const wxString& str) { return wxCRT_AtolW(str.wc_str()); } #else -inline long wxAtol(const wxString& str) { return wxCRT_AtolA(str.mb_str()); } +inline long wxAtol(const wxString& str) { return wxCRT_AtolA(str.mb_str(wxConvLibc)); } #endif #ifdef wxCRT_AtofW inline double wxAtof(const wxString& str) { return wxCRT_AtofW(str.wc_str()); } #else -inline double wxAtof(const wxString& str) { return wxCRT_AtofA(str.mb_str()); } +inline double wxAtof(const wxString& str) { return wxCRT_AtofA(str.mb_str(wxConvLibc)); } #endif inline double wxStrtod(const char *nptr, char **endptr) @@ -913,15 +1033,17 @@ WX_STRTOX_FUNC(wxULongLong_t, wxStrtoull, wxCRT_StrtoullA, wxCRT_StrtoullW) // functions in their wide versions #ifdef wxCRT_SystemW inline int wxSystem(const wxString& str) { return wxCRT_SystemW(str.wc_str()); } -#else +#elif !defined wxNO_IMPLICIT_WXSTRING_ENCODING inline int wxSystem(const wxString& str) { return wxCRT_SystemA(str.mb_str()); } #endif #endif inline char* wxGetenv(const char *name) { return wxCRT_GetenvA(name); } inline wchar_t* wxGetenv(const wchar_t *name) { return wxCRT_GetenvW(name); } +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline char* wxGetenv(const wxString& name) { return wxCRT_GetenvA(name.mb_str()); } inline char* wxGetenv(const wxCStrData& name) { return wxCRT_GetenvA(name.AsCharBuf()); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline char* wxGetenv(const wxScopedCharBuffer& name) { return wxCRT_GetenvA(name.data()); } inline wchar_t* wxGetenv(const wxScopedWCharBuffer& name) { return wxCRT_GetenvW(name.data()); } @@ -929,9 +1051,11 @@ inline wchar_t* wxGetenv(const wxScopedWCharBuffer& name) { return wxCRT_GetenvW // time.h functions // ---------------------------------------------------------------------------- +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING inline size_t wxStrftime(char *s, size_t max, const wxString& format, const struct tm *tm) { return wxCRT_StrftimeA(s, max, format.mb_str(), tm); } +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline size_t wxStrftime(wchar_t *s, size_t max, const wxString& format, const struct tm *tm) diff --git a/include/wx/wxcrtvararg.h b/include/wx/wxcrtvararg.h index 79a657123c..4d998df14f 100644 --- a/include/wx/wxcrtvararg.h +++ b/include/wx/wxcrtvararg.h @@ -280,14 +280,14 @@ WX_DEFINE_VARARG_FUNC_SANS_N0(int, wxPrintf, 1, (const wxFormatString&), wxCRT_PrintfNative, wxCRT_PrintfA) inline int wxPrintf(const wxFormatString& s) { - return wxPrintf("%s", s.InputAsString()); + return wxPrintf(wxASCII_STR("%s"), s.InputAsString()); } WX_DEFINE_VARARG_FUNC_SANS_N0(int, wxFprintf, 2, (FILE*, const wxFormatString&), wxCRT_FprintfNative, wxCRT_FprintfA) inline int wxFprintf(FILE *f, const wxFormatString& s) { - return wxFprintf(f, "%s", s.InputAsString()); + return wxFprintf(f, wxASCII_STR("%s"), s.InputAsString()); } // va_list versions of printf functions simply forward to the respective @@ -440,12 +440,16 @@ WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxScopedCharBuffer& str, const char *form wxCRT_SscanfA, (str.data(), format)) WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxScopedWCharBuffer& str, const wchar_t *format), wxCRT_SscanfW, (str.data(), wxScanfConvertFormatW(format))) +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxString& str, const char *format), wxCRT_SscanfA, (str.mb_str(), format)) +#endif WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxString& str, const wchar_t *format), wxCRT_SscanfW, (str.wc_str(), wxScanfConvertFormatW(format))) +#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxCStrData& str, const char *format), wxCRT_SscanfA, (str.AsCharBuf(), format)) +#endif WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxCStrData& str, const wchar_t *format), wxCRT_SscanfW, (str.AsWCharBuf(), wxScanfConvertFormatW(format)))