1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _PERF_SANE_CTYPE_H
3 #define _PERF_SANE_CTYPE_H
5 /* Sane ctype - no locale, and works with signed chars */
18 extern unsigned char sane_ctype[256];
19 #define GIT_SPACE 0x01
20 #define GIT_DIGIT 0x02
21 #define GIT_ALPHA 0x04
22 #define GIT_GLOB_SPECIAL 0x08
23 #define GIT_REGEX_SPECIAL 0x10
24 #define GIT_PRINT_EXTRA 0x20
25 #define GIT_PRINT 0x3E
26 #define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
27 #define isascii(x) (((x) & ~0x7f) == 0)
28 #define isspace(x) sane_istest(x,GIT_SPACE)
29 #define isdigit(x) sane_istest(x,GIT_DIGIT)
31 (sane_istest(toupper(x), GIT_ALPHA | GIT_DIGIT) && toupper(x) < 'G')
32 #define isalpha(x) sane_istest(x,GIT_ALPHA)
33 #define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
34 #define isprint(x) sane_istest(x,GIT_PRINT)
35 #define islower(x) (sane_istest(x,GIT_ALPHA) && (x & 0x20))
36 #define isupper(x) (sane_istest(x,GIT_ALPHA) && !(x & 0x20))
37 #define tolower(x) sane_case((unsigned char)(x), 0x20)
38 #define toupper(x) sane_case((unsigned char)(x), 0)
40 static inline int sane_case(int x, int high)
42 if (sane_istest(x, GIT_ALPHA))
43 x = (x & ~0x20) | high;
47 #endif /* _PERF_SANE_CTYPE_H */