697e1d7b9e8750bd310825fef25802d8a9a2d5bd
[apps/madmutt.git] / lib-lib / ascii.c
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 2001 Thomas Roessler <roessler@does-not-exist.org>
4  *
5  * This file is part of mutt-ng, see http://www.muttng.org/.
6  * It's licensed under the GNU General Public License,
7  * please see the file GPL in the top level source directory.
8  */
9
10 /*
11  * Versions of the string comparison functions which are
12  * locale-insensitive.
13  */
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include "ascii.h"
18
19 int ascii_strcasecmp(const char *a, const char *b)
20 {
21     int i;
22
23     if (a == b)
24         return 0;
25     if (a == NULL && b)
26         return -1;
27     if (b == NULL && a)
28         return 1;
29
30     for (; *a || *b; a++, b++) {
31         if ((i = ascii_tolower(*a) - ascii_tolower(*b)))
32             return i;
33     }
34
35     return 0;
36 }
37
38 int ascii_strncasecmp (const char *a, const char *b, int n)
39 {
40     int i, j;
41
42     if (a == b)
43         return 0;
44     if (a == NULL && b)
45         return -1;
46     if (b == NULL && a)
47         return 1;
48
49     for (j = 0; (*a || *b) && j < n; a++, b++, j++) {
50         if ((i = ascii_tolower(*a) - ascii_tolower(*b)))
51             return i;
52     }
53
54     return 0;
55 }