From 7433ec9074051ea5d9f91458e2e91e29ec8020f2 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 27 Feb 2009 15:21:33 +0000 Subject: Fixed a bug in Bu::FString, it wouldn't concatinate properly when using the + operator and the left-hand-side FString was const. Also, added a formatter << operator for Bu::List. The other containers should get their own formatter << operators soon too. --- src/fbasicstring.h | 28 ++++++++++++++-------------- src/list.h | 18 ++++++++++++++++++ src/unit/fstring.unit | 9 +++++++++ 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/fbasicstring.h b/src/fbasicstring.h index cac7dd7..a532d69 100644 --- a/src/fbasicstring.h +++ b/src/fbasicstring.h @@ -999,7 +999,7 @@ namespace Bu * Plus equals operator for FString. *@param pData (const chr *) The data to append to your FString. */ - MyType &operator +=( const chr *pData ) + MyType &operator+=( const chr *pData ) { append( pData ); @@ -1010,7 +1010,7 @@ namespace Bu * Plus equals operator for FString. *@param pData (const MyType &) The FString to append to your FString. */ - MyType &operator +=( const MyType &rSrc ) + MyType &operator+=( const MyType &rSrc ) { if( rSrc.nLength == 0 ) return (*this); @@ -1024,7 +1024,7 @@ namespace Bu * Plus equals operator for FString. *@param pData (const chr) The character to append to your FString. */ - MyType &operator +=( const chr cData ) + MyType &operator+=( const chr cData ) { if( pLast && pLast->nLength < nMinSize ) { @@ -1046,7 +1046,7 @@ namespace Bu *@param pData (const chr *) The character array to append to your * FString. */ - MyType &operator =( const chr *pData ) + MyType &operator=( const chr *pData ) { clear(); append( pData ); @@ -1054,7 +1054,7 @@ namespace Bu return (*this); } - MyType &operator =( const std::basic_string &rData ) + MyType &operator=( const std::basic_string &rData ) { clear(); append( rData.c_str(), rData.size() ); @@ -1062,21 +1062,21 @@ namespace Bu return (*this); } - MyType operator +( const MyType &rRight ) + MyType operator+( const MyType &rRight ) const { MyType ret( *this ); ret.append( rRight ); return ret; } - MyType operator +( const chr *pRight ) + MyType operator+( const chr *pRight ) const { MyType ret( *this ); ret.append( pRight ); return ret; } - MyType operator +( chr *pRight ) + MyType operator+( chr *pRight ) const { MyType ret( *this ); ret.append( pRight ); @@ -1171,7 +1171,7 @@ namespace Bu * Assignment operator. *@param rSrc (const MyType &) The FString to set your FString to. */ - MyType &operator =( const MyType &rSrc ) + MyType &operator=( const MyType &rSrc ) { copyFrom( rSrc ); @@ -1183,7 +1183,7 @@ namespace Bu *@param pData (const chr *) The character array to compare your FString * to. */ - bool operator ==( const chr *pData ) const + bool operator==( const chr *pData ) const { if( pFirst == NULL ) { if( pData == NULL ) @@ -1212,7 +1212,7 @@ namespace Bu * Equals comparison operator. *@param pData (const MyType &) The FString to compare your FString to. */ - bool operator ==( const MyType &pData ) const + bool operator==( const MyType &pData ) const { if( pFirst == pData.pFirst ) return true; @@ -1239,7 +1239,7 @@ namespace Bu *@param pData (const chr *) The character array to compare your FString * to. */ - bool operator !=(const chr *pData ) const + bool operator!=(const chr *pData ) const { return !(*this == pData); } @@ -1248,7 +1248,7 @@ namespace Bu * Not equals comparison operator. *@param pData (const MyType &) The FString to compare your FString to. */ - bool operator !=(const MyType &pData ) const + bool operator!=(const MyType &pData ) const { return !(*this == pData); } @@ -1759,7 +1759,7 @@ namespace Bu mutable chunkalloc aChunk; }; - template FBasicString operator +( const T *pLeft, const FBasicString &rRight ) + template FBasicString operator+( const T *pLeft, const FBasicString &rRight ) { Bu::FBasicString ret( pLeft ); ret.append( rRight ); diff --git a/src/list.h b/src/list.h index f11336e..b52f9fc 100644 --- a/src/list.h +++ b/src/list.h @@ -669,6 +669,24 @@ namespace Bu long nSize; cmpfunc cmp; }; + + class Formatter; + Formatter &operator<<( Formatter &rOut, char *sStr ); + Formatter &operator<<( Formatter &rOut, signed char c ); + template + Formatter &operator<<( Formatter &f, const Bu::List &l ) + { + f << '['; + for( typename Bu::List::const_iterator i = l.begin(); i; i++ ) + { + if( i != l.begin() ) + f << ", "; + f << *i; + } + f << ']'; + + return f; + } } #endif diff --git a/src/unit/fstring.unit b/src/unit/fstring.unit index a0d62da..fbebd39 100644 --- a/src/unit/fstring.unit +++ b/src/unit/fstring.unit @@ -129,6 +129,15 @@ unitTest( c == "Hello/Dude" ); } +{%add7} +{ + const Bu::FString a("hello "); + Bu::FString b(" how "); + unitTest( a == "hello " ); + unitTest( a + "dude" == "hello dude" ); + unitTest( a + "dude" + b + "are you?" == "hello dude how are you?" ); +} + {%subStr1} { Bu::FString a("abcdefghijklmnop"); -- cgit v1.2.3