diff options
Diffstat (limited to 'src/formatter.cpp')
| -rw-r--r-- | src/formatter.cpp | 76 |
1 files changed, 68 insertions, 8 deletions
diff --git a/src/formatter.cpp b/src/formatter.cpp index c6ae3b7..1ec3c39 100644 --- a/src/formatter.cpp +++ b/src/formatter.cpp | |||
| @@ -33,7 +33,7 @@ void Bu::Formatter::writeAligned( const Bu::FString &sStr ) | |||
| 33 | { | 33 | { |
| 34 | case Fmt::Right: | 34 | case Fmt::Right: |
| 35 | for( int k = 0; k < iRem; k++ ) | 35 | for( int k = 0; k < iRem; k++ ) |
| 36 | write(" ", 1 ); | 36 | write( &fLast.cFillChar, 1 ); |
| 37 | write( sStr ); | 37 | write( sStr ); |
| 38 | break; | 38 | break; |
| 39 | 39 | ||
| @@ -41,18 +41,18 @@ void Bu::Formatter::writeAligned( const Bu::FString &sStr ) | |||
| 41 | { | 41 | { |
| 42 | int iHlf = iRem/2; | 42 | int iHlf = iRem/2; |
| 43 | for( int k = 0; k < iHlf; k++ ) | 43 | for( int k = 0; k < iHlf; k++ ) |
| 44 | write(" ", 1 ); | 44 | write( &fLast.cFillChar, 1 ); |
| 45 | write( sStr ); | 45 | write( sStr ); |
| 46 | iHlf = iRem-iHlf;; | 46 | iHlf = iRem-iHlf;; |
| 47 | for( int k = 0; k < iHlf; k++ ) | 47 | for( int k = 0; k < iHlf; k++ ) |
| 48 | write(" ", 1 ); | 48 | write( &fLast.cFillChar, 1 ); |
| 49 | } | 49 | } |
| 50 | break; | 50 | break; |
| 51 | 51 | ||
| 52 | case Fmt::Left: | 52 | case Fmt::Left: |
| 53 | write( sStr ); | 53 | write( sStr ); |
| 54 | for( int k = 0; k < iRem; k++ ) | 54 | for( int k = 0; k < iRem; k++ ) |
| 55 | write(" ", 1 ); | 55 | write( &fLast.cFillChar, 1 ); |
| 56 | break; | 56 | break; |
| 57 | } | 57 | } |
| 58 | } | 58 | } |
| @@ -73,7 +73,7 @@ void Bu::Formatter::writeAligned( const char *sStr, int iLen ) | |||
| 73 | { | 73 | { |
| 74 | case Fmt::Right: | 74 | case Fmt::Right: |
| 75 | for( int k = 0; k < iRem; k++ ) | 75 | for( int k = 0; k < iRem; k++ ) |
| 76 | write(" ", 1 ); | 76 | write( &fLast.cFillChar, 1 ); |
| 77 | write( sStr, iLen ); | 77 | write( sStr, iLen ); |
| 78 | break; | 78 | break; |
| 79 | 79 | ||
| @@ -81,18 +81,18 @@ void Bu::Formatter::writeAligned( const char *sStr, int iLen ) | |||
| 81 | { | 81 | { |
| 82 | int iHlf = iRem/2; | 82 | int iHlf = iRem/2; |
| 83 | for( int k = 0; k < iHlf; k++ ) | 83 | for( int k = 0; k < iHlf; k++ ) |
| 84 | write(" ", 1 ); | 84 | write( &fLast.cFillChar, 1 ); |
| 85 | write( sStr, iLen ); | 85 | write( sStr, iLen ); |
| 86 | iHlf = iRem-iHlf;; | 86 | iHlf = iRem-iHlf;; |
| 87 | for( int k = 0; k < iHlf; k++ ) | 87 | for( int k = 0; k < iHlf; k++ ) |
| 88 | write(" ", 1 ); | 88 | write( &fLast.cFillChar, 1 ); |
| 89 | } | 89 | } |
| 90 | break; | 90 | break; |
| 91 | 91 | ||
| 92 | case Fmt::Left: | 92 | case Fmt::Left: |
| 93 | write( sStr, iLen ); | 93 | write( sStr, iLen ); |
| 94 | for( int k = 0; k < iRem; k++ ) | 94 | for( int k = 0; k < iRem; k++ ) |
| 95 | write(" ", 1 ); | 95 | write( &fLast.cFillChar, 1 ); |
| 96 | break; | 96 | break; |
| 97 | } | 97 | } |
| 98 | } | 98 | } |
| @@ -100,6 +100,42 @@ void Bu::Formatter::writeAligned( const char *sStr, int iLen ) | |||
| 100 | usedFormat(); | 100 | usedFormat(); |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | Bu::Formatter::Fmt &Bu::Formatter::Fmt::width( unsigned int uWidth ) | ||
| 104 | { | ||
| 105 | this->uMinWidth = uWidth; | ||
| 106 | return *this; | ||
| 107 | } | ||
| 108 | |||
| 109 | Bu::Formatter::Fmt &Bu::Formatter::Fmt::fill( char cFill ) | ||
| 110 | { | ||
| 111 | this->cFillChar = (unsigned char)cFill; | ||
| 112 | return *this; | ||
| 113 | } | ||
| 114 | |||
| 115 | Bu::Formatter::Fmt &Bu::Formatter::Fmt::radix( unsigned int uRadix ) | ||
| 116 | { | ||
| 117 | this->uRadix = uRadix; | ||
| 118 | return *this; | ||
| 119 | } | ||
| 120 | |||
| 121 | Bu::Formatter::Fmt &Bu::Formatter::Fmt::align( Alignment eAlign ) | ||
| 122 | { | ||
| 123 | this->uAlign = eAlign; | ||
| 124 | return *this; | ||
| 125 | } | ||
| 126 | |||
| 127 | Bu::Formatter::Fmt &Bu::Formatter::Fmt::plus( bool bPlus ) | ||
| 128 | { | ||
| 129 | this->bPlus = bPlus; | ||
| 130 | return *this; | ||
| 131 | } | ||
| 132 | |||
| 133 | Bu::Formatter::Fmt &Bu::Formatter::Fmt::caps( bool bCaps ) | ||
| 134 | { | ||
| 135 | this->bCaps = bCaps; | ||
| 136 | return *this; | ||
| 137 | } | ||
| 138 | |||
| 103 | Bu::Formatter &Bu::operator<<( Bu::Formatter &rOut, const Bu::Formatter::Fmt &f ) | 139 | Bu::Formatter &Bu::operator<<( Bu::Formatter &rOut, const Bu::Formatter::Fmt &f ) |
| 104 | { | 140 | { |
| 105 | rOut.setTempFormat( f ); | 141 | rOut.setTempFormat( f ); |
| @@ -195,3 +231,27 @@ Bu::Formatter &Bu::operator<<( Bu::Formatter &rOut, unsigned long long i ) | |||
| 195 | return rOut; | 231 | return rOut; |
| 196 | } | 232 | } |
| 197 | 233 | ||
| 234 | Bu::Formatter &Bu::operator<<( Bu::Formatter &rOut, float f ) | ||
| 235 | { | ||
| 236 | rOut.ffmt<float>( f ); | ||
| 237 | return rOut; | ||
| 238 | } | ||
| 239 | |||
| 240 | Bu::Formatter &Bu::operator<<( Bu::Formatter &rOut, double f ) | ||
| 241 | { | ||
| 242 | rOut.ffmt<double>( f ); | ||
| 243 | return rOut; | ||
| 244 | } | ||
| 245 | |||
| 246 | Bu::Formatter &Bu::operator<<( Bu::Formatter &rOut, long double f ) | ||
| 247 | { | ||
| 248 | rOut.ffmt<long double>( f ); | ||
| 249 | return rOut; | ||
| 250 | } | ||
| 251 | |||
| 252 | Bu::Formatter &Bu::operator<<( Bu::Formatter &rOut, bool b ) | ||
| 253 | { | ||
| 254 | rOut.writeAligned( b?("true"):("false") ); | ||
| 255 | return rOut; | ||
| 256 | } | ||
| 257 | |||
