OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #pragma once | 18 #pragma once |
19 | 19 |
| 20 #include <cwctype> |
| 21 |
20 #include "String.h" | 22 #include "String.h" |
21 | 23 |
22 class StringScanner | 24 class StringScanner |
23 { | 25 { |
24 private: | 26 private: |
25 const DependentString mStr; | 27 const DependentString mStr; |
26 String::size_type mPos; | 28 String::size_type mPos; |
27 String::size_type mEnd; | 29 String::size_type mEnd; |
28 String::value_type mTerminator; | 30 String::value_type mTerminator; |
29 public: | 31 public: |
(...skipping 17 matching lines...) Expand all Loading... |
47 mPos--; | 49 mPos--; |
48 } | 50 } |
49 | 51 |
50 String::value_type next() | 52 String::value_type next() |
51 { | 53 { |
52 String::value_type result = done() ? mTerminator : mStr[mPos]; | 54 String::value_type result = done() ? mTerminator : mStr[mPos]; |
53 mPos++; | 55 mPos++; |
54 return result; | 56 return result; |
55 } | 57 } |
56 | 58 |
| 59 bool skipWhiteSpace() |
| 60 { |
| 61 bool skipped = false; |
| 62 while (!done() && std::iswspace(mStr[mPos])) |
| 63 { |
| 64 skipped = true; |
| 65 mPos++; |
| 66 } |
| 67 |
| 68 return skipped; |
| 69 } |
| 70 |
| 71 bool skipString(const String& str) |
| 72 { |
| 73 bool skipped = false; |
| 74 |
| 75 if (str.length() > mStr.length() - mPos) |
| 76 return false; |
| 77 |
| 78 if (std::memcmp(str.data(), |
| 79 mStr.data() + mPos, |
| 80 sizeof(String::value_type) * str.length()) == 0) |
| 81 { |
| 82 mPos += str.length(); |
| 83 skipped = true; |
| 84 } |
| 85 |
| 86 return skipped; |
| 87 } |
| 88 |
57 bool skipOne(String::value_type ch) | 89 bool skipOne(String::value_type ch) |
58 { | 90 { |
59 if (!done() && mStr[mPos] == ch) | 91 if (!done() && mStr[mPos] == ch) |
60 { | 92 { |
61 mPos++; | 93 mPos++; |
62 return true; | 94 return true; |
63 } | 95 } |
64 | 96 |
65 return false; | 97 return false; |
66 } | 98 } |
67 | 99 |
68 bool skip(String::value_type ch) | 100 bool skip(String::value_type ch) |
69 { | 101 { |
70 bool skipped = false; | 102 bool skipped = false; |
71 while ((skipped = skipOne(ch))); | 103 while ((skipped = skipOne(ch))); |
72 return skipped; | 104 return skipped; |
73 } | 105 } |
74 }; | 106 }; |
OLD | NEW |