diff --git a/src/string_utils.h b/src/string_utils.h index 3c30c5ce..d77816c7 100644 --- a/src/string_utils.h +++ b/src/string_utils.h @@ -2,7 +2,9 @@ // Copyright (c) Yuxuan Shui #pragma once #include +#include #include +#include #include "compiler.h" @@ -59,6 +61,13 @@ static inline char *skip_space_mut(char *src) { #define skip_space(x) \ _Generic((x), char *: skip_space_mut, const char *: skip_space_const)(x) +static inline bool starts_with(const char *str, const char *needle, bool ignore_case) { + if (ignore_case) { + return strncasecmp(str, needle, strlen(needle)); + } + return strncmp(str, needle, strlen(needle)); +} + /// Similar to `asprintf`, but it reuses the allocated memory pointed to by `*strp`, and /// reallocates it if it's not big enough. int asnprintf(char **strp, size_t *capacity, const char *fmt, ...);