Left: | ||
Right: |
OLD | NEW |
---|---|
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 for (let text of filters) | 68 for (let text of filters) |
69 { | 69 { |
70 let filter = Filter.fromText(text); | 70 let filter = Filter.fromText(text); |
71 if (filter.isActiveOnDomain(domain) && | 71 if (filter.isActiveOnDomain(domain) && |
72 !ElemHide.getException(filter, domain)) | 72 !ElemHide.getException(filter, domain)) |
73 { | 73 { |
74 result.push(filter); | 74 result.push(filter); |
75 } | 75 } |
76 } | 76 } |
77 return result; | 77 return result; |
78 }, | |
79 | |
80 /** | |
81 * Parses a script and returns a list of all its commands and their arguments | |
82 * @param {string} script | |
83 * @return {Array.<string[]>} | |
Manish Jethani
2018/04/26 13:25:17
I had to use Array.<string[]> instead of string[][
| |
84 */ | |
85 parseScript(script) | |
86 { | |
87 let tree = []; | |
88 | |
89 let escape = false; | |
90 let literal = false; | |
91 | |
92 let call = []; | |
93 let argument = ""; | |
94 | |
95 for (let character of [...script.trim(), ";"]) | |
Manish Jethani
2018/04/26 13:25:17
The parsing here is as per the specification in Tr
| |
96 { | |
97 if (escape) | |
98 { | |
99 escape = false; | |
100 | |
101 argument += character; | |
102 } | |
103 else if (character == "\\") | |
104 { | |
105 escape = true; | |
106 } | |
107 else if (character == "'") | |
108 { | |
109 literal = !literal; | |
110 } | |
111 else if (literal || character != ";" && !/\s/u.test(character)) | |
112 { | |
113 argument += character; | |
114 } | |
115 else | |
116 { | |
117 if (argument) | |
118 { | |
119 call.push(argument); | |
120 argument = ""; | |
121 } | |
122 | |
123 if (character == ";" && call.length > 0) | |
124 { | |
125 tree.push(call); | |
126 call = []; | |
127 } | |
128 } | |
129 } | |
130 | |
131 return tree; | |
78 } | 132 } |
79 }; | 133 }; |
80 | 134 |
81 exports.Snippets = Snippets; | 135 exports.Snippets = Snippets; |
OLD | NEW |