From 8165c5d4768261a90085b1378a4b29c28738b8e1 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 11 Jul 2007 19:09:04 +0000 Subject: TafWriter now indents by default, I'll make that configurable soon. --- src/tafwriter.cpp | 21 +++++++++++++++++---- src/tafwriter.h | 2 ++ 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 @@ #include "tafwriter.h" Bu::TafWriter::TafWriter( Bu::Stream &sOut ) : - sOut( sOut ) + sOut( sOut ), + iDepth( 0 ) { } @@ -9,11 +10,19 @@ Bu::TafWriter::~TafWriter() { } +void Bu::TafWriter::ident() +{ + for( int j = 0; j < iDepth; j++ ) + sOut.write(" ", 4 ); +} + void Bu::TafWriter::writeGroup( const Bu::TafGroup *pRoot ) { + ident(); sOut.write("{", 1 ); writeString( pRoot->getName() ); - sOut.write(": ", 2 ); + sOut.write(":\n", 2 ); + iDepth++; const Bu::TafGroup::NodeList &nl = pRoot->getChildren(); for( Bu::TafGroup::NodeList::const_iterator i = nl.begin(); i != nl.end(); i++ ) { @@ -32,22 +41,26 @@ void Bu::TafWriter::writeGroup( const Bu::TafGroup *pRoot ) break; } } - sOut.write("}", 1 ); + iDepth--; + ident(); + sOut.write("}\n", 2 ); } void Bu::TafWriter::writeProperty( const Bu::TafProperty *pProp ) { + ident(); writeString( pProp->getName() ); if( pProp->getValue().getStr() != NULL ) { sOut.write("=", 1 ); writeString( pProp->getValue() ); } - sOut.write(" ", 1 ); + sOut.write("\n", 1 ); } void Bu::TafWriter::writeComment( const Bu::TafComment *pComment ) { + ident(); sOut.write("/*", 2 ); sOut.write( pComment->getText().getStr(), pComment->getText().getSize() ); 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 void writeProperty( const Bu::TafProperty *pProp ); void writeComment( const Bu::TafComment *pComment ); void writeString( const Bu::FString &str ); + void ident(); Bu::Stream &sOut; + int iDepth; }; } -- cgit v1.2.3