Improved native substring capabilities

This commit is contained in:
Devine Lu Linvega 2024-04-20 18:56:04 -07:00
parent 9295a4d2b4
commit 4322d96ee2
2 changed files with 8 additions and 4 deletions

View File

@ -39,11 +39,13 @@ compare (abc abc abc) (#t) test
replace-empty abc = ?y test replace-empty abc = ?y test
?(?-) (Connecting register output) ?(?-) (Substring registers)
<> (connect ?x ?y ?z) (?x-?y?z) <> (connect ?x ?y ?z) (?x-?y?z)
<> (prefix-?x) (?x-suffix)
connect foo bar baz = foo-barbaz test connect foo bar baz = foo-barbaz test
prefix-anything = anything-suffix test
?(?-) (Inline register) ?(?-) (Inline register)

View File

@ -97,20 +97,22 @@ static char *
match_rule(Rule *r, char *p) match_rule(Rule *r, char *p)
{ {
int i; int i;
char c, last = 0, *a = r->a, *b = p; char c, *a = r->a, *b = p;
if(rmax) { if(rmax) {
for(i = rmin; i <= rmax; i++) for(i = rmin; i <= rmax; i++)
regs[i] = 0; regs[i] = 0;
rmin = 0xff, rmax = 0x00; rmin = 0xff, rmax = 0x00;
} }
while((c = *a)) { while((c = *a)) {
if(c == '?' && spacer(last) && spacer(a[2])) { if(c == '?') {
if(!set_reg(*(++a), b)) return NULL; if(!set_reg(*(++a), b)) return NULL;
a++, b = walk(b); a++, b = walk(b);
if(!spacer(*a))
while((c = *a) && !spacer(c)) a++;
continue; continue;
} }
if(c != *b) return NULL; if(c != *b) return NULL;
a++, b++, last = c; a++, b++;
} }
c = *b; c = *b;
return spacer(c) ? b : NULL; return spacer(c) ? b : NULL;