From 2ab64959d83ed2793d71ab3fa03b8ebdd4925902 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 9 Nov 2007 22:38:47 +0000 Subject: Figured I might as well add single-line comments to taf, it now supports // style comments. --- src/tafnode.cpp | 10 ++++++++-- src/tafnode.h | 4 +++- src/tafreader.cpp | 41 ++++++++++++++++++++++++++++++++--------- src/tafreader.h | 2 +- src/tafwriter.cpp | 15 ++++++++++++--- 5 files changed, 56 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/tafnode.cpp b/src/tafnode.cpp index c04455b..ec51535 100644 --- a/src/tafnode.cpp +++ b/src/tafnode.cpp @@ -141,9 +141,10 @@ const Bu::FString &Bu::TafProperty::getValue() const return sValue; } -Bu::TafComment::TafComment( const Bu::FString &sText ) : +Bu::TafComment::TafComment( const Bu::FString &sText, bool bEOL ) : TafNode( typeComment ), - sText( sText ) + sText( sText ), + bEOL( bEOL ) { } @@ -156,3 +157,8 @@ const Bu::FString &Bu::TafComment::getText() const return sText; } +bool Bu::TafComment::isEOLStyle() const +{ + return bEOL; +} + diff --git a/src/tafnode.h b/src/tafnode.h index 585ba73..e2e1cc0 100644 --- a/src/tafnode.h +++ b/src/tafnode.h @@ -98,13 +98,15 @@ namespace Bu class TafComment : public TafNode { public: - TafComment( const Bu::FString &sText ); + TafComment( const Bu::FString &sText, bool bEOL=false ); virtual ~TafComment(); const Bu::FString &getText() const; + bool isEOLStyle() const; private: Bu::FString sText; + bool bEOL; }; } diff --git a/src/tafreader.cpp b/src/tafreader.cpp index 5609f7c..efcb3d9 100644 --- a/src/tafreader.cpp +++ b/src/tafreader.cpp @@ -49,6 +49,8 @@ void Bu::TafReader::groupContent( Bu::TafGroup *pGroup ) return; else if( c == '/' && la == '*' ) pGroup->addChild( readComment() ); + else if( c == '/' && la == '/' ) + pGroup->addChild( readComment( true ) ); else if( c == ':' ) throw TafException("Encountered stray ':' in taf stream."); else @@ -71,22 +73,43 @@ Bu::TafProperty *Bu::TafReader::readProperty() //printf(" %s = %s\n", sName.getStr(), sValue.getStr() ); } -Bu::TafComment *Bu::TafReader::readComment() +Bu::TafComment *Bu::TafReader::readComment( bool bEOL ) { - next(); FString sCmnt; - for(;;) + next(); + if( bEOL ) { - next(); - if( c == '*' && la == '/' ) + for(;;) { - next(); next(); - break; + next(); + if( c == '\n' && la == '\r' ) + { + next(); next(); + break; + } + else if( c == '\n' || c == '\r' ) + { + next(); + break; + } + sCmnt += c; + } + } + else + { + for(;;) + { + next(); + if( c == '*' && la == '/' ) + { + next(); next(); + break; + } + sCmnt += c; } - sCmnt += c; } - return new TafComment( sCmnt ); + return new TafComment( sCmnt, bEOL ); } Bu::FString Bu::TafReader::readStr() diff --git a/src/tafreader.h b/src/tafreader.h index da285ab..f722ca4 100644 --- a/src/tafreader.h +++ b/src/tafreader.h @@ -23,7 +23,7 @@ namespace Bu private: void groupContent( Bu::TafGroup *pNode ); Bu::TafProperty *readProperty(); - Bu::TafComment *readComment(); + Bu::TafComment *readComment( bool bEOL=false ); void ws(); bool isws(); void next(); diff --git a/src/tafwriter.cpp b/src/tafwriter.cpp index b5690fc..c2fbc50 100644 --- a/src/tafwriter.cpp +++ b/src/tafwriter.cpp @@ -65,9 +65,18 @@ void Bu::TafWriter::writeProperty( const Bu::TafProperty *pProp ) void Bu::TafWriter::writeComment( const Bu::TafComment *pComment ) { ident(); - sOut.write("/*", 2 ); - sOut.write( pComment->getText().getStr(), pComment->getText().getSize() ); - sOut.write("*/ ", 3 ); + if( pComment->isEOLStyle() ) + { + sOut.write("//", 2 ); + sOut.write( pComment->getText().getStr(), pComment->getText().getSize() ); + sOut.write("\n", 1 ); + } + else + { + sOut.write("/*", 2 ); + sOut.write( pComment->getText().getStr(), pComment->getText().getSize() ); + sOut.write("*/ ", 3 ); + } } void Bu::TafWriter::writeString( const Bu::FString &str ) -- cgit v1.2.3