From 1c42750cdf08e425a9f9000a1784a868bf797ef8 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 30 Oct 2017 12:19:24 -0700 Subject: Add new helfer for strcasestr That's not a standard functions, so let's just build it. This is not the most efficient way to write it, but it will do. Signed-off-by: Dirk Hohndel --- core/dive.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'core/dive.h') diff --git a/core/dive.h b/core/dive.h index f72aaf1d5..d3b755491 100644 --- a/core/dive.h +++ b/core/dive.h @@ -37,6 +37,21 @@ static inline int same_string_caseinsensitive(const char *a, const char *b) return !strcasecmp(a ?: "", b ?: ""); } +static inline int includes_string_caseinsensitive(const char *haystack, const char *needle) +{ + if (!needle) + return 1; /* every string includes the NULL string */ + if (!haystack) + return 0; /* nothing is included in the NULL string */ + int len = strlen(needle); + while (*haystack) { + if (strncasecmp(haystack, needle, len)) + return 1; + haystack++; + } + return 0; +} + static inline char *copy_string(const char *s) { return (s && *s) ? strdup(s) : NULL; -- cgit v1.2.3-70-g09d2