src/content/prefs.js
/* This ugly function takes an exception, with our custom
         * grammar, and converts it to a regular expression that we can
         * match later.  Hostname and path components are processed in
         * separate calls; re_star and re_dblstar define the regexp syntax
         * for * and ** wildcards for this pattern.  (This is because
         * wildcards have different semantics for host vs path.)
         *
         * Function returns a list of [length, pattern, sub] where length
         * is the number of literal (non-wildcard) characters, pattern is
         * the regexp that will be used to match against the URI, and sub is
         * used (via regexp.replace) to create the site name based on the
         * URI.
         */
This ugly function takes an exception, with our custom
grammar, and converts it to a regular expression that we can
match later.  Hostname and path components are processed in
separate calls; re_star and re_dblstar define the regexp syntax
for * and ** wildcards for this pattern.  (This is because
wildcards have different semantics for host vs path.)

Function returns a list of [length, pattern, sub] where length
is the number of literal (non-wildcard) characters, pattern is
the regexp that will be used to match against the URI, and sub is
used (via regexp.replace) to create the site name based on the
URI.
This ugly function takes an exception with our custom grammar and converts it to a regular expression that we can match later . Hostname and path components are processed in separate calls ; re_star and re_dblstar define the regexp syntax for * and ** wildcards for this pattern . ( This is because wildcards have different semantics for host vs path . ) Function returns a list of [ length pattern sub ] where length is the number of literal ( non - wildcard ) characters pattern is the regexp that will be used to match against the URI and sub is used ( via regexp . replace ) to create the site name based on the URI .
function regexpify(pattern, re_star, re_dblstar) {
            var parts = pattern.split(/(\[\*+\]|\*+)/);
            pattern = [];
            var sub = [];
            var length = 0;
            var wildcards = {
                '*': '(' + re_star + ')',
                '**': '(' + re_dblstar + ')',
                '[*]': re_star,
                '[**]': re_dblstar
            };
            var group = 1;
            for (let part in iter(parts)) {
                if (part == '')
                    continue;
                if (wildcards[part])
                    pattern.push(wildcards[part]);
                else {
                    length += part.length;
                    pattern.push('(' + part + ')');
                }
                if (part[0] == '[')
                    sub.push(part.slice(1, -1));
                else
                    sub.push('$' + group++);
            }
            return [length, pattern.join(''), sub.join('')];
        }
function regexpify ( pattern , re_star , re_dblstar ) { var parts = pattern . split ( / (\[\*+\]|\*+) / ) ; pattern = [ ] ; var sub = [ ] ; var length = 0 ; var wildcards = { '*' : '(' + re_star + ')' , '**' : '(' + re_dblstar + ')' , '[*]' : re_star , '[**]' : re_dblstar } ; var group = 1 ; for ( let part in iter ( parts ) ) { if ( part == '' ) continue ; if ( wildcards [ part ] ) pattern . push ( wildcards [ part ] ) ; else { length += part . length ; pattern . push ( '(' + part + ')' ) ; } if ( part [ 0 ] == '[' ) sub . push ( part . slice ( 1 , - 1 ) ) ; else sub . push ( '$' + group ++ ) ; } return [ length , pattern . join ( '' ) , sub . join ( '' ) ] ; }
This ugly function takes an exception, with our custom
 grammar, and converts it to a regular expression that we can
 match later.
This ugly function takes an exception with our custom grammar and converts it to a regular expression that we can match later .
// Maps wildcards in custom grammar to regexp equivalent.