Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: compiled/StringScanner.h

Issue 29630576: Issue 5146 - Part 2: Process http response in C++ (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebased Created Aug. 14, 2018, 12:45 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | compiled/bindings/main.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base.h" 22 #include "base.h"
23
21 #include "String.h" 24 #include "String.h"
22 25
23 ABP_NS_BEGIN 26 ABP_NS_BEGIN
24 27
25 class StringScanner 28 class StringScanner
26 { 29 {
27 private: 30 private:
28 const DependentString mStr; 31 const DependentString mStr;
29 String::size_type mPos; 32 String::size_type mPos;
30 String::size_type mEnd; 33 String::size_type mEnd;
(...skipping 19 matching lines...) Expand all
50 mPos--; 53 mPos--;
51 } 54 }
52 55
53 String::value_type next() 56 String::value_type next()
54 { 57 {
55 String::value_type result = done() ? mTerminator : mStr[mPos]; 58 String::value_type result = done() ? mTerminator : mStr[mPos];
56 mPos++; 59 mPos++;
57 return result; 60 return result;
58 } 61 }
59 62
63 bool skipWhiteSpace()
64 {
65 bool skipped = false;
66 while (!done() && std::iswspace(mStr[mPos]))
67 {
68 skipped = true;
69 mPos++;
70 }
71
72 return skipped;
73 }
74
75 bool skipString(const String& str)
76 {
77 bool skipped = false;
78
79 if (str.length() > mStr.length() - mPos)
80 return false;
81
82 if (std::memcmp(str.data(),
83 mStr.data() + mPos,
84 sizeof(String::value_type) * str.length()) == 0)
85 {
86 mPos += str.length();
87 skipped = true;
88 }
89
90 return skipped;
91 }
92
60 bool skipOne(String::value_type ch) 93 bool skipOne(String::value_type ch)
61 { 94 {
62 if (!done() && mStr[mPos] == ch) 95 if (!done() && mStr[mPos] == ch)
63 { 96 {
64 mPos++; 97 mPos++;
65 return true; 98 return true;
66 } 99 }
67 100
68 return false; 101 return false;
69 } 102 }
70 103
71 bool skip(String::value_type ch) 104 bool skip(String::value_type ch)
72 { 105 {
73 bool skipped = false; 106 bool skipped = false;
74 while ((skipped = skipOne(ch))); 107 while ((skipped = skipOne(ch)));
75 return skipped; 108 return skipped;
76 } 109 }
77 }; 110 };
78 111
79 ABP_NS_END 112 ABP_NS_END
OLDNEW
« no previous file with comments | « no previous file | compiled/bindings/main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld