1/*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source.  A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12/*
13 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
14 */
15
16/*
17 * ASCII versions of ctype character classification functions.  This avoids
18 * pulling in the entire locale framework that is in libc.
19 */
20
21int
22isdigit(int c)
23{
24	return ((c >= '0' && c <= '9') ? 1 : 0);
25}
26
27int
28isupper(int c)
29{
30	return ((c >= 'A' && c <= 'Z') ? 1 : 0);
31}
32
33
34int
35islower(int c)
36{
37	return ((c >= 'a' && c <= 'z') ? 1 : 0);
38}
39
40int
41isspace(int c)
42{
43	return (((c == ' ') || (c == '\t') || (c == '\r') || (c == '\n') ||
44	    (c == '\v') || (c == '\f')) ? 1 : 0);
45}
46
47int
48isxdigit(int c)
49{
50	return ((isdigit(c) || (c >= 'A' && c <= 'F') ||
51	    (c >= 'a' && c <= 'f')) ? 1 : 0);
52}
53
54int
55isalpha(int c)
56{
57	return ((isupper(c) || islower(c)) ? 1 : 0);
58}
59
60
61int
62isalnum(int c)
63{
64	return ((isalpha(c) || isdigit(c)) ? 1 : 0);
65}
66
67int
68ispunct(int c)
69{
70	return (((c >= '!') && (c <= '/')) ||
71	    ((c >= ':') && (c <= '@')) ||
72	    ((c >= '[') && (c <= '`')) ||
73	    ((c >= '{') && (c <= '~')));
74}
75
76int
77iscntrl(int c)
78{
79	return ((c < 0x20) || (c == 0x7f));
80}
81
82int
83isprint(int c)
84{
85	/*
86	 * Almost the inverse of iscntrl, but be careful that c > 0x7f
87	 * returns false for everything.
88	 */
89	return ((c >= ' ') && (c <= '~'));
90}
91
92int
93isgraph(int c)
94{
95	/* isgraph is like is print, but excludes <space> */
96	return ((c >= '!') && (c <= '~'));
97}
98