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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "msvcrt/ctype.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
28 /* Some abbreviations to make the following table readable */
37 WORD MSVCRT__ctype [257] = {
38 0, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|_C_, _S_|_C_,
39 _S_|_C_, _S_|_C_, _S_|_C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_,
40 _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|_BLANK,
41 _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_,
42 _P_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_,
43 _D_|_H_, _D_|_H_, _D_|_H_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _U_|_H_,
44 _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_, _U_, _U_, _U_, _U_,
45 _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_,
46 _U_, _P_, _P_, _P_, _P_, _P_, _P_, _L_|_H_, _L_|_H_, _L_|_H_, _L_|_H_,
47 _L_|_H_, _L_|_H_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_,
48 _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _P_, _P_, _P_, _P_,
49 _C_, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
54 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
57 /* Internal: Current ctype table for locale */
58 WORD MSVCRT_current_ctype[257];
60 /* pctype is used by macros in the Win32 headers. It must point
61 * To a table of flags exactly like ctype. To allow locale
62 * changes to affect ctypes (i.e. isleadbyte), we use a second table
63 * and update its flags whenever the current locale changes.
65 WORD* MSVCRT__pctype = MSVCRT_current_ctype + 1;
68 extern int MSVCRT___mb_cur_max;
69 extern LCID MSVCRT_current_lc_all_lcid;
71 /*********************************************************************
72 * __p__pctype (MSVCRT.@)
74 WORD** __p__pctype(void)
76 return &MSVCRT__pctype;
79 /*********************************************************************
82 int _isctype(int c, int type)
84 if (c >= -1 && c <= 255)
85 return MSVCRT__pctype[c] & type;
87 if (MSVCRT___mb_cur_max != 1 && c > 0)
89 /* FIXME: Is there a faster way to do this? */
91 char convert[3], *pconv = convert;
93 if (MSVCRT__pctype[(UINT)c >> 8] & _LEADBYTE)
94 *pconv++ = (UINT)c >> 8;
97 /* FIXME: Use ctype LCID, not lc_all */
98 if (GetStringTypeExA(MSVCRT_current_lc_all_lcid, CT_CTYPE1,
99 convert, convert[1] ? 2 : 1, &typeInfo))
100 return typeInfo & type;
105 /*********************************************************************
108 int MSVCRT_isalnum(int c)
110 return _isctype( c, _ALPHA | _DIGIT );
113 /*********************************************************************
116 int MSVCRT_isalpha(int c)
118 return _isctype( c, _ALPHA );
121 /*********************************************************************
124 int MSVCRT_iscntrl(int c)
126 return _isctype( c, _CONTROL );
129 /*********************************************************************
132 int MSVCRT_isdigit(int c)
134 return _isctype( c, _DIGIT );
137 /*********************************************************************
140 int MSVCRT_isgraph(int c)
142 return _isctype( c, _ALPHA | _DIGIT | _PUNCT );
145 /*********************************************************************
146 * isleadbyte (MSVCRT.@)
148 int MSVCRT_isleadbyte(int c)
150 return _isctype( c, _LEADBYTE );
153 /*********************************************************************
156 int MSVCRT_islower(int c)
158 return _isctype( c, _LOWER );
161 /*********************************************************************
164 int MSVCRT_isprint(int c)
166 return _isctype( c, _ALPHA | _DIGIT | _BLANK | _PUNCT );
169 /*********************************************************************
172 int MSVCRT_ispunct(int c)
174 return _isctype( c, _PUNCT );
177 /*********************************************************************
180 int MSVCRT_isspace(int c)
182 return _isctype( c, _SPACE );
185 /*********************************************************************
188 int MSVCRT_isupper(int c)
190 return _isctype( c, _UPPER );
193 /*********************************************************************
194 * isxdigit (MSVCRT.@)
196 int MSVCRT_isxdigit(int c)
198 return _isctype( c, _HEX );
201 /*********************************************************************
202 * __isascii (MSVCRT.@)
204 int MSVCRT___isascii(int c)
206 return isascii((unsigned)c);
209 /*********************************************************************
210 * __toascii (MSVCRT.@)
212 int MSVCRT___toascii(int c)
214 return (unsigned)c & 0x7f;
217 /*********************************************************************
218 * iswascii (MSVCRT.@)
221 int MSVCRT_iswascii(MSVCRT_wchar_t c)
223 return ((unsigned)c < 0x80);
226 /*********************************************************************
227 * __iscsym (MSVCRT.@)
229 int MSVCRT___iscsym(int c)
231 return (c < 127 && (isalnum(c) || c == '_'));
234 /*********************************************************************
235 * __iscsymf (MSVCRT.@)
237 int MSVCRT___iscsymf(int c)
239 return (c < 127 && (isalpha(c) || c == '_'));
242 /*********************************************************************
243 * _toupper (MSVCRT.@)
245 int MSVCRT__toupper(int c)
247 return c - 0x20; /* sic */
250 /*********************************************************************
251 * _tolower (MSVCRT.@)
253 int MSVCRT__tolower(int c)
255 return c + 0x20; /* sic */