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 /*********************************************************************
69 * _isctype_l (MSVCRT.@)
71 int CDECL
_isctype_l(int c
, int type
, MSVCRT__locale_t locale
)
74 locale
= get_locale();
76 if (c
>= -1 && c
<= 255)
77 return locale
->locinfo
->pctype
[c
] & type
;
79 if (locale
->locinfo
->mb_cur_max
!= 1 && c
> 0)
81 /* FIXME: Is there a faster way to do this? */
83 char convert
[3], *pconv
= convert
;
85 if (locale
->locinfo
->pctype
[(UINT
)c
>> 8] & MSVCRT__LEADBYTE
)
86 *pconv
++ = (UINT
)c
>> 8;
90 if (GetStringTypeExA(locale
->locinfo
->lc_handle
[MSVCRT_LC_CTYPE
],
91 CT_CTYPE1
, convert
, convert
[1] ? 2 : 1, &typeInfo
))
92 return typeInfo
& type
;
97 /*********************************************************************
100 int CDECL
_isctype(int c
, int type
)
102 return _isctype_l(c
, type
, NULL
);
105 /*********************************************************************
108 int CDECL
MSVCRT_isalnum(int c
)
110 return _isctype( c
, MSVCRT__ALPHA
| MSVCRT__DIGIT
);
113 /*********************************************************************
116 int CDECL
MSVCRT_isalpha(int c
)
118 return _isctype( c
, MSVCRT__ALPHA
);
121 /*********************************************************************
124 int CDECL
MSVCRT_iscntrl(int c
)
126 return _isctype( c
, MSVCRT__CONTROL
);
129 /*********************************************************************
132 int CDECL
MSVCRT_isdigit(int c
)
134 return _isctype( c
, MSVCRT__DIGIT
);
137 /*********************************************************************
140 int CDECL
MSVCRT_isgraph(int c
)
142 return _isctype( c
, MSVCRT__ALPHA
| MSVCRT__DIGIT
| MSVCRT__PUNCT
);
145 /*********************************************************************
146 * isleadbyte (MSVCRT.@)
148 int CDECL
MSVCRT_isleadbyte(int c
)
150 return _isctype( c
, MSVCRT__LEADBYTE
);
153 /*********************************************************************
156 int CDECL
MSVCRT_islower(int c
)
158 return _isctype( c
, MSVCRT__LOWER
);
161 /*********************************************************************
164 int CDECL
MSVCRT_isprint(int c
)
166 return _isctype( c
, MSVCRT__ALPHA
| MSVCRT__DIGIT
| MSVCRT__BLANK
| MSVCRT__PUNCT
);
169 /*********************************************************************
172 int CDECL
MSVCRT_ispunct(int c
)
174 return _isctype( c
, MSVCRT__PUNCT
);
177 /*********************************************************************
180 int CDECL
MSVCRT_isspace(int c
)
182 return _isctype( c
, MSVCRT__SPACE
);
185 /*********************************************************************
188 int CDECL
MSVCRT_isupper(int c
)
190 return _isctype( c
, MSVCRT__UPPER
);
193 /*********************************************************************
194 * isxdigit (MSVCRT.@)
196 int CDECL
MSVCRT_isxdigit(int c
)
198 return _isctype( c
, MSVCRT__HEX
);
201 /*********************************************************************
202 * __isascii (MSVCRT.@)
204 int CDECL
MSVCRT___isascii(int c
)
206 return isascii((unsigned)c
);
209 /*********************************************************************
210 * __toascii (MSVCRT.@)
212 int CDECL
MSVCRT___toascii(int c
)
214 return (unsigned)c
& 0x7f;
217 /*********************************************************************
218 * iswascii (MSVCRT.@)
221 int CDECL
MSVCRT_iswascii(MSVCRT_wchar_t c
)
223 return ((unsigned)c
< 0x80);
226 /*********************************************************************
227 * __iscsym (MSVCRT.@)
229 int CDECL
MSVCRT___iscsym(int c
)
231 return (c
< 127 && (isalnum(c
) || c
== '_'));
234 /*********************************************************************
235 * __iscsymf (MSVCRT.@)
237 int CDECL
MSVCRT___iscsymf(int c
)
239 return (c
< 127 && (isalpha(c
) || c
== '_'));
242 /*********************************************************************
243 * _toupper (MSVCRT.@)
245 int CDECL
MSVCRT__toupper(int c
)
247 return c
- 0x20; /* sic */
250 /*********************************************************************
251 * _tolower (MSVCRT.@)
253 int CDECL
MSVCRT__tolower(int c
)
255 return c
+ 0x20; /* sic */