diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2009-03-16 07:54:47 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2009-03-16 07:54:47 +0000 |
| commit | 94fff060ee9ec6c2a8da75568702d8e944963d46 (patch) | |
| tree | ca1180937070a61f82f3b63406d3b229b162f48a /src/formatter.cpp | |
| parent | 7433ec9074051ea5d9f91458e2e91e29ec8020f2 (diff) | |
| download | libbu++-94fff060ee9ec6c2a8da75568702d8e944963d46.tar.gz libbu++-94fff060ee9ec6c2a8da75568702d8e944963d46.tar.bz2 libbu++-94fff060ee9ec6c2a8da75568702d8e944963d46.tar.xz libbu++-94fff060ee9ec6c2a8da75568702d8e944963d46.zip | |
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.
Diffstat (limited to '')
| -rw-r--r-- | src/formatter.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
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 @@ | |||
| 1 | #include "formatter.h" | 1 | #include "formatter.h" |
| 2 | 2 | ||
| 3 | Bu::Formatter::Formatter( Stream &rOut ) : | 3 | Bu::Formatter::Formatter( Stream &rOut ) : |
| 4 | rOut( rOut ) | 4 | rOut( rOut ), |
| 5 | uIndent( 0 ), | ||
| 6 | cIndent( '\t' ) | ||
| 5 | { | 7 | { |
| 6 | } | 8 | } |
| 7 | 9 | ||
| @@ -100,6 +102,33 @@ void Bu::Formatter::writeAligned( const char *sStr, int iLen ) | |||
| 100 | usedFormat(); | 102 | usedFormat(); |
| 101 | } | 103 | } |
| 102 | 104 | ||
| 105 | void Bu::Formatter::incIndent() | ||
| 106 | { | ||
| 107 | if( uIndent < 0xFFU ) | ||
| 108 | uIndent++; | ||
| 109 | } | ||
| 110 | |||
| 111 | void Bu::Formatter::decIndent() | ||
| 112 | { | ||
| 113 | if( uIndent > 0 ) | ||
| 114 | uIndent--; | ||
| 115 | } | ||
| 116 | |||
| 117 | void Bu::Formatter::setIndent( uint8_t uLevel ) | ||
| 118 | { | ||
| 119 | uIndent = uLevel; | ||
| 120 | } | ||
| 121 | |||
| 122 | void Bu::Formatter::clearIndent() | ||
| 123 | { | ||
| 124 | uIndent = 0; | ||
| 125 | } | ||
| 126 | |||
| 127 | void Bu::Formatter::setIndentChar( char cIndent ) | ||
| 128 | { | ||
| 129 | this->cIndent = cIndent; | ||
| 130 | } | ||
| 131 | |||
| 103 | Bu::Formatter::Fmt &Bu::Formatter::Fmt::width( unsigned int uWidth ) | 132 | Bu::Formatter::Fmt &Bu::Formatter::Fmt::width( unsigned int uWidth ) |
| 104 | { | 133 | { |
| 105 | this->uMinWidth = uWidth; | 134 | this->uMinWidth = uWidth; |
| @@ -148,6 +177,9 @@ Bu::Formatter &Bu::operator<<( Bu::Formatter &rOut, Bu::Formatter::Special s ) | |||
| 148 | { | 177 | { |
| 149 | case Formatter::nl: | 178 | case Formatter::nl: |
| 150 | rOut.write("\n", 1 ); | 179 | rOut.write("\n", 1 ); |
| 180 | char ci = rOut.getIndentChar(); | ||
| 181 | for( int j = 0; j < rOut.getIndent(); j++ ) | ||
| 182 | rOut.write( &ci, 1 ); | ||
| 151 | break; | 183 | break; |
| 152 | } | 184 | } |
| 153 | return rOut; | 185 | return rOut; |
