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: Merged filter parsing and normalization Created Feb. 4, 2016, 3:01 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 enum class TrippleState {YES, NO, ANY}; 6 enum class TrippleState {YES, NO, ANY};
8 7
9 struct RegExpFilterData 8 struct RegExpFilterData
10 { 9 {
11 mutable String::size_type mPatternStart; 10 mutable String::size_type mPatternStart;
12 union 11 union
(...skipping 19 matching lines...) Expand all
32 { 31 {
33 mRegexpId = regexpId; 32 mRegexpId = regexpId;
34 mPatternStart = String::npos; 33 mPatternStart = String::npos;
35 } 34 }
36 35
37 bool HasRegExp() const 36 bool HasRegExp() const
38 { 37 {
39 return RegExpParsingDone() && mRegexpId; 38 return RegExpParsingDone() && mRegexpId;
40 } 39 }
41 40
42 const String GetRegExpSource(const String& text) const 41 const DependentString GetRegExpSource(const String& text) const
43 { 42 {
44 return String(text, mPatternStart, mPatternEnd - mPatternStart); 43 return DependentString(text, mPatternStart, mPatternEnd - mPatternStart);
45 } 44 }
46 45
47 bool DomainsParsingDone() const 46 bool DomainsParsingDone() const
48 { 47 {
49 return mDomainsStart == String::npos; 48 return mDomainsStart == String::npos;
50 } 49 }
51 50
52 void SetDomainsParsingDone() const 51 void SetDomainsParsingDone() const
53 { 52 {
54 mDomainsStart = String::npos; 53 mDomainsStart = String::npos;
55 } 54 }
56 55
57 const String GetDomainsSource(const String& text) const 56 const DependentString GetDomainsSource(const String& text) const
58 { 57 {
59 return String(text, mDomainsStart, mDomainsEnd - mDomainsStart); 58 return DependentString(text, mDomainsStart, mDomainsEnd - mDomainsStart);
60 } 59 }
61 60
62 bool SitekeyParsingDone() const 61 bool SitekeyParsingDone() const
63 { 62 {
64 return mSitekeysStart == String::npos; 63 return mSitekeysStart == String::npos;
65 } 64 }
66 65
67 void SetSitekeysParsingDone() const 66 void SetSitekeysParsingDone() const
68 { 67 {
69 mSitekeysStart = String::npos; 68 mSitekeysStart = String::npos;
70 } 69 }
71 70
72 const String GetSitekeysSource(const String& text) const 71 const DependentString GetSitekeysSource(const String& text) const
73 { 72 {
74 return String(text, mSitekeysStart, mSitekeysEnd - mSitekeysStart); 73 return DependentString(text, mSitekeysStart, mSitekeysEnd - mSitekeysStart);
75 } 74 }
76 }; 75 };
77 76
78 class RegExpFilter : public ActiveFilter, protected RegExpFilterData 77 class RegExpFilter : public ActiveFilter
79 { 78 {
80 private: 79 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; 80 void ParseSitekeys(const String& sitekeys) const;
86 81
87 protected: 82 protected:
88 virtual DomainMap* GetDomains() const; 83 RegExpFilterData mData;
89 virtual SitekeySet* GetSitekeys() const; 84
85 DomainMap* GetDomains() const override;
86 SitekeySet* GetSitekeys() const override;
90 public: 87 public:
91 RegExpFilter(const String& text, const RegExpFilterData& data); 88 explicit RegExpFilter(Type type, const String& text, const RegExpFilterData& d ata);
92 ~RegExpFilter(); 89 ~RegExpFilter();
93 static Type Parse(String& text, String& error, RegExpFilterData& data); 90 static Type Parse(DependentString& text, DependentString& error,
91 RegExpFilterData& data);
94 EMSCRIPTEN_KEEPALIVE static void InitJSTypes(); 92 EMSCRIPTEN_KEEPALIVE static void InitJSTypes();
95 static String RegExpFromSource(const String& source); 93 static OwnedString RegExpFromSource(const String& source);
96 Type GetType() const;
97 EMSCRIPTEN_KEEPALIVE bool Matches(const String& location, int typeMask, 94 EMSCRIPTEN_KEEPALIVE bool Matches(const String& location, int typeMask,
98 String& docDomain, bool thirdParty, const String& sitekey) const; 95 DependentString& docDomain, bool thirdParty, const String& sitekey) const;
99 }; 96 };
100
101 #endif
LEFTRIGHT

Powered by Google App Engine
This is Rietveld