summaryrefslogtreecommitdiffstats
path: root/txr.1
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-10-05 06:19:02 -0700
committerKaz Kylheku <kaz@kylheku.com>2020-10-05 06:19:02 -0700
commit2d4d37907eb060fc23cc4a9f8ebf6b577db3a18b (patch)
treef3d7a0a522c2ccacde21ab944fb53ec0c7363c85 /txr.1
parent77f92bd8b4cb96ddae97b2cdec2427fd4c16c6ee (diff)
downloadtxr-2d4d37907eb060fc23cc4a9f8ebf6b577db3a18b.tar.gz
txr-2d4d37907eb060fc23cc4a9f8ebf6b577db3a18b.tar.bz2
txr-2d4d37907eb060fc23cc4a9f8ebf6b577db3a18b.zip
New functions trim-left and trim-right.
* regex.c (trim_left, trim_right): New static functions. (regex_init): New intrinsics registered. * tests/015/trim.tl, tests/015/trim.expected: New files. * txr.1: Documented.
Diffstat (limited to 'txr.1')
-rw-r--r--txr.171
1 files changed, 71 insertions, 0 deletions
diff --git a/txr.1 b/txr.1
index 8991fed4..9637ab8d 100644
--- a/txr.1
+++ b/txr.1
@@ -45689,6 +45689,77 @@ is a compiled regular expression
object. For any other object type, it returns
.codn nil .
+.coNP Functions @ trim-left and @ trim-right
+.synb
+.mets (trim-left >> { regex | << prefix } << string )
+.mets (trim-right >> { regex | << suffix } << string )
+.syne
+.desc
+The
+.code trim-left
+and
+.code trim-right
+functions return a new string, equivalent to
+.meta string
+with a leading or trailing portion removed.
+
+If the first argument is a regular expression
+.metn regex ,
+then, respectively,
+.code trim-left
+and
+.code trim-right
+find a prefix or suffix of
+.meta string
+which matches the regular expression.
+If there is no match, or if the match is empty, then
+.meta string
+is returned. Otherwise, a copy of
+.meta string
+is returned in which the matching characters are removed.
+If
+.meta regex
+matches all of
+.meta string
+then the empty string is returned.
+
+If the first argument is a character string, then it is treated
+as if it were a regular expression match for that literal
+sequence of characters. Thus,
+.code trim-left
+interprets that string as a
+.meta prefix
+to be removed, and
+.code trim-right
+as a
+.metn suffix .
+If
+.meta string
+starts with
+.metn prefix ,
+then
+.code trim-left
+returns a copy of
+.meta string
+with
+.meta prefix
+removed. Otherwise,
+.meta string
+is returned.
+Likewise, if
+.meta string
+ends with
+.metn suffix ,
+then
+.code trim-right
+returns a copy of
+.meta string
+with
+.meta suffix
+removed. Otherwise,
+.meta string
+is returned.
+
.coNP Function @ regex-compile
.synb
.mets (regex-compile < form-or-string <> [ error-stream ])