Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: compiled/RegExpFilter.h

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Left Patch Set: Reworked JS binding generation Created Feb. 1, 2016, 9:14 p.m.
Right Patch Set: Addressed comments from Patch Set 28 Created March 21, 2017, 10:04 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « compiled/InvalidFilter.cpp ('k') | compiled/RegExpFilter.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #ifndef ADBLOCK_PLUS_REG_EXP_FILTER_H 1 #pragma once
2 #define ADBLOCK_PLUS_REG_EXP_FILTER_H
3 2
4 #include "Filter.h" 3 #include "Filter.h"
5 #include "ActiveFilter.h" 4 #include "ActiveFilter.h"
6 5
7 class RegExpFilter : public ActiveFilter 6 enum class TrippleState {YES, NO, ANY};
7
8 struct RegExpFilterData
8 { 9 {
9 private: 10 mutable String::size_type mPatternStart;
10 enum TrippleState {YES, NO, ANY}; 11 union
11 12 {
12 mutable int mRegexpId; 13 mutable int mRegexpId;
13 String mRegexpSource; 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;
14 int mContentType; 20 int mContentType;
15 bool mMatchCase; 21 bool mMatchCase;
16 TrippleState mThirdParty; 22 TrippleState mThirdParty;
17 TrippleState mCollapse; 23 TrippleState mCollapse;
18 void ProcessOption(String& options, int optionStart, 24
19 int optionEnd, int valueStart, int valueEnd); 25 bool RegExpParsingDone() const
20 public: 26 {
21 explicit RegExpFilter(const String& text, 27 return mPatternStart == String::npos;
22 String::size_type patternStart, String::size_type patternEnd); 28 }
23 ~RegExpFilter(); 29
24 static Filter* Create(const String& text); 30 void SetRegExp(int regexpId) const
25 EMSCRIPTEN_KEEPALIVE static void InitJSTypes(); 31 {
26 static String RegExpFromSource(const String& source); 32 mRegexpId = regexpId;
27 Type GetType() const; 33 mPatternStart = String::npos;
28 EMSCRIPTEN_KEEPALIVE bool Matches(const String& location, int typeMask, String & docDomain, 34 }
29 bool thirdParty, const String& sitekey) const; 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 }
30 }; 75 };
31 76
32 #endif 77 class RegExpFilter : public ActiveFilter
78 {
79 private:
80 void ParseSitekeys(const String& sitekeys) const;
81
82 protected:
83 RegExpFilterData mData;
84
85 DomainMap* GetDomains() const override;
86 SitekeySet* GetSitekeys() const override;
87 public:
88 explicit RegExpFilter(Type type, const String& text, const RegExpFilterData& d ata);
89 ~RegExpFilter();
90 static Type Parse(DependentString& text, DependentString& error,
91 RegExpFilterData& data);
92 EMSCRIPTEN_KEEPALIVE static void InitJSTypes();
93 static OwnedString RegExpFromSource(const String& source);
94 EMSCRIPTEN_KEEPALIVE bool Matches(const String& location, int typeMask,
95 DependentString& docDomain, bool thirdParty, const String& sitekey) const;
96 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld