Skip to content

Instantly share code, notes, and snippets.

@jhasse
Created April 6, 2018 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhasse/dbeefcf5c11e4f087f29238c86028889 to your computer and use it in GitHub Desktop.
Save jhasse/dbeefcf5c11e4f087f29238c86028889 to your computer and use it in GitHub Desktop.
diff --git a/include/wx/string.h b/include/wx/string.h
index a4e682b8ff..ad0cc200a2 100644
--- a/include/wx/string.h
+++ b/include/wx/string.h
@@ -17,6 +17,8 @@
#ifndef _WX_WXSTRING_H__
#define _WX_WXSTRING_H__
+#define wxNO_UNSAFE_WXSTRING_CONV2 1
+
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
@@ -142,6 +144,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*
+#if wxNO_UNSAFE_WXSTRING_CONV2
+ wxEXPLICIT
+#endif
inline wxCStrData(char *buf);
inline wxCStrData(wchar_t *buf);
inline wxCStrData(const wxCStrData& data);
@@ -163,6 +168,9 @@ public:
inline const char* AsChar() const;
const unsigned char* AsUnsignedChar() const
{ return (const unsigned char *) AsChar(); }
+#if wxNO_UNSAFE_WXSTRING_CONV2
+ wxEXPLICIT
+#endif
operator const char*() const { return AsChar(); }
operator const unsigned char*() const { return AsUnsignedChar(); }
@@ -1122,6 +1130,9 @@ public:
{ assign(nRepeat, ch); }
// ctors from char* strings:
+#if wxNO_UNSAFE_WXSTRING_CONV2
+ wxEXPLICIT
+#endif
wxString(const char *psz)
: m_impl(ImplStr(psz)) {}
wxString(const char *psz, const wxMBConv& conv)
@@ -1200,6 +1211,9 @@ public:
// instead we ask the client code to define this wxUSE_STD_STRING symbol if
// they need it
#if wxUSE_STD_STRING
+ #if wxNO_UNSAFE_WXSTRING_CONV2
+ wxEXPLICIT
+ #endif
#if wxUSE_UNICODE_WCHAR
wxString(const wxStdWideString& str) : m_impl(str) {}
#else // UTF-8 or ANSI
@@ -1525,7 +1539,7 @@ public:
operator const wchar_t*() const { return c_str(); }
#if wxUSE_UNSAFE_WXSTRING_CONV && !defined(wxNO_UNSAFE_WXSTRING_CONV)
- operator const char*() const { return c_str(); }
+ operator const char*() const { return mb_str(); }
// implicit conversion to untyped pointer for compatibility with previous
// wxWidgets versions: this is the same as conversion to const char * so it
// may fail!
@@ -1617,7 +1631,7 @@ public:
static wxString FromUTF8(const char *utf8)
{
if ( !utf8 || !wxStringOperations::IsValidUtf8String(utf8) )
- return "";
+ return wxString();
return FromImpl(wxStringImpl(utf8));
}
@@ -1627,7 +1641,7 @@ public:
return FromUTF8(utf8);
if ( !utf8 || !wxStringOperations::IsValidUtf8String(utf8, len) )
- return "";
+ return wxString();
return FromImpl(wxStringImpl(utf8, len));
}
@@ -2047,6 +2061,18 @@ public:
// same as Cmp() but not case-sensitive
int CmpNoCase(const wxString& s) const;
+ int CmpNoCase(const char *psz) const
+ { return CmpNoCase(wxString::FromUTF8(psz)); }
+ int CmpNoCase(const wxScopedCharTypeBuffer<char>& s) const
+ { return CmpNoCase(wxString::FromUTF8(s)); }
+
+ int CmpNoCase(const wxCStrData& s) const
+ { return CmpNoCase(wxString(s)); }
+ int CmpNoCase(const wchar_t *pwz) const
+ { return CmpNoCase(wxString(pwz)); }
+ int CmpNoCase(const wxScopedCharTypeBuffer<wchar_t>& s) const
+ { return CmpNoCase(wxString(s)); }
+
// test for the string equality, either considering case or not
// (if compareWithCase then the case matters)
bool IsSameAs(const wxString& str, bool compareWithCase = true) const
@@ -2058,15 +2084,19 @@ public:
#endif
return (compareWithCase ? Cmp(str) : CmpNoCase(str)) == 0;
}
+#if !wxNO_UNSAFE_WXSTRING_CONV2
bool IsSameAs(const char *str, bool compareWithCase = true) const
{ return (compareWithCase ? Cmp(str) : CmpNoCase(str)) == 0; }
+#endif
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); }
+#if !wxNO_UNSAFE_WXSTRING_CONV2
bool IsSameAs(const wxScopedCharBuffer& str, bool compareWithCase = true) const
{ return IsSameAs(str.data(), compareWithCase); }
+#endif
bool IsSameAs(const wxScopedWCharBuffer& str, bool compareWithCase = true) const
{ return IsSameAs(str.data(), compareWithCase); }
// comparison with a single character: returns true if equal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment