aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-03-29 04:01:45 +0000
committerMike Buland <eichlan@xagasoft.com>2011-03-29 04:01:45 +0000
commitc7636dc954eddfe58f7959392602fbc9072d77e7 (patch)
treebef0b41561287ead10b5a17ccaa8a66c45efa6a1
parent86e3e2ed03a4889cf64a9149f1f0f5047a889c56 (diff)
downloadlibbu++-c7636dc954eddfe58f7959392602fbc9072d77e7.tar.gz
libbu++-c7636dc954eddfe58f7959392602fbc9072d77e7.tar.bz2
libbu++-c7636dc954eddfe58f7959392602fbc9072d77e7.tar.xz
libbu++-c7636dc954eddfe58f7959392602fbc9072d77e7.zip
String's replace function now doesn't get false positives on partial matches at
the end of strings. Build should work much better now.
-rw-r--r--src/formatter.h2
-rw-r--r--src/string.cpp2
-rw-r--r--src/string.h15
-rw-r--r--src/unit/string.unit7
4 files changed, 20 insertions, 6 deletions
diff --git a/src/formatter.h b/src/formatter.h
index a7689e1..b66f621 100644
--- a/src/formatter.h
+++ b/src/formatter.h
@@ -160,7 +160,7 @@ namespace Bu
160 int c = f; 160 int c = f;
161 fTmp += (char)((c<10)?('0'+c):(cBase+c-10)); 161 fTmp += (char)((c<10)?('0'+c):(cBase+c-10));
162 f -= (int)f; 162 f -= (int)f;
163 for( int j = 0; j < 150 && f; j++ ) 163 for( int j = 0; j < 8 && f; j++ )
164 { 164 {
165 if( iScale - j == 0 ) 165 if( iScale - j == 0 )
166 fTmp += '.'; 166 fTmp += '.';
diff --git a/src/string.cpp b/src/string.cpp
index 957d52d..5834da1 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -994,7 +994,7 @@ Bu::String::const_iterator Bu::String::find( const String &rStr,
994 if( !iStart ) iStart = begin(); 994 if( !iStart ) iStart = begin();
995 for( ; iStart; iStart++ ) 995 for( ; iStart; iStart++ )
996 { 996 {
997 if( iStart.compare( rStr ) ) 997 if( iStart.compare( rStr, rStr.getSize() ) )
998 return iStart; 998 return iStart;
999 } 999 }
1000 return end(); 1000 return end();
diff --git a/src/string.h b/src/string.h
index 9270c55..3ac161b 100644
--- a/src/string.h
+++ b/src/string.h
@@ -203,6 +203,7 @@ namespace Bu
203 if( *a != *b ) 203 if( *a != *b )
204 return false; 204 return false;
205 } 205 }
206
206 return true; 207 return true;
207 } 208 }
208 209
@@ -212,11 +213,14 @@ namespace Bu
212 const_iterator b = c; 213 const_iterator b = c;
213 if( a == b ) 214 if( a == b )
214 return true; 215 return true;
215 for(int j = 0; a && b && j < nLen; a++, b++, j++ ) 216 int j;
217 for( j = 0; a && b && j < nLen; a++, b++, j++ )
216 { 218 {
217 if( *a != *b ) 219 if( *a != *b )
218 return false; 220 return false;
219 } 221 }
222 if( j < nLen )
223 return false;
220 return true; 224 return true;
221 } 225 }
222 226
@@ -252,7 +256,7 @@ namespace Bu
252 bool compare( const String &s ) const 256 bool compare( const String &s ) const
253 { 257 {
254 if( !pChunk ) return false; 258 if( !pChunk ) return false;
255 return compare( s.begin() ); 259 return compare( s.begin(), s.getSize() );
256 } 260 }
257 261
258 bool compare( const String &s, int nLen ) const 262 bool compare( const String &s, int nLen ) const
@@ -458,11 +462,14 @@ namespace Bu
458 iterator b = c; 462 iterator b = c;
459 if( a == b ) 463 if( a == b )
460 return true; 464 return true;
461 for(int j = 0; a && b && j < nLen; a++, b++, j++ ) 465 int j;
466 for( j = 0; a && b && j < nLen; a++, b++, j++ )
462 { 467 {
463 if( *a != *b ) 468 if( *a != *b )
464 return false; 469 return false;
465 } 470 }
471 if( j < nLen )
472 return false;
466 return true; 473 return true;
467 } 474 }
468 475
@@ -498,7 +505,7 @@ namespace Bu
498 bool compare( const String &s ) const 505 bool compare( const String &s ) const
499 { 506 {
500 if( !pChunk ) return false; 507 if( !pChunk ) return false;
501 return compare( s.begin() ); 508 return compare( s.begin(), s.getSize() );
502 } 509 }
503 510
504 bool compare( const String &s, int nLen ) const 511 bool compare( const String &s, int nLen ) const
diff --git a/src/unit/string.unit b/src/unit/string.unit
index 8f65c70..4911597 100644
--- a/src/unit/string.unit
+++ b/src/unit/string.unit
@@ -340,6 +340,13 @@ suite String
340 unitTest( a.replace("i", "ooo") == "Thooos ooos a test." ); 340 unitTest( a.replace("i", "ooo") == "Thooos ooos a test." );
341 } 341 }
342 342
343 test replace2
344 {
345 Bu::String a;
346 a = "aaaboostuffb";
347 unitTest( a.replace("boo", "/") == "aaa/stuffb" );
348 }
349
343 test coreDerefBug1 350 test coreDerefBug1
344 { 351 {
345 Bu::String a, b; 352 Bu::String a, b;