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