OLD | NEW |
(Empty) | |
| 1 #ifndef ADBLOCK_PLUS_STRING_SCANNER_H |
| 2 #define ADBLOCK_PLUS_STRING_SCANNER_H |
| 3 |
| 4 #include "String.h" |
| 5 |
| 6 class StringScanner |
| 7 { |
| 8 private: |
| 9 const String mStr; |
| 10 String::size_type mPos; |
| 11 String::size_type mEnd; |
| 12 String::value_type mTerminator; |
| 13 public: |
| 14 StringScanner(const String& str, String::size_type pos = 0, |
| 15 String::value_type terminator = u'\0') |
| 16 : mStr(str), mPos(pos), mEnd(str.length()), mTerminator(terminator) {} |
| 17 |
| 18 bool done() |
| 19 { |
| 20 return mPos >= mEnd; |
| 21 } |
| 22 |
| 23 String::size_type position() |
| 24 { |
| 25 return mPos - 1; |
| 26 } |
| 27 |
| 28 String::value_type next() |
| 29 { |
| 30 String::value_type result = done() ? mTerminator : mStr[mPos]; |
| 31 mPos++; |
| 32 return result; |
| 33 } |
| 34 |
| 35 bool skipOne(String::value_type ch) |
| 36 { |
| 37 if (!done() && mStr[mPos] == ch) |
| 38 { |
| 39 mPos++; |
| 40 return true; |
| 41 } |
| 42 |
| 43 return false; |
| 44 } |
| 45 |
| 46 bool skip(String::value_type ch) |
| 47 { |
| 48 String::size_type oldPos = mPos; |
| 49 while (!done() && mStr[mPos] == ch) |
| 50 mPos++; |
| 51 return oldPos != mPos; |
| 52 } |
| 53 }; |
| 54 |
| 55 #endif |
OLD | NEW |