1 | |
---|
2 | #include "Indentation.h" |
---|
3 | |
---|
4 | using namespace std; |
---|
5 | |
---|
6 | |
---|
7 | Indentation indent; |
---|
8 | |
---|
9 | |
---|
10 | Indentation::Indentation () |
---|
11 | : _tabulationSize(2) |
---|
12 | , _indentation() |
---|
13 | { } |
---|
14 | |
---|
15 | |
---|
16 | Indentation& Indentation::operator++ () |
---|
17 | { |
---|
18 | _indentation.append ( _tabulationSize, ' ' ); |
---|
19 | return *this; |
---|
20 | } |
---|
21 | |
---|
22 | |
---|
23 | Indentation Indentation::operator++ (int) |
---|
24 | { |
---|
25 | Indentation before (*this); |
---|
26 | |
---|
27 | _indentation.append ( _tabulationSize, ' ' ); |
---|
28 | return before; |
---|
29 | } |
---|
30 | |
---|
31 | |
---|
32 | Indentation& Indentation::operator-- () |
---|
33 | { |
---|
34 | if ( _indentation.length() > _tabulationSize ) |
---|
35 | _indentation.resize ( _indentation.length() - _tabulationSize ); |
---|
36 | else |
---|
37 | _indentation.clear (); |
---|
38 | return *this; |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | Indentation Indentation::operator-- (int) |
---|
43 | { |
---|
44 | Indentation before (*this); |
---|
45 | |
---|
46 | if ( _indentation.length() > _tabulationSize ) |
---|
47 | _indentation.resize ( _indentation.length() - _tabulationSize ); |
---|
48 | else |
---|
49 | _indentation.clear (); |
---|
50 | return before; |
---|
51 | } |
---|
52 | |
---|
53 | |
---|
54 | ostream& operator<< ( ostream& o, const Indentation& indent ) |
---|
55 | { |
---|
56 | o << indent._indentation; |
---|
57 | return o; |
---|
58 | } |
---|