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

Side by Side Diff: compiled/RegExpFilter.h

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Patch Set: Merged filter parsing and normalization Created Feb. 4, 2016, 3:01 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « compiled/InvalidFilter.cpp ('k') | compiled/RegExpFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 String GetRegExpSource(const String& text) const
43 {
44 return String(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 String GetDomainsSource(const String& text) const
58 {
59 return String(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 String GetSitekeysSource(const String& text) const
73 {
74 return String(text, mSitekeysStart, mSitekeysEnd - mSitekeysStart);
75 }
76 };
77
78 class RegExpFilter : public ActiveFilter, protected RegExpFilterData
79 {
80 private:
81 static void ParseOptions(String& text, String& error, RegExpFilterData& data,
82 String::size_type optionsStart);
83 static void ParseOption(String& text, String& error, RegExpFilterData& data,
84 int optionStart, int optionEnd, int valueStart, int valueEnd);
85 void ParseSitekeys(const String& sitekeys) const;
86
87 protected:
88 virtual DomainMap* GetDomains() const;
89 virtual SitekeySet* GetSitekeys() const;
90 public:
91 RegExpFilter(const String& text, const RegExpFilterData& data);
92 ~RegExpFilter();
93 static Type Parse(String& text, String& error, RegExpFilterData& data);
94 EMSCRIPTEN_KEEPALIVE static void InitJSTypes();
95 static String RegExpFromSource(const String& source);
96 Type GetType() const;
97 EMSCRIPTEN_KEEPALIVE bool Matches(const String& location, int typeMask,
98 String& docDomain, bool thirdParty, const String& sitekey) const;
99 };
100
101 #endif
OLDNEW
« no previous file with comments | « compiled/InvalidFilter.cpp ('k') | compiled/RegExpFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld