]> git.saurik.com Git - wxWidgets.git/commitdiff
don't stop on NULs in Replace()
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 12 Apr 2008 17:10:28 +0000 (17:10 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 12 Apr 2008 17:10:28 +0000 (17:10 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53144 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/string.cpp

index 6b6582462259fcedddf1c7f99c4f158dc9339b26..a287759822baabf199d1bc79f2845cba128072b3 100644 (file)
@@ -1239,31 +1239,24 @@ size_t wxString::Replace(const wxString& strOld,
     size_t uiOldLen = strOld.length();
     size_t uiNewLen = strNew.length();
 
     size_t uiOldLen = strOld.length();
     size_t uiNewLen = strNew.length();
 
-    size_t dwPos = 0;
-
-    while ( (*this)[dwPos] != wxT('\0') )
+    for ( size_t dwPos = 0; dwPos < length(); )
     {
     {
-        //DO NOT USE STRSTR HERE
-        //this string can contain embedded null characters,
-        //so strstr will function incorrectly
         dwPos = find(strOld, dwPos);
         if ( dwPos == npos )
         dwPos = find(strOld, dwPos);
         if ( dwPos == npos )
-            break;                  // exit the loop
-        else
-        {
-            //replace this occurance of the old string with the new one
-            replace(dwPos, uiOldLen, strNew, uiNewLen);
+            break;
 
 
-            //move up pos past the string that was replaced
-            dwPos += uiNewLen;
+        // replace this occurance of the old string with the new one
+        replace(dwPos, uiOldLen, strNew, uiNewLen);
 
 
-            //increase replace count
-            ++uiCount;
+        // move up pos past the string that was replaced
+        dwPos += uiNewLen;
 
 
-            // stop now?
-            if ( !bReplaceAll )
-                break;                  // exit the loop
-        }
+        // increase replace count
+        ++uiCount;
+
+        // stop after the first one?
+        if ( !bReplaceAll )
+            break;
     }
 
     return uiCount;
     }
 
     return uiCount;