mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-31 15:25:46 +01:00
Allow \c/\C in regexp options and so forth.
This commit is contained in:
@@ -177,20 +177,18 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
* @returns {RegExp}
|
||||
*/
|
||||
charListToRegexp: function charListToRegexp(list, accepted) {
|
||||
let list = list.replace(/\s+/g, "");
|
||||
list = list.replace(/\s+/g, "");
|
||||
|
||||
// check for chars not in the accepted range
|
||||
this.assert(RegExp("^[" + accepted + "-]+$").test(list),
|
||||
"Character list outside the range " + accepted.quote());
|
||||
"Character list outside the range " + accepted.quote());
|
||||
|
||||
// check for illegal ranges
|
||||
let matches = list.match(RegExp("[" + accepted + "]-[" + accepted + "]", "g"));
|
||||
if (matches) {
|
||||
for (let match in values(matches))
|
||||
this.assert(match[0] <= match[2],
|
||||
"Invalid character range: " + list.match(match + ".*")[0]);
|
||||
}
|
||||
return RegExp("[" + list + "]");
|
||||
for (let [match] in this.regexp.iterate(/.-./g, list))
|
||||
this.assert(match.charCodeAt(0) <= match.charCodeAt(2),
|
||||
"Invalid character range: " + list.slice(list.indexOf(match)))
|
||||
|
||||
return RegExp("[" + util.regexp.escape(list) + "]");
|
||||
},
|
||||
|
||||
get chromePackages() {
|
||||
@@ -822,6 +820,18 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
bottom: Math.min(r1.bottom, r2.bottom)
|
||||
}),
|
||||
|
||||
/**
|
||||
* Returns true if the given stack frame resides in Dactyl code.
|
||||
*
|
||||
* @param {nsIStackFrame} frame
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isDactyl: Class.memoize(function () {
|
||||
let base = util.regexp.escape(Components.stack.filename.replace(/[^\/]+$/, ""));
|
||||
let re = RegExp("^(resource://dactyl|" + base + ")\\S+( -> resource://dactyl(?!-content/eval.js)\\S+)?$");
|
||||
return function isDactyl(frame) re.test(frame.filename);
|
||||
}),
|
||||
|
||||
/**
|
||||
* Returns true if *url* is in the domain *domain*.
|
||||
*
|
||||
@@ -1340,6 +1350,16 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
if (isinstance(expr, ["RegExp"]))
|
||||
expr = expr.source;
|
||||
|
||||
expr = String.replace(expr, /\\(.)/, function (m, m1) {
|
||||
if (m1 === "c")
|
||||
flags = flags.replace(/i/g, "") + "i";
|
||||
else if (m === "C")
|
||||
flags = flags.replace(/i/g, "");
|
||||
else
|
||||
return m;
|
||||
return "";
|
||||
});
|
||||
|
||||
// Replace replacement <tokens>.
|
||||
if (tokens)
|
||||
expr = String.replace(expr, /(\(?P)?<(\w+)>/g, function (m, n1, n2) !n1 && set.has(tokens, n2) ? tokens[n2].dactylSource || tokens[n2].source || tokens[n2] : m);
|
||||
|
||||
Reference in New Issue
Block a user