From f461b3c1839e5cfc85685ed1cb828ecaa74d6912 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 29 Dec 2008 21:33:08 +0000 Subject: Fixed some horror inside the Taf writer. It had a strange corner case when adding a property to a group that had a name but an empty value. Also added a isEmpty() function to Bu::FString, finally. --- src/fstring.h | 15 +++++++++++++++ src/tafwriter.cpp | 4 +--- src/unit/taf.cpp | 19 +++++++++++++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/fstring.h b/src/fstring.h index 5c70919..e1660f9 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -928,26 +928,41 @@ namespace Bu iterator begin() { + if( nLength == 0 ) + return NULL; flatten(); return pFirst->pData; } const_iterator begin() const { + if( nLength == 0 ) + return NULL; flatten(); return pFirst->pData; } iterator end() { + if( nLength == 0 ) + return NULL; return pFirst->pData+pFirst->nLength; } const_iterator end() const { + if( nLength == 0 ) + return NULL; return pFirst->pData+pFirst->nLength; } + bool isEmpty() const + { + if( nLength == 0 ) + return true; + return false; + } + private: void flatten() const { diff --git a/src/tafwriter.cpp b/src/tafwriter.cpp index 8e5fcdc..b0f5def 100644 --- a/src/tafwriter.cpp +++ b/src/tafwriter.cpp @@ -58,7 +58,7 @@ void Bu::TafWriter::writeGroup( const Bu::TafGroup *pRoot ) void Bu::TafWriter::writeProperty( const Bu::TafProperty *pProp ) { ident(); - if( pProp->getName().getStr() != NULL && pProp->getName() != "" ) + if( !pProp->getName().isEmpty() ) { writeString( pProp->getName() ); sOut.write("=", 1 ); @@ -90,8 +90,6 @@ void Bu::TafWriter::writeComment( const Bu::TafComment *pComment ) void Bu::TafWriter::writeString( const Bu::FString &str ) { - if( str.getStr() == NULL ) - return; sOut.write("\"", 1 ); for( Bu::FString::const_iterator s = str.begin(); s != str.end(); s++ ) { diff --git a/src/unit/taf.cpp b/src/unit/taf.cpp index 0813444..3bf7cc6 100644 --- a/src/unit/taf.cpp +++ b/src/unit/taf.cpp @@ -21,7 +21,8 @@ public: { setName("taf"); addTest( Unit::read1 ); - addTest( Unit::encode ); + addTest( Unit::encode1 ); + addTest( Unit::emptyStr1 ); } virtual ~Unit() @@ -50,7 +51,7 @@ public: #undef FN_TMP } - void encode() + void encode1() { Bu::MemBuf mb; Bu::TafWriter tw( mb ); @@ -93,6 +94,20 @@ public: unitTest( rg->getProperty("Encoded") == sData ); delete rg; } + + void emptyStr1() + { + Bu::MemBuf mb; + Bu::TafWriter tw( mb ); + + Bu::TafGroup g("Test Group"); + Bu::FString sVal; + g.addChild( new Bu::TafProperty("Lame", sVal) ); + tw.writeGroup( &g ); + + unitTest( + mb.getString() == "{\"Test Group\":\n \"Lame\"=\"\"\n}\n" ); + } }; int main( int argc, char *argv[] ) -- cgit v1.2.3