aboutsummaryrefslogtreecommitdiff
path: root/lib/strequal.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-06-13 08:32:57 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-06-13 08:32:57 +0000
commit61bded1d8265211f434143aa7984783f2ab2a045 (patch)
tree1bc279afa2b60a217ab8a9e38fb327155688fc70 /lib/strequal.c
parent4b3937373af17717fb4a3cc31e7d994fe5beafec (diff)
added Curl_strcasestr() for case insensitive strstr() searching
Diffstat (limited to 'lib/strequal.c')
-rw-r--r--lib/strequal.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/lib/strequal.c b/lib/strequal.c
index 37a68876e..ec4910281 100644
--- a/lib/strequal.c
+++ b/lib/strequal.c
@@ -1,8 +1,8 @@
/***************************************************************************
- * _ _ ____ _
- * Project ___| | | | _ \| |
- * / __| | | | |_) | |
- * | (__| |_| | _ <| |___
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
@@ -10,7 +10,7 @@
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
- *
+ *
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING 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
@@ -90,7 +109,7 @@ int curl_strnequal(const char *first, const char *second, size_t max)
* src. While this may seem somewhat confusing it was done to make trunca-
* tion detection simple.
*
- *
+ *
*/
size_t Curl_strlcat(char *dst, const char *src, size_t siz)
{