summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-10-26 21:14:37 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-10-26 21:14:37 -0700
commitc69000bfe99f2503aed9d389cf6590a6229e7fd0 (patch)
tree9ddb5f260dc0c423c80edaab2722ded405755f3d /lib.c
parent992e3ca99dc73b3dbbdf7a9bfda471df29add006 (diff)
downloadtxr-c69000bfe99f2503aed9d389cf6590a6229e7fd0.tar.gz
txr-c69000bfe99f2503aed9d389cf6590a6229e7fd0.tar.bz2
txr-c69000bfe99f2503aed9d389cf6590a6229e7fd0.zip
Same fix in tok-where as tok-str.
lib.c (tok_where) Implement new loop which suppresses empty tokens immediately matching after non-empty tokens. Old loop available under compatibility. No documentation update needed since tok-where is already documented as working like tok-str.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index ab07ed10..5b304237 100644
--- a/lib.c
+++ b/lib.c
@@ -4049,8 +4049,9 @@ val tok_where(val str, val tok_regex)
{
list_collect_decl (out, iter);
val pos = zero;
+ int prev_empty = 1;
- for (;;) {
+ if (opt_compat && opt_compat <= 155) for (;;) {
val range = range_regex(str, tok_regex, pos, nil);
if (range) {
@@ -4066,6 +4067,27 @@ val tok_where(val str, val tok_regex)
}
break;
+ } else for (;;) {
+ val range = range_regex(str, tok_regex, pos, nil);
+
+ if (range) {
+ range_bind (match_start, match_end, range);
+
+ if (match_end != match_start || prev_empty) {
+ iter = list_collect(iter, range);
+ prev_empty = (match_end == match_start);
+ } else {
+ prev_empty = 1;
+ }
+
+ pos = match_end;
+
+ if (match_end == match_start)
+ pos = plus(pos, one);
+ continue;
+ }
+
+ break;
}
return out;