c4dce9e3001bfee9b7d38abcdb19bf55d2dd9e64
[linux-2.6-microblaze.git] / tools / perf / util / sane_ctype.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _PERF_SANE_CTYPE_H
3 #define _PERF_SANE_CTYPE_H
4
5 /* Sane ctype - no locale, and works with signed chars */
6 #undef isascii
7 #undef isspace
8 #undef isdigit
9 #undef isxdigit
10 #undef isalpha
11 #undef isprint
12 #undef isalnum
13 #undef islower
14 #undef isupper
15 #undef tolower
16 #undef toupper
17
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)
30 #define isxdigit(x)     \
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)
39
40 static inline int sane_case(int x, int high)
41 {
42         if (sane_istest(x, GIT_ALPHA))
43                 x = (x & ~0x20) | high;
44         return x;
45 }
46
47 #endif /* _PERF_SANE_CTYPE_H */