| 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-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 #pragma once | 18 #pragma once |
| 19 | 19 |
| 20 #include "Filter.h" | 20 #include "Filter.h" |
| 21 #include "ActiveFilter.h" | 21 #include "ActiveFilter.h" |
| 22 #include "../bindings/runtime.h" | 22 #include "../bindings/runtime.h" |
| 23 | 23 |
| 24 enum class TrippleState {YES, NO, ANY}; | 24 enum class TrippleState {YES, NO, ANY}; |
| 25 | 25 |
| 26 struct RegExpFilterData | 26 struct RegExpFilterData |
| 27 { | 27 { |
| 28 mutable String::size_type mPatternStart; | 28 mutable String::size_type mPatternStart; |
| 29 union | 29 mutable String::size_type mPatternEnd; |
| 30 { | 30 mutable int mRegexpId; |
| 31 mutable int mRegexpId; | |
| 32 mutable String::size_type mPatternEnd; | |
| 33 }; | |
| 34 mutable String::size_type mDomainsStart; | 31 mutable String::size_type mDomainsStart; |
| 35 mutable String::size_type mDomainsEnd; | 32 mutable String::size_type mDomainsEnd; |
| 36 mutable String::size_type mSitekeysStart; | 33 mutable String::size_type mSitekeysStart; |
| 37 mutable String::size_type mSitekeysEnd; | 34 mutable String::size_type mSitekeysEnd; |
| 38 int mContentType; | 35 int mContentType; |
| 39 bool mMatchCase; | 36 bool mMatchCase; |
| 40 TrippleState mThirdParty; | 37 TrippleState mThirdParty; |
| 41 TrippleState mCollapse; | 38 TrippleState mCollapse; |
| 42 | 39 |
| 43 bool RegExpParsingDone() const | 40 bool RegExpParsingDone() const |
| 44 { | 41 { |
| 45 return mPatternStart == String::npos; | 42 return mRegexpId >= 0; |
| 46 } | |
| 47 | |
| 48 void SetRegExp(int regexpId) const | |
| 49 { | |
| 50 mRegexpId = regexpId; | |
| 51 mPatternStart = String::npos; | |
| 52 } | 43 } |
| 53 | 44 |
| 54 bool HasRegExp() const | 45 bool HasRegExp() const |
| 55 { | 46 { |
| 56 return RegExpParsingDone() && mRegexpId; | 47 return RegExpParsingDone() && mRegexpId; |
| 57 } | 48 } |
| 58 | 49 |
| 59 const DependentString GetRegExpSource(const String& text) const | 50 const DependentString GetRegExpSource(const String& text) const |
| 60 { | 51 { |
| 61 return DependentString(text, mPatternStart, mPatternEnd - mPatternStart); | 52 return DependentString(text, mPatternStart, mPatternEnd - mPatternStart); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 SitekeySet* GetSitekeys() const override; | 95 SitekeySet* GetSitekeys() const override; |
| 105 public: | 96 public: |
| 106 static constexpr Type classType = Type::REGEXP; | 97 static constexpr Type classType = Type::REGEXP; |
| 107 explicit RegExpFilter(Type type, const String& text, const RegExpFilterData& d
ata); | 98 explicit RegExpFilter(Type type, const String& text, const RegExpFilterData& d
ata); |
| 108 ~RegExpFilter(); | 99 ~RegExpFilter(); |
| 109 static Type Parse(DependentString& text, DependentString& error, | 100 static Type Parse(DependentString& text, DependentString& error, |
| 110 RegExpFilterData& data); | 101 RegExpFilterData& data); |
| 111 static void GenerateCustomBindings(); | 102 static void GenerateCustomBindings(); |
| 112 bool BINDINGS_EXPORTED Matches(const String& location, int typeMask, | 103 bool BINDINGS_EXPORTED Matches(const String& location, int typeMask, |
| 113 DependentString& docDomain, bool thirdParty, const String& sitekey) const; | 104 DependentString& docDomain, bool thirdParty, const String& sitekey) const; |
| 105 const DependentString GetRegExpSource() const |
| 106 { |
| 107 return mData.GetRegExpSource(mText); |
| 108 } |
| 114 }; | 109 }; |
| 115 | 110 |
| 116 typedef intrusive_ptr<RegExpFilter> RegExpFilterPtr; | 111 typedef intrusive_ptr<RegExpFilter> RegExpFilterPtr; |
| OLD | NEW |