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 21 int 22 isdigit(int c) 23 { 24 return ((c >= '0' && c <= '9') ? 1 : 0); 25 } 26 27 int 28 isupper(int c) 29 { 30 return ((c >= 'A' && c <= 'Z') ? 1 : 0); 31 } 32 33 34 int 35 islower(int c) 36 { 37 return ((c >= 'a' && c <= 'z') ? 1 : 0); 38 } 39 40 int 41 isspace(int c) 42 { 43 return (((c == ' ') || (c == '\t') || (c == '\r') || (c == '\n') || 44 (c == '\v') || (c == '\f')) ? 1 : 0); 45 } 46 47 int 48 isxdigit(int c) 49 { 50 return ((isdigit(c) || (c >= 'A' && c <= 'F') || 51 (c >= 'a' && c <= 'f')) ? 1 : 0); 52 } 53 54 int 55 isalpha(int c) 56 { 57 return ((isupper(c) || islower(c)) ? 1 : 0); 58 } 59 60 61 int 62 isalnum(int c) 63 { 64 return ((isalpha(c) || isdigit(c)) ? 1 : 0); 65 } 66 67 int 68 ispunct(int c) 69 { 70 return (((c >= '!') && (c <= '/')) || 71 ((c >= ':') && (c <= '@')) || 72 ((c >= '[') && (c <= '`')) || 73 ((c >= '{') && (c <= '~'))); 74 } 75 76 int 77 iscntrl(int c) 78 { 79 return ((c < 0x20) || (c == 0x7f)); 80 } 81 82 int 83 isprint(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 92 int 93 isgraph(int c) 94 { 95 /* isgraph is like is print, but excludes <space> */ 96 return ((c >= '!') && (c <= '~')); 97 } 98