From c7636dc954eddfe58f7959392602fbc9072d77e7 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 29 Mar 2011 04:01:45 +0000 Subject: String's replace function now doesn't get false positives on partial matches at the end of strings. Build should work much better now. --- src/formatter.h | 2 +- src/string.cpp | 2 +- src/string.h | 15 +++++++++++---- src/unit/string.unit | 7 +++++++ 4 files changed, 20 insertions(+), 6 deletions(-) (limited to 'src') 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 int c = f; fTmp += (char)((c<10)?('0'+c):(cBase+c-10)); f -= (int)f; - for( int j = 0; j < 150 && f; j++ ) + for( int j = 0; j < 8 && f; j++ ) { if( iScale - j == 0 ) 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, if( !iStart ) iStart = begin(); for( ; iStart; iStart++ ) { - if( iStart.compare( rStr ) ) + if( iStart.compare( rStr, rStr.getSize() ) ) return iStart; } 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 if( *a != *b ) return false; } + return true; } @@ -212,11 +213,14 @@ namespace Bu const_iterator b = c; if( a == b ) return true; - for(int j = 0; a && b && j < nLen; a++, b++, j++ ) + int j; + for( j = 0; a && b && j < nLen; a++, b++, j++ ) { if( *a != *b ) return false; } + if( j < nLen ) + return false; return true; } @@ -252,7 +256,7 @@ namespace Bu bool compare( const String &s ) const { if( !pChunk ) return false; - return compare( s.begin() ); + return compare( s.begin(), s.getSize() ); } bool compare( const String &s, int nLen ) const @@ -458,11 +462,14 @@ namespace Bu iterator b = c; if( a == b ) return true; - for(int j = 0; a && b && j < nLen; a++, b++, j++ ) + int j; + for( j = 0; a && b && j < nLen; a++, b++, j++ ) { if( *a != *b ) return false; } + if( j < nLen ) + return false; return true; } @@ -498,7 +505,7 @@ namespace Bu bool compare( const String &s ) const { if( !pChunk ) return false; - return compare( s.begin() ); + return compare( s.begin(), s.getSize() ); } 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 unitTest( a.replace("i", "ooo") == "Thooos ooos a test." ); } + test replace2 + { + Bu::String a; + a = "aaaboostuffb"; + unitTest( a.replace("boo", "/") == "aaa/stuffb" ); + } + test coreDerefBug1 { Bu::String a, b; -- cgit v1.2.3