diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | lib.c | 31 | ||||
-rw-r--r-- | txr.1 | 19 |
3 files changed, 44 insertions, 13 deletions
@@ -1,5 +1,12 @@ 2014-06-09 Kaz Kylheku <kaz@kylheku.com> + * lib.c (match_str): Extended to suffix testing, with a negative + start argument. + + * txr.1: Documented. + +2014-06-09 Kaz Kylheku <kaz@kylheku.com> + * Makefile: fix broken tests; numerous test cases output bindings, and need the -B option. One test case does not need the -l option which now implies -B. @@ -2077,15 +2077,30 @@ val match_str(val bigstr, val str, val pos) pos = default_arg(pos, zero); - for (i = zero; - length_str_gt(bigstr, p = plus(pos, i)) && length_str_gt(str, i); - i = plus(i, one)) - { - if (chr_str(bigstr, p) != chr_str(str, i)) - return nil; - } + if (ge(pos, zero)) { + for (i = zero; + length_str_gt(bigstr, p = plus(pos, i)) && length_str_gt(str, i); + i = plus(i, one)) + { + if (chr_str(bigstr, p) != chr_str(str, i)) + return nil; + } - return length_str_le(str, i) ? t : nil; + return length_str_le(str, i) ? t : nil; + } else { + pos = plus(pos, length(bigstr)); + pos = plus(minus(pos, length(str)), one); + + for (i = minus(length(str), one); + ge(i, zero) && ge(p = plus(pos, i), zero); + i = minus(i, one)) + { + if (chr_str(bigstr, p) != chr_str(str, i)) + return nil; + } + + return lt(i, zero) ? t : nil; + } } val match_str_tree(val bigstr, val tree, val pos) @@ -8884,12 +8884,21 @@ Syntax: .TP Description: -The match-str function determines how many characters of <littlestring> match a -prefix of <bigstring>. +Without the <start> argument, the match-str function determines whether +<littlestring> is a prefix of <bigstring>, returning a t or nil +indication. -If the <start> argument is specified, then the function tests how many -characters of <littlestring> match a prefix of that portion of <bigstring> -which starts at the given position. +If the <start> argument is specified, and is a non-negative integer, then the +function tests whether <littlestring> matches a prefix of that portion of +<bigstring> which starts at the given position. + +If the <start> argument is a negative integer, then match-str determines +whether <littlestring> is a suffix of <bigstring>, ending on that position +of bigstring, where -1 denotes the last character of <bigstring>, +-2 the second last one and so on. + +If <start> is -1, then this corresponds to testing whether <littlestring> +is a suffix of <bigstring>. .SS Function match-str-tree |