aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-02-03 10:54:07 +0000
committerFuwn <[email protected]>2022-02-03 10:54:07 +0000
commit15722d02ba53568a34ace9e617198b427030f045 (patch)
tree587a2ffa3c1cb2e6aa53190cf85a0af2aa2f65ce
parentfix(ui): unused locals, default branch (diff)
downloadarchived-viv-15722d02ba53568a34ace9e617198b427030f045.tar.xz
archived-viv-15722d02ba53568a34ace9e617198b427030f045.zip
feat(viv): implement `VIV_split` for future use
-rw-r--r--include/viv/viv.h4
-rw-r--r--viv/viv.c15
2 files changed, 19 insertions, 0 deletions
diff --git a/include/viv/viv.h b/include/viv/viv.h
index c6906ca..82c7583 100644
--- a/include/viv/viv.h
+++ b/include/viv/viv.h
@@ -6,8 +6,12 @@
#pragma once
+typedef void(*split_fn)(const char *, int, void *);
+
static const char *VIV_version = "1.0.0";
int VIV_exit(int, const char *, ...);
+/* http://www.martinbroadhurst.com/split-a-string-in-c.html */
+void VIV_split(const char *, char, split_fn, void *);
#endif /* VIV_VIV_H */
diff --git a/viv/viv.c b/viv/viv.c
index 410c14e..8759408 100644
--- a/viv/viv.c
+++ b/viv/viv.c
@@ -168,3 +168,18 @@ int VIV_exit(int exit_code, const char *format, ...) {
return print_result;
}
+
+void VIV_split(const char *string, char separator, split_fn function, void *data) {
+ unsigned int start, stop;
+
+ start, stop = 0;
+
+ for (stop = 0; string[stop]; ++stop) {
+ if (string[stop] == separator) {
+ function(string + start, stop - start, data);
+ start = stop + 1;
+ }
+ }
+
+ function(string + start, stop - start, data);
+}