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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 #include <cctype> | 18 #include <cctype> |
19 #include <climits> | 19 #include <climits> |
20 #include <cstdio> | 20 #include <cstdio> |
21 #include <string> | 21 #include <string> |
22 | 22 |
23 #include <emscripten.h> | 23 #include <emscripten.h> |
24 | 24 |
25 #include "RegExpFilter.h" | 25 #include "RegExpFilter.h" |
26 #include "../StringScanner.h" | 26 #include "../StringScanner.h" |
27 #include "../StringMap.h" | 27 #include "../StringMap.h" |
28 | 28 |
| 29 extern "C" |
| 30 { |
| 31 int GenerateRegExp(const String& regexp, bool matchCase); |
| 32 void DeleteRegExp(int id); |
| 33 bool TestRegExp(int id, const String& str); |
| 34 } |
| 35 |
29 namespace | 36 namespace |
30 { | 37 { |
31 enum | 38 enum |
32 { | 39 { |
33 TYPE_OTHER = 0x1, | 40 TYPE_OTHER = 0x1, |
34 TYPE_SCRIPT = 0x2, | 41 TYPE_SCRIPT = 0x2, |
35 TYPE_IMAGE = 0x4, | 42 TYPE_IMAGE = 0x4, |
36 TYPE_STYLESHEET = 0x8, | 43 TYPE_STYLESHEET = 0x8, |
37 TYPE_OBJECT = 0x10, | 44 TYPE_OBJECT = 0x10, |
38 TYPE_SUBDOCUMENT = 0x20, | 45 TYPE_SUBDOCUMENT = 0x20, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 { | 137 { |
131 result.append(u'\\'); | 138 result.append(u'\\'); |
132 } | 139 } |
133 result.append(currChar); | 140 result.append(currChar); |
134 } | 141 } |
135 prevChar = currChar; | 142 prevChar = currChar; |
136 } | 143 } |
137 return result; | 144 return result; |
138 } | 145 } |
139 | 146 |
140 int GenerateRegExp(const String& regexp, bool matchCase) | |
141 { | |
142 return EM_ASM_INT(return regexps.create($0, $1), ®exp, matchCase); | |
143 } | |
144 | |
145 void NormalizeWhitespace(DependentString& text) | 147 void NormalizeWhitespace(DependentString& text) |
146 { | 148 { |
147 // We want to remove all spaces but bail out early in the common scenario | 149 // We want to remove all spaces but bail out early in the common scenario |
148 // that the string contains no spaces. | 150 // that the string contains no spaces. |
149 | 151 |
150 // Look for the first space | 152 // Look for the first space |
151 String::size_type len = text.length(); | 153 String::size_type len = text.length(); |
152 String::size_type pos; | 154 String::size_type pos; |
153 for (pos = 0; pos < len; pos++) | 155 for (pos = 0; pos < len; pos++) |
154 if (text[pos] == ' ') | 156 if (text[pos] == ' ') |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 } | 286 } |
285 | 287 |
286 RegExpFilter::RegExpFilter(Type type, const String& text, const RegExpFilterData
& data) | 288 RegExpFilter::RegExpFilter(Type type, const String& text, const RegExpFilterData
& data) |
287 : ActiveFilter(type, text, true), mData(data) | 289 : ActiveFilter(type, text, true), mData(data) |
288 { | 290 { |
289 } | 291 } |
290 | 292 |
291 RegExpFilter::~RegExpFilter() | 293 RegExpFilter::~RegExpFilter() |
292 { | 294 { |
293 if (mData.HasRegExp()) | 295 if (mData.HasRegExp()) |
294 EM_ASM_ARGS(regexps.delete($0), mData.mRegexpId); | 296 DeleteRegExp(mData.mRegexpId); |
295 } | 297 } |
296 | 298 |
297 Filter::Type RegExpFilter::Parse(DependentString& text, DependentString& error, | 299 Filter::Type RegExpFilter::Parse(DependentString& text, DependentString& error, |
298 RegExpFilterData& data) | 300 RegExpFilterData& data) |
299 { | 301 { |
300 NormalizeWhitespace(text); | 302 NormalizeWhitespace(text); |
301 | 303 |
302 Filter::Type type = Type::BLOCKING; | 304 Filter::Type type = Type::BLOCKING; |
303 | 305 |
304 data.mPatternStart = 0; | 306 data.mPatternStart = 0; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 !IsActiveOnDomain(docDomain, sitekey)) | 394 !IsActiveOnDomain(docDomain, sitekey)) |
393 { | 395 { |
394 return false; | 396 return false; |
395 } | 397 } |
396 | 398 |
397 if (!mData.RegExpParsingDone()) | 399 if (!mData.RegExpParsingDone()) |
398 { | 400 { |
399 const OwnedString pattern(mData.GetRegExpSource(mText)); | 401 const OwnedString pattern(mData.GetRegExpSource(mText)); |
400 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase))
; | 402 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase))
; |
401 } | 403 } |
402 return EM_ASM_INT(return regexps.test($0, $1), mData.mRegexpId, &location); | 404 return TestRegExp(mData.mRegexpId, location); |
403 } | 405 } |
OLD | NEW |