1 // Copyright (c) 1999-2018 David Muse 2 // See the COPYING file for more information. 3 4 #include <rudiments/character.h> 5 6 #ifdef RUDIMENTS_HAVE_CTYPE_H 7 #include <ctype.h> 8 #endif 9 10 #include <stdio.h> 11 isAlphanumeric(int32_t c)12bool character::isAlphanumeric(int32_t c) { 13 return isalnum(c)!=0; 14 } 15 isAlphabetical(int32_t c)16bool character::isAlphabetical(int32_t c) { 17 return isalpha(c)!=0; 18 } 19 isAlphabeticalExtended(int32_t c)20bool character::isAlphabeticalExtended(int32_t c) { 21 // see http://www.theasciicode.com.ar/ 22 return isAlphabetical(c) || 23 (c>=128 && c<=154) || 24 (c>=160 && c<=165) || 25 (c>=181 && c<=183) || 26 (c>=198 && c<=199) || 27 (c>=208 && c<=216) || 28 (c>=224 && c<=237); 29 } 30 isControlCharacter(int32_t c)31bool character::isControlCharacter(int32_t c) { 32 return iscntrl(c)!=0; 33 } 34 isDigit(int32_t c)35bool character::isDigit(int32_t c) { 36 return isdigit(c)!=0; 37 } 38 isLowerCase(int32_t c)39bool character::isLowerCase(int32_t c) { 40 return islower(c)!=0; 41 } 42 isLowerCaseExtended(int32_t c)43bool character::isLowerCaseExtended(int32_t c) { 44 // see http://www.theasciicode.com.ar/ 45 return isLowerCase(c) || 46 (c>=129 && c<=141) || 47 (c==145) || 48 (c>=147 && c<=152) || 49 (c>=160 && c<=164) || 50 (c==198) || 51 (c==208) || 52 (c==213) || 53 (c==228) || 54 (c>=230 && c<=231) || 55 (c==236); 56 } 57 isPrintableNonSpace(int32_t c)58bool character::isPrintableNonSpace(int32_t c) { 59 return isgraph(c)!=0; 60 } 61 isPrintable(int32_t c)62bool character::isPrintable(int32_t c) { 63 return isprint(c)!=0; 64 } 65 isPunctuation(int32_t c)66bool character::isPunctuation(int32_t c) { 67 return ispunct(c)!=0; 68 } 69 isUpperCase(int32_t c)70bool character::isUpperCase(int32_t c) { 71 return isupper(c)!=0; 72 } 73 isUpperCaseExtended(int32_t c)74bool character::isUpperCaseExtended(int32_t c) { 75 // see http://www.theasciicode.com.ar/ 76 return isUpperCase(c) || 77 (c==128) || 78 (c>=142 && c<=144) || 79 (c==146) || 80 (c>=153 && c<=154) || 81 (c==165) || 82 (c>=181 && c<=183) || 83 (c==199) || 84 (c>=209 && c<=212) || 85 (c>=214 && c<=216) || 86 (c>=224 && c<=227) || 87 (c>=232 && c<=235) || 88 (c==237); 89 } 90 isHexDigit(int32_t c)91bool character::isHexDigit(int32_t c) { 92 return isxdigit(c)!=0; 93 } 94 isBlank(int32_t c)95bool character::isBlank(int32_t c) { 96 // don't be tempted to use isblank() here, it's too challenging to get 97 // it to work on every platform without a bunch of confusing #defines 98 // before including ctype.h 99 return (c==' ' || c==' '); 100 } 101 isWhitespace(int32_t c)102bool character::isWhitespace(int32_t c) { 103 return isspace(c)!=0; 104 } 105 isAscii(int32_t c)106bool character::isAscii(int32_t c) { 107 return isascii(c)!=0; 108 } 109 toUpperCase(int32_t c)110int32_t character::toUpperCase(int32_t c) { 111 return toupper(c); 112 } 113 toLowerCase(int32_t c)114int32_t character::toLowerCase(int32_t c) { 115 return tolower(c); 116 } 117 toAscii(int32_t c)118int32_t character::toAscii(int32_t c) { 119 return toascii(c); 120 } 121 inSet(char c,const char * set)122bool character::inSet(char c, const char *set) { 123 for (uint16_t i=0; set[i]; i++) { 124 if (set[i]==c) { 125 return true; 126 } 127 } 128 return false; 129 } 130