diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2011-10-24 23:48:54 -0400 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2011-10-24 23:48:54 -0400 |
commit | 689421c6a76223cae4d12e1fc897e2fcb46098e6 (patch) | |
tree | 0728fea297e86cff1ef59b46c1a701ed0bd1e95d | |
parent | 77b9c8f289df7b0ba45668e09cdc040252c681c8 (diff) | |
download | txr-689421c6a76223cae4d12e1fc897e2fcb46098e6.tar.gz txr-689421c6a76223cae4d12e1fc897e2fcb46098e6.tar.bz2 txr-689421c6a76223cae4d12e1fc897e2fcb46098e6.zip |
Bugs #34641, #34629.
* lib.c (search_str_tree): If multiple strings from the needle tree
matching within within the haystack string, then take the leftmost
match. If there are multiple matches at the same leftmost position,
take the longest one.
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | lib.c | 17 |
2 files changed, 22 insertions, 4 deletions
@@ -1,5 +1,14 @@ 2011-10-24 Kaz Kylheku <kaz@kylheku.com> + Bugs #34641, #34629. + + * lib.c (search_str_tree): If multiple strings from the needle tree + matching within within the haystack string, then take the leftmost + match. If there are multiple matches at the same leftmost position, + take the longest one. + +2011-10-24 Kaz Kylheku <kaz@kylheku.com> + * filter.c (function_filter): New function. (get_filter): Handle (fun ...) syntax. @@ -1023,12 +1023,21 @@ val search_str_tree(val haystack, val tree, val start_num, val from_end) if (result) return cons(result, length_str(tree)); } else if (consp(tree)) { - while (tree) { + val it = nil, minpos = nil, maxlen = nil; + + for (; tree; tree = cdr(tree)) { val result = search_str_tree(haystack, car(tree), start_num, from_end); - if (result) - return result; - tree = cdr(tree); + if (result) { + cons_bind (pos, len, result); + if (!it || lt(pos, minpos) || (eq(pos, minpos) && gt(len, maxlen))) { + minpos = pos; + maxlen = len; + it = result; + } + } } + + return it; } return nil; |