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: Almost complete implementation, missing CSS property filters Created Jan. 20, 2016, 12:04 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> 3 #include "String.h"
5 4
6 class StringScanner 5 class StringScanner
7 { 6 {
8 private: 7 private:
9 const std::u16string str; 8 const DependentString mStr;
10 size_t pos; 9 String::size_type mPos;
11 size_t end; 10 String::size_type mEnd;
11 String::value_type mTerminator;
12 public: 12 public:
13 StringScanner(const std::u16string& str) : str(str), pos(0), end(str.length()) {} 13 explicit StringScanner(const String& str, String::size_type pos = 0,
14 String::value_type terminator = u'\0')
15 : mStr(str), mPos(pos), mEnd(str.length()), mTerminator(terminator) {}
14 16
15 bool done() 17 bool done() const
16 { 18 {
17 return pos >= end; 19 return mPos >= mEnd;
18 } 20 }
19 21
20 size_t position() 22 String::size_type position() const
21 { 23 {
22 return pos - 1; 24 return mPos - 1;
23 } 25 }
24 26
25 char16_t next() 27 String::value_type next()
26 { 28 {
27 return done() ? u'\0' : str[pos++]; 29 String::value_type result = done() ? mTerminator : mStr[mPos];
30 mPos++;
31 return result;
32 }
33
34 bool skipOne(String::value_type ch)
35 {
36 if (!done() && mStr[mPos] == ch)
37 {
38 mPos++;
39 return true;
40 }
41
42 return false;
43 }
44
45 bool skip(String::value_type ch)
46 {
47 bool skipped = false;
48 while ((skipped = skipOne(ch)));
49 return skipped;
28 } 50 }
29 }; 51 };
30
31 #endif
LEFTRIGHT

Powered by Google App Engine
This is Rietveld