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

Side by Side Diff: compiled/filter/ActiveFilter.cpp

Issue 29721753: Issue 6180 - use ABP_TEXT everywhere in order to let String be a UTF-8 string (Closed) Base URL: https://github.com/adblockplus/adblockpluscore.git@adb2678354813ce5b6de095072954c5a784a7bc4
Patch Set: Created March 13, 2018, 6:20 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
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <cstdio> 18 #include <cstdio>
19 19
20 #include "ActiveFilter.h" 20 #include "ActiveFilter.h"
21 #include "../StringScanner.h" 21 #include "../StringScanner.h"
22 22
23 ABP_NS_USING 23 ABP_NS_USING
24 24
25 const DependentString ActiveFilter::DEFAULT_DOMAIN(u""_str); 25 const DependentString ActiveFilter::DEFAULT_DOMAIN(ABP_TEXT(""_str));
26 26
27 ActiveFilter::ActiveFilter(Type type, const String& text, bool ignoreTrailingDot ) 27 ActiveFilter::ActiveFilter(Type type, const String& text, bool ignoreTrailingDot )
28 : Filter(type, text), mIgnoreTrailingDot(ignoreTrailingDot), 28 : Filter(type, text), mIgnoreTrailingDot(ignoreTrailingDot),
29 mDisabled(false), mHitCount(0), mLastHit(0) 29 mDisabled(false), mHitCount(0), mLastHit(0)
30 { 30 {
31 } 31 }
32 32
33 ActiveFilter::DomainMap* ActiveFilter::GetDomains() const 33 ActiveFilter::DomainMap* ActiveFilter::GetDomains() const
34 { 34 {
35 return mDomains.get(); 35 return mDomains.get();
(...skipping 17 matching lines...) Expand all
53 53
54 StringScanner scanner(domains, 0, separator); 54 StringScanner scanner(domains, 0, separator);
55 String::size_type start = 0; 55 String::size_type start = 0;
56 bool reverse = false; 56 bool reverse = false;
57 bool hasIncludes = false; 57 bool hasIncludes = false;
58 bool done = scanner.done(); 58 bool done = scanner.done();
59 while (!done) 59 while (!done)
60 { 60 {
61 done = scanner.done(); 61 done = scanner.done();
62 String::value_type currChar = scanner.next(); 62 String::value_type currChar = scanner.next();
63 if (currChar == u'~' && scanner.position() == start) 63 if (currChar == ABP_TEXT('~') && scanner.position() == start)
64 { 64 {
65 start++; 65 start++;
66 reverse = true; 66 reverse = true;
67 } 67 }
68 else if (currChar == separator) 68 else if (currChar == separator)
69 { 69 {
70 String::size_type len = scanner.position() - start; 70 String::size_type len = scanner.position() - start;
71 if (len > 0 && mIgnoreTrailingDot && domains[start + len - 1] == '.') 71 if (len > 0 && mIgnoreTrailingDot && domains[start + len - 1] == ABP_TEXT( '.'))
72 len--; 72 len--;
73 if (len > 0) 73 if (len > 0)
74 { 74 {
75 enter_context("Adding to ActiveFilter.mDomains"); 75 enter_context("Adding to ActiveFilter.mDomains");
76 (*mDomains)[DependentString(domains, start, len)] = !reverse; 76 (*mDomains)[DependentString(domains, start, len)] = !reverse;
77 exit_context(); 77 exit_context();
78 78
79 if (!reverse) 79 if (!reverse)
80 hasIncludes = true; 80 hasIncludes = true;
81 } 81 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 return true; 113 return true;
114 114
115 // If the document has no host name, match only if the filter isn't restricted 115 // If the document has no host name, match only if the filter isn't restricted
116 // to specific domains 116 // to specific domains
117 if (docDomain.empty()) 117 if (docDomain.empty())
118 return (*domains)[DEFAULT_DOMAIN]; 118 return (*domains)[DEFAULT_DOMAIN];
119 119
120 docDomain.toLower(); 120 docDomain.toLower();
121 121
122 String::size_type len = docDomain.length(); 122 String::size_type len = docDomain.length();
123 if (len > 0 && mIgnoreTrailingDot && docDomain[len - 1] == '.') 123 if (len > 0 && mIgnoreTrailingDot && docDomain[len - 1] == ABP_TEXT('.'))
124 docDomain.reset(docDomain, 0, len - 1); 124 docDomain.reset(docDomain, 0, len - 1);
125 while (true) 125 while (true)
126 { 126 {
127 auto it = domains->find(docDomain); 127 auto it = domains->find(docDomain);
128 if (it) 128 if (it)
129 return it->second; 129 return it->second;
130 130
131 String::size_type nextDot = docDomain.find(u'.'); 131 String::size_type nextDot = docDomain.find(ABP_TEXT('.'));
132 if (nextDot == docDomain.npos) 132 if (nextDot == docDomain.npos)
133 break; 133 break;
134 docDomain.reset(docDomain, nextDot + 1); 134 docDomain.reset(docDomain, nextDot + 1);
135 } 135 }
136 return (*domains)[DEFAULT_DOMAIN]; 136 return (*domains)[DEFAULT_DOMAIN];
137 } 137 }
138 138
139 bool ActiveFilter::IsActiveOnlyOnDomain(DependentString& docDomain) const 139 bool ActiveFilter::IsActiveOnlyOnDomain(DependentString& docDomain) const
140 { 140 {
141 auto domains = GetDomains(); 141 auto domains = GetDomains();
142 if (!domains || docDomain.empty() || (*domains)[DEFAULT_DOMAIN]) 142 if (!domains || docDomain.empty() || (*domains)[DEFAULT_DOMAIN])
143 return false; 143 return false;
144 144
145 docDomain.toLower(); 145 docDomain.toLower();
146 146
147 String::size_type len = docDomain.length(); 147 String::size_type len = docDomain.length();
148 if (len > 0 && mIgnoreTrailingDot && docDomain[len - 1] == '.') 148 if (len > 0 && mIgnoreTrailingDot && docDomain[len - 1] == ABP_TEXT('.'))
149 docDomain.reset(docDomain, 0, len - 1); 149 docDomain.reset(docDomain, 0, len - 1);
150 for (const auto& item : *domains) 150 for (const auto& item : *domains)
151 { 151 {
152 if (!item.second || item.first.equals(docDomain)) 152 if (!item.second || item.first.equals(docDomain))
153 continue; 153 continue;
154 154
155 size_t len1 = item.first.length(); 155 size_t len1 = item.first.length();
156 size_t len2 = docDomain.length(); 156 size_t len2 = docDomain.length();
157 if (len1 > len2 && 157 if (len1 > len2 &&
158 DependentString(item.first, len1 - len2).equals(docDomain) && 158 DependentString(item.first, len1 - len2).equals(docDomain) &&
159 item.first[len1 - len2 - 1] == u'.') 159 item.first[len1 - len2 - 1] == ABP_TEXT('.'))
160 { 160 {
161 continue; 161 continue;
162 } 162 }
163 163
164 return false; 164 return false;
165 } 165 }
166 return true; 166 return true;
167 } 167 }
168 168
169 bool ActiveFilter::IsGeneric() const 169 bool ActiveFilter::IsGeneric() const
170 { 170 {
171 auto sitekeys = GetSitekeys(); 171 auto sitekeys = GetSitekeys();
172 auto domains = GetDomains(); 172 auto domains = GetDomains();
173 return !sitekeys && (!domains || (*domains)[DEFAULT_DOMAIN]); 173 return !sitekeys && (!domains || (*domains)[DEFAULT_DOMAIN]);
174 } 174 }
175 175
176 OwnedString ActiveFilter::Serialize() const 176 OwnedString ActiveFilter::Serialize() const
177 { 177 {
178 /* TODO this is very inefficient */ 178 /* TODO this is very inefficient */
179 OwnedString result(Filter::Serialize()); 179 OwnedString result(Filter::Serialize());
180 if (mDisabled) 180 if (mDisabled)
181 result.append(u"disabled=true\n"_str); 181 result.append(ABP_TEXT("disabled=true\n"_str));
182 if (mHitCount) 182 if (mHitCount)
183 { 183 {
184 result.append(u"hitCount="_str); 184 result.append(ABP_TEXT("hitCount="_str));
185 result.append(mHitCount); 185 result.append(mHitCount);
186 result.append(u'\n'); 186 result.append(ABP_TEXT('\n'));
187 } 187 }
188 if (mLastHit) 188 if (mLastHit)
189 { 189 {
190 result.append(u"lastHit="_str); 190 result.append(ABP_TEXT("lastHit="_str));
191 result.append(mLastHit); 191 result.append(mLastHit);
192 result.append(u'\n'); 192 result.append(ABP_TEXT('\n'));
193 } 193 }
194 return result; 194 return result;
195 } 195 }
OLDNEW

Powered by Google App Engine
This is Rietveld