1 /*
2 * Copyright (c) 2008 Travis Geiselbrecht
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #include <ctype.h>
24
isblank(int c)25 int isblank(int c)
26 {
27 return (c == ' ' || c == '\t');
28 }
29
isspace(int c)30 int isspace(int c)
31 {
32 return (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v');
33 }
34
islower(int c)35 int islower(int c)
36 {
37 return ((c >= 'a') && (c <= 'z'));
38 }
39
isupper(int c)40 int isupper(int c)
41 {
42 return ((c >= 'A') && (c <= 'Z'));
43 }
44
isdigit(int c)45 int isdigit(int c)
46 {
47 return ((c >= '0') && (c <= '9'));
48 }
49
isalpha(int c)50 int isalpha(int c)
51 {
52 return isupper(c) || islower(c);
53 }
54
isalnum(int c)55 int isalnum(int c)
56 {
57 return isalpha(c) || isdigit(c);
58 }
59
isxdigit(int c)60 int isxdigit(int c)
61 {
62 return isdigit(c) || ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F'));
63 }
64
isgraph(int c)65 int isgraph(int c)
66 {
67 return ((c > ' ') && (c < 0x7f));
68 }
69
iscntrl(int c)70 int iscntrl(int c)
71 {
72 return ((c < ' ') || (c == 0x7f));
73 }
74
isprint(int c)75 int isprint(int c)
76 {
77 return ((c >= 0x20) && (c < 0x7f));
78 }
79
ispunct(int c)80 int ispunct(int c)
81 {
82 return isgraph(c) && (!isalnum(c));
83 }
84
tolower(int c)85 int tolower(int c)
86 {
87 if ((c >= 'A') && (c <= 'Z'))
88 return c + ('a' - 'A');
89 return c;
90 }
91
toupper(int c)92 int toupper(int c)
93 {
94 if ((c >= 'a') && (c <= 'z'))
95 return c + ('A' - 'a');
96 return c;
97 }
98
99