From 9ac1ca968081bcb826cf9ee70666bc44983d087f Mon Sep 17 00:00:00 2001 From: wrmr Date: Fri, 8 Nov 2024 23:57:30 -0500 Subject: simplify strv_head interface, rename to strv_split --- strv.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'strv.c') diff --git a/strv.c b/strv.c index a3e9f6a..0d37a6f 100644 --- a/strv.c +++ b/strv.c @@ -6,13 +6,13 @@ strv_t strv(const char *s) { return (strv_t) { s, strlen(s) }; } -strv_t strv_head(strv_t ss, int chr, size_t *i) { - size_t j = i ? *i : 0; - char *c = memchr(&ss.s[j], chr, ss.n - j); - strv_t r = { - &ss.s[j], - c ? c - &ss.s[j] : ss.n - j +int strv_split(strv_t *src, int chr, strv_t *dest) { + char *c = memchr(src->s, chr, src->n); + *dest = (strv_t) { + src->s, + c ? c - src->s : src->n }; - if (i) *i = j + r.n + !!c; - return r; + src->s = c ? c + 1 : &src->s[src->n]; + src->n -= dest->n + !!c; + return dest->n > 0; } -- cgit 1.4.1-2-gfad0