mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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:
parent
15cdcdbc69
commit
1c42750cdf
1 changed files with 15 additions and 0 deletions
15
core/dive.h
15
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue