2 * msvcrt.dll ctype functions
4 * Copyright 2000 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 /* Some abbreviations to make the following table readable */
25 #define _C_ MSVCRT__CONTROL
26 #define _S_ MSVCRT__SPACE
27 #define _P_ MSVCRT__PUNCT
28 #define _D_ MSVCRT__DIGIT
29 #define _H_ MSVCRT__HEX
30 #define _U_ MSVCRT__UPPER
31 #define _L_ MSVCRT__LOWER
33 WORD MSVCRT__ctype [257] = {
34 0, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|_C_, _S_|_C_,
35 _S_|_C_, _S_|_C_, _S_|_C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_,
36 _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|MSVCRT__BLANK,
37 _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_,
38 _P_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_,
39 _D_|_H_, _D_|_H_, _D_|_H_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _U_|_H_,
40 _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_, _U_, _U_, _U_, _U_,
41 _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_,
42 _U_, _P_, _P_, _P_, _P_, _P_, _P_, _L_|_H_, _L_|_H_, _L_|_H_, _L_|_H_,
43 _L_|_H_, _L_|_H_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_,
44 _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _P_, _P_, _P_, _P_,
45 _C_, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
47 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
48 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
49 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
50 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
53 /* Internal: Current ctype table for locale */
54 WORD MSVCRT_current_ctype[257];
56 /* pctype is used by macros in the Win32 headers. It must point
57 * To a table of flags exactly like ctype. To allow locale
58 * changes to affect ctypes (i.e. isleadbyte), we use a second table
59 * and update its flags whenever the current locale changes.
61 WORD* MSVCRT__pctype = MSVCRT_current_ctype + 1;
63 /*********************************************************************
64 * __pctype_func (MSVCRT.@)
66 WORD** CDECL MSVCRT___pctype_func(void)
68 return &MSVCRT__pctype;
71 /*********************************************************************
74 int CDECL _isctype(int c, int type)
76 if (c >= -1 && c <= 255)
77 return MSVCRT__pctype[c] & type;
79 if (MSVCRT___mb_cur_max != 1 && c > 0)
81 /* FIXME: Is there a faster way to do this? */
83 char convert[3], *pconv = convert;
85 if (MSVCRT__pctype[(UINT)c >> 8] & MSVCRT__LEADBYTE)
86 *pconv++ = (UINT)c >> 8;
89 /* FIXME: Use ctype LCID, not lc_all */
90 if (GetStringTypeExA(MSVCRT_current_lc_all_lcid, CT_CTYPE1,
91 convert, convert[1] ? 2 : 1, &typeInfo))
92 return typeInfo & type;
97 /*********************************************************************
100 int CDECL MSVCRT_isalnum(int c)
102 return _isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT );
105 /*********************************************************************
108 int CDECL MSVCRT_isalpha(int c)
110 return _isctype( c, MSVCRT__ALPHA );
113 /*********************************************************************
116 int CDECL MSVCRT_iscntrl(int c)
118 return _isctype( c, MSVCRT__CONTROL );
121 /*********************************************************************
124 int CDECL MSVCRT_isdigit(int c)
126 return _isctype( c, MSVCRT__DIGIT );
129 /*********************************************************************
132 int CDECL MSVCRT_isgraph(int c)
134 return _isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__PUNCT );
137 /*********************************************************************
138 * isleadbyte (MSVCRT.@)
140 int CDECL MSVCRT_isleadbyte(int c)
142 return _isctype( c, MSVCRT__LEADBYTE );
145 /*********************************************************************
148 int CDECL MSVCRT_islower(int c)
150 return _isctype( c, MSVCRT__LOWER );
153 /*********************************************************************
156 int CDECL MSVCRT_isprint(int c)
158 return _isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__BLANK | MSVCRT__PUNCT );
161 /*********************************************************************
164 int CDECL MSVCRT_ispunct(int c)
166 return _isctype( c, MSVCRT__PUNCT );
169 /*********************************************************************
172 int CDECL MSVCRT_isspace(int c)
174 return _isctype( c, MSVCRT__SPACE );
177 /*********************************************************************
180 int CDECL MSVCRT_isupper(int c)
182 return _isctype( c, MSVCRT__UPPER );
185 /*********************************************************************
186 * isxdigit (MSVCRT.@)
188 int CDECL MSVCRT_isxdigit(int c)
190 return _isctype( c, MSVCRT__HEX );
193 /*********************************************************************
194 * __isascii (MSVCRT.@)
196 int CDECL MSVCRT___isascii(int c)
198 return isascii((unsigned)c);
201 /*********************************************************************
202 * __toascii (MSVCRT.@)
204 int CDECL MSVCRT___toascii(int c)
206 return (unsigned)c & 0x7f;
209 /*********************************************************************
210 * iswascii (MSVCRT.@)
213 int CDECL MSVCRT_iswascii(MSVCRT_wchar_t c)
215 return ((unsigned)c < 0x80);
218 /*********************************************************************
219 * __iscsym (MSVCRT.@)
221 int CDECL MSVCRT___iscsym(int c)
223 return (c < 127 && (isalnum(c) || c == '_'));
226 /*********************************************************************
227 * __iscsymf (MSVCRT.@)
229 int CDECL MSVCRT___iscsymf(int c)
231 return (c < 127 && (isalpha(c) || c == '_'));
234 /*********************************************************************
235 * _toupper (MSVCRT.@)
237 int CDECL MSVCRT__toupper(int c)
239 return c - 0x20; /* sic */
242 /*********************************************************************
243 * _tolower (MSVCRT.@)
245 int CDECL MSVCRT__tolower(int c)
247 return c + 0x20; /* sic */