mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 18:07:58 +01:00
Rename util.(escapeRegexp|regexpSource) to util.regexp.(escape|getSource).
This commit is contained in:
@@ -86,7 +86,7 @@ const AutoCommands = Module("autocommands", {
|
||||
+
|
||||
template.map(items, function (item)
|
||||
<tr>
|
||||
<td> {util.regexpSource(item.pattern)}</td>
|
||||
<td> {util.regexp.getSource(item.pattern)}</td>
|
||||
<td>{item.command}</td>
|
||||
</tr>))
|
||||
}
|
||||
@@ -114,7 +114,7 @@ const AutoCommands = Module("autocommands", {
|
||||
for (let [, autoCmd] in Iterator(autoCmds)) {
|
||||
if (autoCmd.pattern.test(url) ^ !autoCmd.pattern.result) {
|
||||
if (!lastPattern || lastPattern.source != autoCmd.pattern.source)
|
||||
dactyl.echomsg("Executing " + event + " Auto commands for " + util.regexpSource(autoCmd.pattern).quote(), 8);
|
||||
dactyl.echomsg("Executing " + event + " Auto commands for " + util.regexp.getSource(autoCmd.pattern).quote(), 8);
|
||||
|
||||
lastPattern = autoCmd.pattern;
|
||||
dactyl.echomsg("autocommand " + autoCmd.command, 9);
|
||||
|
||||
@@ -921,7 +921,7 @@ const Completion = Module("completion", {
|
||||
function (tok) contains(item.url, tok) ||
|
||||
contains(item.title, tok)));
|
||||
|
||||
let re = RegExp(tokens.filter(util.identity).map(util.escapeRegexp).join("|"), "g");
|
||||
let re = RegExp(tokens.filter(util.identity).map(util.regexp.escape).join("|"), "g");
|
||||
function highlight(item, text, i) process[i].call(this, item, template.highlightRegexp(text, re));
|
||||
let process = context.process;
|
||||
context.process = [
|
||||
|
||||
@@ -1274,7 +1274,7 @@ const Dactyl = Module("dactyl", {
|
||||
setter: function (value) {
|
||||
let win = document.documentElement;
|
||||
function updateTitle(old, current) {
|
||||
document.title = document.title.replace(RegExp("(.*)" + util.escapeRegexp(old)), "$1" + current);
|
||||
document.title = document.title.replace(RegExp("(.*)" + util.regexp.escape(old)), "$1" + current);
|
||||
}
|
||||
|
||||
// TODO: remove this FF3.5 test when we no longer support 3.0
|
||||
|
||||
@@ -391,7 +391,7 @@ const Option = Class("Option", {
|
||||
re.toString = function () Option.unparseRegexp(this);
|
||||
return re;
|
||||
},
|
||||
unparseRegexp: function (re) re.bang + Option.quote(util.regexpSource(re), /^!|:/) +
|
||||
unparseRegexp: function (re) re.bang + Option.quote(util.regexp.getSource(re), /^!|:/) +
|
||||
(typeof re.result === "boolean" ? "" : ":" + Option.quote(re.result)),
|
||||
|
||||
getKey: {
|
||||
|
||||
@@ -493,7 +493,7 @@ const File = Class("File", {
|
||||
|
||||
// expand ~
|
||||
// Yuck.
|
||||
if (!relative && RegExp("~(?:$|[/" + util.escapeRegexp(File.PATH_SEP) + "])").test(path)) {
|
||||
if (!relative && RegExp("~(?:$|[/" + util.regexp.escape(File.PATH_SEP) + "])").test(path)) {
|
||||
// Try $HOME first, on all systems
|
||||
let home = getenv("HOME");
|
||||
|
||||
|
||||
@@ -387,16 +387,6 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
return str.replace(/&/g, "&").replace(/</g, "<");
|
||||
},
|
||||
|
||||
/**
|
||||
* Escapes Regular Expression special characters in *str*.
|
||||
*
|
||||
* @param {string} str
|
||||
* @returns {string}
|
||||
*/
|
||||
escapeRegexp: function escapeRegexp(str) {
|
||||
return str.replace(/([\\{}()[\].?*+])/g, "\\$1");
|
||||
},
|
||||
|
||||
/**
|
||||
* Escapes quotes, newline and tab characters in *str*. The returned string
|
||||
* is delimited by *delimiter* or " if *delimiter* is not specified.
|
||||
@@ -960,21 +950,29 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
* @param {string} flags Flags to apply to the new RegExp.
|
||||
* @param {object} tokens The tokens to substitute. @optional
|
||||
*/
|
||||
regexp: function (expr, flags, tokens) {
|
||||
regexp: update(function (expr, flags, tokens) {
|
||||
if (tokens)
|
||||
expr = String.replace(expr, /<(\w+)>/g, function (m, n1) set.has(tokens, n1) ? tokens[n1].source || tokens[n1] : m);
|
||||
expr = String.replace(expr, /\/\/[^\n]*|\/\*[^]*?\*\//gm, "")
|
||||
.replace(/\s+/g, "");
|
||||
return RegExp(expr, flags);
|
||||
},
|
||||
}, {
|
||||
/**
|
||||
* Escapes Regular Expression special characters in *str*.
|
||||
*
|
||||
* @param {string} str
|
||||
* @returns {string}
|
||||
*/
|
||||
escape: function regexp_escape(str) str.replace(/([\\{}()[\].?*+])/g, "\\$1"),
|
||||
|
||||
/**
|
||||
* Given a RegExp, returns its source in the form showable to the user.
|
||||
*
|
||||
* @param {RegExp} re The regexp showable source of which is to be returned.
|
||||
* @returns {string}
|
||||
*/
|
||||
regexpSource: function regexpSource(re) re.source.replace(/\\(.)/g, function (m0, m1) m1 === "/" ? "/" : m0),
|
||||
/**
|
||||
* Given a RegExp, returns its source in the form showable to the user.
|
||||
*
|
||||
* @param {RegExp} re The regexp showable source of which is to be returned.
|
||||
* @returns {string}
|
||||
*/
|
||||
getSource: function regexp_getSource(re) re.source.replace(/\\(.)/g, function (m0, m1) m1 === "/" ? "/" : m0),
|
||||
}),
|
||||
|
||||
maxErrors: 15,
|
||||
errors: Class.memoize(function () []),
|
||||
|
||||
Reference in New Issue
Block a user