Index: compiled/StringScanner.h |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/compiled/StringScanner.h |
@@ -0,0 +1,51 @@ |
+#pragma once |
+ |
+#include "String.h" |
+ |
+class StringScanner |
+{ |
+private: |
+ const DependentString mStr; |
+ String::size_type mPos; |
+ String::size_type mEnd; |
+ String::value_type mTerminator; |
+public: |
+ StringScanner(const String& str, String::size_type pos = 0, |
+ String::value_type terminator = u'\0') |
+ : mStr(str), mPos(pos), mEnd(str.length()), mTerminator(terminator) {} |
+ |
+ bool done() |
sergei
2017/01/10 15:58:08
this method should be const.
Wladimir Palant
2017/03/13 17:42:30
Done.
|
+ { |
+ return mPos >= mEnd; |
+ } |
+ |
+ 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.
|
+ { |
+ return mPos - 1; |
+ } |
+ |
+ String::value_type next() |
+ { |
+ String::value_type result = done() ? mTerminator : mStr[mPos]; |
+ mPos++; |
+ return result; |
+ } |
+ |
+ bool skipOne(String::value_type ch) |
+ { |
+ if (!done() && mStr[mPos] == ch) |
+ { |
+ mPos++; |
+ return true; |
+ } |
+ |
+ return false; |
+ } |
+ |
+ bool skip(String::value_type ch) |
+ { |
+ bool skipped = false; |
+ 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
|
+ return skipped; |
+ } |
+}; |