| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
|
Wladimir Palant
2017/10/19 07:59:28
Nit: This newline is unnecessary. And the block co
hub
2017/10/19 12:48:26
Done.
| |
| 126 static constexpr String::value_type OPENING_CURLY_REPLACEMENT[] = u"\\7B "; | 129 OwnedString EscapeCurlies(String::size_type replacementCount, |
| 127 static constexpr String::value_type CLOSING_CURLY_REPLACEMENT[] = u"\\7D "; | 130 const DependentString& str) |
| 128 static constexpr String::size_type CURLY_REPLACEMENT_SIZE = sizeof(OPENING_CURLY _REPLACEMENT) / sizeof(OPENING_CURLY_REPLACEMENT[0]) - 1; | 131 { |
| 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; | |
| 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 Loading... | |
| 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 } |
| LEFT | RIGHT |