1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-06 03:04:12 +01:00

Rename util.(escapeRegexp|regexpSource) to util.regexp.(escape|getSource).

This commit is contained in:
Kris Maglione
2010-12-15 06:06:42 -05:00
parent 097309f28c
commit f07f067309
6 changed files with 23 additions and 25 deletions

View File

@@ -387,16 +387,6 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
return str.replace(/&/g, "&amp;").replace(/</g, "&lt;");
},
/**
* 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 () []),