Git for Windows Git-1.6.5.1-preview20100112-with-cheetah
[msysgit.git] / mingw / include / ctype.h
blob551566bc44f846dffc555de347c27fb73db62885
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.
7 * Functions for testing character types and converting characters.
9 */
11 #ifndef _CTYPE_H_
12 #define _CTYPE_H_
14 /* All the headers include this file. */
15 #include <_mingw.h>
17 #define __need_wchar_t
18 #define __need_wint_t
19 #ifndef RC_INVOKED
20 #include <stddef.h>
21 #endif /* Not RC_INVOKED */
25 * The following flags are used to tell iswctype and _isctype what character
26 * types you are looking for.
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
40 #define _ALPHA 0x0103
42 #ifndef RC_INVOKED
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
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);
60 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
61 || !defined __STRICT_ANSI__
62 int __cdecl __MINGW_NOTHROW isblank (int);
63 #endif
65 #ifndef __STRICT_ANSI__
66 _CRTIMP int __cdecl __MINGW_NOTHROW _isctype (int, int);
67 #endif
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);
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.
78 #ifndef __STRICT_ANSI__
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
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 */
98 #else /* ! __DECLSPEC_SUPPORTED */
99 # ifdef __MSVCRT__
100 extern int* _imp____mb_cur_max;
101 # define MB_CUR_MAX (*_imp____mb_cur_max)
102 # else /* not __MSVCRT */
103 extern int* _imp____mb_cur_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 */
110 #ifdef __DECLSPEC_SUPPORTED
111 # if __MSVCRT_VERSION__ <= 0x0700
112 __MINGW_IMPORT unsigned short _ctype[];
113 # endif
114 # ifdef __MSVCRT__
115 __MINGW_IMPORT unsigned short* _pctype;
116 # else /* CRTDLL */
117 __MINGW_IMPORT unsigned short* _pctype_dll;
118 # define _pctype _pctype_dll
119 # endif
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 */
136 * Use inlines here rather than macros, because macros will upset
137 * C++ usage (eg, ::isalnum), and so usually get undefined
139 * According to standard for SB chars, these function are defined only
140 * for input values representable by unsigned char or EOF.
141 * Thus, there is no range test.
142 * This reproduces behaviour of MSVCRT.dll lib implemention for SB chars.
144 * If no MB char support is needed, these can be simplified even
145 * more by command line define -DMB_CUR_MAX=1. The compiler will then
146 * optimise away the constant condition.
149 #if !(defined (__NO_INLINE__) || defined (__NO_CTYPE_INLINES) \
150 || defined (__STRICT_ANSI__))
152 /* use simple lookup if SB locale, else _isctype() */
153 #define __ISCTYPE(c, mask) (MB_CUR_MAX == 1 ? (_pctype[c] & mask) : _isctype(c, mask))
154 __CRT_INLINE int __cdecl __MINGW_NOTHROW isalnum(int c) {return __ISCTYPE(c, (_ALPHA|_DIGIT));}
155 __CRT_INLINE int __cdecl __MINGW_NOTHROW isalpha(int c) {return __ISCTYPE(c, _ALPHA);}
156 __CRT_INLINE int __cdecl __MINGW_NOTHROW iscntrl(int c) {return __ISCTYPE(c, _CONTROL);}
157 __CRT_INLINE int __cdecl __MINGW_NOTHROW isdigit(int c) {return __ISCTYPE(c, _DIGIT);}
158 __CRT_INLINE int __cdecl __MINGW_NOTHROW isgraph(int c) {return __ISCTYPE(c, (_PUNCT|_ALPHA|_DIGIT));}
159 __CRT_INLINE int __cdecl __MINGW_NOTHROW islower(int c) {return __ISCTYPE(c, _LOWER);}
160 __CRT_INLINE int __cdecl __MINGW_NOTHROW isprint(int c) {return __ISCTYPE(c, (_BLANK|_PUNCT|_ALPHA|_DIGIT));}
161 __CRT_INLINE int __cdecl __MINGW_NOTHROW ispunct(int c) {return __ISCTYPE(c, _PUNCT);}
162 __CRT_INLINE int __cdecl __MINGW_NOTHROW isspace(int c) {return __ISCTYPE(c, _SPACE);}
163 __CRT_INLINE int __cdecl __MINGW_NOTHROW isupper(int c) {return __ISCTYPE(c, _UPPER);}
164 __CRT_INLINE int __cdecl __MINGW_NOTHROW isxdigit(int c) {return __ISCTYPE(c, _HEX);}
166 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
167 || !defined __STRICT_ANSI__
168 __CRT_INLINE int __cdecl __MINGW_NOTHROW isblank (int c)
169 {return (__ISCTYPE(c, _BLANK) || c == '\t');}
170 #endif
172 /* these reproduce behaviour of lib underscored versions */
173 __CRT_INLINE int __cdecl __MINGW_NOTHROW _tolower(int c) {return ( c -'A'+'a');}
174 __CRT_INLINE int __cdecl __MINGW_NOTHROW _toupper(int c) {return ( c -'a'+'A');}
176 /* TODO? Is it worth inlining ANSI tolower, toupper? Probably only
177 if we only want C-locale. */
179 #endif /* _NO_CTYPE_INLINES */
181 /* Wide character equivalents */
183 #ifndef WEOF
184 #define WEOF (wchar_t)(0xFFFF)
185 #endif
187 #ifndef _WCTYPE_T_DEFINED
188 typedef wchar_t wctype_t;
189 #define _WCTYPE_T_DEFINED
190 #endif
192 _CRTIMP int __cdecl __MINGW_NOTHROW iswalnum(wint_t);
193 _CRTIMP int __cdecl __MINGW_NOTHROW iswalpha(wint_t);
194 _CRTIMP int __cdecl __MINGW_NOTHROW iswascii(wint_t);
195 _CRTIMP int __cdecl __MINGW_NOTHROW iswcntrl(wint_t);
196 _CRTIMP int __cdecl __MINGW_NOTHROW iswctype(wint_t, wctype_t);
197 _CRTIMP int __cdecl __MINGW_NOTHROW is_wctype(wint_t, wctype_t); /* Obsolete! */
198 _CRTIMP int __cdecl __MINGW_NOTHROW iswdigit(wint_t);
199 _CRTIMP int __cdecl __MINGW_NOTHROW iswgraph(wint_t);
200 _CRTIMP int __cdecl __MINGW_NOTHROW iswlower(wint_t);
201 _CRTIMP int __cdecl __MINGW_NOTHROW iswprint(wint_t);
202 _CRTIMP int __cdecl __MINGW_NOTHROW iswpunct(wint_t);
203 _CRTIMP int __cdecl __MINGW_NOTHROW iswspace(wint_t);
204 _CRTIMP int __cdecl __MINGW_NOTHROW iswupper(wint_t);
205 _CRTIMP int __cdecl __MINGW_NOTHROW iswxdigit(wint_t);
207 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
208 || !defined __STRICT_ANSI__ || defined __cplusplus
209 int __cdecl __MINGW_NOTHROW iswblank (wint_t);
210 #endif
212 /* Older MS docs uses wchar_t for arg and return type, while newer
213 online MS docs say arg is wint_t and return is int.
214 ISO C uses wint_t for both. */
215 _CRTIMP wint_t __cdecl __MINGW_NOTHROW towlower (wint_t);
216 _CRTIMP wint_t __cdecl __MINGW_NOTHROW towupper (wint_t);
218 _CRTIMP int __cdecl __MINGW_NOTHROW isleadbyte (int);
220 /* Also in wctype.h */
221 #if ! (defined (__NO_INLINE__) || defined(__NO_CTYPE_INLINES) \
222 || defined(__WCTYPE_INLINES_DEFINED))
223 #define __WCTYPE_INLINES_DEFINED
224 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswalnum(wint_t wc) {return (iswctype(wc,_ALPHA|_DIGIT));}
225 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswalpha(wint_t wc) {return (iswctype(wc,_ALPHA));}
226 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswascii(wint_t wc) {return ((wc & ~0x7F) ==0);}
227 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswcntrl(wint_t wc) {return (iswctype(wc,_CONTROL));}
228 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswdigit(wint_t wc) {return (iswctype(wc,_DIGIT));}
229 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswgraph(wint_t wc) {return (iswctype(wc,_PUNCT|_ALPHA|_DIGIT));}
230 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswlower(wint_t wc) {return (iswctype(wc,_LOWER));}
231 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswprint(wint_t wc) {return (iswctype(wc,_BLANK|_PUNCT|_ALPHA|_DIGIT));}
232 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswpunct(wint_t wc) {return (iswctype(wc,_PUNCT));}
233 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswspace(wint_t wc) {return (iswctype(wc,_SPACE));}
234 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswupper(wint_t wc) {return (iswctype(wc,_UPPER));}
235 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswxdigit(wint_t wc) {return (iswctype(wc,_HEX));}
236 __CRT_INLINE int __cdecl __MINGW_NOTHROW isleadbyte(int c) {return (_pctype[(unsigned char)(c)] & _LEADBYTE);}
237 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
238 || !defined __STRICT_ANSI__ || defined __cplusplus
239 __CRT_INLINE int __cdecl __MINGW_NOTHROW iswblank (wint_t wc)
240 {return (iswctype(wc,_BLANK) || wc == L'\t');}
241 #endif
243 #endif /* !(defined(__NO_CTYPE_INLINES) || defined(__WCTYPE_INLINES_DEFINED)) */
245 #ifndef __STRICT_ANSI__
246 int __cdecl __MINGW_NOTHROW __isascii (int);
247 int __cdecl __MINGW_NOTHROW __toascii (int);
248 int __cdecl __MINGW_NOTHROW __iscsymf (int); /* Valid first character in C symbol */
249 int __cdecl __MINGW_NOTHROW __iscsym (int); /* Valid character in C symbol (after first) */
251 #if !(defined (__NO_INLINE__) || defined (__NO_CTYPE_INLINES))
252 __CRT_INLINE int __cdecl __MINGW_NOTHROW __isascii(int c) {return ((c & ~0x7F) == 0);}
253 __CRT_INLINE int __cdecl __MINGW_NOTHROW __toascii(int c) {return (c & 0x7F);}
254 __CRT_INLINE int __cdecl __MINGW_NOTHROW __iscsymf(int c) {return (isalpha(c) || (c == '_'));}
255 __CRT_INLINE int __cdecl __MINGW_NOTHROW __iscsym(int c) {return (isalnum(c) || (c == '_'));}
256 #endif /* __NO_CTYPE_INLINES */
258 #ifndef _NO_OLDNAMES
259 /* Not _CRTIMP */
260 int __cdecl __MINGW_NOTHROW isascii (int);
261 int __cdecl __MINGW_NOTHROW toascii (int);
262 int __cdecl __MINGW_NOTHROW iscsymf (int);
263 int __cdecl __MINGW_NOTHROW iscsym (int);
264 #endif /* Not _NO_OLDNAMES */
266 #endif /* Not __STRICT_ANSI__ */
268 #ifdef __cplusplus
270 #endif
272 #endif /* Not RC_INVOKED */
274 #endif /* Not _CTYPE_H_ */