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

Delta Between Two Patch Sets: compiled/StringScanner.h

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Left Patch Set: Split up String class into two, cleaned up RegExpFilter methods Created Feb. 4, 2016, 7:20 p.m.
Right Patch Set: Addressed comments from Patch Set 28 Created March 21, 2017, 10:04 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « compiled/StringMap.h ('k') | compiled/WhitelistFilter.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #ifndef ADBLOCK_PLUS_STRING_SCANNER_H 1 #pragma once
2 #define ADBLOCK_PLUS_STRING_SCANNER_H
3 2
4 #include "String.h" 3 #include "String.h"
5 4
6 class StringScanner 5 class StringScanner
7 { 6 {
8 private: 7 private:
9 const String mStr; 8 const DependentString mStr;
10 String::size_type mPos; 9 String::size_type mPos;
11 String::size_type mEnd; 10 String::size_type mEnd;
12 String::value_type mTerminator; 11 String::value_type mTerminator;
13 public: 12 public:
14 StringScanner(const String& str, String::size_type pos = 0, 13 explicit StringScanner(const String& str, String::size_type pos = 0,
15 String::value_type terminator = u'\0') 14 String::value_type terminator = u'\0')
16 : mStr(str), mPos(pos), mEnd(str.length()), mTerminator(terminator) {} 15 : mStr(str), mPos(pos), mEnd(str.length()), mTerminator(terminator) {}
17 16
18 bool done() 17 bool done() const
19 { 18 {
20 return mPos >= mEnd; 19 return mPos >= mEnd;
21 } 20 }
22 21
23 String::size_type position() 22 String::size_type position() const
24 { 23 {
25 return mPos - 1; 24 return mPos - 1;
26 } 25 }
27 26
28 String::value_type next() 27 String::value_type next()
29 { 28 {
30 String::value_type result = done() ? mTerminator : mStr[mPos]; 29 String::value_type result = done() ? mTerminator : mStr[mPos];
31 mPos++; 30 mPos++;
32 return result; 31 return result;
33 } 32 }
34 33
35 bool skipOne(String::value_type ch) 34 bool skipOne(String::value_type ch)
36 { 35 {
37 if (!done() && mStr[mPos] == ch) 36 if (!done() && mStr[mPos] == ch)
38 { 37 {
39 mPos++; 38 mPos++;
40 return true; 39 return true;
41 } 40 }
42 41
43 return false; 42 return false;
44 } 43 }
45 44
46 bool skip(String::value_type ch) 45 bool skip(String::value_type ch)
47 { 46 {
48 String::size_type oldPos = mPos; 47 bool skipped = false;
49 while (!done() && mStr[mPos] == ch) 48 while ((skipped = skipOne(ch)));
50 mPos++; 49 return skipped;
51 return oldPos != mPos;
52 } 50 }
53 }; 51 };
54
55 #endif
LEFTRIGHT

Powered by Google App Engine
This is Rietveld