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

Delta Between Two Patch Sets: lib/common.js

Issue 29361668: Issue 4394 - Create a filter class for element hiding emulation filters (Closed) Base URL: https://bitbucket.org/fhd/adblockpluscore
Left Patch Set: Created Nov. 3, 2016, 3:42 p.m.
Right Patch Set: Improve compliance with the 80 column rule Created Nov. 21, 2016, 8:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « chrome/content/elemHideEmulation.js ('k') | lib/elemHideEmulation.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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 * Converts filter text into regular expression string
20 * @param {String} text as in Filter()
21 * @return {String} regular expression representation of filter text
22 */
23 function filterToRegExp(text)
24 {
25 return text
26 // remove multiple wildcards
27 .replace(/\*+/g, "*")
28 // remove anchors following separator placeholder
29 .replace(/\^\|$/, "^")
30 // escape special symbols
31 .replace(/\W/g, "\\$&")
32 // replace wildcards by .*
33 .replace(/\\\*/g, ".*")
34 // process separator placeholders (all ANSI characters but alphanumeric
35 // characters and _%.-)
36 .replace(/\\\^/g, "(?:[\\x00-\\x24\\x26-\\x2C\\x2F\\x3A-\\x40\\x5B-\\x5E\\x6 0\\x7B-\\x7F]|$)")
37 // process extended anchor at expression start
38 .replace(/^\\\|\\\|/, "^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?")
39 // process anchor at expression start
40 .replace(/^\\\|/, "^")
41 // process anchor at expression end
42 .replace(/\\\|$/, "$")
43 // remove leading wildcards
44 .replace(/^(\.\*)/, "")
45 // remove trailing wildcards
46 .replace(/(\.\*)$/, "");
47 }
48
49 if (typeof exports != "undefined")
50 exports.filterToRegExp = filterToRegExp;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld