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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 whitespace = 0; | 165 whitespace = 0; |
166 | 166 |
167 // Increment the index by the size of the character. Note that for Unicode | 167 // Increment the index by the size of the character. Note that for Unicode |
168 // composite characters (like emoji) this will be more than one. | 168 // composite characters (like emoji) this will be more than one. |
169 index += character.length; | 169 index += character.length; |
170 } | 170 } |
171 | 171 |
172 return selector.length - index + whitespace; | 172 return selector.length - index + whitespace; |
173 } | 173 } |
174 | 174 |
175 /** | |
176 * Qualifies a CSS selector with a qualifier, which may be another CSS selector | |
177 * or an empty string. For example, given the selector "div.bar" and the | |
178 * qualifier "#foo", this function returns "div#foo.bar". | |
179 * @param {string} selector The selector to qualify. | |
180 * @param {string} qualifier The qualifier with which to qualify the selector. | |
181 * @returns {string} The qualified selector. | |
182 */ | |
175 function qualifySelector(selector, qualifier) | 183 function qualifySelector(selector, qualifier) |
hub
2018/05/14 19:35:12
It would be nice to have a bit of documentation to
Manish Jethani
2018/05/15 12:03:58
Done.
| |
176 { | 184 { |
177 let qualifiedSelector = ""; | 185 let qualifiedSelector = ""; |
178 | 186 |
179 for (let sub of splitSelector(selector)) | 187 for (let sub of splitSelector(selector)) |
180 { | 188 { |
181 sub = sub.trim(); | 189 sub = sub.trim(); |
182 | 190 |
183 qualifiedSelector += ", "; | 191 qualifiedSelector += ", "; |
184 | 192 |
185 let index = findTargetSelectorIndex(sub); | 193 let index = findTargetSelectorIndex(sub); |
186 let [, type = "", rest] = /^([a-z][a-z-]*)?(.*)/i.exec(sub.substr(index)); | 194 let [, type = "", rest] = /^([a-z][a-z-]*)?(.*)/i.exec(sub.substr(index)); |
187 | 195 |
188 // Note that the first group in the regular expression is optional. If it | 196 // Note that the first group in the regular expression is optional. If it |
189 // doesn't match (e.g. "#foo::nth-child(1)"), type will be an empty string. | 197 // doesn't match (e.g. "#foo::nth-child(1)"), type will be an empty string. |
190 qualifiedSelector += sub.substr(0, index) + type + qualifier + rest; | 198 qualifiedSelector += sub.substr(0, index) + type + qualifier + rest; |
191 } | 199 } |
192 | 200 |
193 // Remove the initial comma and space. | 201 // Remove the initial comma and space. |
194 return qualifiedSelector.substr(2); | 202 return qualifiedSelector.substr(2); |
195 } | 203 } |
196 | 204 |
197 exports.qualifySelector = qualifySelector; | 205 exports.qualifySelector = qualifySelector; |
LEFT | RIGHT |