diff options
Diffstat (limited to 'space.js')
-rw-r--r-- | space.js | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -138,12 +138,7 @@ function Space(){ return loc; } - this.regex = function(strlines){ - if (typeof strlines[0] !== 'string') throw ".regex needs arr of strings"; - let lines = []; - for (let i = 0; i < strlines.length; i++) { - lines.push(new RegExp(strlines[i], 'g')); - } + this.nullprint = function(){ let data = []; for (let ln of this.data){ let newln = ""; @@ -153,9 +148,19 @@ function Space(){ } data.push(newln); } - let loc; + return data; + } + + this.regex = function(strlines){ + if (typeof strlines[0] !== 'string') throw ".regex needs arr of strings"; + let lines = []; + for (let i = 0; i < strlines.length; i++) { + lines.push(new RegExp(strlines[i], 'g')); + } + let data = this.nullprint(); + let loc = []; data.forEach( (ln, ind) => { - if (loc || ((data.length - ind) < lines.length)) return; + if (((data.length - ind) < lines.length)) return; let match; while ( (match = lines[0].exec(ln)) !== null){ let xdisp = match.index; @@ -168,12 +173,11 @@ function Space(){ } } if (lnmatch){ - loc = [ind, xdisp]; - break; + loc.push([ind, xdisp]); } } }); - return (loc === undefined ? [] : loc); + return loc; } this.subsection = function(range){ // range is a coordinate pair |