diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-07-10 08:44:16 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-07-10 08:44:16 -0700 |
commit | 91d1a70c1d64c67bbaa5dc94dabf7461ad97bb8d (patch) | |
tree | 08f93715512867f64d942fcecaddece9e2d7b141 /lib.c | |
parent | 44fc04addc852cd4d0bbfa53a44b69679aaa29c2 (diff) | |
download | txr-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.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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; |