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 /* pctype is used by macros in the Win32 headers. It must point
54 * To a table of flags exactly like ctype. To allow locale
55 * changes to affect ctypes (i.e. isleadbyte), we use a second table
56 * and update its flags whenever the current locale changes.
58 WORD* MSVCRT__pctype = NULL;
60 /*********************************************************************
61 * __pctype_func (MSVCRT.@)
63 WORD** CDECL MSVCRT___pctype_func(void)
65 return &get_locale()->locinfo->pctype;
68 /*********************************************************************
71 int CDECL _isctype(int c, int type)
73 MSVCRT__locale_t locale = get_locale();
75 if (c >= -1 && c <= 255)
76 return locale->locinfo->pctype[c] & type;
78 if (locale->locinfo->mb_cur_max != 1 && c > 0)
80 /* FIXME: Is there a faster way to do this? */
82 char convert[3], *pconv = convert;
84 if (locale->locinfo->pctype[(UINT)c >> 8] & MSVCRT__LEADBYTE)
85 *pconv++ = (UINT)c >> 8;
88 /* FIXME: Use ctype LCID, not lc_all */
89 if (GetStringTypeExA(get_locale()->locinfo->lc_handle[MSVCRT_LC_CTYPE],
90 CT_CTYPE1, convert, convert[1] ? 2 : 1, &typeInfo))
91 return typeInfo & type;
96 /*********************************************************************
99 int CDECL MSVCRT_isalnum(int c)
101 return _isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT );
104 /*********************************************************************
107 int CDECL MSVCRT_isalpha(int c)
109 return _isctype( c, MSVCRT__ALPHA );
112 /*********************************************************************
115 int CDECL MSVCRT_iscntrl(int c)
117 return _isctype( c, MSVCRT__CONTROL );
120 /*********************************************************************
123 int CDECL MSVCRT_isdigit(int c)
125 return _isctype( c, MSVCRT__DIGIT );
128 /*********************************************************************
131 int CDECL MSVCRT_isgraph(int c)
133 return _isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__PUNCT );
136 /*********************************************************************
137 * isleadbyte (MSVCRT.@)
139 int CDECL MSVCRT_isleadbyte(int c)
141 return _isctype( c, MSVCRT__LEADBYTE );
144 /*********************************************************************
147 int CDECL MSVCRT_islower(int c)
149 return _isctype( c, MSVCRT__LOWER );
152 /*********************************************************************
155 int CDECL MSVCRT_isprint(int c)
157 return _isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__BLANK | MSVCRT__PUNCT );
160 /*********************************************************************
163 int CDECL MSVCRT_ispunct(int c)
165 return _isctype( c, MSVCRT__PUNCT );
168 /*********************************************************************
171 int CDECL MSVCRT_isspace(int c)
173 return _isctype( c, MSVCRT__SPACE );
176 /*********************************************************************
179 int CDECL MSVCRT_isupper(int c)
181 return _isctype( c, MSVCRT__UPPER );
184 /*********************************************************************
185 * isxdigit (MSVCRT.@)
187 int CDECL MSVCRT_isxdigit(int c)
189 return _isctype( c, MSVCRT__HEX );
192 /*********************************************************************
193 * __isascii (MSVCRT.@)
195 int CDECL MSVCRT___isascii(int c)
197 return isascii((unsigned)c);
200 /*********************************************************************
201 * __toascii (MSVCRT.@)
203 int CDECL MSVCRT___toascii(int c)
205 return (unsigned)c & 0x7f;
208 /*********************************************************************
209 * iswascii (MSVCRT.@)
212 int CDECL MSVCRT_iswascii(MSVCRT_wchar_t c)
214 return ((unsigned)c < 0x80);
217 /*********************************************************************
218 * __iscsym (MSVCRT.@)
220 int CDECL MSVCRT___iscsym(int c)
222 return (c < 127 && (isalnum(c) || c == '_'));
225 /*********************************************************************
226 * __iscsymf (MSVCRT.@)
228 int CDECL MSVCRT___iscsymf(int c)
230 return (c < 127 && (isalpha(c) || c == '_'));
233 /*********************************************************************
234 * _toupper (MSVCRT.@)
236 int CDECL MSVCRT__toupper(int c)
238 return c - 0x20; /* sic */
241 /*********************************************************************
242 * _tolower (MSVCRT.@)
244 int CDECL MSVCRT__tolower(int c)
246 return c + 0x20; /* sic */