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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2017-10-30 12:19:24 -07:00
parent 15cdcdbc69
commit 1c42750cdf

View file

@ -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;