Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 #pragma once | |
2 | |
3 #include "String.h" | |
4 | |
5 class StringScanner | |
6 { | |
7 private: | |
8 const DependentString mStr; | |
9 String::size_type mPos; | |
10 String::size_type mEnd; | |
11 String::value_type mTerminator; | |
12 public: | |
13 StringScanner(const String& str, String::size_type pos = 0, | |
14 String::value_type terminator = u'\0') | |
15 : mStr(str), mPos(pos), mEnd(str.length()), mTerminator(terminator) {} | |
16 | |
17 bool done() | |
sergei
2017/01/10 15:58:08
this method should be const.
Wladimir Palant
2017/03/13 17:42:30
Done.
| |
18 { | |
19 return mPos >= mEnd; | |
20 } | |
21 | |
22 String::size_type position() | |
sergei
2017/01/10 15:58:10
this method also should be const.
Wladimir Palant
2017/03/13 17:42:25
Done.
| |
23 { | |
24 return mPos - 1; | |
25 } | |
26 | |
27 String::value_type next() | |
28 { | |
29 String::value_type result = done() ? mTerminator : mStr[mPos]; | |
30 mPos++; | |
31 return result; | |
32 } | |
33 | |
34 bool skipOne(String::value_type ch) | |
35 { | |
36 if (!done() && mStr[mPos] == ch) | |
37 { | |
38 mPos++; | |
39 return true; | |
40 } | |
41 | |
42 return false; | |
43 } | |
44 | |
45 bool skip(String::value_type ch) | |
46 { | |
47 bool skipped = false; | |
48 while ((skipped = skipOne(ch))); | |
sergei
2017/01/10 15:58:06
Nit: extra parentheses are actually not needed.
Wladimir Palant
2017/03/13 17:42:28
They are, in order to avoid a compiler warning - t
| |
49 return skipped; | |
50 } | |
51 }; | |
OLD | NEW |