OLD | NEW |
(Empty) | |
| 1 #ifndef ADBLOCK_PLUS_REG_EXP_FILTER_H |
| 2 #define ADBLOCK_PLUS_REG_EXP_FILTER_H |
| 3 |
| 4 #include "Filter.h" |
| 5 #include "ActiveFilter.h" |
| 6 |
| 7 enum class TrippleState {YES, NO, ANY}; |
| 8 |
| 9 struct RegExpFilterData |
| 10 { |
| 11 mutable String::size_type mPatternStart; |
| 12 union |
| 13 { |
| 14 mutable int mRegexpId; |
| 15 mutable String::size_type mPatternEnd; |
| 16 }; |
| 17 mutable String::size_type mDomainsStart; |
| 18 mutable String::size_type mDomainsEnd; |
| 19 mutable String::size_type mSitekeysStart; |
| 20 mutable String::size_type mSitekeysEnd; |
| 21 int mContentType; |
| 22 bool mMatchCase; |
| 23 TrippleState mThirdParty; |
| 24 TrippleState mCollapse; |
| 25 |
| 26 bool RegExpParsingDone() const |
| 27 { |
| 28 return mPatternStart == String::npos; |
| 29 } |
| 30 |
| 31 void SetRegExp(int regexpId) const |
| 32 { |
| 33 mRegexpId = regexpId; |
| 34 mPatternStart = String::npos; |
| 35 } |
| 36 |
| 37 bool HasRegExp() const |
| 38 { |
| 39 return RegExpParsingDone() && mRegexpId; |
| 40 } |
| 41 |
| 42 const DependentString GetRegExpSource(const String& text) const |
| 43 { |
| 44 return DependentString(text, mPatternStart, mPatternEnd - mPatternStart); |
| 45 } |
| 46 |
| 47 bool DomainsParsingDone() const |
| 48 { |
| 49 return mDomainsStart == String::npos; |
| 50 } |
| 51 |
| 52 void SetDomainsParsingDone() const |
| 53 { |
| 54 mDomainsStart = String::npos; |
| 55 } |
| 56 |
| 57 const DependentString GetDomainsSource(const String& text) const |
| 58 { |
| 59 return DependentString(text, mDomainsStart, mDomainsEnd - mDomainsStart); |
| 60 } |
| 61 |
| 62 bool SitekeyParsingDone() const |
| 63 { |
| 64 return mSitekeysStart == String::npos; |
| 65 } |
| 66 |
| 67 void SetSitekeysParsingDone() const |
| 68 { |
| 69 mSitekeysStart = String::npos; |
| 70 } |
| 71 |
| 72 const DependentString GetSitekeysSource(const String& text) const |
| 73 { |
| 74 return DependentString(text, mSitekeysStart, mSitekeysEnd - mSitekeysStart); |
| 75 } |
| 76 }; |
| 77 |
| 78 class RegExpFilter : public ActiveFilter, protected RegExpFilterData |
| 79 { |
| 80 private: |
| 81 void ParseSitekeys(const String& sitekeys) const; |
| 82 |
| 83 protected: |
| 84 virtual DomainMap* GetDomains() const; |
| 85 virtual SitekeySet* GetSitekeys() const; |
| 86 public: |
| 87 RegExpFilter(const String& text, const RegExpFilterData& data); |
| 88 ~RegExpFilter(); |
| 89 static Type Parse(DependentString& text, OwnedString& error, |
| 90 RegExpFilterData& data); |
| 91 EMSCRIPTEN_KEEPALIVE static void InitJSTypes(); |
| 92 static OwnedString RegExpFromSource(const String& source); |
| 93 Type GetType() const; |
| 94 EMSCRIPTEN_KEEPALIVE bool Matches(const String& location, int typeMask, |
| 95 DependentString& docDomain, bool thirdParty, const String& sitekey) const; |
| 96 }; |
| 97 |
| 98 #endif |
OLD | NEW |