summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-07-10 08:44:16 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-07-10 08:44:16 -0700
commit91d1a70c1d64c67bbaa5dc94dabf7461ad97bb8d (patch)
tree08f93715512867f64d942fcecaddece9e2d7b141 /lib.c
parent44fc04addc852cd4d0bbfa53a44b69679aaa29c2 (diff)
downloadtxr-91d1a70c1d64c67bbaa5dc94dabf7461ad97bb8d.tar.gz
txr-91d1a70c1d64c67bbaa5dc94dabf7461ad97bb8d.tar.bz2
txr-91d1a70c1d64c67bbaa5dc94dabf7461ad97bb8d.zip
New functions: trim-short-suffix, trim-long-suffix.
* lib.c, lib.h (chk_substrdup): New function. * stream.c, stream.h (trim_short_suffix, trim_long_suffix): New functions. (stream_init): trim-short-suffix and trim-long-suffix intrinsics registered. * tests/018/path.tl: New tests. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 006036a9..0e8bbbb1 100644
--- a/lib.c
+++ b/lib.c
@@ -4064,6 +4064,21 @@ wchar_t *chk_strdup(const wchar_t *str)
return copy;
}
+wchar_t *chk_substrdup(const wchar_t *str, size_t off, size_t len)
+{
+ size_t size = wcslen(str) + 1, nchar;
+ wchar_t *copy;
+ if (off >= size - 1)
+ return chk_strdup(L"");
+ if (off + len < off)
+ uw_throw(error_s, lit("string size overflow"));
+ nchar = min(size - off, len + 1);
+ copy = chk_wmalloc(nchar);
+ wmemcpy(copy, str, nchar - 1);
+ copy[nchar - 1] = 0;
+ return copy;
+}
+
char *chk_strdup_utf8(const char *str)
{
size_t nchar = strlen(str) + 1;