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

Delta Between Two Patch Sets: compiled/RegExpFilter.cpp

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Left Patch Set: Addressed comments from Patch Set 24 Created Dec. 6, 2016, 10:43 a.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/RegExpFilter.h ('k') | compiled/String.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 #include <climits> 1 #include <climits>
2 2
3 #include <emscripten.h> 3 #include <emscripten.h>
4 4
5 #include "RegExpFilter.h" 5 #include "RegExpFilter.h"
6 #include "StringScanner.h" 6 #include "StringScanner.h"
7 #include "StringMap.h" 7 #include "StringMap.h"
8 8
9 namespace 9 namespace
10 { 10 {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 data.mContentType &= ~it->second; 118 data.mContentType &= ~it->second;
119 else 119 else
120 data.mContentType |= it->second; 120 data.mContentType |= it->second;
121 } 121 }
122 else if (name.equals(u"domain"_str)) 122 else if (name.equals(u"domain"_str))
123 { 123 {
124 if (valueStart >= 0 && valueEnd > valueStart) 124 if (valueStart >= 0 && valueEnd > valueStart)
125 { 125 {
126 data.mDomainsStart = valueStart; 126 data.mDomainsStart = valueStart;
127 data.mDomainsEnd = valueEnd; 127 data.mDomainsEnd = valueEnd;
128 DependentString(text, valueStart, valueEnd - valueStart).tolower(); 128 DependentString(text, valueStart, valueEnd - valueStart).toLower();
129 } 129 }
130 } 130 }
131 else if (name.equals(u"sitekey"_str)) 131 else if (name.equals(u"sitekey"_str))
132 { 132 {
133 if (valueStart >= 0 && valueEnd > valueStart) 133 if (valueStart >= 0 && valueEnd > valueStart)
134 { 134 {
135 data.mSitekeysStart = valueStart; 135 data.mSitekeysStart = valueStart;
136 data.mSitekeysEnd = valueEnd; 136 data.mSitekeysEnd = valueEnd;
137 } 137 }
138 } 138 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 { 209 {
210 if (mData.HasRegExp()) 210 if (mData.HasRegExp())
211 EM_ASM_ARGS(regexps.delete($0), mData.mRegexpId); 211 EM_ASM_ARGS(regexps.delete($0), mData.mRegexpId);
212 } 212 }
213 213
214 Filter::Type RegExpFilter::Parse(DependentString& text, DependentString& error, 214 Filter::Type RegExpFilter::Parse(DependentString& text, DependentString& error,
215 RegExpFilterData& data) 215 RegExpFilterData& data)
216 { 216 {
217 NormalizeWhitespace(text); 217 NormalizeWhitespace(text);
218 218
219 bool blocking = true; 219 Filter::Type type = Type::BLOCKING;
220 220
221 data.mPatternStart = 0; 221 data.mPatternStart = 0;
222 if (text.length() >= 2 && text[0] == u'@' && text[1] == u'@') 222 if (text.length() >= 2 && text[0] == u'@' && text[1] == u'@')
223 { 223 {
224 blocking = false; 224 type = Type::WHITELIST;
225 data.mPatternStart = 2; 225 data.mPatternStart = 2;
226 } 226 }
227 227
228 data.mPatternEnd = text.find(u'$', data.mPatternStart); 228 data.mPatternEnd = text.find(u'$', data.mPatternStart);
229 if (data.mPatternEnd == text.npos) 229 if (data.mPatternEnd == text.npos)
230 data.mPatternEnd = text.length(); 230 data.mPatternEnd = text.length();
231 231
232 ParseOptions(text, error, data, data.mPatternEnd + 1); 232 ParseOptions(text, error, data, data.mPatternEnd + 1);
233 if (!error.empty()) 233 if (!error.empty())
234 return Type::INVALID; 234 return Type::INVALID;
235 235
236 if (data.mPatternEnd - data.mPatternStart >= 2 && 236 if (data.mPatternEnd - data.mPatternStart >= 2 &&
237 text[data.mPatternStart] == u'/' && 237 text[data.mPatternStart] == u'/' &&
238 text[data.mPatternEnd - 1] == u'/') 238 text[data.mPatternEnd - 1] == u'/')
239 { 239 {
240 data.SetRegExp(GenerateRegExp(DependentString(text, data.mPatternStart + 1, 240 data.SetRegExp(GenerateRegExp(DependentString(text, data.mPatternStart + 1,
241 data.mPatternEnd - data.mPatternStart - 2), data.mMatchCase)); 241 data.mPatternEnd - data.mPatternStart - 2), data.mMatchCase));
242 if (data.mRegexpId == -1) 242 if (data.mRegexpId == -1)
243 { 243 {
244 error.reset(u"filter_invalid_regexp"_str); 244 error.reset(u"filter_invalid_regexp"_str);
245 return Type::INVALID; 245 return Type::INVALID;
246 } 246 }
247 } 247 }
248 248
249 if (blocking) 249 return type;
250 return Type::BLOCKING;
251 else
252 return Type::WHITELIST;
sergei 2017/01/10 15:57:50 It seems we could simply change type of blocking v
Wladimir Palant 2017/03/13 17:42:11 Done.
253 } 250 }
254 251
255 void RegExpFilter::ParseSitekeys(const String& sitekeys) const 252 void RegExpFilter::ParseSitekeys(const String& sitekeys) const
256 { 253 {
257 StringScanner scanner(sitekeys, 0, u'|'); 254 StringScanner scanner(sitekeys, 0, u'|');
258 size_t start = 0; 255 size_t start = 0;
259 bool done = false; 256 bool done = false;
260 while (!done) 257 while (!done)
261 { 258 {
262 done = scanner.done(); 259 done = scanner.done();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 return false; 363 return false;
367 } 364 }
368 365
369 if (!mData.RegExpParsingDone()) 366 if (!mData.RegExpParsingDone())
370 { 367 {
371 const OwnedString pattern(mData.GetRegExpSource(mText)); 368 const OwnedString pattern(mData.GetRegExpSource(mText));
372 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase)) ; 369 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase)) ;
373 } 370 }
374 return EM_ASM_INT(return regexps.test($0, $1), mData.mRegexpId, &location); 371 return EM_ASM_INT(return regexps.test($0, $1), mData.mRegexpId, &location);
375 } 372 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld