diff options
| author | Fuwn <[email protected]> | 2022-02-03 10:54:07 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-02-03 10:54:07 +0000 |
| commit | 15722d02ba53568a34ace9e617198b427030f045 (patch) | |
| tree | 587a2ffa3c1cb2e6aa53190cf85a0af2aa2f65ce | |
| parent | fix(ui): unused locals, default branch (diff) | |
| download | archived-viv-15722d02ba53568a34ace9e617198b427030f045.tar.xz archived-viv-15722d02ba53568a34ace9e617198b427030f045.zip | |
feat(viv): implement `VIV_split` for future use
| -rw-r--r-- | include/viv/viv.h | 4 | ||||
| -rw-r--r-- | viv/viv.c | 15 |
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 */ @@ -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); +} |