diff options
| author | peter <peter@pmikkelsen.com> | 2026-09-10 21:10:18 +0000 |
|---|---|---|
| committer | peter <peter@pmikkelsen.com> | 2026-09-10 21:10:18 +0000 |
| commit | 9075e91263f6cd74d33d0e078ba9ab77a95f1083 (patch) | |
| tree | 0c7c66d92a4d26642b4687a7a5db7d2e63a5188f /src/lib/string.c | |
| parent | d2cfbd1dcc42f2b5e5f1cb04c20691a20039ad6e (diff) | |
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
Diffstat (limited to 'src/lib/string.c')
| -rw-r--r-- | src/lib/string.c | 24 |
1 files changed, 24 insertions, 0 deletions
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; +} |