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

Side by Side Diff: lib/matcher.js

Issue 29897555: Issue 6940 - Use underscore prefixes lib/matcher.js (Closed)
Patch Set: Created Oct. 1, 2018, 5:46 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 23 matching lines...) Expand all
34 /** 34 /**
35 * Lookup table for filters by their associated keyword 35 * Lookup table for filters by their associated keyword
36 * @type {Map.<string,(Filter|Filter[])>} 36 * @type {Map.<string,(Filter|Filter[])>}
37 */ 37 */
38 this.filterByKeyword = new Map(); 38 this.filterByKeyword = new Map();
39 39
40 /** 40 /**
41 * Lookup table for keywords by the filter 41 * Lookup table for keywords by the filter
42 * @type {Map.<Filter,string>} 42 * @type {Map.<Filter,string>}
43 */ 43 */
44 this.keywordByFilter = new Map(); 44 this._keywordByFilter = new Map();
Manish Jethani 2018/10/01 15:08:59 I think we should add the `@private` tag here. Ot
Manish Jethani 2018/10/01 15:10:00 I'm wondering where exactly it should be added. I
Jon Sonesen 2018/10/21 03:07:07 Done.
45 } 45 }
46 46
47 /** 47 /**
48 * Removes all known filters 48 * Removes all known filters
49 */ 49 */
50 clear() 50 clear()
51 { 51 {
52 this.filterByKeyword.clear(); 52 this.filterByKeyword.clear();
53 this.keywordByFilter.clear(); 53 this._keywordByFilter.clear();
54 } 54 }
55 55
56 /** 56 /**
57 * Adds a filter to the matcher 57 * Adds a filter to the matcher
58 * @param {RegExpFilter} filter 58 * @param {RegExpFilter} filter
59 */ 59 */
60 add(filter) 60 add(filter)
61 { 61 {
62 if (this.keywordByFilter.has(filter)) 62 if (this._keywordByFilter.has(filter))
63 return; 63 return;
64 64
65 // Look for a suitable keyword 65 // Look for a suitable keyword
66 let keyword = this.findKeyword(filter); 66 let keyword = this.findKeyword(filter);
67 let oldEntry = this.filterByKeyword.get(keyword); 67 let oldEntry = this.filterByKeyword.get(keyword);
68 if (typeof oldEntry == "undefined") 68 if (typeof oldEntry == "undefined")
69 this.filterByKeyword.set(keyword, filter); 69 this.filterByKeyword.set(keyword, filter);
70 else if (oldEntry.length == 1) 70 else if (oldEntry.length == 1)
71 this.filterByKeyword.set(keyword, [oldEntry, filter]); 71 this.filterByKeyword.set(keyword, [oldEntry, filter]);
72 else 72 else
73 oldEntry.push(filter); 73 oldEntry.push(filter);
74 this.keywordByFilter.set(filter, keyword); 74 this._keywordByFilter.set(filter, keyword);
75 } 75 }
76 76
77 /** 77 /**
78 * Removes a filter from the matcher 78 * Removes a filter from the matcher
79 * @param {RegExpFilter} filter 79 * @param {RegExpFilter} filter
80 */ 80 */
81 remove(filter) 81 remove(filter)
82 { 82 {
83 let keyword = this.keywordByFilter.get(filter); 83 let keyword = this._keywordByFilter.get(filter);
84 if (typeof keyword == "undefined") 84 if (typeof keyword == "undefined")
85 return; 85 return;
86 86
87 let list = this.filterByKeyword.get(keyword); 87 let list = this.filterByKeyword.get(keyword);
88 if (list.length <= 1) 88 if (list.length <= 1)
89 this.filterByKeyword.delete(keyword); 89 this.filterByKeyword.delete(keyword);
90 else 90 else
91 { 91 {
92 let index = list.indexOf(filter); 92 let index = list.indexOf(filter);
93 if (index >= 0) 93 if (index >= 0)
94 { 94 {
95 list.splice(index, 1); 95 list.splice(index, 1);
96 if (list.length == 1) 96 if (list.length == 1)
97 this.filterByKeyword.set(keyword, list[0]); 97 this.filterByKeyword.set(keyword, list[0]);
98 } 98 }
99 } 99 }
100 100
101 this.keywordByFilter.delete(filter); 101 this._keywordByFilter.delete(filter);
102 } 102 }
103 103
104 /** 104 /**
105 * Chooses a keyword to be associated with the filter 105 * Chooses a keyword to be associated with the filter
106 * @param {Filter} filter 106 * @param {Filter} filter
107 * @returns {string} keyword or an empty string if no keyword could be found 107 * @returns {string} keyword or an empty string if no keyword could be found
108 */ 108 */
109 findKeyword(filter) 109 findKeyword(filter)
110 { 110 {
111 let result = ""; 111 let result = "";
(...skipping 26 matching lines...) Expand all
138 return result; 138 return result;
139 } 139 }
140 140
141 /** 141 /**
142 * Checks whether a particular filter is being matched against. 142 * Checks whether a particular filter is being matched against.
143 * @param {RegExpFilter} filter 143 * @param {RegExpFilter} filter
144 * @returns {boolean} 144 * @returns {boolean}
145 */ 145 */
146 hasFilter(filter) 146 hasFilter(filter)
147 { 147 {
148 return this.keywordByFilter.has(filter); 148 return this._keywordByFilter.has(filter);
149 } 149 }
150 150
151 /** 151 /**
152 * Returns the keyword used for a filter, <code>null</code> 152 * Returns the keyword used for a filter, <code>null</code>
153 * for unknown filters. 153 * for unknown filters.
154 * @param {RegExpFilter} filter 154 * @param {RegExpFilter} filter
155 * @returns {?string} 155 * @returns {?string}
156 */ 156 */
157 getKeywordForFilter(filter) 157 getKeywordForFilter(filter)
158 { 158 {
159 let keyword = this.keywordByFilter.get(filter); 159 let keyword = this._keywordByFilter.get(filter);
160 return typeof keyword != "undefined" ? keyword : null; 160 return typeof keyword != "undefined" ? keyword : null;
161 } 161 }
162 162
163 /** 163 /**
164 * Checks whether the entries for a particular keyword match a URL 164 * Checks whether the entries for a particular keyword match a URL
165 * @param {string} keyword 165 * @param {string} keyword
166 * @param {string} location 166 * @param {string} location
167 * @param {number} typeMask 167 * @param {number} typeMask
168 * @param {string} [docDomain] 168 * @param {string} [docDomain]
169 * @param {boolean} [thirdParty] 169 * @param {boolean} [thirdParty]
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 414
415 exports.CombinedMatcher = CombinedMatcher; 415 exports.CombinedMatcher = CombinedMatcher;
416 416
417 /** 417 /**
418 * Shared {@link CombinedMatcher} instance that should usually be used. 418 * Shared {@link CombinedMatcher} instance that should usually be used.
419 * @type {CombinedMatcher} 419 * @type {CombinedMatcher}
420 */ 420 */
421 let defaultMatcher = new CombinedMatcher(); 421 let defaultMatcher = new CombinedMatcher();
422 422
423 exports.defaultMatcher = defaultMatcher; 423 exports.defaultMatcher = defaultMatcher;
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld