From 1f894ce98811eb8a2ab893db6c2d53cd77a111e7 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 24 Nov 2009 04:39:06 +0000 Subject: Added a replace function to fstring...sweeet. --- src/fbasicstring.h | 22 ++++++++++++++++++++++ src/unit/fstring.unit | 7 +++++++ 2 files changed, 29 insertions(+) (limited to 'src') diff --git a/src/fbasicstring.h b/src/fbasicstring.h index 0e63efe..1c1f8a2 100644 --- a/src/fbasicstring.h +++ b/src/fbasicstring.h @@ -1035,6 +1035,28 @@ namespace Bu core->clear(); } + MyType replace( const MyType &fnd, const MyType &rep ) const + { + MyType out; + const_iterator o = begin(); + while( true ) + { + const_iterator i = o.find( fnd ); + if( !i ) + { + out.append( o ); + return out; + } + else + { + out.append( o, i ); + out.append( rep ); + o = i; + o += fnd.getSize(); + } + } + } + /** * Force the string to resize *@param nNewSize (long) The new size of the string. diff --git a/src/unit/fstring.unit b/src/unit/fstring.unit index d218a07..2f2eb69 100644 --- a/src/unit/fstring.unit +++ b/src/unit/fstring.unit @@ -333,3 +333,10 @@ unitTest( b == "Goodbye" ); } +{%replace1} +{ + Bu::FString a; + a = "This is a test."; + unitTest( a.replace("i", "ooo") == "Thooos ooos a test." ); +} + -- cgit v1.2.3