From 2ea6ca3ef8151d94d2a3f306a9035ae7ae001fcd Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 9 Jun 2014 19:37:51 -0700 Subject: * lib.c (match_str): Extended to suffix testing, with a negative start argument. * txr.1: Documented. --- ChangeLog | 7 +++++++ lib.c | 31 +++++++++++++++++++++++-------- txr.1 | 19 ++++++++++++++----- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index d60aac61..2fab8a4d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2014-06-09 Kaz Kylheku + + * lib.c (match_str): Extended to suffix testing, with a negative + start argument. + + * txr.1: Documented. + 2014-06-09 Kaz Kylheku * Makefile: fix broken tests; numerous test cases output diff --git a/lib.c b/lib.c index d46ab2e6..b0118f45 100644 --- a/lib.c +++ b/lib.c @@ -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) diff --git a/txr.1 b/txr.1 index 9ac40b64..1d8a617b 100644 --- a/txr.1 +++ b/txr.1 @@ -8884,12 +8884,21 @@ Syntax: .TP Description: -The match-str function determines how many characters of match a -prefix of . +Without the argument, the match-str function determines whether + is a prefix of , returning a t or nil +indication. -If the argument is specified, then the function tests how many -characters of match a prefix of that portion of -which starts at the given position. +If the argument is specified, and is a non-negative integer, then the +function tests whether matches a prefix of that portion of + which starts at the given position. + +If the argument is a negative integer, then match-str determines +whether is a suffix of , ending on that position +of bigstring, where -1 denotes the last character of , +-2 the second last one and so on. + +If is -1, then this corresponds to testing whether +is a suffix of . .SS Function match-str-tree -- cgit v1.2.3