blob: c1282644bd6785661b1d973635b41835af2b8ecc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
#pragma once
#include <sys/cdefs.h>
#include <string.h>
__BEGIN_DECLS
ALWAYS_INLINE int __isascii(int ch)
{
return (ch & ~0x7f) == 0;
}
ALWAYS_INLINE int __isspace(int ch)
{
return ch == ' ' || ch == '\f' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\v';
}
ALWAYS_INLINE int __islower(int c)
{
return c >= 'a' && c <= 'z';
}
ALWAYS_INLINE int __isupper(int c)
{
return c >= 'A' && c <= 'Z';
}
ALWAYS_INLINE int __tolower(int c)
{
if (__isupper(c))
return c | 0x20;
return c;
}
ALWAYS_INLINE int __toupper(int c)
{
if (__islower(c))
return c & ~0x20;
return c;
}
ALWAYS_INLINE int __isdigit(int c)
{
return c >= '0' && c <= '9';
}
ALWAYS_INLINE int __ispunct(int c)
{
const char* punctuation_characters = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
return !!strchr(punctuation_characters, c);
}
ALWAYS_INLINE int __isprint(int c)
{
return c >= 0x20 && c != 0x7f;
}
ALWAYS_INLINE int __isalpha(int c)
{
return __isupper(c) || __islower(c);
}
ALWAYS_INLINE int __isalnum(int c)
{
return __isalpha(c) || __isdigit(c);
}
ALWAYS_INLINE int __iscntrl(int c)
{
return (c >= 0 && c <= 0x1f) || c == 0x7f;
}
ALWAYS_INLINE int __isxdigit(int c)
{
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
}
ALWAYS_INLINE int __isgraph(int c)
{
return __isalnum(c) || __ispunct(c);
}
#ifdef __cplusplus
#define __CTYPE_FUNC(name) static inline int name(int c) { return __ ## name(c); }
__CTYPE_FUNC(isascii)
__CTYPE_FUNC(isspace)
__CTYPE_FUNC(islower)
__CTYPE_FUNC(isupper)
__CTYPE_FUNC(tolower)
__CTYPE_FUNC(toupper)
__CTYPE_FUNC(isdigit)
__CTYPE_FUNC(ispunct)
__CTYPE_FUNC(isprint)
__CTYPE_FUNC(isalpha)
__CTYPE_FUNC(isalnum)
__CTYPE_FUNC(iscntrl)
__CTYPE_FUNC(isxdigit)
__CTYPE_FUNC(isgraph)
#else
#define isascii(c) __isascii(c)
#define isspace(c) __isspace(c)
#define islower(c) __islower(c)
#define isupper(c) __isupper(c)
#define tolower(c) __tolower(c)
#define toupper(c) __toupper(c)
#define isdigit(c) __isdigit(c)
#define ispunct(c) __ispunct(c)
#define isprint(c) __isprint(c)
#define isalpha(c) __isalpha(c)
#define isalnum(c) __isalnum(c)
#define iscntrl(c) __iscntrl(c)
#define isxdigit(c) __isxdigit(c)
#define isgraph(c) __isgraph(c)
#endif
__END_DECLS
|