LEFT | RIGHT |
1 #include "ElemHideBase.h" | 1 #include "ElemHideBase.h" |
2 #include "CSSPropertyFilter.h" | 2 #include "CSSPropertyFilter.h" |
3 #include "StringScanner.h" | 3 #include "StringScanner.h" |
4 | 4 |
5 namespace | 5 namespace |
6 { | 6 { |
7 void NormalizeWhitespace(DependentString& text, String::size_type& domainsEnd, | 7 void NormalizeWhitespace(DependentString& text, String::size_type& domainsEnd, |
8 String::size_type& selectorStart) | 8 String::size_type& selectorStart) |
9 { | 9 { |
10 // For element hiding filters we only want to remove spaces preceding the | 10 // For element hiding filters we only want to remove spaces preceding the |
(...skipping 15 matching lines...) Expand all Loading... |
26 delta++; | 26 delta++; |
27 else | 27 else |
28 text[pos - delta] = text[pos]; | 28 text[pos - delta] = text[pos]; |
29 } | 29 } |
30 selectorStart -= delta; | 30 selectorStart -= delta; |
31 | 31 |
32 text.reset(text, 0, len - delta); | 32 text.reset(text, 0, len - delta); |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 ElemHideBase::ElemHideBase(const String& text, const ElemHideBaseData& data) | 36 ElemHideBase::ElemHideBase(Type type, const String& text, const ElemHideBaseData
& data) |
37 : ActiveFilter(text, false), ElemHideBaseData(data) | 37 : ActiveFilter(type, text, false), mData(data) |
38 { | 38 { |
39 if (HasDomains()) | 39 if (mData.HasDomains()) |
40 ParseDomains(GetDomainsSource(mText), u','); | 40 ParseDomains(mData.GetDomainsSource(mText), u','); |
41 } | 41 } |
42 | 42 |
43 Filter::Type ElemHideBase::Parse(DependentString& text, ElemHideData& data) | 43 Filter::Type ElemHideBase::Parse(DependentString& text, ElemHideData& data) |
44 { | 44 { |
45 StringScanner scanner(text); | 45 StringScanner scanner(text); |
46 | 46 |
47 // Domains part | 47 // Domains part |
48 bool seenSpaces = false; | 48 bool seenSpaces = false; |
49 while (!scanner.done()) | 49 while (!scanner.done()) |
50 { | 50 { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 { | 93 { |
94 case u'{': | 94 case u'{': |
95 case u'}': | 95 case u'}': |
96 return Type::UNKNOWN; | 96 return Type::UNKNOWN; |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 // We are done validating, now we can normalize whitespace and the domain part | 100 // We are done validating, now we can normalize whitespace and the domain part |
101 if (seenSpaces) | 101 if (seenSpaces) |
102 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart); | 102 NormalizeWhitespace(text, data.mDomainsEnd, data.mSelectorStart); |
103 ToLower(text, 0, data.mDomainsEnd); | 103 DependentString(text, 0, data.mDomainsEnd).toLower(); |
104 | 104 |
105 if (exception) | 105 if (exception) |
106 return Type::ELEMHIDEEXCEPTION; | 106 return Type::ELEMHIDEEXCEPTION; |
107 | 107 |
108 do | 108 do |
109 { | 109 { |
110 // Is this a CSS property rule maybe? | 110 // Is this a CSS property rule maybe? |
111 String searchString(u"[-abp-properties="_str); | 111 DependentString searchString(u"[-abp-properties="_str); |
112 data.mPrefixEnd = text.find(searchString, data.mSelectorStart); | 112 data.mPrefixEnd = text.find(searchString, data.mSelectorStart); |
113 if (data.mPrefixEnd == text.npos || | 113 if (data.mPrefixEnd == text.npos || |
114 data.mPrefixEnd + searchString.length() + 1 >= text.length()) | 114 data.mPrefixEnd + searchString.length() + 1 >= text.length()) |
115 { | 115 { |
116 break; | 116 break; |
117 } | 117 } |
118 | 118 |
119 data.mRegexpStart = data.mPrefixEnd + searchString.length() + 1; | 119 data.mRegexpStart = data.mPrefixEnd + searchString.length() + 1; |
120 char16_t quotation = text[data.mRegexpStart - 1]; | 120 char16_t quotation = text[data.mRegexpStart - 1]; |
121 if (quotation != u'\'' && quotation != u'"') | 121 if (quotation != u'\'' && quotation != u'"') |
(...skipping 22 matching lines...) Expand all Loading... |
144 for (auto it = mDomains->begin(); it != mDomains->end(); ++it) | 144 for (auto it = mDomains->begin(); it != mDomains->end(); ++it) |
145 { | 145 { |
146 if (it->second && !it->first.empty()) | 146 if (it->second && !it->first.empty()) |
147 { | 147 { |
148 if (!result.empty()) | 148 if (!result.empty()) |
149 result.append(u','); | 149 result.append(u','); |
150 result.append(it->first); | 150 result.append(it->first); |
151 } | 151 } |
152 } | 152 } |
153 } | 153 } |
154 return std::move(result); | 154 return result; |
155 } | 155 } |
LEFT | RIGHT |