root/ascii.c

Revision 4343:2bccf51eedac, 2.0 kB (checked in by Brendan Cully <brendan@…>, 3 years ago)

Gah, forgot the zip code when updating the FSF address...

Line 
1/*
2 * Copyright (C) 2001 Thomas Roessler <roessler@does-not-exist.org>
3 *
4 *     This program is free software; you can redistribute it
5 *     and/or modify it under the terms of the GNU General Public
6 *     License as published by the Free Software Foundation; either
7 *     version 2 of the License, or (at your option) any later
8 *     version.
9 *
10 *     This program is distributed in the hope that it will be
11 *     useful, but WITHOUT ANY WARRANTY; without even the implied
12 *     warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 *     PURPOSE.  See the GNU General Public License for more
14 *     details.
15 *
16 *     You should have received a copy of the GNU General Public
17 *     License along with this program; if not, write to the Free
18 *     Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 *     Boston, MA  02110-1301, USA.
20 *
21 */
22
23
24/*
25 * Versions of the string comparison functions which are
26 * locale-insensitive.
27 */
28
29#if HAVE_CONFIG_H
30# include "config.h"
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include "ascii.h"
36
37int ascii_isupper (int c)
38{
39  return (c >= 'A') && (c <= 'Z');
40}
41
42int ascii_islower (int c)
43{
44  return (c >= 'a') && (c <= 'z');
45}
46
47int ascii_toupper (int c)
48{
49  if (ascii_islower (c))
50    return c & ~32;
51 
52  return c;
53}
54
55int ascii_tolower (int c)
56{
57  if (ascii_isupper (c))
58    return c | 32;
59 
60  return c;
61}
62
63int ascii_strcasecmp (const char *a, const char *b)
64{
65  int i;
66 
67  if (a == b)
68    return 0;
69  if (a == NULL && b)
70    return -1;
71  if (b == NULL && a)
72    return 1;
73 
74  for (; *a || *b; a++, b++)
75  {
76    if ((i = ascii_tolower (*a) - ascii_tolower (*b)))
77      return i;
78  }
79 
80  return 0;
81}
82
83int ascii_strncasecmp (const char *a, const char *b, int n)
84{
85  int i, j;
86 
87  if (a == b)
88    return 0;
89  if (a == NULL && b)
90    return -1;
91  if (b == NULL && a)
92    return 1;
93 
94  for (j = 0; (*a || *b) && j < n; a++, b++, j++)
95  {
96    if ((i = ascii_tolower (*a) - ascii_tolower (*b)))
97      return i;
98  }
99 
100  return 0;
101}
Note: See TracBrowser for help on using the browser.