1 /* 2 * Copyright (c) 2008 Travis Geiselbrecht 3 * 4 * Use of this source code is governed by a MIT-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/MIT 7 */ 8 #include <ctype.h> 9 isblank(int c)10int isblank(int c) { 11 return (c == ' ' || c == '\t'); 12 } 13 isspace(int c)14int isspace(int c) { 15 return (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v'); 16 } 17 islower(int c)18int islower(int c) { 19 return ((c >= 'a') && (c <= 'z')); 20 } 21 isupper(int c)22int isupper(int c) { 23 return ((c >= 'A') && (c <= 'Z')); 24 } 25 isdigit(int c)26int isdigit(int c) { 27 return ((c >= '0') && (c <= '9')); 28 } 29 isalpha(int c)30int isalpha(int c) { 31 return isupper(c) || islower(c); 32 } 33 isalnum(int c)34int isalnum(int c) { 35 return isalpha(c) || isdigit(c); 36 } 37 isxdigit(int c)38int isxdigit(int c) { 39 return isdigit(c) || ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F')); 40 } 41 isgraph(int c)42int isgraph(int c) { 43 return ((c > ' ') && (c < 0x7f)); 44 } 45 iscntrl(int c)46int iscntrl(int c) { 47 return ((c < ' ') || (c == 0x7f)); 48 } 49 isprint(int c)50int isprint(int c) { 51 return ((c >= 0x20) && (c < 0x7f)); 52 } 53 ispunct(int c)54int ispunct(int c) { 55 return isgraph(c) && (!isalnum(c)); 56 } 57 tolower(int c)58int tolower(int c) { 59 if ((c >= 'A') && (c <= 'Z')) 60 return c + ('a' - 'A'); 61 return c; 62 } 63 toupper(int c)64int toupper(int c) { 65 if ((c >= 'a') && (c <= 'z')) 66 return c + ('A' - 'a'); 67 return c; 68 } 69 70