]> git.saurik.com Git - wxWidgets.git/commitdiff
UTF-8 build fixes for appending, setting or searching for NUL characters
authorVáclav Slavík <vslavik@fastmail.fm>
Sun, 27 Jan 2008 16:29:52 +0000 (16:29 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Sun, 27 Jan 2008 16:29:52 +0000 (16:29 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51411 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/string.h

index 2d7d3e3a9c21c8dcabb23429952a0a1fc0c14341..deecb1795bf7193f172beb2f33bd1c772fd657c6 100644 (file)
@@ -1343,7 +1343,15 @@ public:
     { return *this = cstr.AsString(); }
     // from a character
   wxString& operator=(wxUniChar ch)
-    { m_impl = wxStringOperations::EncodeChar(ch); return *this; }
+  {
+#if wxUSE_UNICODE_UTF8
+    if ( !ch.IsAscii() )
+        m_impl = wxStringOperations::EncodeChar(ch);
+    else
+#endif
+        m_impl = (wxStringCharType)ch;
+    return *this;
+  }
   wxString& operator=(wxUniCharRef ch)
     { return operator=((wxUniChar)ch); }
   wxString& operator=(char ch)
@@ -2242,8 +2250,15 @@ public:
     // find the first occurence of character ch after nStart
   size_t find(wxUniChar ch, size_t nStart = 0) const
   {
-    return PosFromImpl(m_impl.find(wxStringOperations::EncodeChar(ch),
-                                   PosToImpl(nStart)));
+#if wxUSE_UNICODE_UTF8
+    if ( !ch.IsAscii() )
+        return PosFromImpl(m_impl.find(wxStringOperations::EncodeChar(ch),
+                                       PosToImpl(nStart)));
+    else
+#endif
+        return PosFromImpl(m_impl.find((wxStringCharType)ch,
+                                       PosToImpl(nStart)));
+
   }
   size_t find(wxUniCharRef ch, size_t nStart = 0) const
     {  return find(wxUniChar(ch), nStart); }
@@ -2280,8 +2295,14 @@ public:
     // as find, but from the end
   size_t rfind(wxUniChar ch, size_t nStart = npos) const
   {
-    return PosFromImpl(m_impl.rfind(wxStringOperations::EncodeChar(ch),
-                                    PosToImpl(nStart)));
+#if wxUSE_UNICODE_UTF8
+    if ( !ch.IsAscii() )
+        return PosFromImpl(m_impl.rfind(wxStringOperations::EncodeChar(ch),
+                                        PosToImpl(nStart)));
+    else
+#endif
+        return PosFromImpl(m_impl.rfind((wxStringCharType)ch,
+                                        PosToImpl(nStart)));
   }
   size_t rfind(wxUniCharRef ch, size_t nStart = npos) const
     {  return rfind(wxUniChar(ch), nStart); }
@@ -2519,7 +2540,15 @@ public:
     { return operator+=(s.data()); }
       // string += char
   wxString& operator+=(wxUniChar ch)
-    { m_impl += wxStringOperations::EncodeChar(ch); return *this; }
+  {
+#if wxUSE_UNICODE_UTF8
+    if ( !ch.IsAscii() )
+        m_impl += wxStringOperations::EncodeChar(ch);
+    else
+#endif
+        m_impl += (wxStringCharType)ch;
+    return *this;
+  }
   wxString& operator+=(wxUniCharRef ch) { return *this += wxUniChar(ch); }
   wxString& operator+=(int ch) { return *this += wxUniChar(ch); }
   wxString& operator+=(char ch) { return *this += wxUniChar(ch); }