OSDN Git Service

Expose C99 features required by C++11; fix issue [#2335]
[mingw/mingw-org-wsl.git] / mingwrt / include / ctype.h
1 /*
2  * ctype.h
3  *
4  * Functions for character classification and conversion.
5  *
6  * $Id$
7  *
8  * Written by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
9  * Copyright (C) 1997-2008, 2016, 2017, MinGW.org Project
10  *
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice, this permission notice, and the following
20  * disclaimer shall be included in all copies or substantial portions of
21  * the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
26  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
29  * DEALINGS IN THE SOFTWARE.
30  *
31  */
32 #ifndef _CTYPE_H
33 #pragma GCC system_header
34 #define _CTYPE_H
35
36 /* All MinGW headers must include <_mingw.h>
37  */
38 #include <_mingw.h>
39
40 /* Although conflicting with both ISO-C and POSIX, Microsoft say that,
41  * in addition to the single byte character classification API which is
42  * properly declared here, this file should also declare elements of the
43  * wide classification API, which is properly declared in <wctype.h>
44  *
45  * To avoid the burden of maintaining duplicate declarations in two
46  * locations, we keep the wide character declarations where ISO-C and
47  * POSIX say they belong, in <wctype.h>, while accommodating Microsoft
48  * compatibility by providing for selective inclusion of the relevant
49  * elements of it here.  (Note that we must do this early, because to
50  * avoid duplication, we delegate the definition of common character
51  * classification macros, with the exception of _LEADBYTE, which is
52  * not required in both headers, to <wctype.h>; we use the quoted
53  * form of inclusion here, to ensure that we get our own "wctype.h",
54  * and not any predecessor which may have been insinuated into the
55  * system include path, and which may interfere with our mechanism
56  * for partial inclusion of shared header content).
57  */
58 #define __CTYPE_H_SOURCED__
59 #include "wctype.h"
60
61 /* This is the one character classification macro, for which definition
62  * is NOT delegated to <wctype.h>
63  */
64 #define _LEADBYTE       0x8000
65
66 #ifndef RC_INVOKED
67
68 _BEGIN_C_DECLS
69
70 _CRTIMP __cdecl __MINGW_NOTHROW  int isalnum(int);
71 _CRTIMP __cdecl __MINGW_NOTHROW  int isalpha(int);
72 _CRTIMP __cdecl __MINGW_NOTHROW  int iscntrl(int);
73 _CRTIMP __cdecl __MINGW_NOTHROW  int isdigit(int);
74 _CRTIMP __cdecl __MINGW_NOTHROW  int isgraph(int);
75 _CRTIMP __cdecl __MINGW_NOTHROW  int islower(int);
76 _CRTIMP __cdecl __MINGW_NOTHROW  int isleadbyte (int);
77 _CRTIMP __cdecl __MINGW_NOTHROW  int isprint(int);
78 _CRTIMP __cdecl __MINGW_NOTHROW  int ispunct(int);
79 _CRTIMP __cdecl __MINGW_NOTHROW  int isspace(int);
80 _CRTIMP __cdecl __MINGW_NOTHROW  int isupper(int);
81 _CRTIMP __cdecl __MINGW_NOTHROW  int isxdigit(int);
82
83 #if _ISOC99_SOURCE
84 __cdecl __MINGW_NOTHROW  int isblank (int);
85 #endif
86
87 #ifndef __STRICT_ANSI__
88 _CRTIMP __cdecl __MINGW_NOTHROW  int _isctype (int, int);
89 #endif
90
91 /* These are ISO-C conforming functions, with correct checking of
92  * argument; they are exported by MSVCRT.DLL, and by CRTDLL.DLL as
93  * such, and are NOT simply old-name mapped variants; however...
94  */
95 _CRTIMP __cdecl __MINGW_NOTHROW  int tolower (int);
96 _CRTIMP __cdecl __MINGW_NOTHROW  int toupper (int);
97
98 #ifndef __STRICT_ANSI__
99 /* ...Microsoft's beloved underscore decorated variants are also
100  * exported.  These are cheap non-standard versions: their return
101  * values are undefined if the argument is not an ASCII character,
102  * or is not of appropriate case for the requested conversion.
103  *
104  * Note that these appear to be approximately equivalent to POSIX
105  * macros of the same names, (declared obsolescent in POSIX.1-2008),
106  * but are implemented as DLL functions, rather than macros.
107  */
108 _CRTIMP __cdecl __MINGW_NOTHROW  int _tolower (int);
109 _CRTIMP __cdecl __MINGW_NOTHROW  int _toupper (int);
110 #endif
111
112 #ifndef MB_CUR_MAX
113 /* FIXME: also defined in stdlib.h; should be factored into ONE
114  * location ONLY, and included into the other.
115  */
116 # ifdef __DECLSPEC_SUPPORTED
117 #  ifdef __MSVCRT__
118 #   define MB_CUR_MAX            __mb_cur_max
119     __MINGW_IMPORT int           __mb_cur_max;
120
121 #  else /* !__MSVCRT__ */
122 #   define MB_CUR_MAX            __mb_cur_max_dll
123     __MINGW_IMPORT int           __mb_cur_max_dll;
124 #  endif        /* !__MSVCRT__ */
125
126 # else  /* !__DECLSPEC_SUPPORTED */
127 #  ifdef __MSVCRT__
128 #   define MB_CUR_MAX           (*_imp____mb_cur_max)
129     extern int                   *_imp____mb_cur_max;
130
131 #  else /* !__MSVCRT__ */
132 #   define MB_CUR_MAX           (*_imp____mb_cur_max_dll)
133     extern int                   *_imp____mb_cur_max_dll;
134 #  endif /* !__MSVCRT__ */
135 # endif /*  __DECLSPEC_SUPPORTED */
136 #endif  /* ! MB_CUR_MAX */
137
138 #ifdef __DECLSPEC_SUPPORTED
139 # if __MSVCRT_VERSION__ <= __MSVCR70_DLL
140   __MINGW_IMPORT unsigned short   _ctype[];
141 # endif
142
143 # ifdef __MSVCRT__
144   __MINGW_IMPORT unsigned short  *_pctype;
145
146 # else  /* !__MSVCRT__ (implies CRTDLL) */
147 # define  _pctype _pctype_dll
148   __MINGW_IMPORT unsigned short  *_pctype_dll;
149 # endif
150
151 #else   /* !__DECLSPEC_SUPPORTED */
152 # if __MSVCRT_VERSION__ <= __MSVCR70_DLL
153 # define _ctype                 (*_imp___ctype)
154   extern unsigned short         **_imp___ctype;
155 # endif
156
157 # ifdef __MSVCRT__
158 # define _pctype                (*_imp___pctype)
159   extern unsigned short         **_imp___pctype;
160
161 # else  /* !__MSVCRT__ (implies CRTDLL) */
162 # define _pctype                (*_imp___pctype_dll)
163   extern unsigned short         **_imp___pctype_dll;
164 # endif /* CRTDLL */
165 #endif  /* !__DECLSPEC_SUPPORTED */
166
167 /* Use inlines here rather than macros, because macros will upset
168  * C++ usage (eg, ::isalnum), and so usually get undefined
169  *
170  * According to standard for SB chars, these function are defined only
171  * for input values representable by unsigned char or EOF.
172  * Thus, there is no range test.
173  * This reproduces behaviour of MSVCRT.dll lib implemention for SB chars.
174  *
175  * If no MB char support is needed, these can be simplified even
176  * more by command line define -DMB_CUR_MAX=1.  The compiler will then
177  * optimise away the constant condition.
178  */
179
180 #if !(defined (__NO_INLINE__)  || defined (__NO_CTYPE_INLINES) \
181         || defined (__STRICT_ANSI__))
182
183 /* Use simple lookup in single byte locales, else _isctype()
184  */
185 #define __ISCTYPE(c, mask)  (MB_CUR_MAX == 1 ? (_pctype[c] & mask) : _isctype (c, mask))
186
187 __CRT_INLINE __cdecl __MINGW_NOTHROW  int isalnum (int c)
188 { return __ISCTYPE(c, (_ALPHA|_DIGIT)); }
189
190 __CRT_INLINE __cdecl __MINGW_NOTHROW  int isalpha (int c)
191 { return __ISCTYPE(c, _ALPHA); }
192
193 __CRT_INLINE __cdecl __MINGW_NOTHROW  int iscntrl (int c)
194 { return __ISCTYPE(c, _CONTROL); }
195
196 __CRT_INLINE __cdecl __MINGW_NOTHROW  int isdigit (int c)
197 { return __ISCTYPE(c, _DIGIT); }
198
199 __CRT_INLINE __cdecl __MINGW_NOTHROW  int isgraph (int c)
200 { return __ISCTYPE(c, (_PUNCT|_ALPHA|_DIGIT)); }
201
202 __CRT_INLINE __cdecl __MINGW_NOTHROW  int islower (int c)
203 { return __ISCTYPE(c, _LOWER); }
204
205 __CRT_INLINE __cdecl __MINGW_NOTHROW  int isprint (int c)
206 { return __ISCTYPE(c, (_BLANK|_PUNCT|_ALPHA|_DIGIT)); }
207
208 __CRT_INLINE __cdecl __MINGW_NOTHROW  int ispunct (int c)
209 { return __ISCTYPE(c, _PUNCT); }
210
211 __CRT_INLINE __cdecl __MINGW_NOTHROW  int isspace (int c)
212 { return __ISCTYPE(c, _SPACE); }
213
214 __CRT_INLINE __cdecl __MINGW_NOTHROW  int isupper (int c)
215 { return __ISCTYPE(c, _UPPER); }
216
217 __CRT_INLINE __cdecl __MINGW_NOTHROW  int isxdigit (int c)
218 { return __ISCTYPE(c, _HEX); }
219
220 #if _ISOC99_SOURCE
221 __CRT_INLINE __cdecl __MINGW_NOTHROW  int isblank (int c)
222 { return (__ISCTYPE(c, _BLANK) || c == '\t'); }
223 #endif
224
225 /* These reproduce the behaviour of their DLL exported namesakes,
226  * and thus ARE the effective equivalents of the similarly named,
227  * and now-obsolescent, POSIX macros.
228  */
229 __CRT_INLINE __cdecl __MINGW_NOTHROW  int _tolower (int c)
230 { return (c - 'A' + 'a'); }
231
232 __CRT_INLINE __cdecl __MINGW_NOTHROW  int _toupper (int c)
233 { return (c - 'a' + 'A'); }
234
235 /* TODO: is it worth inlining ANSI tolower(), and toupper()?
236  * Probably only if we only want C-locale.
237  */
238 #endif /* _NO_CTYPE_INLINES */
239
240 __CRT_INLINE __cdecl __MINGW_NOTHROW  int isleadbyte (int c)
241 { return (_pctype[(unsigned char)(c)] & _LEADBYTE); }
242
243 #ifndef __STRICT_ANSI__
244 __cdecl __MINGW_NOTHROW  int __isascii (int);
245 __cdecl __MINGW_NOTHROW  int __toascii (int);
246 __cdecl __MINGW_NOTHROW  int __iscsymf (int);   /* Valid as first character in a C symbol */
247 __cdecl __MINGW_NOTHROW  int __iscsym (int);    /* Valid character in C symbol (after first) */
248
249 #if !(defined (__NO_INLINE__) || defined (__NO_CTYPE_INLINES))
250
251 __CRT_INLINE __cdecl __MINGW_NOTHROW  int __isascii (int c)
252 { return ((c & ~0x7F) == 0); }
253
254 __CRT_INLINE __cdecl __MINGW_NOTHROW  int __toascii (int c)
255 { return (c & 0x7F); }
256
257 __CRT_INLINE __cdecl __MINGW_NOTHROW  int __iscsymf (int c)
258 { return (isalpha(c) || (c == '_')); }
259
260 __CRT_INLINE __cdecl __MINGW_NOTHROW  int __iscsym (int c)
261 { return  (isalnum(c) || (c == '_')); }
262
263 #endif /* !__NO_CTYPE_INLINES */
264
265 #ifndef _NO_OLDNAMES
266 /* Not _CRTIMP */
267 __cdecl __MINGW_NOTHROW  int isascii (int);
268 __cdecl __MINGW_NOTHROW  int toascii (int);
269 __cdecl __MINGW_NOTHROW  int iscsymf (int);
270 __cdecl __MINGW_NOTHROW  int iscsym (int);
271 #endif  /* !_NO_OLDNAMES */
272
273 #endif  /* !__STRICT_ANSI__ */
274
275 _END_C_DECLS
276
277 #endif  /* ! RC_INVOKED */
278
279 #undef __CTYPE_H_SOURCED__
280 #endif  /* !_CTYPE_H: $RCSfile$: end of file */