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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 this.knownSubscriptions = new Map(); | 57 this.knownSubscriptions = new Map(); |
58 | 58 |
59 this._wantObj = true; | 59 this._wantObj = true; |
60 this._curObj = this.fileProperties; | 60 this._curObj = this.fileProperties; |
61 this._curSection = null; | 61 this._curSection = null; |
62 } | 62 } |
63 | 63 |
64 /** | 64 /** |
65 * Processes a line of filter data. | 65 * Processes a line of filter data. |
66 * | 66 * |
67 * @param {string?} value The line of filter data to process. This may be | 67 * @param {string?} line The line of filter data to process. This may be |
68 * <code>null</code>, which indicates the end of the filter data. | 68 * <code>null</code>, which indicates the end of the filter data. |
69 */ | 69 */ |
70 process(value) | 70 process(line) |
71 { | 71 { |
72 let origKnownFilters = Filter.knownFilters; | 72 let origKnownFilters = Filter.knownFilters; |
73 Filter.knownFilters = this.knownFilters; | 73 Filter.knownFilters = this.knownFilters; |
74 | 74 |
75 let origKnownSubscriptions = Subscription.knownSubscriptions; | 75 let origKnownSubscriptions = Subscription.knownSubscriptions; |
76 Subscription.knownSubscriptions = this.knownSubscriptions; | 76 Subscription.knownSubscriptions = this.knownSubscriptions; |
77 | 77 |
78 try | 78 try |
79 { | 79 { |
80 let match; | 80 let match; |
81 if (this._wantObj === true && (match = /^(\w+)=(.*)$/.exec(value))) | 81 if (this._wantObj === true && (match = /^(\w+)=(.*)$/.exec(line))) |
82 { | 82 { |
83 this._curObj[match[1]] = match[2]; | 83 this._curObj[match[1]] = match[2]; |
84 } | 84 } |
85 else if (value === null || (match = /^\s*\[(.+)\]\s*$/.exec(value))) | 85 else if (line === null || (match = /^\s*\[(.+)\]\s*$/.exec(line))) |
86 { | 86 { |
87 if (this._curObj) | 87 if (this._curObj) |
88 { | 88 { |
89 // Process current object before going to next section | 89 // Process current object before going to next section |
90 switch (this._curSection) | 90 switch (this._curSection) |
91 { | 91 { |
92 case "filter": | 92 case "filter": |
93 if ("text" in this._curObj) | 93 if ("text" in this._curObj) |
94 Filter.fromObject(this._curObj); | 94 Filter.fromObject(this._curObj); |
95 break; | 95 break; |
(...skipping 14 matching lines...) Expand all Loading... |
110 { | 110 { |
111 let filter = Filter.fromText(text); | 111 let filter = Filter.fromText(text); |
112 currentSubscription.filters.push(filter); | 112 currentSubscription.filters.push(filter); |
113 filter.subscriptions.add(currentSubscription); | 113 filter.subscriptions.add(currentSubscription); |
114 } | 114 } |
115 } | 115 } |
116 break; | 116 break; |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 if (value === null) | 120 if (line === null) |
121 return; | 121 return; |
122 | 122 |
123 this._curSection = match[1].toLowerCase(); | 123 this._curSection = match[1].toLowerCase(); |
124 switch (this._curSection) | 124 switch (this._curSection) |
125 { | 125 { |
126 case "filter": | 126 case "filter": |
127 case "subscription": | 127 case "subscription": |
128 this._wantObj = true; | 128 this._wantObj = true; |
129 this._curObj = {}; | 129 this._curObj = {}; |
130 break; | 130 break; |
131 case "subscription filters": | 131 case "subscription filters": |
132 this._wantObj = false; | 132 this._wantObj = false; |
133 this._curObj = []; | 133 this._curObj = []; |
134 break; | 134 break; |
135 default: | 135 default: |
136 this._wantObj = null; | 136 this._wantObj = null; |
137 this._curObj = null; | 137 this._curObj = null; |
138 } | 138 } |
139 } | 139 } |
140 else if (this._wantObj === false && value) | 140 else if (this._wantObj === false && line) |
141 { | 141 { |
142 this._curObj.push(value.replace(/\\\[/g, "[")); | 142 this._curObj.push(line.replace(/\\\[/g, "[")); |
143 } | 143 } |
144 } | 144 } |
145 finally | 145 finally |
146 { | 146 { |
147 Filter.knownFilters = origKnownFilters; | 147 Filter.knownFilters = origKnownFilters; |
148 Subscription.knownSubscriptions = origKnownSubscriptions; | 148 Subscription.knownSubscriptions = origKnownSubscriptions; |
149 } | 149 } |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 exports.INIParser = INIParser; | 153 exports.INIParser = INIParser; |
LEFT | RIGHT |