summaryrefslogtreecommitdiffstats
path: root/Utilities/cmcurl/lib/strcase.c
diff options
context:
space:
mode:
Diffstat (limited to 'Utilities/cmcurl/lib/strcase.c')
-rw-r--r--Utilities/cmcurl/lib/strcase.c49
1 files changed, 21 insertions, 28 deletions
diff --git a/Utilities/cmcurl/lib/strcase.c b/Utilities/cmcurl/lib/strcase.c
index 09d2a8a..7fb9c80 100644
--- a/Utilities/cmcurl/lib/strcase.c
+++ b/Utilities/cmcurl/lib/strcase.c
@@ -83,16 +83,13 @@ char Curl_raw_tolower(char in)
}
/*
- * Curl_strcasecompare() is for doing "raw" case insensitive strings. This is
- * meant to be locale independent and only compare strings we know are safe
- * for this. See
- * https://daniel.haxx.se/blog/2008/10/15/strcasecmp-in-turkish/ for some
- * further explanation to why this function is necessary.
- *
- * @unittest: 1301
+ * curl_strequal() is for doing "raw" case insensitive strings. This is meant
+ * to be locale independent and only compare strings we know are safe for
+ * this. See https://daniel.haxx.se/blog/2008/10/15/strcasecmp-in-turkish/ for
+ * further explanations as to why this function is necessary.
*/
-int Curl_strcasecompare(const char *first, const char *second)
+static int casecompare(const char *first, const char *second)
{
while(*first && *second) {
if(Curl_raw_toupper(*first) != Curl_raw_toupper(*second))
@@ -108,25 +105,22 @@ int Curl_strcasecompare(const char *first, const char *second)
return !*first == !*second;
}
-int Curl_safe_strcasecompare(const char *first, const char *second)
+/* --- public function --- */
+int curl_strequal(const char *first, const char *second)
{
if(first && second)
/* both pointers point to something then compare them */
- return Curl_strcasecompare(first, second);
+ return casecompare(first, second);
/* if both pointers are NULL then treat them as equal */
return (NULL == first && NULL == second);
}
-/*
- * @unittest: 1301
- */
-int Curl_strncasecompare(const char *first, const char *second, size_t max)
+static int ncasecompare(const char *first, const char *second, size_t max)
{
while(*first && *second && max) {
- if(Curl_raw_toupper(*first) != Curl_raw_toupper(*second)) {
- break;
- }
+ if(Curl_raw_toupper(*first) != Curl_raw_toupper(*second))
+ return 0;
max--;
first++;
second++;
@@ -137,6 +131,16 @@ int Curl_strncasecompare(const char *first, const char *second, size_t max)
return Curl_raw_toupper(*first) == Curl_raw_toupper(*second);
}
+/* --- public function --- */
+int curl_strnequal(const char *first, const char *second, size_t max)
+{
+ if(first && second)
+ /* both pointers point to something then compare them */
+ return ncasecompare(first, second, max);
+
+ /* if both pointers are NULL then treat them as equal if max is non-zero */
+ return (NULL == first && NULL == second && max);
+}
/* Copy an upper case version of the string from src to dest. The
* strings may overlap. No more than n characters of the string are copied
* (including any NUL) and the destination string will NOT be
@@ -198,14 +202,3 @@ int Curl_timestrcmp(const char *a, const char *b)
return a || b;
return match;
}
-
-/* --- public functions --- */
-
-int curl_strequal(const char *first, const char *second)
-{
- return Curl_strcasecompare(first, second);
-}
-int curl_strnequal(const char *first, const char *second, size_t max)
-{
- return Curl_strncasecompare(first, second, max);
-}