LEFT | RIGHT |
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 "RegExpFilter.h" | 23 #include "RegExpFilter.h" |
24 #include "../library.h" | 24 #include "../library.h" |
25 #include "../StringScanner.h" | 25 #include "../StringScanner.h" |
26 #include "../StringMap.h" | 26 #include "../StringMap.h" |
| 27 |
| 28 ABP_NS_USING |
27 | 29 |
28 namespace | 30 namespace |
29 { | 31 { |
30 enum | 32 enum |
31 { | 33 { |
32 TYPE_OTHER = 0x1, | 34 TYPE_OTHER = 0x1, |
33 TYPE_SCRIPT = 0x2, | 35 TYPE_SCRIPT = 0x2, |
34 TYPE_IMAGE = 0x4, | 36 TYPE_IMAGE = 0x4, |
35 TYPE_STYLESHEET = 0x8, | 37 TYPE_STYLESHEET = 0x8, |
36 TYPE_OBJECT = 0x10, | 38 TYPE_OBJECT = 0x10, |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 { | 213 { |
212 data.mSitekeysStart = valueStart; | 214 data.mSitekeysStart = valueStart; |
213 data.mSitekeysEnd = valueEnd; | 215 data.mSitekeysEnd = valueEnd; |
214 } | 216 } |
215 } | 217 } |
216 else if (name.equals(u"match-case"_str)) | 218 else if (name.equals(u"match-case"_str)) |
217 data.mMatchCase = !reverse; | 219 data.mMatchCase = !reverse; |
218 else if (name.equals(u"third-party"_str)) | 220 else if (name.equals(u"third-party"_str)) |
219 data.mThirdParty = reverse ? TrippleState::NO : TrippleState::YES; | 221 data.mThirdParty = reverse ? TrippleState::NO : TrippleState::YES; |
220 else if (name.equals(u"collapse"_str)) | 222 else if (name.equals(u"collapse"_str)) |
221 data.mCollapse = reverse ? TrippleState::NO : TrippleState::YES; | 223 data.mCollapse = !reverse; |
222 else | 224 else |
223 error.reset(u"filter_unknown_option"_str); | 225 error.reset(u"filter_unknown_option"_str); |
224 } | 226 } |
225 | 227 |
226 void ParseOptions(String& text, DependentString& error, RegExpFilterData& data
, | 228 void ParseOptions(String& text, DependentString& error, RegExpFilterData& data
, |
227 String::size_type optionsStart) | 229 String::size_type optionsStart) |
228 { | 230 { |
229 data.mMatchCase = false; | 231 data.mMatchCase = false; |
230 data.mThirdParty = TrippleState::ANY; | 232 data.mThirdParty = TrippleState::ANY; |
231 data.mCollapse = TrippleState::ANY; | 233 data.mCollapse = true; |
232 data.mDomainsStart = String::npos; | 234 data.mDomainsStart = String::npos; |
233 data.mSitekeysStart = String::npos; | 235 data.mSitekeysStart = String::npos; |
234 if (optionsStart >= text.length()) | 236 if (optionsStart >= text.length()) |
235 { | 237 { |
236 data.mContentType = defaultTypeMask; | 238 data.mContentType = defaultTypeMask; |
237 return; | 239 return; |
238 } | 240 } |
239 | 241 |
240 data.mContentType = -1; | 242 data.mContentType = -1; |
241 | 243 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 } | 345 } |
344 } | 346 } |
345 | 347 |
346 void RegExpFilter::GenerateCustomBindings() | 348 void RegExpFilter::GenerateCustomBindings() |
347 { | 349 { |
348 printf("exports.RegExpFilter.typeMap = {\n"); | 350 printf("exports.RegExpFilter.typeMap = {\n"); |
349 | 351 |
350 for (const auto& item : typeMap) | 352 for (const auto& item : typeMap) |
351 { | 353 { |
352 std::string type(item.first.length(), '\0'); | 354 std::string type(item.first.length(), '\0'); |
353 for (int i = 0; i < item.first.length(); i++) | 355 for (String::size_type i = 0; i < item.first.length(); i++) |
354 type[i] = (item.first[i] == '-' ? '_' : toupper(item.first[i])); | 356 type[i] = (item.first[i] == '-' ? '_' : toupper(item.first[i])); |
355 printf(" %s: %i,\n", type.c_str(), item.second); | 357 printf(" %s: %i,\n", type.c_str(), item.second); |
356 } | 358 } |
357 printf("};\n"); | 359 printf("};\n"); |
358 } | 360 } |
359 | 361 |
360 RegExpFilter::DomainMap* RegExpFilter::GetDomains() const | 362 RegExpFilter::DomainMap* RegExpFilter::GetDomains() const |
361 { | 363 { |
362 if (!mData.DomainsParsingDone()) | 364 if (!mData.DomainsParsingDone()) |
363 { | 365 { |
(...skipping 24 matching lines...) Expand all Loading... |
388 return false; | 390 return false; |
389 } | 391 } |
390 | 392 |
391 if (!mData.RegExpParsingDone()) | 393 if (!mData.RegExpParsingDone()) |
392 { | 394 { |
393 const OwnedString pattern(mData.GetRegExpSource(mText)); | 395 const OwnedString pattern(mData.GetRegExpSource(mText)); |
394 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase))
; | 396 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase))
; |
395 } | 397 } |
396 return TestRegExp(mData.mRegexpId, location); | 398 return TestRegExp(mData.mRegexpId, location); |
397 } | 399 } |
LEFT | RIGHT |