From 9075e91263f6cd74d33d0e078ba9ab77a95f1083 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 10 Sep 2026 21:10:18 +0000 Subject: Work in progress changes for the module system. I am only committing to save my work somewhere, but it doesn't work yet. FossilOrigin-Name: 45400ea0e451183f360a3d0cbb14f262cbec2e62167bad732fd396ed0ce4acaf --- src/lib/string.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/lib/string.c') diff --git a/src/lib/string.c b/src/lib/string.c index 05549e0..db08b28 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -168,3 +168,27 @@ string_compare(struct string *a, struct string *b) else return 0; } + +struct string * +substring(struct aplwc *aplwc, struct string *s, size_t start, size_t length) +{ + size_t bytes, i; + struct string *r; + + MEMPTRS(aplwc, 1); + MEMPTR(0, s); + + bytes = 0; + for(i = 0; i < length; i++) + bytes += char_length(s, start+i); + + r = memory_alloc_string(aplwc, bytes); + if(r){ + r->bytes = bytes; + r->chars = length; + memcpy(r->utf8, s->utf8+start, bytes); + } + + MEMPTRS_EXIT(aplwc); + return r; +} -- cgit v1.2.3