# HG changeset patch
# User Ralf Schlatterbeck <[EMAIL PROTECTED]>
# Date 1213254873 -7200
# Node ID e05be11aba4051ab564e712cde597a7702e97329
# Parent  c97ed6cb9928c9df9a879e988ee9c8942684a946
Fix String::replaceInRange bug: We don't want to subtract 1 but the
lenght of the "before" string argument. The old implementation both
sometimes fails to replace a string when it should and sometimes
replaces when it shouldn't.
Before the change I had the following results on replacement:
str          index size   before after result
"sip:+43650"     0    2   "sip:" ""    "+43650" <- Wrong, shouldn't replace
"sip:+43650"     0    4   "sip:" ""    "+43650"
"0043650"        0    2   "00"   "+"   "+43650"
"10043650"       0    2   "00"   "+"   "10043650"
"0650"           0    1   "0"    "+43" "0650"   <- Wrong, should replace
"10650"          0    1   "0"    "+43" "10650"
"0650"           0    2   "0"    "+43" "+43650"
"10650"          0    2   "0"    "+43" "10650"  <- Wrong, should replace

After the change this yields:
str          index size   before after result
"sip:+43650"     0    2   "sip:" ""    "sip:+43650"
"sip:+43650"     0    4   "sip:" ""    "+43650"
"0043650"        0    2   "00"   "+"   "+43650"
"10043650"       0    2   "00"   "+"   "10043650"
"0650"           0    1   "0"    "+43" "+43650"
"10650"          0    1   "0"    "+43" "10650"
"0650"           0    2   "0"    "+43" "+43650"
"10650"          0    2   "0"    "+43" "1+43650"

diff -r c97ed6cb9928 -r e05be11aba40 libs/owutil/util/src/String.cpp
--- a/libs/owutil/util/src/String.cpp   Wed Jun 11 16:16:20 2008 +0200
+++ b/libs/owutil/util/src/String.cpp   Thu Jun 12 09:14:33 2008 +0200
@@ -130,12 +130,13 @@ void String::replaceInRange(unsigned ind
 
        //Searches on tmp + before2 rather than this + before
        string::size_type pos = index;
+       string::size_type l = before2.length();
        pos = tmp.find(before2, pos);
        if ((pos != string::npos)
-               && ((pos - index + 1) < size)) {
+               && ((pos - index + l) <= size)) {
                //Replaces on this + tmp
-               string::replace(pos, before2.length(), after);
-               tmp.replace(pos, before2.length(), after);
+               string::replace(pos, l, after);
+               tmp.replace(pos, l, after);
        }
 }
 
-- 
Dr. Ralf Schlatterbeck                  Tel:   +43/2243/26465-16
Open Source Consulting                  Fax:   +43/2243/26465-23
Reichergasse 131                        www:   http://www.runtux.com
A-3411 Weidling                         email: [EMAIL PROTECTED]
osAlliance member                       email: [EMAIL PROTECTED]
_______________________________________________
QuteCom-dev mailing list
[email protected]
http://lists.qutecom.org/mailman/listinfo/qutecom-dev

Reply via email to