| 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 14 matching lines...) Expand all Loading... |
| 25 function textToRegExp(text) | 25 function textToRegExp(text) |
| 26 { | 26 { |
| 27 return text.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); | 27 return text.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); |
| 28 } | 28 } |
| 29 | 29 |
| 30 exports.textToRegExp = textToRegExp; | 30 exports.textToRegExp = textToRegExp; |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * Converts filter text into regular expression string | 33 * Converts filter text into regular expression string |
| 34 * @param {string} text as in Filter() | 34 * @param {string} text as in Filter() |
| 35 * @param {boolean} [optimize=true] whether to optimize the regular expression | 35 * @param {boolean} [captureAll=false] whether to enable the capturing of |
| 36 * leading and trailing wildcards in the filter text; by default, leading and |
| 37 * trailing wildcards are stripped out |
| 36 * @return {string} regular expression representation of filter text | 38 * @return {string} regular expression representation of filter text |
| 37 */ | 39 */ |
| 38 function filterToRegExp(text, optimize = true) | 40 function filterToRegExp(text, captureAll = false) |
| 39 { | 41 { |
| 40 if (optimize) | 42 // remove multiple wildcards |
| 41 { | 43 text = text.replace(/\*+/g, "*"); |
| 42 // remove multiple wildcards | 44 |
| 43 text = text.replace(/\*+/g, "*"); | 45 if (!captureAll) |
| 44 | 46 { |
| 45 // remove leading wildcard | 47 // remove leading wildcard |
| 46 if (text[0] == "*") | 48 if (text[0] == "*") |
| 47 text = text.substring(1); | 49 text = text.substring(1); |
| 48 | 50 |
| 49 // remove trailing wildcard | 51 // remove trailing wildcard |
| 50 if (text[text.length - 1] == "*") | 52 if (text[text.length - 1] == "*") |
| 51 text = text.substring(0, text.length - 1); | 53 text = text.substring(0, text.length - 1); |
| 52 } | 54 } |
| 53 | 55 |
| 54 return text | 56 return text |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // Note that the first group in the regular expression is optional. If it | 207 // Note that the first group in the regular expression is optional. If it |
| 206 // doesn't match (e.g. "#foo::nth-child(1)"), type will be an empty string. | 208 // doesn't match (e.g. "#foo::nth-child(1)"), type will be an empty string. |
| 207 qualifiedSelector += sub.substr(0, index) + type + qualifier + rest; | 209 qualifiedSelector += sub.substr(0, index) + type + qualifier + rest; |
| 208 } | 210 } |
| 209 | 211 |
| 210 // Remove the initial comma and space. | 212 // Remove the initial comma and space. |
| 211 return qualifiedSelector.substr(2); | 213 return qualifiedSelector.substr(2); |
| 212 } | 214 } |
| 213 | 215 |
| 214 exports.qualifySelector = qualifySelector; | 216 exports.qualifySelector = qualifySelector; |
| LEFT | RIGHT |