]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/string.h
decouple item index from string value (patch 1905702)
[wxWidgets.git] / include / wx / string.h
index 2e7b6ca1b671ca5655cd3aabba2ffff00f17c6ec..f3afbd34fff8e74b19858fb3c80e6f0022c171e2 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "wx/defs.h"        // everybody should include this
 
+#ifndef __WXPALMOS5__
 #if defined(__WXMAC__) || defined(__VISAGECPP__)
     #include <ctype.h>
 #endif
 #ifdef HAVE_STRCASECMP_IN_STRINGS_H
     #include <strings.h>    // for strcasecmp()
 #endif // HAVE_STRCASECMP_IN_STRINGS_H
-
-#ifdef __WXPALMOS__
-    #include <StringMgr.h>
-#endif
+#endif // ! __WXPALMOS5__
 
 #include "wx/wxcrtbase.h"   // for wxChar, wxStrlen() etc.
 #include "wx/strvararg.h"
@@ -657,7 +655,14 @@ public:
       iterator(const iterator& i)
           : m_cur(i.m_cur), m_node(i.str(), &m_cur) {}
       iterator& operator=(const iterator& i)
-        { m_cur = i.m_cur; m_node.set(i.str(), &m_cur); return *this; }
+      {
+          if (&i != this)
+          {
+              m_cur = i.m_cur;
+              m_node.set(i.str(), &m_cur);
+          }
+          return *this;
+      }
 
       reference operator*()
         { return wxUniCharRef::CreateForString(m_node, m_cur); }
@@ -692,7 +697,14 @@ public:
           : m_cur(i.m_cur), m_node(i.str(), &m_cur) {}
 
       const_iterator& operator=(const const_iterator& i)
-        { m_cur = i.m_cur; m_node.set(i.str(), &m_cur); return *this; }
+      {
+          if (&i != this)
+          {
+              m_cur = i.m_cur;
+              m_node.set(i.str(), &m_cur);
+          }
+          return *this;
+      }
       const_iterator& operator=(const iterator& i)
         { m_cur = i.m_cur; m_node.set(i.str(), &m_cur); return *this; }
 
@@ -1324,12 +1336,20 @@ public:
   // overloaded assignment
     // from another wxString
   wxString& operator=(const wxString& stringSrc)
-    { m_impl = stringSrc.m_impl; return *this; }
+    { if (&stringSrc != this) m_impl = stringSrc.m_impl; return *this; }
   wxString& operator=(const wxCStrData& cstr)
     { 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)
@@ -2228,8 +2248,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); }
@@ -2266,8 +2293,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); }
@@ -2505,7 +2538,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); }