From 1618886a0fb697303cba1e5cb9e669e84babce68 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 7 Dec 2015 22:33:26 -0800 Subject: range-regex returns range, not cons. * regex.c (range_regex): Return range. (search_regst): Use appropriate accessors on range returned by range_regex. * lib.c (tok_where): Destructure range returned by range_regex, using range_bind. * txr.1: Documented changed behavior. --- lib.c | 2 +- regex.c | 4 ++-- txr.1 | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib.c b/lib.c index ee6c270d..acc55a90 100644 --- a/lib.c +++ b/lib.c @@ -3550,7 +3550,7 @@ val tok_where(val str, val tok_regex) for (;;) { val range = range_regex(str, tok_regex, pos, nil); - cons_bind (match_start, match_end, range); + range_bind (match_start, match_end, range); if (!match_start) break; diff --git a/regex.c b/regex.c index 859f9f8f..7643d22b 100644 --- a/regex.c +++ b/regex.c @@ -2388,7 +2388,7 @@ val range_regex(val haystack, val needle_regex, val start, if (result) { cons_bind (pos, len, result); - rplacd(result, plus(pos, len)); + return rcons(pos, plus(pos, len)); } return result; @@ -2484,7 +2484,7 @@ val regsub(val regex, val repl, val str) val search_regst(val haystack, val needle_regex, val start_num, val from_end) { val range = range_regex(haystack, needle_regex, start_num, from_end); - return if2(range, sub_str(haystack, car(range), cdr(range))); + return if2(range, sub_str(haystack, from(range), to(range))); } val match_regst(val str, val regex, val pos_in) diff --git a/txr.1 b/txr.1 index f5971170..3f08dcc9 100644 --- a/txr.1 +++ b/txr.1 @@ -28834,11 +28834,11 @@ function is similar to .codn search-regex , except that when a match is found, it returns a position range, rather than a position -and length. A cons is returned whose -.code car -indicates the position +and length. A range object is returned whose +.code from +field indicates the position of the match, and whose -.code cdr +.code to indicates the position one element past the last character of the match. If the match is empty, the two integers are equal. -- cgit v1.2.3