c5e587025a1eb1fbea30c489a630c004b90cd72c
[reactos.git] / reactos / include / crt / ctype.h
1 /*
2 * ctype.h
3 * This file has no copyright assigned and is placed in the Public Domain.
4 * This file is a part of the mingw-runtime package.
5 * No warranty is given; refer to the file DISCLAIMER within the package.
6 *
7 * Functions for testing character types and converting characters.
8 *
9 */
10
11 #ifndef _CTYPE_H_
12 #define _CTYPE_H_
13
14 /* All the headers include this file. */
15 #include <_mingw.h>
16
17 #define __need_wchar_t
18 #define __need_wint_t
19 #ifndef RC_INVOKED
20 #include <stddef.h>
21 #endif /* Not RC_INVOKED */
22
23
24 /*
25 * The following flags are used to tell iswctype and _isctype what character
26 * types you are looking for.
27 */
28 #define _UPPER 0x0001
29 #define _LOWER 0x0002
30 #define _DIGIT 0x0004
31 #define _SPACE 0x0008 /* HT LF VT FF CR SP */
32 #define _PUNCT 0x0010
33 #define _CONTROL 0x0020
34 /* _BLANK is set for SP and non-ASCII horizontal space chars (eg,
35 "no-break space", 0xA0, in CP1250) but not for HT. */
36 #define _BLANK 0x0040
37 #define _HEX 0x0080
38 #define _LEADBYTE 0x8000
39
40 #define _ALPHA 0x0103
41
42 #ifndef RC_INVOKED
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 _CRTIMP int __cdecl __MINGW_NOTHROW isalnum(int);
49 _CRTIMP int __cdecl __MINGW_NOTHROW isalpha(int);
50 _CRTIMP int __cdecl __MINGW_NOTHROW iscntrl(int);
51 _CRTIMP int __cdecl __MINGW_NOTHROW isdigit(int);
52 _CRTIMP int __cdecl __MINGW_NOTHROW isgraph(int);
53 _CRTIMP int __cdecl __MINGW_NOTHROW islower(int);
54 _CRTIMP int __cdecl __MINGW_NOTHROW isprint(int);
55 _CRTIMP int __cdecl __MINGW_NOTHROW ispunct(int);
56 _CRTIMP int __cdecl __MINGW_NOTHROW isspace(int);
57 _CRTIMP int __cdecl __MINGW_NOTHROW isupper(int);
58 _CRTIMP int __cdecl __MINGW_NOTHROW isxdigit(int);
59
60 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
61 || !defined __STRICT_ANSI__
62 int __cdecl __MINGW_NOTHROW isblank (int);
63 #endif
64
65 #ifndef __STRICT_ANSI__
66 _CRTIMP int __cdecl __MINGW_NOTHROW _isctype (int, int);
67 #endif
68
69 /* These are the ANSI versions, with correct checking of argument */
70 _CRTIMP int __cdecl __MINGW_NOTHROW tolower(int);
71 _CRTIMP int __cdecl __MINGW_NOTHROW toupper(int);
72
73 /*
74 * NOTE: The above are not old name type wrappers, but functions exported
75 * explicitly by MSVCRT/CRTDLL. However, underscored versions are also
76 * exported.
77 */
78 #ifndef __STRICT_ANSI__
79 /*
80 * These are the cheap non-std versions: The return values are undefined
81 * if the argument is not ASCII char or is not of appropriate case
82 */
83 _CRTIMP int __cdecl __MINGW_NOTHROW _tolower(int);
84 _CRTIMP int __cdecl __MINGW_NOTHROW _toupper(int);
85 #endif
86
87 /* Also defined in stdlib.h */
88 #ifndef MB_CUR_MAX
89 #ifdef __DECLSPEC_SUPPORTED
90 # ifdef __MSVCRT__
91 # define MB_CUR_MAX __mb_cur_max
92 __MINGW_IMPORT int __mb_cur_max;
93 # else /* not __MSVCRT */
94 # define MB_CUR_MAX __mb_cur_max_dll
95 __MINGW_IMPORT int __mb_cur_max_dll;
96 # endif /* not __MSVCRT */
97
98 #else /* ! __DECLSPEC_SUPPORTED */
99 # ifdef __MSVCRT__
100 extern int* _imp____mbcur_max;
101 # define MB_CUR_MAX (*_imp____mb_cur_max)
102 # else /* not __MSVCRT */
103 extern int* _imp____mbcur_max_dll;
104 # define MB_CUR_MAX (*_imp____mb_cur_max_dll)
105 # endif /* not __MSVCRT */
106 #endif /* __DECLSPEC_SUPPORTED */
107 #endif /* MB_CUR_MAX */
108
109 #ifndef _WCTYPE_H_
110 #ifdef __DECLSPEC_SUPPORTED
111 # if __MSVCRT_VERSION__ <= 0x0700
112 __MINGW_IMPORT unsigned short _ctype[];
113 # endif
114 # ifdef __MSVCRT__
115 __MINGW_IMPORT const unsigned short* _pctype;
116 # else /* CRTDLL */
117 __MINGW_IMPORT const unsigned short* _pctype_dll;
118 # define _pctype _pctype_dll
119 # endif
120
121 #else /* __DECLSPEC_SUPPORTED */
122 # if __MSVCRT_VERSION__ <= 0x0700
123 extern unsigned short** _imp___ctype;
124 # define _ctype (*_imp___ctype)
125 # endif
126 # ifdef __MSVCRT__
127 extern unsigned short** _imp___pctype;
128 # define _pctype (*_imp___pctype)
129 # else /* CRTDLL */
130 extern unsigned short** _imp___pctype_dll;
131 # define _pctype (*_imp___pctype_dll)
132 # endif /* CRTDLL */
133 #endif /* __DECLSPEC_SUPPORTED */
134 #endif
135
136 /*
137 * Use inlines here rather than macros, because macros will upset
138 * C++ usage (eg, ::isalnum), and so usually get undefined
139 *
140 * According to standard for SB chars, these function are defined only
141 * for input values representable by unsigned char or EOF.
142 * Thus, there is no range test.
143 * This reproduces behaviour of MSVCRT.dll lib implemention for SB chars.
144 *
145 * If no MB char support is needed, these can be simplified even
146 * more by command line define -DMB_CUR_MAX=1. The compiler will then
147 * optimise away the constant condition.
148 */
149
150 #if !(defined (__NO_INLINE__) || defined (__NO_CTYPE_INLINES) \
151 || defined (__STRICT_ANSI__))
152
153 /* use simple lookup if SB locale, else _isctype() */
154 #define __ISCTYPE(c, mask) (MB_CUR_MAX == 1 ? (_pctype[c] & mask) : _isctype(c, mask))
155 __CRT_INLINE int __cdecl __MINGW_NOTHROW isalnum(int c) {return __ISCTYPE(c, (_ALPHA|_DIGIT));}
156 __CRT_INLINE int __cdecl __MINGW_NOTHROW isalpha(int c) {return __ISCTYPE(c, _ALPHA);}
157 __CRT_INLINE int __cdecl __MINGW_NOTHROW iscntrl(int c) {return __ISCTYPE(c, _CONTROL);}
158 __CRT_INLINE int __cdecl __MINGW_NOTHROW isdigit(int c) {return __ISCTYPE(c, _DIGIT);}
159 __CRT_INLINE int __cdecl __MINGW_NOTHROW isgraph(int c) {return __ISCTYPE(c, (_PUNCT|_ALPHA|_DIGIT));}
160 __CRT_INLINE int __cdecl __MINGW_NOTHROW islower(int c) {return __ISCTYPE(c, _LOWER);}
161 __CRT_INLINE int __cdecl __MINGW_NOTHROW isprint(int c) {return __ISCTYPE(c, (_BLANK|_PUNCT|_ALPHA|_DIGIT));}
162 __CRT_INLINE int __cdecl __MINGW_NOTHROW ispunct(int c) {return __ISCTYPE(c, _PUNCT);}
163 __CRT_INLINE int __cdecl __MINGW_NOTHROW isspace(int c) {return __ISCTYPE(c, _SPACE);}
164 __CRT_INLINE int __cdecl __MINGW_NOTHROW isupper(int c) {return __ISCTYPE(c, _UPPER);}
165 __CRT_INLINE int __cdecl __MINGW_NOTHROW isxdigit(int c) {return __ISCTYPE(c, _HEX);}
166
167 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
168 || !defined __STRICT_ANSI__
169 __CRT_INLINE int __cdecl __MINGW_NOTHROW isblank (int c)
170 {return (__ISCTYPE(c, _BLANK) || c == '\t');}
171 #endif
172
173 /* these reproduce behaviour of lib underscored versions */
174 __CRT_INLINE int __cdecl __MINGW_NOTHROW _tolower(int c) {return ( c -'A'+'a');}
175 __CRT_INLINE int __cdecl __MINGW_NOTHROW _toupper(int c) {return ( c -'a'+'A');}
176
177 /* TODO? Is it worth inlining ANSI tolower, toupper? Probably only
178 if we only want C-locale. */
179
180 #endif /* _NO_CTYPE_INLINES */
181
182 /* Wide character equivalents */
183
184 #ifndef WEOF
185 #define WEOF (wchar_t)(0xFFFF)
186 #endif
187
188 #ifndef _WCTYPE_T_DEFINED
189 typedef wchar_t wctype_t;
190 #define _WCTYPE_T_DEFINED
191 #endif
192
193 _CRTIMP int __cdecl __MINGW_NOTHROW iswctype(wint_t, wctype_t);
194 _CRTIMP int __cdecl __MINGW_NOTHROW is_wctype(wint_t, wctype_t); /* Obsolete! */
195
196 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
197 || !defined __STRICT_ANSI__ || defined __cplusplus
198 int __cdecl __MINGW_NOTHROW iswblank (wint_t);
199 #endif
200
201 /* Older MS docs uses wchar_t for arg and return type, while newer
202 online MS docs say arg is wint_t and return is int.
203 ISO C uses wint_t for both. */
204 _CRTIMP wint_t __cdecl __MINGW_NOTHROW towlower (wint_t);
205 _CRTIMP wint_t __cdecl __MINGW_NOTHROW towupper (wint_t);
206
207 _CRTIMP int __cdecl __MINGW_NOTHROW isleadbyte (int);
208
209 /* Also in wctype.h */
210 #if ! (defined (__NO_INLINE__) || defined(__NO_CTYPE_INLINES) \
211 || defined(__WCTYPE_INLINES_DEFINED))
212 #define __WCTYPE_INLINES_DEFINED
213 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswalnum(wint_t wc) {return (iswctype(wc,_ALPHA|_DIGIT));}
214 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswalpha(wint_t wc) {return (iswctype(wc,_ALPHA));}
215 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswascii(wint_t wc) {return ((wc & ~0x7F) ==0);}
216 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswcntrl(wint_t wc) {return (iswctype(wc,_CONTROL));}
217 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswdigit(wint_t wc) {return (iswctype(wc,_DIGIT));}
218 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswgraph(wint_t wc) {return (iswctype(wc,_PUNCT|_ALPHA|_DIGIT));}
219 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswlower(wint_t wc) {return (iswctype(wc,_LOWER));}
220 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswprint(wint_t wc) {return (iswctype(wc,_BLANK|_PUNCT|_ALPHA|_DIGIT));}
221 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswpunct(wint_t wc) {return (iswctype(wc,_PUNCT));}
222 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswspace(wint_t wc) {return (iswctype(wc,_SPACE));}
223 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswupper(wint_t wc) {return (iswctype(wc,_UPPER));}
224 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswxdigit(wint_t wc) {return (iswctype(wc,_HEX));}
225 __CRT_INLINE int __cdecl __MINGW_NOTHROW isleadbyte(int c) {return (_pctype[(unsigned char)(c)] & _LEADBYTE);}
226 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
227 || !defined __STRICT_ANSI__ || defined __cplusplus
228 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswblank (wint_t wc)
229 {return (iswctype(wc,_BLANK) || wc == L'\t');}
230 #endif
231
232 #endif /* !(defined(__NO_CTYPE_INLINES) || defined(__WCTYPE_INLINES_DEFINED)) */
233
234 #ifndef __WCTYPE_INLINES_DEFINED
235 _CRTIMP int __cdecl __MINGW_NOTHROW iswalnum(wint_t);
236 _CRTIMP int __cdecl __MINGW_NOTHROW iswalpha(wint_t);
237 _CRTIMP int __cdecl __MINGW_NOTHROW iswascii(wint_t);
238 _CRTIMP int __cdecl __MINGW_NOTHROW iswcntrl(wint_t);
239 _CRTIMP int __cdecl __MINGW_NOTHROW iswdigit(wint_t);
240 _CRTIMP int __cdecl __MINGW_NOTHROW iswgraph(wint_t);
241 _CRTIMP int __cdecl __MINGW_NOTHROW iswlower(wint_t);
242 _CRTIMP int __cdecl __MINGW_NOTHROW iswprint(wint_t);
243 _CRTIMP int __cdecl __MINGW_NOTHROW iswpunct(wint_t);
244 _CRTIMP int __cdecl __MINGW_NOTHROW iswspace(wint_t);
245 _CRTIMP int __cdecl __MINGW_NOTHROW iswupper(wint_t);
246 _CRTIMP int __cdecl __MINGW_NOTHROW iswxdigit(wint_t);
247 #endif
248
249 #ifndef __STRICT_ANSI__
250 int __cdecl __MINGW_NOTHROW __isascii (int);
251 int __cdecl __MINGW_NOTHROW __toascii (int);
252 int __cdecl __MINGW_NOTHROW __iscsymf (int); /* Valid first character in C symbol */
253 int __cdecl __MINGW_NOTHROW __iscsym (int); /* Valid character in C symbol (after first) */
254
255 #if !(defined (__NO_INLINE__) || defined (__NO_CTYPE_INLINES))
256 __CRT_INLINE int __cdecl __MINGW_NOTHROW __isascii(int c) {return ((c & ~0x7F) == 0);}
257 __CRT_INLINE int __cdecl __MINGW_NOTHROW __toascii(int c) {return (c & 0x7F);}
258 __CRT_INLINE int __cdecl __MINGW_NOTHROW __iscsymf(int c) {return (isalpha(c) || (c == '_'));}
259 __CRT_INLINE int __cdecl __MINGW_NOTHROW __iscsym(int c) {return (isalnum(c) || (c == '_'));}
260 #endif /* __NO_CTYPE_INLINES */
261
262 #ifndef _NO_OLDNAMES
263 /* Not _CRTIMP */
264 int __cdecl __MINGW_NOTHROW isascii (int);
265 int __cdecl __MINGW_NOTHROW toascii (int);
266 int __cdecl __MINGW_NOTHROW iscsymf (int);
267 int __cdecl __MINGW_NOTHROW iscsym (int);
268 #endif /* Not _NO_OLDNAMES */
269
270 #endif /* Not __STRICT_ANSI__ */
271
272 #ifdef __cplusplus
273 }
274 #endif
275
276 #endif /* Not RC_INVOKED */
277
278 #endif /* Not _CTYPE_H_ */
279
280