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

Side by Side Diff: lib/shared.js

Issue 29361668: Issue 4394 - Create a filter class for element hiding emulation filters (Closed) Base URL: https://bitbucket.org/fhd/adblockpluscore
Patch Set: Created Nov. 3, 2016, 3:42 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 /**
19 * Map of features supported by element hiding emulation filters
20 */
21 var elemHideEmulationFeatureMap = {
22 PROPERTY_SELECTOR: 1,
23 HAS_PSEUDO_CLASS: 2
24 };
25
26 /**
27 * Converts filter text into regular expression string
28 * @param {String} text as in Filter()
29 * @return {String} regular expression representation of filter text
30 */
31 function filterToRegExp(text)
32 {
33 return text
34 .replace(/\*+/g, "*") // remove multiple wildcards
35 .replace(/\^\|$/, "^") // remove anchors following separator placehold er
kzar 2016/11/04 15:45:56 Nit: Mind fixing these long lines?
Felix Dahlke 2016/11/04 16:43:35 Well, I tried to leave the code alone since I'm ju
Felix Dahlke 2016/11/11 11:51:42 Done.
36 .replace(/\W/g, "\\$&") // escape special symbols
37 .replace(/\\\*/g, ".*") // replace wildcards by .*
38 // process separator placeholders (all ANSI characters but alphanumeric char acters and _%.-)
39 .replace(/\\\^/g, "(?:[\\x00-\\x24\\x26-\\x2C\\x2F\\x3A-\\x40\\x5B-\\x5E\\x6 0\\x7B-\\x7F]|$)")
40 .replace(/^\\\|\\\|/, "^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?") // process ex tended anchor at expression start
41 .replace(/^\\\|/, "^") // process anchor at expression start
42 .replace(/\\\|$/, "$") // process anchor at expression end
43 .replace(/^(\.\*)/, "") // remove leading wildcards
44 .replace(/(\.\*)$/, ""); // remove trailing wildcards
45 }
46
47 if (typeof exports != "undefined")
48 {
49 exports.filterToRegExp = filterToRegExp;
50 exports.elemHideEmulationFeatureMap = elemHideEmulationFeatureMap;
51 }
OLDNEW

Powered by Google App Engine
This is Rietveld