aboutsummaryrefslogtreecommitdiff
path: root/src/fmt.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-03-18 23:02:54 +0000
committerMike Buland <eichlan@xagasoft.com>2011-03-18 23:02:54 +0000
commitcba6293cf22e2c2ae17dd3954ad7d097f379c7ac (patch)
treedcdbda1f54d3d39a0066f2f42c7e1714e1ceb834 /src/fmt.h
parentfcf2dde54316a3ac35936157babccae8c8d8d90b (diff)
downloadlibbu++-cba6293cf22e2c2ae17dd3954ad7d097f379c7ac.tar.gz
libbu++-cba6293cf22e2c2ae17dd3954ad7d097f379c7ac.tar.bz2
libbu++-cba6293cf22e2c2ae17dd3954ad7d097f379c7ac.tar.xz
libbu++-cba6293cf22e2c2ae17dd3954ad7d097f379c7ac.zip
Wow, a lot has changed. String is not a template class, and it can do it's own
formatting ala QString.
Diffstat (limited to 'src/fmt.h')
-rw-r--r--src/fmt.h92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/fmt.h b/src/fmt.h
new file mode 100644
index 0000000..15d8efc
--- /dev/null
+++ b/src/fmt.h
@@ -0,0 +1,92 @@
1#ifndef BU_FMT_H
2#define BU_FMT_H
3
4namespace Bu
5{
6 typedef struct Fmt
7 {
8 enum Alignment
9 {
10 Left = 0,
11 Center = 1,
12 Right = 2
13 };
14 Fmt() :
15 uMinWidth( 0 ),
16 cFillChar(' '),
17 uRadix( 10 ),
18 uAlign( Right ),
19 bPlus( false ),
20 bCaps( true ),
21 bTokenize( true )
22 {
23 }
24
25 Fmt( unsigned int uMinWidth, unsigned int uRadix=10,
26 Alignment a=Right, bool bPlus=false, bool bCaps=true,
27 char cFill=' ') :
28 uMinWidth( uMinWidth ),
29 cFillChar(cFill),
30 uRadix( uRadix ),
31 uAlign( a ),
32 bPlus( bPlus ),
33 bCaps( bCaps ),
34 bTokenize( true )
35 {
36 }
37 Fmt( unsigned int uMinWidth, Alignment a,
38 unsigned int uRadix=10, bool bPlus=false, bool bCaps=true,
39 char cFill=' ') :
40 uMinWidth( uMinWidth ),
41 cFillChar(cFill),
42 uRadix( uRadix ),
43 uAlign( a ),
44 bPlus( bPlus ),
45 bCaps( bCaps ),
46 bTokenize( true )
47 {
48 }
49
50 static Fmt hex( unsigned int uWidth=0, bool bCaps=true )
51 {
52 return Fmt( uWidth, 16, Right, false, bCaps, '0' );
53 }
54
55 static Fmt oct( unsigned int uWidth=0 )
56 {
57 return Fmt( uWidth, 8, Right, false, false, '0' );
58 }
59
60 static Fmt bin( unsigned int uWidth=0 )
61 {
62 return Fmt( uWidth, 1, Right, false, false, '0' );
63 }
64
65 static Fmt ptr( bool bCaps=true )
66 {
67 return Fmt( sizeof(ptrdiff_t)*2, 16, Right, false, bCaps, '0' );
68 }
69
70 Fmt &width( unsigned int uWidth );
71 Fmt &fill( char cFill='0' );
72 Fmt &radix( unsigned int uRadix );
73 Fmt &align( Alignment eAlign );
74 Fmt &plus( bool bPlus=true );
75 Fmt &caps( bool bCaps=true );
76 Fmt &tokenize( bool bTokenize=true );
77
78 Fmt &left();
79 Fmt &right();
80 Fmt &center();
81
82 unsigned char uMinWidth;
83 char cFillChar;
84 unsigned short uRadix : 6;
85 unsigned short uAlign : 2;
86 unsigned short bPlus : 1;
87 unsigned short bCaps : 1;
88 unsigned short bTokenize : 1;
89 } Fmt;
90};
91
92#endif