more simplifications.
[apps/madmutt.git] / lib-lib / str.c
index f55aa45..7b57305 100644 (file)
@@ -140,3 +140,41 @@ const char *m_stristrn(const char *haystack, const char *needle, ssize_t nlen)
         haystack++;
     }
 }
+
+int ascii_strcasecmp(const char *a, const char *b)
+{
+    int i;
+
+    if (a == b)
+        return 0;
+    if (a == NULL && b)
+        return -1;
+    if (b == NULL && a)
+        return 1;
+
+    for (; *a || *b; a++, b++) {
+        if ((i = ascii_tolower(*a) - ascii_tolower(*b)))
+            return i;
+    }
+
+    return 0;
+}
+
+int ascii_strncasecmp (const char *a, const char *b, ssize_t n)
+{
+    int i, j;
+
+    if (a == b)
+        return 0;
+    if (a == NULL && b)
+        return -1;
+    if (b == NULL && a)
+        return 1;
+
+    for (j = 0; (*a || *b) && j < n; a++, b++, j++) {
+        if ((i = ascii_tolower(*a) - ascii_tolower(*b)))
+            return i;
+    }
+
+    return 0;
+}