8 |
#define _CTYPE_H |
#define _CTYPE_H |
9 |
|
|
10 |
#include <klibc/extern.h> |
#include <klibc/extern.h> |
11 |
|
#include <klibc/compiler.h> |
12 |
|
|
13 |
/* |
/* |
14 |
* This relies on the following definitions: |
* This relies on the following definitions: |
29 |
__ctype_cntrl = (1 << 7), |
__ctype_cntrl = (1 << 7), |
30 |
}; |
}; |
31 |
|
|
32 |
|
__extern int isalnum(int); |
33 |
|
__extern int isalpha(int); |
34 |
|
__extern int isascii(int); |
35 |
|
__extern int isblank(int); |
36 |
|
__extern int iscntrl(int); |
37 |
|
__extern int isdigit(int); |
38 |
|
__extern int isgraph(int); |
39 |
|
__extern int islower(int); |
40 |
|
__extern int isprint(int); |
41 |
|
__extern int ispunct(int); |
42 |
|
__extern int isspace(int); |
43 |
|
__extern int isupper(int); |
44 |
|
__extern int isxdigit(int); |
45 |
|
__extern int toupper(int); |
46 |
|
__extern int tolower(int); |
47 |
|
|
48 |
extern const unsigned char __ctypes[]; |
extern const unsigned char __ctypes[]; |
49 |
|
|
50 |
static inline int __ctype_isalnum(int __c) |
__must_inline int __ctype_isalnum(int __c) |
51 |
{ |
{ |
52 |
return __ctypes[__c + 1] & |
return __ctypes[__c + 1] & |
53 |
(__ctype_upper | __ctype_lower | __ctype_digit); |
(__ctype_upper | __ctype_lower | __ctype_digit); |
54 |
} |
} |
55 |
|
|
56 |
static inline int __ctype_isalpha(int __c) |
__must_inline int __ctype_isalpha(int __c) |
57 |
{ |
{ |
58 |
return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower); |
return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower); |
59 |
} |
} |
60 |
|
|
61 |
static inline int __ctype_isascii(int __c) |
__must_inline int __ctype_isascii(int __c) |
62 |
{ |
{ |
63 |
return !(__c & ~0x7f); |
return !(__c & ~0x7f); |
64 |
} |
} |
65 |
|
|
66 |
static inline int __ctype_isblank(int __c) |
__must_inline int __ctype_isblank(int __c) |
67 |
{ |
{ |
68 |
return (__c == '\t') || (__c == ' '); |
return (__c == '\t') || (__c == ' '); |
69 |
} |
} |
70 |
|
|
71 |
static inline int __ctype_iscntrl(int __c) |
__must_inline int __ctype_iscntrl(int __c) |
72 |
{ |
{ |
73 |
return __ctypes[__c + 1] & __ctype_cntrl; |
return __ctypes[__c + 1] & __ctype_cntrl; |
74 |
} |
} |
75 |
|
|
76 |
static inline int __ctype_isdigit(int __c) |
__must_inline int __ctype_isdigit(int __c) |
77 |
{ |
{ |
78 |
return ((unsigned)__c - '0') <= 9; |
return ((unsigned)__c - '0') <= 9; |
79 |
} |
} |
80 |
|
|
81 |
static inline int __ctype_isgraph(int __c) |
__must_inline int __ctype_isgraph(int __c) |
82 |
{ |
{ |
83 |
return __ctypes[__c + 1] & |
return __ctypes[__c + 1] & |
84 |
(__ctype_upper | __ctype_lower | __ctype_digit | __ctype_punct); |
(__ctype_upper | __ctype_lower | __ctype_digit | __ctype_punct); |
85 |
} |
} |
86 |
|
|
87 |
static inline int __ctype_islower(int __c) |
__must_inline int __ctype_islower(int __c) |
88 |
{ |
{ |
89 |
return __ctypes[__c + 1] & __ctype_lower; |
return __ctypes[__c + 1] & __ctype_lower; |
90 |
} |
} |
91 |
|
|
92 |
static inline int __ctype_isprint(int __c) |
__must_inline int __ctype_isprint(int __c) |
93 |
{ |
{ |
94 |
return __ctypes[__c + 1] & __ctype_print; |
return __ctypes[__c + 1] & __ctype_print; |
95 |
} |
} |
96 |
|
|
97 |
static inline int __ctype_ispunct(int __c) |
__must_inline int __ctype_ispunct(int __c) |
98 |
{ |
{ |
99 |
return __ctypes[__c + 1] & __ctype_punct; |
return __ctypes[__c + 1] & __ctype_punct; |
100 |
} |
} |
101 |
|
|
102 |
static inline int __ctype_isspace(int __c) |
__must_inline int __ctype_isspace(int __c) |
103 |
{ |
{ |
104 |
return __ctypes[__c + 1] & __ctype_space; |
return __ctypes[__c + 1] & __ctype_space; |
105 |
} |
} |
106 |
|
|
107 |
static inline int __ctype_isupper(int __c) |
__must_inline int __ctype_isupper(int __c) |
108 |
{ |
{ |
109 |
return __ctypes[__c + 1] & __ctype_upper; |
return __ctypes[__c + 1] & __ctype_upper; |
110 |
} |
} |
111 |
|
|
112 |
static inline int __ctype_isxdigit(int __c) |
__must_inline int __ctype_isxdigit(int __c) |
113 |
{ |
{ |
114 |
return __ctypes[__c + 1] & __ctype_xdigit; |
return __ctypes[__c + 1] & __ctype_xdigit; |
115 |
} |
} |
118 |
#define _toupper(__c) ((__c) & ~32) |
#define _toupper(__c) ((__c) & ~32) |
119 |
#define _tolower(__c) ((__c) | 32) |
#define _tolower(__c) ((__c) | 32) |
120 |
|
|
121 |
static inline int __ctype_toupper(int __c) |
__must_inline int __ctype_toupper(int __c) |
122 |
{ |
{ |
123 |
return __ctype_islower(__c) ? _toupper(__c) : __c; |
return __ctype_islower(__c) ? _toupper(__c) : __c; |
124 |
} |
} |
125 |
|
|
126 |
static inline int __ctype_tolower(int __c) |
__must_inline int __ctype_tolower(int __c) |
127 |
{ |
{ |
128 |
return __ctype_isupper(__c) ? _tolower(__c) : __c; |
return __ctype_isupper(__c) ? _tolower(__c) : __c; |
129 |
} |
} |
140 |
#endif |
#endif |
141 |
|
|
142 |
__CTYPEFUNC(isalnum) |
__CTYPEFUNC(isalnum) |
143 |
__CTYPEFUNC(isalpha) |
__CTYPEFUNC(isalpha) |
144 |
__CTYPEFUNC(isascii) |
__CTYPEFUNC(isascii) |
145 |
__CTYPEFUNC(isblank) |
__CTYPEFUNC(isblank) |
146 |
__CTYPEFUNC(iscntrl) |
__CTYPEFUNC(iscntrl) |
147 |
__CTYPEFUNC(isdigit) |
__CTYPEFUNC(isdigit) |
148 |
__CTYPEFUNC(isgraph) |
__CTYPEFUNC(isgraph) |
149 |
__CTYPEFUNC(islower) |
__CTYPEFUNC(islower) |
150 |
__CTYPEFUNC(isprint) |
__CTYPEFUNC(isprint) |
151 |
__CTYPEFUNC(ispunct) |
__CTYPEFUNC(ispunct) |
152 |
__CTYPEFUNC(isspace) |
__CTYPEFUNC(isspace) |
153 |
__CTYPEFUNC(isupper) |
__CTYPEFUNC(isupper) |
154 |
__CTYPEFUNC(isxdigit) |
__CTYPEFUNC(isxdigit) |
155 |
__CTYPEFUNC(toupper) |
__CTYPEFUNC(toupper) |
156 |
__CTYPEFUNC(tolower) |
__CTYPEFUNC(tolower) |
157 |
#endif /* _CTYPE_H */ |
#endif /* _CTYPE_H */ |