aboutsummaryrefslogtreecommitdiff
path: root/space.js
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-07-16 20:48:14 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-07-16 20:48:14 -0400
commitb62c8fd41cf32ea33de9d4f74415c665d315ecb1 (patch)
tree8e46f8e2aae34c35807906424dc18da50df30344 /space.js
parentb06268b3ab9da5140bb87fdc1ef7cde27e5ffd47 (diff)
search.js uses `space` regexes now, improving nword match
Diffstat (limited to 'space.js')
-rw-r--r--space.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/space.js b/space.js
index 65b5355..c5a0927 100644
--- a/space.js
+++ b/space.js
@@ -138,6 +138,44 @@ 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'));
+ }
+ let data = [];
+ for (let ln of this.data){
+ let newln = "";
+ for (c of ln){
+ if (c === '') newln += '\0';
+ else newln += c;
+ }
+ data.push(newln);
+ }
+ let loc;
+ data.forEach( (ln, ind) => {
+ if (loc || ((data.length - ind) < lines.length)) return;
+ let match;
+ while ( (match = lines[0].exec(ln)) !== null){
+ let xdisp = match.index;
+ let lnmatch = true;
+ for (let i=1; lines[i] !== undefined; i+= 1){
+ let imatch = lines[i].exec(data[ind+i].slice(xdisp));
+ if (!imatch || imatch.index !== 0){
+ lnmatch = false;
+ break;
+ }
+ }
+ if (lnmatch){
+ loc = [ind, xdisp];
+ break;
+ }
+ }
+ });
+ return (loc === undefined ? [] : loc);
+ }
+
this.subsection = function(range){ // range is a coordinate pair
if (range.length !== 2 || range[0].length !== 2) throw "not subsecting a coord pair";
// Similarly excludes this.loc