aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-11-24 04:39:06 +0000
committerMike Buland <eichlan@xagasoft.com>2009-11-24 04:39:06 +0000
commit1f894ce98811eb8a2ab893db6c2d53cd77a111e7 (patch)
tree29c8fde4b73779b7e942291914b5d3feae81a972
parent2389e95360e37cd601e6b28cec47fef290c009d3 (diff)
downloadlibbu++-1f894ce98811eb8a2ab893db6c2d53cd77a111e7.tar.gz
libbu++-1f894ce98811eb8a2ab893db6c2d53cd77a111e7.tar.bz2
libbu++-1f894ce98811eb8a2ab893db6c2d53cd77a111e7.tar.xz
libbu++-1f894ce98811eb8a2ab893db6c2d53cd77a111e7.zip
Added a replace function to fstring...sweeet.
-rw-r--r--src/fbasicstring.h22
-rw-r--r--src/unit/fstring.unit7
2 files changed, 29 insertions, 0 deletions
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
1035 core->clear(); 1035 core->clear();
1036 } 1036 }
1037 1037
1038 MyType replace( const MyType &fnd, const MyType &rep ) const
1039 {
1040 MyType out;
1041 const_iterator o = begin();
1042 while( true )
1043 {
1044 const_iterator i = o.find( fnd );
1045 if( !i )
1046 {
1047 out.append( o );
1048 return out;
1049 }
1050 else
1051 {
1052 out.append( o, i );
1053 out.append( rep );
1054 o = i;
1055 o += fnd.getSize();
1056 }
1057 }
1058 }
1059
1038 /** 1060 /**
1039 * Force the string to resize 1061 * Force the string to resize
1040 *@param nNewSize (long) The new size of the string. 1062 *@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 @@
333 unitTest( b == "Goodbye" ); 333 unitTest( b == "Goodbye" );
334} 334}
335 335
336{%replace1}
337{
338 Bu::FString a;
339 a = "This is a test.";
340 unitTest( a.replace("i", "ooo") == "Thooos ooos a test." );
341}
342