mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-04 21:25:46 +01:00
util.regexp.iterate
--HG-- extra : rebase_source : 2c9d5a20ceb0a3ffde32ad8989ce6f594df8c406
This commit is contained in:
@@ -330,11 +330,9 @@ var Styles = Module("Styles", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
propertyIter: function (str, always) {
|
propertyIter: function (str, always) {
|
||||||
this.propertyPattern.lastIndex = 0;
|
let i = 0;
|
||||||
|
for (let match in this.propertyPattern.iterate(str))
|
||||||
let match, i = 0;
|
if (always && !i++ || match[0] && match.value)
|
||||||
while ((!match || match[0]) && (match = Styles.propertyPattern.exec(str)))
|
|
||||||
if (always && !i++ || match[0] && match[3])
|
|
||||||
yield match;
|
yield match;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -367,15 +365,6 @@ var Styles = Module("Styles", {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
patterns: memoize({
|
patterns: memoize({
|
||||||
iter: function (pattern, str) {
|
|
||||||
pattern = this[pattern];
|
|
||||||
pattern.lastIndex = 0;
|
|
||||||
|
|
||||||
let match;
|
|
||||||
while ((match = pattern.exec(str)) && match[0].length)
|
|
||||||
yield match;
|
|
||||||
},
|
|
||||||
|
|
||||||
get property() util.regexp(<![CDATA[
|
get property() util.regexp(<![CDATA[
|
||||||
(?:
|
(?:
|
||||||
(?P<preSpace> <space>*)
|
(?P<preSpace> <space>*)
|
||||||
|
|||||||
@@ -161,9 +161,7 @@ var Template = Module("Template", {
|
|||||||
|
|
||||||
highlightRegexp: function highlightRegexp(str, re, highlight) {
|
highlightRegexp: function highlightRegexp(str, re, highlight) {
|
||||||
return this.highlightSubstrings(str, (function () {
|
return this.highlightSubstrings(str, (function () {
|
||||||
re.lastIndex = 0;
|
for (let res in util.regexp.iterate(re, str))
|
||||||
let res;
|
|
||||||
while ((res = re.exec(str)) && res[0].length)
|
|
||||||
yield [res.index, res[0].length, res.wholeMatch ? [res] : res];
|
yield [res.index, res[0].length, res.wholeMatch ? [res] : res];
|
||||||
})(), highlight || template.filter);
|
})(), highlight || template.filter);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -268,8 +268,9 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
valid: function (obj) this.elements.every(function (e) !e.test || e.test(obj))
|
valid: function (obj) this.elements.every(function (e) !e.test || e.test(obj))
|
||||||
});
|
});
|
||||||
|
|
||||||
let match, end = 0, re = /(.*?)%(.)/gy;
|
let end = 0;
|
||||||
while (match = re.exec(format)) {
|
for (let match in util.regexp.iterate(/(.*?)%(.)/gy, format)) {
|
||||||
|
|
||||||
let [, prefix, char] = match;
|
let [, prefix, char] = match;
|
||||||
end += match[0].length;
|
end += match[0].length;
|
||||||
|
|
||||||
@@ -327,7 +328,6 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
|
|
||||||
let defaults = { lt: "<", gt: ">" };
|
let defaults = { lt: "<", gt: ">" };
|
||||||
|
|
||||||
let match, end = 0;
|
|
||||||
let re = util.regexp(<![CDATA[
|
let re = util.regexp(<![CDATA[
|
||||||
([^]*?) // 1
|
([^]*?) // 1
|
||||||
(?:
|
(?:
|
||||||
@@ -337,7 +337,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
)
|
)
|
||||||
]]>, "giy");
|
]]>, "giy");
|
||||||
macro = String(macro);
|
macro = String(macro);
|
||||||
while (match = re.exec(macro)) {
|
let end = 0;
|
||||||
|
for (let match in re.iterate(macro)) {
|
||||||
let [, prefix, open, full, macro, close] = match;
|
let [, prefix, open, full, macro, close] = match;
|
||||||
end += match[0].length;
|
end += match[0].length;
|
||||||
|
|
||||||
@@ -1264,7 +1265,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
|
|
||||||
let res = update(RegExp(expr, flags), {
|
let res = update(RegExp(expr, flags), {
|
||||||
closure: Class.Property(Object.getOwnPropertyDescriptor(Class.prototype, "closure")),
|
closure: Class.Property(Object.getOwnPropertyDescriptor(Class.prototype, "closure")),
|
||||||
dactylPropertyNames: ["exec", "match", "test", "toSource", "toString", "global", "ignoreCase", "lastIndex", "multiLine", "source", "sticky"]
|
dactylPropertyNames: ["exec", "match", "test", "toSource", "toString", "global", "ignoreCase", "lastIndex", "multiLine", "source", "sticky"],
|
||||||
|
iterate: function (str, idx) util.regexp.iterate(this, str, idx)
|
||||||
});
|
});
|
||||||
if (struct)
|
if (struct)
|
||||||
update(res, {
|
update(res, {
|
||||||
@@ -1287,7 +1289,27 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
* @param {RegExp} re The regexp showable source of which is to be returned.
|
* @param {RegExp} re The regexp showable source of which is to be returned.
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
getSource: function regexp_getSource(re) re.source.replace(/\\(.)/g, function (m0, m1) m1 === "/" ? "/" : m0)
|
getSource: function regexp_getSource(re) re.source.replace(/\\(.)/g, function (m0, m1) m1 === "/" ? "/" : m0),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterates over all matches of the given regexp in the given
|
||||||
|
* string.
|
||||||
|
*
|
||||||
|
* @param {RegExp} regexp The regular expression to execute.
|
||||||
|
* @param {string} string The string to search.
|
||||||
|
* @param {number} lastIndex The index at which to begin searching. @optional
|
||||||
|
*/
|
||||||
|
iterate: function iterate(regexp, string, lastIndex) {
|
||||||
|
regexp.lastIndex = lastIndex = lastIndex || 0;
|
||||||
|
let match;
|
||||||
|
while (match = regexp.exec(string)) {
|
||||||
|
lastIndex = regexp.lastIndex;
|
||||||
|
yield match;
|
||||||
|
regexp.lastIndex = lastIndex;
|
||||||
|
if (match[0].length == 0 || !regexp.global)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
rehash: function (args) {
|
rehash: function (args) {
|
||||||
|
|||||||
Reference in New Issue
Block a user