From 94fff060ee9ec6c2a8da75568702d8e944963d46 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 16 Mar 2009 07:54:47 +0000 Subject: Added some experimental indenting code to the formatter, not sure I quite dig it yet, I'd recommend not using it much for now, the API could change drastically. --- src/formatter.cpp | 34 +++++++++++++++++++++++++++++++++- src/formatter.h | 10 ++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/formatter.cpp b/src/formatter.cpp index 36e49c8..6eb3b86 100644 --- a/src/formatter.cpp +++ b/src/formatter.cpp @@ -1,7 +1,9 @@ #include "formatter.h" Bu::Formatter::Formatter( Stream &rOut ) : - rOut( rOut ) + rOut( rOut ), + uIndent( 0 ), + cIndent( '\t' ) { } @@ -100,6 +102,33 @@ void Bu::Formatter::writeAligned( const char *sStr, int iLen ) usedFormat(); } +void Bu::Formatter::incIndent() +{ + if( uIndent < 0xFFU ) + uIndent++; +} + +void Bu::Formatter::decIndent() +{ + if( uIndent > 0 ) + uIndent--; +} + +void Bu::Formatter::setIndent( uint8_t uLevel ) +{ + uIndent = uLevel; +} + +void Bu::Formatter::clearIndent() +{ + uIndent = 0; +} + +void Bu::Formatter::setIndentChar( char cIndent ) +{ + this->cIndent = cIndent; +} + Bu::Formatter::Fmt &Bu::Formatter::Fmt::width( unsigned int uWidth ) { this->uMinWidth = uWidth; @@ -148,6 +177,9 @@ Bu::Formatter &Bu::operator<<( Bu::Formatter &rOut, Bu::Formatter::Special s ) { case Formatter::nl: rOut.write("\n", 1 ); + char ci = rOut.getIndentChar(); + for( int j = 0; j < rOut.getIndent(); j++ ) + rOut.write( &ci, 1 ); break; } return rOut; diff --git a/src/formatter.h b/src/formatter.h index d9066cb..693c3ed 100644 --- a/src/formatter.h +++ b/src/formatter.h @@ -87,6 +87,14 @@ namespace Bu void writeAligned( const Bu::FString &sStr ); void writeAligned( const char *sStr, int iLen ); + void incIndent(); + void decIndent(); + void setIndent( uint8_t uLevel ); + void clearIndent(); + uint8_t getIndent() const { return uIndent; } + void setIndentChar( char cIndent ); + char getIndentChar() const { return cIndent; } + void setFormat( const Fmt &f ) { fLast = f; @@ -178,6 +186,8 @@ namespace Bu Stream &rOut; Fmt fLast; bool bTempFmt; + uint8_t uIndent; + char cIndent; }; typedef Formatter::Fmt Fmt; -- cgit v1.2.3