move ascii.* into the lib-lib.
[apps/madmutt.git] / lib-lib / ascii.c
diff --git a/lib-lib/ascii.c b/lib-lib/ascii.c
new file mode 100644 (file)
index 0000000..697e1d7
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright notice from original mutt:
+ * Copyright (C) 2001 Thomas Roessler <roessler@does-not-exist.org>
+ *
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * It's licensed under the GNU General Public License,
+ * please see the file GPL in the top level source directory.
+ */
+
+/*
+ * Versions of the string comparison functions which are
+ * locale-insensitive.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "ascii.h"
+
+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, int 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;
+}