summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-04-26 07:05:54 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-04-26 07:05:54 -0700
commit59a96304bd8716eb68c672ab6970111565e3f269 (patch)
tree88627b28154f4de368887c6b142e7e07d9f77622
parent5917bcb01bff764b0734e45cc86f9e19e20ba984 (diff)
downloadtxr-59a96304bd8716eb68c672ab6970111565e3f269.tar.gz
txr-59a96304bd8716eb68c672ab6970111565e3f269.tar.bz2
txr-59a96304bd8716eb68c672ab6970111565e3f269.zip
match-str: return useful position instead of t.
* lib.c (match_str): The match_str function is hereby altered to return an integer instead of the symbol t in the matching case. * txr.1: Updated.
-rw-r--r--lib.c4
-rw-r--r--txr.126
2 files changed, 22 insertions, 8 deletions
diff --git a/lib.c b/lib.c
index 917a59e1..ea90164b 100644
--- a/lib.c
+++ b/lib.c
@@ -4511,7 +4511,7 @@ val match_str(val bigstr, val str, val pos)
return nil;
}
- return length_str_le(str, i) ? t : nil;
+ return length_str_le(str, i) ? succ(i) : nil;
} else {
pos = plus(pos, length(bigstr));
pos = plus(minus(pos, length(str)), one);
@@ -4524,7 +4524,7 @@ val match_str(val bigstr, val str, val pos)
return nil;
}
- return minusp(i);
+ return minusp(i) ? pos : nil;
}
}
diff --git a/txr.1 b/txr.1
index 1589215e..88663164 100644
--- a/txr.1
+++ b/txr.1
@@ -23606,12 +23606,7 @@ argument, the
function determines whether
.meta littlestring
is a prefix of
-.metn bigstring ,
-returning a
-.code t
-or
-.code nil
-indication.
+.metn bigstring .
If the
.meta start
@@ -23648,6 +23643,25 @@ then this corresponds to testing whether
is a suffix of
.metn bigstring .
+The
+.code match-str
+function returns
+.code nil
+if there is no match.
+
+If a prefix match is successful,
+then an integer value is returned indicating the position, inside
+.metn bigstring ,
+one character past the matching prefix. If the entire string is matched, then
+this value corresponds to the length of
+.metn bigstring .
+
+If a suffix match is successful, the return value is the position within
+.meta bigstring
+where the leftmost character of
+.meta littlestring
+matched.
+
.coNP Function @ match-str-tree
.synb
.mets (match-str-tree < bigstring < tree <> [ start ])