aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2008-12-29 21:33:08 +0000
committerMike Buland <eichlan@xagasoft.com>2008-12-29 21:33:08 +0000
commitf461b3c1839e5cfc85685ed1cb828ecaa74d6912 (patch)
tree5b04dabaea17632ba7c8ab448c9472ecfdaf765e /src
parentfc9da0992217c7d593ad97d2f338850b40cbaaec (diff)
downloadlibbu++-f461b3c1839e5cfc85685ed1cb828ecaa74d6912.tar.gz
libbu++-f461b3c1839e5cfc85685ed1cb828ecaa74d6912.tar.bz2
libbu++-f461b3c1839e5cfc85685ed1cb828ecaa74d6912.tar.xz
libbu++-f461b3c1839e5cfc85685ed1cb828ecaa74d6912.zip
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.
Diffstat (limited to '')
-rw-r--r--src/fstring.h15
-rw-r--r--src/tafwriter.cpp4
-rw-r--r--src/unit/taf.cpp19
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
928 928
929 iterator begin() 929 iterator begin()
930 { 930 {
931 if( nLength == 0 )
932 return NULL;
931 flatten(); 933 flatten();
932 return pFirst->pData; 934 return pFirst->pData;
933 } 935 }
934 936
935 const_iterator begin() const 937 const_iterator begin() const
936 { 938 {
939 if( nLength == 0 )
940 return NULL;
937 flatten(); 941 flatten();
938 return pFirst->pData; 942 return pFirst->pData;
939 } 943 }
940 944
941 iterator end() 945 iterator end()
942 { 946 {
947 if( nLength == 0 )
948 return NULL;
943 return pFirst->pData+pFirst->nLength; 949 return pFirst->pData+pFirst->nLength;
944 } 950 }
945 951
946 const_iterator end() const 952 const_iterator end() const
947 { 953 {
954 if( nLength == 0 )
955 return NULL;
948 return pFirst->pData+pFirst->nLength; 956 return pFirst->pData+pFirst->nLength;
949 } 957 }
950 958
959 bool isEmpty() const
960 {
961 if( nLength == 0 )
962 return true;
963 return false;
964 }
965
951 private: 966 private:
952 void flatten() const 967 void flatten() const
953 { 968 {
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 )
58void Bu::TafWriter::writeProperty( const Bu::TafProperty *pProp ) 58void Bu::TafWriter::writeProperty( const Bu::TafProperty *pProp )
59{ 59{
60 ident(); 60 ident();
61 if( pProp->getName().getStr() != NULL && pProp->getName() != "" ) 61 if( !pProp->getName().isEmpty() )
62 { 62 {
63 writeString( pProp->getName() ); 63 writeString( pProp->getName() );
64 sOut.write("=", 1 ); 64 sOut.write("=", 1 );
@@ -90,8 +90,6 @@ void Bu::TafWriter::writeComment( const Bu::TafComment *pComment )
90 90
91void Bu::TafWriter::writeString( const Bu::FString &str ) 91void Bu::TafWriter::writeString( const Bu::FString &str )
92{ 92{
93 if( str.getStr() == NULL )
94 return;
95 sOut.write("\"", 1 ); 93 sOut.write("\"", 1 );
96 for( Bu::FString::const_iterator s = str.begin(); s != str.end(); s++ ) 94 for( Bu::FString::const_iterator s = str.begin(); s != str.end(); s++ )
97 { 95 {
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:
21 { 21 {
22 setName("taf"); 22 setName("taf");
23 addTest( Unit::read1 ); 23 addTest( Unit::read1 );
24 addTest( Unit::encode ); 24 addTest( Unit::encode1 );
25 addTest( Unit::emptyStr1 );
25 } 26 }
26 27
27 virtual ~Unit() 28 virtual ~Unit()
@@ -50,7 +51,7 @@ public:
50#undef FN_TMP 51#undef FN_TMP
51 } 52 }
52 53
53 void encode() 54 void encode1()
54 { 55 {
55 Bu::MemBuf mb; 56 Bu::MemBuf mb;
56 Bu::TafWriter tw( mb ); 57 Bu::TafWriter tw( mb );
@@ -93,6 +94,20 @@ public:
93 unitTest( rg->getProperty("Encoded") == sData ); 94 unitTest( rg->getProperty("Encoded") == sData );
94 delete rg; 95 delete rg;
95 } 96 }
97
98 void emptyStr1()
99 {
100 Bu::MemBuf mb;
101 Bu::TafWriter tw( mb );
102
103 Bu::TafGroup g("Test Group");
104 Bu::FString sVal;
105 g.addChild( new Bu::TafProperty("Lame", sVal) );
106 tw.writeGroup( &g );
107
108 unitTest(
109 mb.getString() == "{\"Test Group\":\n \"Lame\"=\"\"\n}\n" );
110 }
96}; 111};
97 112
98int main( int argc, char *argv[] ) 113int main( int argc, char *argv[] )