1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

added Curl_strcasestr() for case insensitive strstr() searching

This commit is contained in:
Daniel Stenberg 2004-06-13 08:32:57 +00:00
parent 4b3937373a
commit 61bded1d82
2 changed files with 33 additions and 11 deletions

View File

@ -78,6 +78,25 @@ int curl_strnequal(const char *first, const char *second, size_t max)
#endif
}
/*
* Curl_strcasestr() finds the first occurrence of the substring needle in the
* string haystack. The terminating `\0' characters are not compared. The
* matching is done CASE INSENSITIVE, which thus is the difference between
* this and strstr().
*/
char *Curl_strcasestr(const char *haystack, const char *needle)
{
size_t nlen = strlen(needle);
size_t hlen = strlen(haystack);
while(hlen-- >= nlen) {
if(curl_strnequal(haystack, needle, nlen))
return (char *)haystack;
haystack++;
}
return NULL;
}
#ifndef HAVE_STRLCAT
/*
* The strlcat() function appends the NUL-terminated string src to the end

View File

@ -36,6 +36,9 @@ int curl_strnequal(const char *first, const char *second, size_t max);
argument is zero-byte terminated */
#define checkprefix(a,b) strnequal(a,b,strlen(a))
/* case insensitive strstr() */
char *Curl_strcasestr(const char *haystack, const char *needle);
#ifndef HAVE_STRLCAT
#define strlcat(x,y,z) Curl_strlcat(x,y,z)
size_t Curl_strlcat(char *dst, const char *src, size_t siz);