From bb6c20f9fa5c6c13e088c205fffbe94900e36588 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 26 Oct 2016 21:14:37 -0700 Subject: 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. --- lib.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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) { @@ -4065,6 +4066,27 @@ val tok_where(val str, val tok_regex) continue; } + 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; } -- cgit v1.2.3