summaryrefslogtreecommitdiffstats
path: root/regex.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-01-27 00:27:47 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-01-27 00:27:47 -0800
commitbcc1770bf64c62dc5c6404596017cf73a6c9e25e (patch)
treef64c291e7a744d117c1de77507476c555b83f530 /regex.c
parent09eb73cde9c64e6fa29cbb410b25c6dd84a8a6f2 (diff)
downloadtxr-bcc1770bf64c62dc5c6404596017cf73a6c9e25e.tar.gz
txr-bcc1770bf64c62dc5c6404596017cf73a6c9e25e.tar.bz2
txr-bcc1770bf64c62dc5c6404596017cf73a6c9e25e.zip
* regex.c (match_regex_right): Fix semantics of second argument
to something more useful. * regex.h (match_regex_right): Change name of parameter. * txr.1: Documented match-regex-right.
Diffstat (limited to 'regex.c')
-rw-r--r--regex.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/regex.c b/regex.c
index 67f17f60..090846b1 100644
--- a/regex.c
+++ b/regex.c
@@ -1854,20 +1854,21 @@ val match_regex(val str, val reg, val pos)
return nil;
}
-val match_regex_right(val str, val regex, val pos)
+val match_regex_right(val str, val regex, val end)
{
+ val pos = zero;
val slen = length(str);
- if (!pos)
- pos = zero;
+ if (!end || gt(end, slen))
+ end = slen;
- for (;;) {
+ while (lt(pos, end)) {
cons_bind (from, len, search_regex(str, regex, pos, nil));
if (!from)
return nil;
- if (eql(plus(from, len), slen))
+ if (eql(plus(from, len), end))
return len;
pos = plus(pos, one);