Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 #pragma once | 1 #pragma once |
2 | 2 |
3 #include "String.h" | 3 #include "String.h" |
4 | 4 |
5 class StringScanner | 5 class StringScanner |
6 { | 6 { |
7 private: | 7 private: |
8 const DependentString mStr; | 8 const DependentString mStr; |
9 String::size_type mPos; | 9 String::size_type mPos; |
10 String::size_type mEnd; | 10 String::size_type mEnd; |
11 String::value_type mTerminator; | 11 String::value_type mTerminator; |
12 public: | 12 public: |
13 explicit StringScanner(const String& str, String::size_type pos = 0, | 13 explicit StringScanner(const String& str, String::size_type pos = 0, |
14 String::value_type terminator = u'\0') | 14 String::value_type terminator = u'\0') |
15 : mStr(str), mPos(pos), mEnd(str.length()), mTerminator(terminator) {} | 15 : mStr(str), mPos(pos), mEnd(str.length()), mTerminator(terminator) {} |
16 | 16 |
17 const bool done() | 17 bool done() const |
sergei
2017/03/20 17:07:12
It should be `bool done() const`.
Wladimir Palant
2017/03/21 10:10:06
Done.
| |
18 { | 18 { |
19 return mPos >= mEnd; | 19 return mPos >= mEnd; |
20 } | 20 } |
21 | 21 |
22 const String::size_type position() | 22 String::size_type position() const |
sergei
2017/03/20 17:07:10
it should be `String::size_type position() const`.
Wladimir Palant
2017/03/21 10:10:09
Done.
| |
23 { | 23 { |
24 return mPos - 1; | 24 return mPos - 1; |
25 } | 25 } |
26 | 26 |
27 String::value_type next() | 27 String::value_type next() |
28 { | 28 { |
29 String::value_type result = done() ? mTerminator : mStr[mPos]; | 29 String::value_type result = done() ? mTerminator : mStr[mPos]; |
30 mPos++; | 30 mPos++; |
31 return result; | 31 return result; |
32 } | 32 } |
33 | 33 |
34 bool skipOne(String::value_type ch) | 34 bool skipOne(String::value_type ch) |
35 { | 35 { |
36 if (!done() && mStr[mPos] == ch) | 36 if (!done() && mStr[mPos] == ch) |
37 { | 37 { |
38 mPos++; | 38 mPos++; |
39 return true; | 39 return true; |
40 } | 40 } |
41 | 41 |
42 return false; | 42 return false; |
43 } | 43 } |
44 | 44 |
45 bool skip(String::value_type ch) | 45 bool skip(String::value_type ch) |
46 { | 46 { |
47 bool skipped = false; | 47 bool skipped = false; |
48 while ((skipped = skipOne(ch))); | 48 while ((skipped = skipOne(ch))); |
49 return skipped; | 49 return skipped; |
50 } | 50 } |
51 }; | 51 }; |
LEFT | RIGHT |