more updates in the build system, gettext related.
[apps/madmutt.git] / 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 #if HAVE_CONFIG_H
16 # include "config.h"
17 #endif
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include "ascii.h"
22
23 int ascii_isupper (int c)
24 {
25   return (c >= 'A') && (c <= 'Z');
26 }
27
28 int ascii_islower (int c)
29 {
30   return (c >= 'a') && (c <= 'z');
31 }
32
33 int ascii_toupper (int c)
34 {
35   if (ascii_islower (c))
36     return c & ~32;
37
38   return c;
39 }
40
41 int ascii_tolower (int c)
42 {
43   if (ascii_isupper (c))
44     return c | 32;
45
46   return c;
47 }
48
49 int ascii_strcasecmp (const char *a, const char *b)
50 {
51   int i;
52
53   if (a == b)
54     return 0;
55   if (a == NULL && b)
56     return -1;
57   if (b == NULL && a)
58     return 1;
59
60   for (; *a || *b; a++, b++) {
61     if ((i = ascii_tolower (*a) - ascii_tolower (*b)))
62       return i;
63   }
64
65   return 0;
66 }
67
68 int ascii_strncasecmp (const char *a, const char *b, int n)
69 {
70   int i, j;
71
72   if (a == b)
73     return 0;
74   if (a == NULL && b)
75     return -1;
76   if (b == NULL && a)
77     return 1;
78
79   for (j = 0; (*a || *b) && j < n; a++, b++, j++) {
80     if ((i = ascii_tolower (*a) - ascii_tolower (*b)))
81       return i;
82   }
83
84   return 0;
85 }