diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-10-26 21:14:37 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-10-26 21:14:37 -0700 |
commit | c69000bfe99f2503aed9d389cf6590a6229e7fd0 (patch) | |
tree | 9ddb5f260dc0c423c80edaab2722ded405755f3d /lib.c | |
parent | 992e3ca99dc73b3dbbdf7a9bfda471df29add006 (diff) | |
download | txr-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.c | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -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; |