summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib.c b/lib.c
index 064cb8ee..d5a6634a 100644
--- a/lib.c
+++ b/lib.c
@@ -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;