From 25cde1651b86455707051a842ed66a6df59a006b Mon Sep 17 00:00:00 2001 From: wrmr Date: Fri, 8 Nov 2024 17:05:41 -0500 Subject: rename struct str_slice -> strv_t (string view), use memchr --- strv.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 strv.c (limited to 'strv.c') diff --git a/strv.c b/strv.c new file mode 100644 index 0000000..5da11f5 --- /dev/null +++ b/strv.c @@ -0,0 +1,14 @@ +#include + +#include "strv.h" + +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 + }; + if (i) *i = j + r.n + !!c; + return r; +} -- cgit 1.4.1-2-gfad0