Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/filterStorage.js

Issue 29867569: Issue 6893, 6741 - Split out INIParser into its own file (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rename value argument to line Created Aug. 28, 2018, 12:49 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/iniParser.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterStorage.js
===================================================================
--- a/lib/filterStorage.js
+++ b/lib/filterStorage.js
@@ -23,16 +23,17 @@
*/
const {IO} = require("io");
const {Prefs} = require("prefs");
const {Filter, ActiveFilter} = require("./filterClasses");
const {Subscription, SpecialSubscription,
ExternalSubscription} = require("./subscriptionClasses");
const {FilterNotifier} = require("./filterNotifier");
+const {INIParser} = require("./iniParser");
/**
* Version number of the filter storage file format.
* @type {number}
*/
let formatVersion = 5;
/**
@@ -675,106 +676,8 @@
function removeSubscriptionFilters(subscription)
{
if (!FilterStorage.knownSubscriptions.has(subscription.url))
return;
for (let filter of subscription.filters)
filter.subscriptions.delete(subscription);
}
-
-/**
- * Listener returned by FilterStorage.importData(), parses filter data.
- * @constructor
- */
-function INIParser()
-{
- this.fileProperties = this.curObj = {};
- this.subscriptions = [];
- this.knownFilters = new Map();
- this.knownSubscriptions = new Map();
-}
-INIParser.prototype =
-{
- linesProcessed: 0,
- subscriptions: null,
- knownFilters: null,
- knownSubscriptions: null,
- wantObj: true,
- fileProperties: null,
- curObj: null,
- curSection: null,
-
- process(val)
- {
- let origKnownFilters = Filter.knownFilters;
- Filter.knownFilters = this.knownFilters;
- let origKnownSubscriptions = Subscription.knownSubscriptions;
- Subscription.knownSubscriptions = this.knownSubscriptions;
- let match;
- try
- {
- if (this.wantObj === true && (match = /^(\w+)=(.*)$/.exec(val)))
- this.curObj[match[1]] = match[2];
- else if (val === null || (match = /^\s*\[(.+)\]\s*$/.exec(val)))
- {
- if (this.curObj)
- {
- // Process current object before going to next section
- switch (this.curSection)
- {
- case "filter":
- if ("text" in this.curObj)
- Filter.fromObject(this.curObj);
- break;
- case "subscription": {
- let subscription = Subscription.fromObject(this.curObj);
- if (subscription)
- this.subscriptions.push(subscription);
- break;
- }
- case "subscription filters":
- if (this.subscriptions.length)
- {
- let subscription = this.subscriptions[
- this.subscriptions.length - 1
- ];
- for (let text of this.curObj)
- {
- let filter = Filter.fromText(text);
- subscription.filters.push(filter);
- filter.subscriptions.add(subscription);
- }
- }
- break;
- }
- }
-
- if (val === null)
- return;
-
- this.curSection = match[1].toLowerCase();
- switch (this.curSection)
- {
- case "filter":
- case "subscription":
- this.wantObj = true;
- this.curObj = {};
- break;
- case "subscription filters":
- this.wantObj = false;
- this.curObj = [];
- break;
- default:
- this.wantObj = null;
- this.curObj = null;
- }
- }
- else if (this.wantObj === false && val)
- this.curObj.push(val.replace(/\\\[/g, "["));
- }
- finally
- {
- Filter.knownFilters = origKnownFilters;
- Subscription.knownSubscriptions = origKnownSubscriptions;
- }
- }
-};
« no previous file with comments | « no previous file | lib/iniParser.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld