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
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
27 /* Some abbreviations to make the following table readable */
28 #define _C_ MSVCRT__CONTROL
29 #define _S_ MSVCRT__SPACE
30 #define _P_ MSVCRT__PUNCT
31 #define _D_ MSVCRT__DIGIT
32 #define _H_ MSVCRT__HEX
33 #define _U_ MSVCRT__UPPER
34 #define _L_ MSVCRT__LOWER
36 WORD MSVCRT__ctype [257] = {
37 0, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|_C_, _S_|_C_,
38 _S_|_C_, _S_|_C_, _S_|_C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_,
39 _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|MSVCRT__BLANK,
40 _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_,
41 _P_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_,
42 _D_|_H_, _D_|_H_, _D_|_H_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _U_|_H_,
43 _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_, _U_, _U_, _U_, _U_,
44 _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_,
45 _U_, _P_, _P_, _P_, _P_, _P_, _P_, _L_|_H_, _L_|_H_, _L_|_H_, _L_|_H_,
46 _L_|_H_, _L_|_H_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_,
47 _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _P_, _P_, _P_, _P_,
48 _C_, 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, 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
56 /* Internal: Current ctype table for locale */
57 WORD MSVCRT_current_ctype[257];
59 /* pctype is used by macros in the Win32 headers. It must point
60 * To a table of flags exactly like ctype. To allow locale
61 * changes to affect ctypes (i.e. isleadbyte), we use a second table
62 * and update its flags whenever the current locale changes.
64 WORD* MSVCRT__pctype = MSVCRT_current_ctype + 1;
67 extern int MSVCRT___mb_cur_max;
68 extern LCID MSVCRT_current_lc_all_lcid;
70 /*********************************************************************
71 * __p__pctype (MSVCRT.@)
73 WORD** CDECL __p__pctype(void)
75 return &MSVCRT__pctype;
78 /*********************************************************************
81 int CDECL _isctype(int c, int type)
83 if (c >= -1 && c <= 255)
84 return MSVCRT__pctype[c] & type;
86 if (MSVCRT___mb_cur_max != 1 && c > 0)
88 /* FIXME: Is there a faster way to do this? */
90 char convert[3], *pconv = convert;
92 if (MSVCRT__pctype[(UINT)c >> 8] & MSVCRT__LEADBYTE)
93 *pconv++ = (UINT)c >> 8;
96 /* FIXME: Use ctype LCID, not lc_all */
97 if (GetStringTypeExA(MSVCRT_current_lc_all_lcid, CT_CTYPE1,
98 convert, convert[1] ? 2 : 1, &typeInfo))
99 return typeInfo & type;
104 /*********************************************************************
107 int CDECL MSVCRT_isalnum(int c)
109 return _isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT );
112 /*********************************************************************
115 int CDECL MSVCRT_isalpha(int c)
117 return _isctype( c, MSVCRT__ALPHA );
120 /*********************************************************************
123 int CDECL MSVCRT_iscntrl(int c)
125 return _isctype( c, MSVCRT__CONTROL );
128 /*********************************************************************
131 int CDECL MSVCRT_isdigit(int c)
133 return _isctype( c, MSVCRT__DIGIT );
136 /*********************************************************************
139 int CDECL MSVCRT_isgraph(int c)
141 return _isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__PUNCT );
144 /*********************************************************************
145 * isleadbyte (MSVCRT.@)
147 int CDECL MSVCRT_isleadbyte(int c)
149 return _isctype( c, MSVCRT__LEADBYTE );
152 /*********************************************************************
155 int CDECL MSVCRT_islower(int c)
157 return _isctype( c, MSVCRT__LOWER );
160 /*********************************************************************
163 int CDECL MSVCRT_isprint(int c)
165 return _isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__BLANK | MSVCRT__PUNCT );
168 /*********************************************************************
171 int CDECL MSVCRT_ispunct(int c)
173 return _isctype( c, MSVCRT__PUNCT );
176 /*********************************************************************
179 int CDECL MSVCRT_isspace(int c)
181 return _isctype( c, MSVCRT__SPACE );
184 /*********************************************************************
187 int CDECL MSVCRT_isupper(int c)
189 return _isctype( c, MSVCRT__UPPER );
192 /*********************************************************************
193 * isxdigit (MSVCRT.@)
195 int CDECL MSVCRT_isxdigit(int c)
197 return _isctype( c, MSVCRT__HEX );
200 /*********************************************************************
201 * __isascii (MSVCRT.@)
203 int CDECL MSVCRT___isascii(int c)
205 return isascii((unsigned)c);
208 /*********************************************************************
209 * __toascii (MSVCRT.@)
211 int CDECL MSVCRT___toascii(int c)
213 return (unsigned)c & 0x7f;
216 /*********************************************************************
217 * iswascii (MSVCRT.@)
220 int CDECL MSVCRT_iswascii(MSVCRT_wchar_t c)
222 return ((unsigned)c < 0x80);
225 /*********************************************************************
226 * __iscsym (MSVCRT.@)
228 int CDECL MSVCRT___iscsym(int c)
230 return (c < 127 && (isalnum(c) || c == '_'));
233 /*********************************************************************
234 * __iscsymf (MSVCRT.@)
236 int CDECL MSVCRT___iscsymf(int c)
238 return (c < 127 && (isalpha(c) || c == '_'));
241 /*********************************************************************
242 * _toupper (MSVCRT.@)
244 int CDECL MSVCRT__toupper(int c)
246 return c - 0x20; /* sic */
249 /*********************************************************************
250 * _tolower (MSVCRT.@)
252 int CDECL MSVCRT__tolower(int c)
254 return c + 0x20; /* sic */