From 7ddeaa42e452a85e275649efa519fe0959210d12 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 11 Sep 2008 21:09:31 +0000 Subject: Fixed some whacky old FBasicString hikinx. Basically it supports all the basic, expected operators now, like plus. It was annoying without them. --- src/fstring.h | 20 ++++++++++++++++++++ src/unit/fstring.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/fstring.h b/src/fstring.h index fb4bf55..93216a1 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -492,6 +492,20 @@ namespace Bu return (*this); } + MyType operator +( const MyType &rRight ) + { + MyType ret( *this ); + ret.append( rRight ); + return ret; + } + + MyType operator +( const chr *pRight ) + { + MyType ret( *this ); + ret.append( pRight ); + return ret; + } + /** * Reset your FString to this character array. *@param pData (const chr *) The character array to set your FString to. @@ -1032,6 +1046,12 @@ namespace Bu template<> uint32_t __calcHashCode( const FString &k ); template<> bool __cmpHashKeys( const FString &a, const FString &b ); + template FBasicString operator +( const T *pLeft, const FBasicString &rRight ) + { + Bu::FBasicString ret( pLeft ); + ret.append( rRight ); + return ret; + } #ifdef BU_TRACE template<> void __tracer_format( const FString &v ); diff --git a/src/unit/fstring.cpp b/src/unit/fstring.cpp index c856b05..ea3342a 100644 --- a/src/unit/fstring.cpp +++ b/src/unit/fstring.cpp @@ -20,6 +20,10 @@ public: addTest( Unit::shared1 ); addTest( Unit::insert ); addTest( Unit::remove ); + addTest( Unit::add1 ); + addTest( Unit::add2 ); + addTest( Unit::add3 ); + addTest( Unit::add4 ); } virtual ~Unit() @@ -90,6 +94,40 @@ public: a.remove( 5, 1 ); unitTest( a = "abcdeghijklmnop" ); } + + void add1() + { + Bu::FString a("hi there"); + Bu::FString b(", yeah!"); + Bu::FString c = a + b; + + unitTest( c == "hi there, yeah!" ); + } + + void add2() + { + Bu::FString a("hi there"); + Bu::FString c = a + ", yeah!"; + + unitTest( c == "hi there, yeah!" ); + } + + void add3() + { + Bu::FString a("hi there"); + Bu::FString b(", yeah!"); + Bu::FString c = a + ", Mr. Man" + b; + + unitTest( c == "hi there, Mr. Man, yeah!" ); + } + + void add4() + { + Bu::FString b(", yeah!"); + Bu::FString c = "hi there" + b; + + unitTest( c == "hi there, yeah!" ); + } }; int main( int argc, char *argv[] ) -- cgit v1.2.3