aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-07-11 19:09:04 +0000
committerMike Buland <eichlan@xagasoft.com>2007-07-11 19:09:04 +0000
commit8165c5d4768261a90085b1378a4b29c28738b8e1 (patch)
treed451a56213cbaad45965e6ad6107cb1310a27008
parentaa4d4db13e647842ad2ad941aeed5bf8b60c4a08 (diff)
downloadlibbu++-8165c5d4768261a90085b1378a4b29c28738b8e1.tar.gz
libbu++-8165c5d4768261a90085b1378a4b29c28738b8e1.tar.bz2
libbu++-8165c5d4768261a90085b1378a4b29c28738b8e1.tar.xz
libbu++-8165c5d4768261a90085b1378a4b29c28738b8e1.zip
TafWriter now indents by default, I'll make that configurable soon.
-rw-r--r--src/tafwriter.cpp21
-rw-r--r--src/tafwriter.h2
2 files changed, 19 insertions, 4 deletions
diff --git a/src/tafwriter.cpp b/src/tafwriter.cpp
index 6b505ef..fe29490 100644
--- a/src/tafwriter.cpp
+++ b/src/tafwriter.cpp
@@ -1,7 +1,8 @@
1#include "tafwriter.h" 1#include "tafwriter.h"
2 2
3Bu::TafWriter::TafWriter( Bu::Stream &sOut ) : 3Bu::TafWriter::TafWriter( Bu::Stream &sOut ) :
4 sOut( sOut ) 4 sOut( sOut ),
5 iDepth( 0 )
5{ 6{
6} 7}
7 8
@@ -9,11 +10,19 @@ Bu::TafWriter::~TafWriter()
9{ 10{
10} 11}
11 12
13void Bu::TafWriter::ident()
14{
15 for( int j = 0; j < iDepth; j++ )
16 sOut.write(" ", 4 );
17}
18
12void Bu::TafWriter::writeGroup( const Bu::TafGroup *pRoot ) 19void Bu::TafWriter::writeGroup( const Bu::TafGroup *pRoot )
13{ 20{
21 ident();
14 sOut.write("{", 1 ); 22 sOut.write("{", 1 );
15 writeString( pRoot->getName() ); 23 writeString( pRoot->getName() );
16 sOut.write(": ", 2 ); 24 sOut.write(":\n", 2 );
25 iDepth++;
17 const Bu::TafGroup::NodeList &nl = pRoot->getChildren(); 26 const Bu::TafGroup::NodeList &nl = pRoot->getChildren();
18 for( Bu::TafGroup::NodeList::const_iterator i = nl.begin(); i != nl.end(); i++ ) 27 for( Bu::TafGroup::NodeList::const_iterator i = nl.begin(); i != nl.end(); i++ )
19 { 28 {
@@ -32,22 +41,26 @@ void Bu::TafWriter::writeGroup( const Bu::TafGroup *pRoot )
32 break; 41 break;
33 } 42 }
34 } 43 }
35 sOut.write("}", 1 ); 44 iDepth--;
45 ident();
46 sOut.write("}\n", 2 );
36} 47}
37 48
38void Bu::TafWriter::writeProperty( const Bu::TafProperty *pProp ) 49void Bu::TafWriter::writeProperty( const Bu::TafProperty *pProp )
39{ 50{
51 ident();
40 writeString( pProp->getName() ); 52 writeString( pProp->getName() );
41 if( pProp->getValue().getStr() != NULL ) 53 if( pProp->getValue().getStr() != NULL )
42 { 54 {
43 sOut.write("=", 1 ); 55 sOut.write("=", 1 );
44 writeString( pProp->getValue() ); 56 writeString( pProp->getValue() );
45 } 57 }
46 sOut.write(" ", 1 ); 58 sOut.write("\n", 1 );
47} 59}
48 60
49void Bu::TafWriter::writeComment( const Bu::TafComment *pComment ) 61void Bu::TafWriter::writeComment( const Bu::TafComment *pComment )
50{ 62{
63 ident();
51 sOut.write("/*", 2 ); 64 sOut.write("/*", 2 );
52 sOut.write( pComment->getText().getStr(), pComment->getText().getSize() ); 65 sOut.write( pComment->getText().getStr(), pComment->getText().getSize() );
53 sOut.write("*/ ", 3 ); 66 sOut.write("*/ ", 3 );
diff --git a/src/tafwriter.h b/src/tafwriter.h
index 5f80504..f34395e 100644
--- a/src/tafwriter.h
+++ b/src/tafwriter.h
@@ -23,7 +23,9 @@ namespace Bu
23 void writeProperty( const Bu::TafProperty *pProp ); 23 void writeProperty( const Bu::TafProperty *pProp );
24 void writeComment( const Bu::TafComment *pComment ); 24 void writeComment( const Bu::TafComment *pComment );
25 void writeString( const Bu::FString &str ); 25 void writeString( const Bu::FString &str );
26 void ident();
26 Bu::Stream &sOut; 27 Bu::Stream &sOut;
28 int iDepth;
27 }; 29 };
28} 30}
29 31