diff options
Diffstat (limited to 'src/util.c')
| -rw-r--r-- | src/util.c | 42 |
1 files changed, 40 insertions, 2 deletions
@@ -108,7 +108,45 @@ char *strcopy(const char *string) return strslice(string, 0, strlen(string)); } -void unreachable(void) +bool strfind(const char *string, const char *cases[]) { - log_panic("Unreachable"); + for (int i = 0; cases[i] != NULL; i++) { + if (strstr(string, cases[i]) != NULL) + return true; + } + return false; +} + +size_t strprefix(const char *string, const char *prefix) +{ + size_t i = 0; + for ( ; prefix[i] != '\0'; i++) { + if (string[i] != prefix[i]) + return 0; + } + return i; +} + +size_t strcount(const char *string, const char *subs[]) +{ + size_t count = 0; + for (int i = 0; string[i] != '\0'; ) { +next: + for (int j = 0; subs[j] != NULL; j++) { + size_t pl = strprefix(string + i, subs[j]); + if (pl) { + i += pl; + count++; + goto next; + } + } + ++i; + } + return count; +} + +char *strformat(const char *string, const char *keys[], const char *values[]) +{ + // TODO + return NULL; } |
