| /* A part of the Native C Library for Windows NT |
| Copyright 2007-2015 PC GO Ld. |
| Copyright 2026 Rivoreo |
| |
| This program is free software; you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
| the Free Software Foundation; either version 2 of the License, or (at |
| your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| General Public License for more details. |
| */ |
| |
| #define __NO_CTYPE |
| #include <ctype.h> |
| |
| static const unsigned int ctype_mask[] = { |
| 0x00000200, 0x00000200, 0x00000200, 0x00000200, |
| 0x00000200, 0x00000200, 0x00000200, 0x00000200, |
| 0x00000200, 0x00024200, 0x00004200, 0x00004200, |
| 0x00004200, 0x00004200, 0x00000200, 0x00000200, |
| 0x00000200, 0x00000200, 0x00000200, 0x00000200, |
| 0x00000200, 0x00000200, 0x00000200, 0x00000200, |
| 0x00000200, 0x00000200, 0x00000200, 0x00000200, |
| 0x00000200, 0x00000200, 0x00000200, 0x00000200, |
| 0x00064000, 0x00042800, 0x00042800, 0x00042800, |
| 0x00042800, 0x00042800, 0x00042800, 0x00042800, |
| 0x00042800, 0x00042800, 0x00042800, 0x00042800, |
| 0x00042800, 0x00042800, 0x00042800, 0x00042800, |
| 0x00450c00, 0x00450c01, 0x00450c02, 0x00450c03, |
| 0x00450c04, 0x00450c05, 0x00450c06, 0x00450c07, |
| 0x00450c08, 0x00450c09, 0x00042800, 0x00042800, |
| 0x00042800, 0x00042800, 0x00042800, 0x00042800, |
| 0x00042800, 0x0005890a, 0x0005890b, 0x0005890c, |
| 0x0005890d, 0x0005890e, 0x0005890f, 0x00048900, |
| 0x00048900, 0x00048900, 0x00048900, 0x00048900, |
| 0x00048900, 0x00048900, 0x00048900, 0x00048900, |
| 0x00048900, 0x00048900, 0x00048900, 0x00048900, |
| 0x00048900, 0x00048900, 0x00048900, 0x00048900, |
| 0x00048900, 0x00048900, 0x00048900, 0x00042800, |
| 0x00042800, 0x00042800, 0x00042800, 0x00042800, |
| 0x00042800, 0x0005190a, 0x0005190b, 0x0005190c, |
| 0x0005190d, 0x0005190e, 0x0005190f, 0x00041900, |
| 0x00041900, 0x00041900, 0x00041900, 0x00041900, |
| 0x00041900, 0x00041900, 0x00041900, 0x00041900, |
| 0x00041900, 0x00041900, 0x00041900, 0x00041900, |
| 0x00041900, 0x00041900, 0x00041900, 0x00041900, |
| 0x00041900, 0x00041900, 0x00041900, 0x00042800, |
| 0x00042800, 0x00042800, 0x00042800, 0x00000200 |
| }; |
| |
| inline int __isctype(int c, unsigned int type) { |
| if(c < 0 || (unsigned int)c >= sizeof ctype_mask / sizeof *ctype_mask) return 0; |
| return ctype_mask[c] & type; |
| } |
| |
| #define DEFINE_CTYPE_FUNCTION(N, T) inline int N(int c) { return __isctype(c, (T)); } |
| DEFINE_CTYPE_FUNCTION(isalnum, _CTYPE_ALPHA | _CTYPE_DIGIT) |
| DEFINE_CTYPE_FUNCTION(isalpha, _CTYPE_ALPHA) |
| DEFINE_CTYPE_FUNCTION(isblank, _CTYPE_BLANK) |
| DEFINE_CTYPE_FUNCTION(iscntrl, _CTYPE_CNTRL) |
| DEFINE_CTYPE_FUNCTION(isdigit, _CTYPE_DIGIT) |
| DEFINE_CTYPE_FUNCTION(islower, _CTYPE_LOWER) |
| DEFINE_CTYPE_FUNCTION(isgraph, _CTYPE_GRAPH) |
| DEFINE_CTYPE_FUNCTION(isprint, _CTYPE_PRINT) |
| DEFINE_CTYPE_FUNCTION(ispunct, _CTYPE_PUNCT) |
| DEFINE_CTYPE_FUNCTION(isspace, _CTYPE_SPACE) |
| DEFINE_CTYPE_FUNCTION(isupper, _CTYPE_UPPER) |
| DEFINE_CTYPE_FUNCTION(isxdigit, _CTYPE_XDIGIT) |
| |
| int tolower(int c) { |
| if(!isupper(c)) return c; |
| return c + ('a' - 'A'); |
| } |
| |
| int toupper(int c) { |
| if(!islower(c)) return c; |
| return c - ('a' - 'A'); |
| } |