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> | |
24 | |
25 #include "RegExpFilter.h" | 23 #include "RegExpFilter.h" |
| 24 #include "../library.h" |
26 #include "../StringScanner.h" | 25 #include "../StringScanner.h" |
27 #include "../StringMap.h" | 26 #include "../StringMap.h" |
28 | 27 |
29 namespace | 28 namespace |
30 { | 29 { |
31 enum | 30 enum |
32 { | 31 { |
33 TYPE_OTHER = 0x1, | 32 TYPE_OTHER = 0x1, |
34 TYPE_SCRIPT = 0x2, | 33 TYPE_SCRIPT = 0x2, |
35 TYPE_IMAGE = 0x4, | 34 TYPE_IMAGE = 0x4, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 { | 129 { |
131 result.append(u'\\'); | 130 result.append(u'\\'); |
132 } | 131 } |
133 result.append(currChar); | 132 result.append(currChar); |
134 } | 133 } |
135 prevChar = currChar; | 134 prevChar = currChar; |
136 } | 135 } |
137 return result; | 136 return result; |
138 } | 137 } |
139 | 138 |
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) | 139 void NormalizeWhitespace(DependentString& text) |
146 { | 140 { |
147 // We want to remove all spaces but bail out early in the common scenario | 141 // We want to remove all spaces but bail out early in the common scenario |
148 // that the string contains no spaces. | 142 // that the string contains no spaces. |
149 | 143 |
150 // Look for the first space | 144 // Look for the first space |
151 String::size_type len = text.length(); | 145 String::size_type len = text.length(); |
152 String::size_type pos; | 146 String::size_type pos; |
153 for (pos = 0; pos < len; pos++) | 147 for (pos = 0; pos < len; pos++) |
154 if (text[pos] == ' ') | 148 if (text[pos] == ' ') |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 } | 278 } |
285 | 279 |
286 RegExpFilter::RegExpFilter(Type type, const String& text, const RegExpFilterData
& data) | 280 RegExpFilter::RegExpFilter(Type type, const String& text, const RegExpFilterData
& data) |
287 : ActiveFilter(type, text, true), mData(data) | 281 : ActiveFilter(type, text, true), mData(data) |
288 { | 282 { |
289 } | 283 } |
290 | 284 |
291 RegExpFilter::~RegExpFilter() | 285 RegExpFilter::~RegExpFilter() |
292 { | 286 { |
293 if (mData.HasRegExp()) | 287 if (mData.HasRegExp()) |
294 EM_ASM_ARGS(regexps.delete($0), mData.mRegexpId); | 288 DeleteRegExp(mData.mRegexpId); |
295 } | 289 } |
296 | 290 |
297 Filter::Type RegExpFilter::Parse(DependentString& text, DependentString& error, | 291 Filter::Type RegExpFilter::Parse(DependentString& text, DependentString& error, |
298 RegExpFilterData& data) | 292 RegExpFilterData& data) |
299 { | 293 { |
300 NormalizeWhitespace(text); | 294 NormalizeWhitespace(text); |
301 | 295 |
302 Filter::Type type = Type::BLOCKING; | 296 Filter::Type type = Type::BLOCKING; |
303 | 297 |
304 data.mPatternStart = 0; | 298 data.mPatternStart = 0; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 !IsActiveOnDomain(docDomain, sitekey)) | 386 !IsActiveOnDomain(docDomain, sitekey)) |
393 { | 387 { |
394 return false; | 388 return false; |
395 } | 389 } |
396 | 390 |
397 if (!mData.RegExpParsingDone()) | 391 if (!mData.RegExpParsingDone()) |
398 { | 392 { |
399 const OwnedString pattern(mData.GetRegExpSource(mText)); | 393 const OwnedString pattern(mData.GetRegExpSource(mText)); |
400 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase))
; | 394 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase))
; |
401 } | 395 } |
402 return EM_ASM_INT(return regexps.test($0, $1), mData.mRegexpId, &location); | 396 return TestRegExp(mData.mRegexpId, location); |
403 } | 397 } |
OLD | NEW |