Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 | 68 |
69 ElemHideBase::ElemHideBase(Type type, const String& text, const ElemHideData& da ta) | 69 ElemHideBase::ElemHideBase(Type type, const String& text, const ElemHideData& da ta) |
70 : ActiveFilter(type, text, false), mData(data) | 70 : ActiveFilter(type, text, false), mData(data) |
71 { | 71 { |
72 if (mData.HasDomains()) | 72 if (mData.HasDomains()) |
73 ParseDomains(mData.GetDomainsSource(mText), u','); | 73 ParseDomains(mData.GetDomainsSource(mText), u','); |
74 } | 74 } |
75 | 75 |
76 Filter::Type ElemHideBase::Parse(DependentString& text, ElemHideData& data, bool & needConversion) | 76 Filter::Type ElemHideBase::Parse(DependentString& text, ElemHideData& data, bool & needConversion) |
77 { | 77 { |
78 needConversion = false; | |
79 | |
78 StringScanner scanner(text); | 80 StringScanner scanner(text); |
79 | |
80 needConversion = false; | |
81 | 81 |
82 // Domains part | 82 // Domains part |
83 bool seenSpaces = false; | 83 bool seenSpaces = false; |
84 while (!scanner.done()) | 84 while (!scanner.done()) |
85 { | 85 { |
86 String::value_type next = scanner.next(); | 86 String::value_type next = scanner.next(); |
87 if (next == u'#') | 87 if (next == u'#') |
88 { | 88 { |
89 data.mDomainsEnd = scanner.position(); | 89 data.mDomainsEnd = scanner.position(); |
90 break; | 90 break; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 String::size_type byte_len() const | 162 String::size_type byte_len() const |
163 { | 163 { |
164 return len() * sizeof(String::value_type); | 164 return len() * sizeof(String::value_type); |
165 } | 165 } |
166 }; | 166 }; |
167 } | 167 } |
168 | 168 |
169 // Convert filter from the old syntax to the new. | 169 // Convert filter from the old syntax to the new. |
170 DependentString ElemHideBase::ConvertFilter(String& text, String::size_type& at) | 170 DependentString ElemHideBase::ConvertFilter(String& text, String::size_type& at) |
171 { | 171 { |
172 auto length = text.length(); | |
173 Range suffix = {at, length}; | |
174 Range prefix = {at, text.find(OLD_PROPS_SELECTOR, at, OLD_PROPS_SELECTOR_LEN)} ; | 172 Range prefix = {at, text.find(OLD_PROPS_SELECTOR, at, OLD_PROPS_SELECTOR_LEN)} ; |
175 if (prefix.end == text.npos) | 173 if (prefix.end == text.npos) |
176 return DependentString(text); | 174 return DependentString(text); |
177 | 175 |
sergei
2018/02/13 09:12:50
Do you mind to move `length` and `suffix` variable
hub
2018/02/13 15:52:25
Done.
| |
176 auto length = text.length(); | |
177 Range suffix = {at, length}; | |
178 Range properties = { prefix.end + OLD_PROPS_SELECTOR_LEN, 0 }; | 178 Range properties = { prefix.end + OLD_PROPS_SELECTOR_LEN, 0 }; |
179 String::value_type quote = 0; | 179 String::value_type quote = 0; |
180 for (auto index = properties.start; | 180 for (auto index = properties.start; |
181 index < length && (suffix.start == at); index++) | 181 index < length && (suffix.start == at); index++) |
182 { | 182 { |
183 auto c = text[index]; | 183 auto c = text[index]; |
184 switch (c) | 184 switch (c) |
185 { | 185 { |
186 case u'"': | 186 case u'"': |
187 case u'\'': | 187 case u'\'': |
188 if (quote == 0) | 188 if (quote == 0) |
189 { | 189 { |
190 // syntax error: we already have a quoted section. | 190 // syntax error: we already have a quoted section. |
191 if (properties.end) | 191 if (properties.end) |
192 return DependentString(); | 192 return DependentString(); |
193 | 193 |
194 if (properties.start != index) | |
195 return DependentString(); | |
196 | |
194 quote = c; | 197 quote = c; |
195 properties.start = index + 1; | 198 properties.start = index + 1; |
196 } | 199 } |
197 else if (quote == c) | 200 else if (quote == c) |
198 { | 201 { |
199 // end of quoted. | 202 // end of quoted. |
200 quote = 0; | 203 quote = 0; |
201 properties.end = index; | 204 properties.end = index; |
202 } | 205 } |
203 break; | 206 break; |
204 case u']': | 207 case u']': |
205 if (quote == 0) | 208 if (quote == 0) |
206 { | 209 { |
207 if (properties.end == 0) | 210 if (properties.end == 0) |
211 return DependentString(); | |
212 if (properties.end + 1 != index) | |
208 return DependentString(); | 213 return DependentString(); |
209 suffix.start = index + 1; | 214 suffix.start = index + 1; |
210 } | 215 } |
211 break; | 216 break; |
212 default: | 217 default: |
213 break; | 218 break; |
214 } | 219 } |
215 } | 220 } |
216 | 221 |
217 if (suffix.start == at) | 222 if (suffix.start == at) |
sergei
2018/02/27 10:56:53
Just for reference, I think it (what the whole for
| |
218 return DependentString(); | 223 return DependentString(); |
219 | 224 |
220 String::size_type delimiter = text.find(ELEM_HIDE_DELIMITER, 0, | 225 String::size_type delimiter = text.find(ELEM_HIDE_DELIMITER, 0, |
221 ELEM_HIDE_DELIMITER_LEN); | 226 ELEM_HIDE_DELIMITER_LEN); |
222 // +1 for the replacement of "##" by "#?#" | 227 // +1 for the replacement of "##" by "#?#" |
223 if (delimiter != text.npos) | 228 if (delimiter != text.npos) |
224 at++; | 229 at++; |
225 auto new_len = at + prefix.len() + PROPS_SELECTOR_LEN + properties.len() + 1 / * ) */ + suffix.len(); | 230 auto new_len = at + prefix.len() + PROPS_SELECTOR_LEN + properties.len() + 1 / * ) */ + suffix.len(); |
226 | 231 |
227 assert2(new_len + 1 == length || (delimiter == text.npos && new_len + 2 == len gth), u"Inconsistent length in filter conversion."_str); | 232 assert2(new_len + 1 == length || (delimiter == text.npos && new_len + 2 == len gth), u"Inconsistent length in filter conversion."_str); |
sergei
2018/02/27 10:56:53
not important just for reference
length == new_len
hub
2018/02/27 13:32:30
Acknowledged.
| |
228 | 233 |
229 DependentString converted(text, 0, new_len); | 234 DependentString converted(text, 0, new_len); |
230 | 235 |
231 if (suffix.len()) | 236 if (suffix.len()) |
232 { | 237 { |
233 new_len -= suffix.len(); | 238 new_len -= suffix.len(); |
234 std::memmove(converted.data() + new_len, | 239 std::memmove(converted.data() + new_len, |
235 text.data() + suffix.start, | 240 text.data() + suffix.start, |
236 suffix.byte_len()); | 241 suffix.byte_len()); |
237 } | 242 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 if (item.second && !item.first.empty()) | 332 if (item.second && !item.first.empty()) |
328 { | 333 { |
329 if (!result.empty()) | 334 if (!result.empty()) |
330 result.append(u','); | 335 result.append(u','); |
331 result.append(item.first); | 336 result.append(item.first); |
332 } | 337 } |
333 } | 338 } |
334 } | 339 } |
335 return result; | 340 return result; |
336 } | 341 } |
LEFT | RIGHT |