aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-07-16 22:07:45 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-07-16 22:07:45 -0400
commitdf8c98f96deb3f0b817e1ab3270fe74b2cca1450 (patch)
treecdc7e3e57b27088a84cda46ce94f9120f8ec5106
parentb62c8fd41cf32ea33de9d4f74415c665d315ecb1 (diff)
split out nullprint and set up space.regex multi-return
-rw-r--r--space.js26
-rw-r--r--tools/search.js5
2 files changed, 18 insertions, 13 deletions
diff --git a/space.js b/space.js
index c5a0927..9125c54 100644
--- a/space.js
+++ b/space.js
@@ -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
diff --git a/tools/search.js b/tools/search.js
index 56137b8..eafb2bf 100644
--- a/tools/search.js
+++ b/tools/search.js
@@ -32,8 +32,9 @@ function Search(){ // searchBlock should be a Space object.
searchspace.comb( this.tiles[tile], comb.add );
});
for (let i=0; i<this.spaces.length; i++){
- let coords = searchspace.regex(this.spaces[i]);
- if (coords.length) this.calls[i](vec.add(coords, searchspace.loc), send, searchspace);
+ let coords = searchspace.regex(this.spaces[i])[0];
+ if (coords) this.calls[i](vec.add(coords, searchspace.loc), send,
+ searchspace);
}
}