diff options
author | wrmr | 2024-11-08 23:57:30 -0500 |
---|---|---|
committer | wrmr | 2024-11-08 23:57:30 -0500 |
commit | 9ac1ca968081bcb826cf9ee70666bc44983d087f (patch) | |
tree | 1d130f91c53c41f5a6f18d357fb4fa96c3088883 /strv.c | |
parent | cd3626642755359eecf64d05e3f9db3d8b00ed24 (diff) |
simplify strv_head interface, rename to strv_split
Diffstat (limited to 'strv.c')
-rw-r--r-- | strv.c | 16 |
1 files changed, 8 insertions, 8 deletions
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; } |