2 * msvcrt.dll ctype functions
4 * Copyright 2000 Jon Griffiths
8 #include "msvcrt/ctype.h"
10 #include "wine/debug.h"
12 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
14 /* Some abbreviations to make the following table readable */
23 WORD MSVCRT__ctype [257] = {
24 0, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|_C_, _S_|_C_,
25 _S_|_C_, _S_|_C_, _S_|_C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_,
26 _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|_BLANK,
27 _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_,
28 _P_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_,
29 _D_|_H_, _D_|_H_, _D_|_H_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _U_|_H_,
30 _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_, _U_, _U_, _U_, _U_,
31 _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_,
32 _U_, _P_, _P_, _P_, _P_, _P_, _P_, _L_|_H_, _L_|_H_, _L_|_H_, _L_|_H_,
33 _L_|_H_, _L_|_H_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_,
34 _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _P_, _P_, _P_, _P_,
35 _C_, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
36 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
38 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
39 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
43 /* Internal: Current ctype table for locale */
44 WORD MSVCRT_current_ctype[257];
46 /* pctype is used by macros in the Win32 headers. It must point
47 * To a table of flags exactly like ctype. To allow locale
48 * changes to affect ctypes (i.e. isleadbyte), we use a second table
49 * and update its flags whenever the current locale changes.
51 WORD* MSVCRT__pctype = MSVCRT_current_ctype + 1;
54 extern int MSVCRT___mb_cur_max;
55 extern LCID MSVCRT_current_lc_all_lcid;
57 /*********************************************************************
58 * __p__pctype (MSVCRT.@)
60 WORD** __p__pctype(void)
62 return &MSVCRT__pctype;
65 /*********************************************************************
68 int _isctype(int c, int type)
70 if (c >= -1 && c <= 255)
71 return MSVCRT__pctype[c] & type;
73 if (MSVCRT___mb_cur_max != 1 && c > 0)
75 /* FIXME: Is there a faster way to do this? */
77 char convert[3], *pconv = convert;
79 if (MSVCRT__pctype[(UINT)c >> 8] & _LEADBYTE)
80 *pconv++ = (UINT)c >> 8;
83 /* FIXME: Use ctype LCID, not lc_all */
84 if (GetStringTypeExA(MSVCRT_current_lc_all_lcid, CT_CTYPE1,
85 convert, convert[1] ? 2 : 1, &typeInfo))
86 return typeInfo & type;
91 /*********************************************************************
94 int MSVCRT_isalnum(int c)
96 return _isctype( c, _ALPHA | _DIGIT );
99 /*********************************************************************
102 int MSVCRT_isalpha(int c)
104 return _isctype( c, _ALPHA );
107 /*********************************************************************
110 int MSVCRT_iscntrl(int c)
112 return _isctype( c, _CONTROL );
115 /*********************************************************************
118 int MSVCRT_isdigit(int c)
120 return _isctype( c, _DIGIT );
123 /*********************************************************************
126 int MSVCRT_isgraph(int c)
128 return _isctype( c, _ALPHA | _DIGIT | _PUNCT );
131 /*********************************************************************
132 * isleadbyte (MSVCRT.@)
134 int MSVCRT_isleadbyte(int c)
136 return _isctype( c, _LEADBYTE );
139 /*********************************************************************
142 int MSVCRT_islower(int c)
144 return _isctype( c, _LOWER );
147 /*********************************************************************
150 int MSVCRT_isprint(int c)
152 return _isctype( c, _ALPHA | _DIGIT | _BLANK | _PUNCT );
155 /*********************************************************************
158 int MSVCRT_ispunct(int c)
160 return _isctype( c, _PUNCT );
163 /*********************************************************************
166 int MSVCRT_isspace(int c)
168 return _isctype( c, _SPACE );
171 /*********************************************************************
174 int MSVCRT_isupper(int c)
176 return _isctype( c, _UPPER );
179 /*********************************************************************
180 * isxdigit (MSVCRT.@)
182 int MSVCRT_isxdigit(int c)
184 return _isctype( c, _HEX );
187 /*********************************************************************
188 * __isascii (MSVCRT.@)
190 int MSVCRT___isascii(int c)
192 return isascii((unsigned)c);
195 /*********************************************************************
196 * __toascii (MSVCRT.@)
198 int MSVCRT___toascii(int c)
200 return (unsigned)c & 0x7f;
203 /*********************************************************************
204 * iswascii (MSVCRT.@)
207 int MSVCRT_iswascii(WCHAR c)
209 return ((unsigned)c < 0x80);
212 /*********************************************************************
213 * __iscsym (MSVCRT.@)
215 int MSVCRT___iscsym(int c)
217 return (c < 127 && (isalnum(c) || c == '_'));
220 /*********************************************************************
221 * __iscsymf (MSVCRT.@)
223 int MSVCRT___iscsymf(int c)
225 return (c < 127 && (isalpha(c) || c == '_'));
228 /*********************************************************************
229 * _toupper (MSVCRT.@)
231 int MSVCRT__toupper(int c)
233 return c - 0x20; /* sic */
236 /*********************************************************************
237 * _tolower (MSVCRT.@)
239 int MSVCRT__tolower(int c)
241 return c + 0x20; /* sic */