forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctype.h
159 lines (133 loc) Β· 3.16 KB
/
ctype.h
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <sys/cdefs.h>
__BEGIN_DECLS
#ifndef EOF
# define EOF (-1)
#endif
/* Do what newlib does to appease GCC's --with-newlib option. */
#define _U 01
#define _L 02
#define _N 04
#define _S 010
#define _P 020
#define _C 040
#define _X 0100
#define _B 0200
/**
* newlib has a 257 byte _ctype_ array to enable compiler tricks to catch
* people passing char instead of int. We don't engage in those tricks,
* but still claim to be newlib to the toolchains
*/
extern char const _ctype_[1 + 256] __attribute__((visibility("default")));
static inline int __inline_isalnum(int c)
{
return _ctype_[(unsigned char)(c) + 1] & (_U | _L | _N);
}
static inline int __inline_isalpha(int c)
{
return _ctype_[(unsigned char)(c) + 1] & (_U | _L);
}
static inline int __inline_isascii(int c)
{
return (unsigned)c <= 127;
}
static inline int __inline_iscntrl(int c)
{
return _ctype_[(unsigned char)(c) + 1] & (_C);
}
static inline int __inline_isdigit(int c)
{
return _ctype_[(unsigned char)(c) + 1] & (_N);
}
static inline int __inline_isxdigit(int c)
{
return _ctype_[(unsigned char)(c) + 1] & (_N | _X);
}
static inline int __inline_isspace(int c)
{
return _ctype_[(unsigned char)(c) + 1] & (_S);
}
static inline int __inline_ispunct(int c)
{
return _ctype_[(unsigned char)(c) + 1] & (_P);
}
static inline int __inline_isprint(int c)
{
return _ctype_[(unsigned char)(c) + 1] & (_P | _U | _L | _N | _B);
}
static inline int __inline_isgraph(int c)
{
return _ctype_[(unsigned char)(c) + 1] & (_P | _U | _L | _N);
}
static inline int __inline_islower(int c)
{
return _ctype_[(unsigned char)(c) + 1] & (_L);
}
static inline int __inline_isupper(int c)
{
return _ctype_[(unsigned char)(c) + 1] & (_U);
}
static inline int __inline_isblank(int c)
{
return _ctype_[(unsigned char)(c) + 1] & (_B) || (c == '\t');
}
static inline int __inline_toascii(int c)
{
return c & 127;
}
static inline int __inline_tolower(int c)
{
if (c >= 'A' && c <= 'Z')
return c | 0x20;
return c;
}
static inline int __inline_toupper(int c)
{
if (c >= 'a' && c <= 'z')
return c & ~0x20;
return c;
}
#ifdef __cplusplus
extern "C" {
#endif
int isalnum(int c);
int isalpha(int c);
int isascii(int c);
int iscntrl(int c);
int isdigit(int c);
int isxdigit(int c);
int isspace(int c);
int ispunct(int c);
int isprint(int c);
int isgraph(int c);
int islower(int c);
int isupper(int c);
int isblank(int c);
int toascii(int c);
int tolower(int c);
int toupper(int c);
#ifdef __cplusplus
}
#endif
#define isalnum __inline_isalnum
#define isalpha __inline_isalpha
#define isascii __inline_isascii
#define iscntrl __inline_iscntrl
#define isdigit __inline_isdigit
#define isxdigit __inline_isxdigit
#define isspace __inline_isspace
#define ispunct __inline_ispunct
#define isprint __inline_isprint
#define isgraph __inline_isgraph
#define islower __inline_islower
#define isupper __inline_isupper
#define isblank __inline_isblank
#define toascii __inline_toascii
#define tolower __inline_tolower
#define toupper __inline_toupper
__END_DECLS