forked from bruderstein/PythonScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathANSIIterator.h
More file actions
93 lines (74 loc) · 1.43 KB
/
ANSIIterator.h
File metadata and controls
93 lines (74 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef ANSIITERATOR_H_1245813891234891238
#define ANSIITERATOR_H_1245813891234891238
class ANSIIterator : public std::iterator<std::bidirectional_iterator_tag, char>
{
public:
ANSIIterator(const char* doc = NULL, int pos = 0, int end = 0) :
_doc(doc),
_pos(pos),
_end(end)
{
// Check for debug builds
assert(_pos <= _end);
// Ensure for release.
if (_pos > _end)
_pos = _end;
}
ANSIIterator(const ANSIIterator& copy) :
_doc(copy._doc),
_pos(copy._pos),
_end(copy._end)
{
}
bool operator == (const ANSIIterator& other) const
{
return (ended() == other.ended()) && (_doc == other._doc) && (_pos == other._pos);
}
bool operator != (const ANSIIterator& other) const
{
return !(*this == other);
}
char operator * () const
{
return _doc[_pos];
}
ANSIIterator& operator = (int pos)
{
_pos = pos;
return *this;
}
ANSIIterator& operator ++ ()
{
assert(_pos < _end);
++_pos;
if (ended())
_pos = _end;
return *this;
}
ANSIIterator& operator -- ()
{
assert(_pos > 0);
--_pos;
if (_pos < 0) {
_pos = 0;
}
return *this;
}
int pos() const
{
return _pos;
}
private:
bool ended() const
{
return bytesLeft() <= 0;
}
int bytesLeft() const
{
return _end - _pos;
}
const char* _doc;
int _pos;
int _end;
};
#endif // ANSIITERATOR_H_1245813891234891238