aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-09-08 17:55:18 +0200
committerFederico Angelilli <code@fedang.net>2024-09-08 17:55:18 +0200
commit4d1abb6d350a3d898a5aedfcb912bc28eef46d45 (patch)
treeb178627ed5e80d22171c0dbf7edd39d01eb502ba /src/util.c
parent5e7f66b34826697537bcdcb60c81f56da956a32b (diff)
Start working on custom formatting
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c
index 044ce70..0a2ade8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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;
}