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