diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2017-10-30 12:19:24 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-10-30 12:27:29 -0700 |
commit | 1c42750cdf08e425a9f9000a1784a868bf797ef8 (patch) | |
tree | 43fd5291981d675da8a40a816b665010eeac88af /core | |
parent | 15cdcdbc6997aa662b7fb76cfab3c147b0bea779 (diff) | |
download | subsurface-1c42750cdf08e425a9f9000a1784a868bf797ef8.tar.gz |
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>
Diffstat (limited to 'core')
-rw-r--r-- | core/dive.h | 15 |
1 files changed, 15 insertions, 0 deletions
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; |