summary refs log tree commit diff
path: root/strv.c
diff options
context:
space:
mode:
authorwrmr2024-11-08 17:05:41 -0500
committerwrmr2024-11-08 17:05:41 -0500
commit25cde1651b86455707051a842ed66a6df59a006b (patch)
treee1241f3f813ba9c0fff7ad099f8fe1d986081b00 /strv.c
parentb977942932bf1cd625f8d7a6f310b0d3a537f72e (diff)
rename struct str_slice -> strv_t (string view), use memchr
Diffstat (limited to 'strv.c')
-rw-r--r--strv.c14
1 files changed, 14 insertions, 0 deletions
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 <string.h>
+
+#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;
+}