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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 let {Filter, InvalidFilter, ElemHideBase} = require("filterClasses"); | 18 let {Filter, InvalidFilter, ElemHideBase} = require("filterClasses"); |
19 | 19 |
20 /** | 20 /** |
21 * Parses and validates a filter given by the user. | 21 * Parses and validates a filter given by the user. |
22 * | 22 * |
23 * @param {string} text | 23 * @param {string} text |
24 * @param {Boolean} [ignore_headers=false] If true, no exception is raised, | 24 * @param {Boolean} [ignore_headers=false] If true, no exception is raised |
25 * but null is returned instead, | 25 * for filter list headers, instead |
26 * if a filter list header is given. | 26 * the function will return null. |
Wladimir Palant
2015/03/02 20:45:15
I have a hard time parsing that sentence :)
How a
Sebastian Noack
2015/03/03 09:07:48
Done.
| |
27 * @return {Filter} | 27 * @return {Filter} |
28 * @throws Will throw an error if filter cannot be parsed | 28 * @throws Will throw an exception if filter cannot be |
Wladimir Palant
2015/03/02 20:45:15
Nit: "throw an exception"?
Sebastian Noack
2015/03/03 09:07:48
Done.
| |
29 * or contains an invalid CSS selector. | 29 * parsed or contains an invalid CSS selector. |
30 */ | 30 */ |
31 function parseFilter(text, ignore_headers) | 31 function parseFilter(text, ignore_headers) |
32 { | 32 { |
33 text = Filter.normalize(text); | 33 text = Filter.normalize(text); |
34 if (!text) | 34 if (!text) |
35 return null; | 35 return null; |
36 | 36 |
37 if (text[0] == "[") | 37 if (text[0] == "[") |
38 { | 38 { |
39 if (ignore_headers) | 39 if (ignore_headers) |
(...skipping 26 matching lines...) Expand all Loading... | |
66 } | 66 } |
67 | 67 |
68 return filter; | 68 return filter; |
69 } | 69 } |
70 exports.parseFilter = parseFilter; | 70 exports.parseFilter = parseFilter; |
71 | 71 |
72 /** | 72 /** |
73 * Parses and validates a newline-separated list of filters given by the user. | 73 * Parses and validates a newline-separated list of filters given by the user. |
74 * | 74 * |
75 * @param {string} text | 75 * @param {string} text |
76 * @param {Boolean} [ignore_headers=false] If true, filter list | 76 * @param {Boolean} [ignore_headers=false] If true, filter list headers |
77 * headers are stripped. | 77 * will be stripped instead of |
Wladimir Palant
2015/03/02 20:45:15
"If true, filter list headers will be stripped ins
Sebastian Noack
2015/03/03 09:07:48
Done.
| |
78 * raising an exception. | |
78 * @return {Filter[]} | 79 * @return {Filter[]} |
79 * @throws Will throw an error if one of the filters cannot | 80 * @throws Will throw an exception if one of the filters cannot |
80 be parsed or contains an invalid CSS selector. | 81 be parsed or contains an invalid CSS selector. |
81 */ | 82 */ |
82 function parseFilters(text, ignore_headers) | 83 function parseFilters(text, ignore_headers) |
83 { | 84 { |
84 let lines = text.split("\n"); | 85 let lines = text.split("\n"); |
85 let filters = []; | 86 let filters = []; |
86 | 87 |
87 for (let i = 0; i < lines.length; i++) | 88 for (let i = 0; i < lines.length; i++) |
88 { | 89 { |
89 let filter; | 90 let filter; |
90 try | 91 try |
91 { | 92 { |
92 filter = parseFilter(lines[i], ignore_headers); | 93 filter = parseFilter(lines[i], ignore_headers); |
93 } | 94 } |
94 catch (error) | 95 catch (error) |
95 { | 96 { |
96 throw ext.i18n.getMessage("line", (i + 1).toString()) + ": " + error; | 97 throw ext.i18n.getMessage("line", (i + 1).toString()) + ": " + error; |
97 } | 98 } |
98 | 99 |
99 if (filter) | 100 if (filter) |
100 filters.push(filter); | 101 filters.push(filter); |
101 } | 102 } |
102 | 103 |
103 return filters; | 104 return filters; |
104 } | 105 } |
105 exports.parseFilters = parseFilters; | 106 exports.parseFilters = parseFilters; |
LEFT | RIGHT |