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

Delta Between Two Patch Sets: compiled/filter/ElemHideBase.cpp

Issue 29580558: Issue 5174 - Allow '{' and '}' in selectors (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: adressed comments Created Oct. 18, 2017, 12:53 p.m.
Right Patch Set: Indent namespace content. Created Oct. 19, 2017, 12:48 p.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/filter/ElemHideBase.h ('k') | test/filterClasses.js » ('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 /* 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 return Type::ELEMHIDEEXCEPTION; 115 return Type::ELEMHIDEEXCEPTION;
116 116
117 if (text.find(u"[-abp-properties="_str, data.mSelectorStart) != text.npos) 117 if (text.find(u"[-abp-properties="_str, data.mSelectorStart) != text.npos)
118 return Type::ELEMHIDEEMULATION; 118 return Type::ELEMHIDEEMULATION;
119 119
120 return Type::ELEMHIDE; 120 return Type::ELEMHIDE;
121 } 121 }
122 122
123 namespace 123 namespace
124 { 124 {
125 static constexpr String::value_type OPENING_CURLY_REPLACEMENT[] = u"\\7B ";
126 static constexpr String::value_type CLOSING_CURLY_REPLACEMENT[] = u"\\7D ";
127 static constexpr String::size_type CURLY_REPLACEMENT_SIZE = sizeof(OPENING_CUR LY_REPLACEMENT) / sizeof(OPENING_CURLY_REPLACEMENT[0]) - 1;
125 128
126 static constexpr String::value_type OPENING_CURLY_REPLACEMENT[] = u"\\x7B "; 129 OwnedString EscapeCurlies(String::size_type replacementCount,
127 static constexpr String::value_type CLOSING_CURLY_REPLACEMENT[] = u"\\x7D "; 130 const DependentString& str)
128 static constexpr String::size_type CURLY_REPLACEMENT_SIZE = sizeof(OPENING_CURLY _REPLACEMENT) / sizeof(OPENING_CURLY_REPLACEMENT[0]) - 1; 131 {
sergei 2017/10/18 14:01:37 What about a constexpr function calculating the le
132 OwnedString result(str.length() + replacementCount * (CURLY_REPLACEMENT_SIZE - 1));
sergei 2017/11/21 11:42:10 I think we should not subtract 1 here because it's
hub 2017/11/21 15:58:21 the -1 is because we are replacing. str.length() a
sergei 2017/11/21 16:18:00 Acknowledged.
129 133
130 OwnedString EscapeCurlies(String::size_type replacementCount, 134 String::value_type* current = result.data();
131 const DependentString& str) 135 for (String::size_type i = 0; i < str.length(); i++)
132 { 136 {
133 OwnedString result(str.length() + replacementCount * (CURLY_REPLACEMENT_SIZE - 1)); 137 switch(str[i])
138 {
139 case u'}':
140 std::memcpy(current, CLOSING_CURLY_REPLACEMENT,
141 sizeof(String::value_type) * CURLY_REPLACEMENT_SIZE);
142 current += CURLY_REPLACEMENT_SIZE;
143 break;
144 case u'{':
145 std::memcpy(current, OPENING_CURLY_REPLACEMENT,
146 sizeof(String::value_type) * CURLY_REPLACEMENT_SIZE);
147 current += CURLY_REPLACEMENT_SIZE;
148 break;
149 default:
150 *current = str[i];
151 current++;
152 break;
153 }
154 }
134 155
135 String::value_type* current = result.data(); 156 return result;
136 for (String::size_type i = 0; i < str.length(); i++)
137 {
138 switch(str[i])
139 {
140 case u'}':
141 std::memcpy(current, CLOSING_CURLY_REPLACEMENT,
142 sizeof(String::value_type) * CURLY_REPLACEMENT_SIZE);
143 current += CURLY_REPLACEMENT_SIZE;
sergei 2017/10/18 14:01:37 What about moving of memcpy into the String class?
144 break;
145 case u'{':
146 std::memcpy(current, OPENING_CURLY_REPLACEMENT,
147 sizeof(String::value_type) * CURLY_REPLACEMENT_SIZE);
148 current += CURLY_REPLACEMENT_SIZE;
149 break;
150 default:
151 *current = str[i];
152 current++;
153 break;
154 }
155 } 157 }
156
157 return result;
158 }
159
160 } 158 }
161 159
162 OwnedString ElemHideBase::GetSelector() const 160 OwnedString ElemHideBase::GetSelector() const
163 { 161 {
164 DependentString selector = mData.GetSelector(mText); 162 DependentString selector = mData.GetSelector(mText);
165 String::size_type replacementCount = 0; 163 String::size_type replacementCount = 0;
166 for (String::size_type i = 0; i < selector.length(); i++) 164 for (String::size_type i = 0; i < selector.length(); i++)
167 if (selector[i] == '}' || selector[i] == '{') 165 if (selector[i] == '}' || selector[i] == '{')
168 replacementCount++; 166 replacementCount++;
169 if (replacementCount) 167 if (replacementCount)
(...skipping 13 matching lines...) Expand all
183 if (item.second && !item.first.empty()) 181 if (item.second && !item.first.empty())
184 { 182 {
185 if (!result.empty()) 183 if (!result.empty())
186 result.append(u','); 184 result.append(u',');
187 result.append(item.first); 185 result.append(item.first);
188 } 186 }
189 } 187 }
190 } 188 }
191 return result; 189 return result;
192 } 190 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld