1 /* -*- buffer-read-only: t -*- vi: set ro: */ 2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */ 3 /* Character handling in C locale. 4 5 Copyright 2000-2003, 2006 Free Software Foundation, Inc. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software Foundation, 19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 20 21 #include <config.h> 22 23 /* Specification. */ 24 #define NO_C_CTYPE_MACROS 25 #include "c-ctype.h" 26 27 /* The function isascii is not locale dependent. Its use in EBCDIC is 28 questionable. */ 29 bool 30 c_isascii (int c) 31 { 32 return (c >= 0x00 && c <= 0x7f); 33 } 34 35 bool 36 c_isalnum (int c) 37 { 38 #if C_CTYPE_CONSECUTIVE_DIGITS \ 39 && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE 40 #if C_CTYPE_ASCII 41 return ((c >= '0' && c <= '9') 42 || ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z')); 43 #else 44 return ((c >= '0' && c <= '9') 45 || (c >= 'A' && c <= 'Z') 46 || (c >= 'a' && c <= 'z')); 47 #endif 48 #else 49 switch (c) 50 { 51 case '0': case '1': case '2': case '3': case '4': case '5': 52 case '6': case '7': case '8': case '9': 53 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 54 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': 55 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': 56 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': 57 case 'Y': case 'Z': 58 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 59 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': 60 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': 61 case 's': case 't': case 'u': case 'v': case 'w': case 'x': 62 case 'y': case 'z': 63 return 1; 64 default: 65 return 0; 66 } 67 #endif 68 } 69 70 bool 71 c_isalpha (int c) 72 { 73 #if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE 74 #if C_CTYPE_ASCII 75 return ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z'); 76 #else 77 return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); 78 #endif 79 #else 80 switch (c) 81 { 82 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 83 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': 84 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': 85 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': 86 case 'Y': case 'Z': 87 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 88 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': 89 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': 90 case 's': case 't': case 'u': case 'v': case 'w': case 'x': 91 case 'y': case 'z': 92 return 1; 93 default: 94 return 0; 95 } 96 #endif 97 } 98 99 bool 100 c_isblank (int c) 101 { 102 return (c == ' ' || c == '\t'); 103 } 104 105 bool 106 c_iscntrl (int c) 107 { 108 #if C_CTYPE_ASCII 109 return ((c & ~0x1f) == 0 || c == 0x7f); 110 #else 111 switch (c) 112 { 113 case ' ': case '!': case '"': case '#': case '$': case '%': 114 case '&': case '\'': case '(': case ')': case '*': case '+': 115 case ',': case '-': case '.': case '/': 116 case '0': case '1': case '2': case '3': case '4': case '5': 117 case '6': case '7': case '8': case '9': 118 case ':': case ';': case '<': case '=': case '>': case '?': 119 case '@': 120 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 121 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': 122 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': 123 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': 124 case 'Y': case 'Z': 125 case '[': case '\\': case ']': case '^': case '_': case '`': 126 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 127 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': 128 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': 129 case 's': case 't': case 'u': case 'v': case 'w': case 'x': 130 case 'y': case 'z': 131 case '{': case '|': case '}': case '~': 132 return 0; 133 default: 134 return 1; 135 } 136 #endif 137 } 138 139 bool 140 c_isdigit (int c) 141 { 142 #if C_CTYPE_CONSECUTIVE_DIGITS 143 return (c >= '0' && c <= '9'); 144 #else 145 switch (c) 146 { 147 case '0': case '1': case '2': case '3': case '4': case '5': 148 case '6': case '7': case '8': case '9': 149 return 1; 150 default: 151 return 0; 152 } 153 #endif 154 } 155 156 bool 157 c_islower (int c) 158 { 159 #if C_CTYPE_CONSECUTIVE_LOWERCASE 160 return (c >= 'a' && c <= 'z'); 161 #else 162 switch (c) 163 { 164 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 165 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': 166 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': 167 case 's': case 't': case 'u': case 'v': case 'w': case 'x': 168 case 'y': case 'z': 169 return 1; 170 default: 171 return 0; 172 } 173 #endif 174 } 175 176 bool 177 c_isgraph (int c) 178 { 179 #if C_CTYPE_ASCII 180 return (c >= '!' && c <= '~'); 181 #else 182 switch (c) 183 { 184 case '!': case '"': case '#': case '$': case '%': case '&': 185 case '\'': case '(': case ')': case '*': case '+': case ',': 186 case '-': case '.': case '/': 187 case '0': case '1': case '2': case '3': case '4': case '5': 188 case '6': case '7': case '8': case '9': 189 case ':': case ';': case '<': case '=': case '>': case '?': 190 case '@': 191 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 192 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': 193 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': 194 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': 195 case 'Y': case 'Z': 196 case '[': case '\\': case ']': case '^': case '_': case '`': 197 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 198 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': 199 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': 200 case 's': case 't': case 'u': case 'v': case 'w': case 'x': 201 case 'y': case 'z': 202 case '{': case '|': case '}': case '~': 203 return 1; 204 default: 205 return 0; 206 } 207 #endif 208 } 209 210 bool 211 c_isprint (int c) 212 { 213 #if C_CTYPE_ASCII 214 return (c >= ' ' && c <= '~'); 215 #else 216 switch (c) 217 { 218 case ' ': case '!': case '"': case '#': case '$': case '%': 219 case '&': case '\'': case '(': case ')': case '*': case '+': 220 case ',': case '-': case '.': case '/': 221 case '0': case '1': case '2': case '3': case '4': case '5': 222 case '6': case '7': case '8': case '9': 223 case ':': case ';': case '<': case '=': case '>': case '?': 224 case '@': 225 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 226 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': 227 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': 228 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': 229 case 'Y': case 'Z': 230 case '[': case '\\': case ']': case '^': case '_': case '`': 231 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 232 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': 233 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': 234 case 's': case 't': case 'u': case 'v': case 'w': case 'x': 235 case 'y': case 'z': 236 case '{': case '|': case '}': case '~': 237 return 1; 238 default: 239 return 0; 240 } 241 #endif 242 } 243 244 bool 245 c_ispunct (int c) 246 { 247 #if C_CTYPE_ASCII 248 return ((c >= '!' && c <= '~') 249 && !((c >= '0' && c <= '9') 250 || ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z'))); 251 #else 252 switch (c) 253 { 254 case '!': case '"': case '#': case '$': case '%': case '&': 255 case '\'': case '(': case ')': case '*': case '+': case ',': 256 case '-': case '.': case '/': 257 case ':': case ';': case '<': case '=': case '>': case '?': 258 case '@': 259 case '[': case '\\': case ']': case '^': case '_': case '`': 260 case '{': case '|': case '}': case '~': 261 return 1; 262 default: 263 return 0; 264 } 265 #endif 266 } 267 268 bool 269 c_isspace (int c) 270 { 271 return (c == ' ' || c == '\t' 272 || c == '\n' || c == '\v' || c == '\f' || c == '\r'); 273 } 274 275 bool 276 c_isupper (int c) 277 { 278 #if C_CTYPE_CONSECUTIVE_UPPERCASE 279 return (c >= 'A' && c <= 'Z'); 280 #else 281 switch (c) 282 { 283 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 284 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': 285 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': 286 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': 287 case 'Y': case 'Z': 288 return 1; 289 default: 290 return 0; 291 } 292 #endif 293 } 294 295 bool 296 c_isxdigit (int c) 297 { 298 #if C_CTYPE_CONSECUTIVE_DIGITS \ 299 && C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE 300 #if C_CTYPE_ASCII 301 return ((c >= '0' && c <= '9') 302 || ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'F')); 303 #else 304 return ((c >= '0' && c <= '9') 305 || (c >= 'A' && c <= 'F') 306 || (c >= 'a' && c <= 'f')); 307 #endif 308 #else 309 switch (c) 310 { 311 case '0': case '1': case '2': case '3': case '4': case '5': 312 case '6': case '7': case '8': case '9': 313 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 314 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 315 return 1; 316 default: 317 return 0; 318 } 319 #endif 320 } 321 322 int 323 c_tolower (int c) 324 { 325 #if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE 326 return (c >= 'A' && c <= 'Z' ? c - 'A' + 'a' : c); 327 #else 328 switch (c) 329 { 330 case 'A': return 'a'; 331 case 'B': return 'b'; 332 case 'C': return 'c'; 333 case 'D': return 'd'; 334 case 'E': return 'e'; 335 case 'F': return 'f'; 336 case 'G': return 'g'; 337 case 'H': return 'h'; 338 case 'I': return 'i'; 339 case 'J': return 'j'; 340 case 'K': return 'k'; 341 case 'L': return 'l'; 342 case 'M': return 'm'; 343 case 'N': return 'n'; 344 case 'O': return 'o'; 345 case 'P': return 'p'; 346 case 'Q': return 'q'; 347 case 'R': return 'r'; 348 case 'S': return 's'; 349 case 'T': return 't'; 350 case 'U': return 'u'; 351 case 'V': return 'v'; 352 case 'W': return 'w'; 353 case 'X': return 'x'; 354 case 'Y': return 'y'; 355 case 'Z': return 'z'; 356 default: return c; 357 } 358 #endif 359 } 360 361 int 362 c_toupper (int c) 363 { 364 #if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE 365 return (c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c); 366 #else 367 switch (c) 368 { 369 case 'a': return 'A'; 370 case 'b': return 'B'; 371 case 'c': return 'C'; 372 case 'd': return 'D'; 373 case 'e': return 'E'; 374 case 'f': return 'F'; 375 case 'g': return 'G'; 376 case 'h': return 'H'; 377 case 'i': return 'I'; 378 case 'j': return 'J'; 379 case 'k': return 'K'; 380 case 'l': return 'L'; 381 case 'm': return 'M'; 382 case 'n': return 'N'; 383 case 'o': return 'O'; 384 case 'p': return 'P'; 385 case 'q': return 'Q'; 386 case 'r': return 'R'; 387 case 's': return 'S'; 388 case 't': return 'T'; 389 case 'u': return 'U'; 390 case 'v': return 'V'; 391 case 'w': return 'W'; 392 case 'x': return 'X'; 393 case 'y': return 'Y'; 394 case 'z': return 'Z'; 395 default: return c; 396 } 397 #endif 398 } 399