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/unicode.h"
25 /* Some abbreviations to make the following table readable */
26 #define _C_ MSVCRT__CONTROL
27 #define _S_ MSVCRT__SPACE
28 #define _P_ MSVCRT__PUNCT
29 #define _D_ MSVCRT__DIGIT
30 #define _H_ MSVCRT__HEX
31 #define _U_ MSVCRT__UPPER
32 #define _L_ MSVCRT__LOWER
34 WORD MSVCRT__ctype
[257] = {
35 0, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _S_
|_C_
, _S_
|_C_
,
36 _S_
|_C_
, _S_
|_C_
, _S_
|_C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
,
37 _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _S_
|MSVCRT__BLANK
,
38 _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
,
39 _P_
, _D_
|_H_
, _D_
|_H_
, _D_
|_H_
, _D_
|_H_
, _D_
|_H_
, _D_
|_H_
, _D_
|_H_
,
40 _D_
|_H_
, _D_
|_H_
, _D_
|_H_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _U_
|_H_
,
41 _U_
|_H_
, _U_
|_H_
, _U_
|_H_
, _U_
|_H_
, _U_
|_H_
, _U_
, _U_
, _U_
, _U_
, _U_
,
42 _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
,
43 _U_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _L_
|_H_
, _L_
|_H_
, _L_
|_H_
, _L_
|_H_
,
44 _L_
|_H_
, _L_
|_H_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
,
45 _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _P_
, _P_
, _P_
, _P_
,
46 _C_
, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
54 /* pctype is used by macros in the Win32 headers. It must point
55 * To a table of flags exactly like ctype. To allow locale
56 * changes to affect ctypes (i.e. isleadbyte), we use a second table
57 * and update its flags whenever the current locale changes.
59 unsigned short *MSVCRT__pctype
= NULL
;
61 /*********************************************************************
62 * __p__pctype (MSVCRT.@)
64 unsigned short** CDECL
MSVCRT___p__pctype(void)
66 return &get_locinfo()->pctype
;
69 /*********************************************************************
70 * __pctype_func (MSVCRT.@)
72 const unsigned short* CDECL
MSVCRT___pctype_func(void)
74 return get_locinfo()->pctype
;
77 /*********************************************************************
78 * _isctype_l (MSVCRT.@)
80 int CDECL
MSVCRT__isctype_l(int c
, int type
, MSVCRT__locale_t locale
)
82 MSVCRT_pthreadlocinfo locinfo
;
85 locinfo
= get_locinfo();
87 locinfo
= locale
->locinfo
;
89 if (c
>= -1 && c
<= 255)
90 return locinfo
->pctype
[c
] & type
;
92 if (locinfo
->mb_cur_max
!= 1 && c
> 0)
94 /* FIXME: Is there a faster way to do this? */
96 char convert
[3], *pconv
= convert
;
98 if (locinfo
->pctype
[(UINT
)c
>> 8] & MSVCRT__LEADBYTE
)
99 *pconv
++ = (UINT
)c
>> 8;
103 if (GetStringTypeExA(locinfo
->lc_handle
[MSVCRT_LC_CTYPE
],
104 CT_CTYPE1
, convert
, convert
[1] ? 2 : 1, &typeInfo
))
105 return typeInfo
& type
;
110 /*********************************************************************
111 * _isctype (MSVCRT.@)
113 int CDECL
MSVCRT__isctype(int c
, int type
)
115 return MSVCRT__isctype_l(c
, type
, NULL
);
118 /*********************************************************************
119 * _isalnum_l (MSVCRT.@)
121 int CDECL
MSVCRT__isalnum_l(int c
, MSVCRT__locale_t locale
)
123 return MSVCRT__isctype_l( c
, MSVCRT__ALPHA
| MSVCRT__DIGIT
, locale
);
126 /*********************************************************************
129 int CDECL
MSVCRT_isalnum(int c
)
131 return MSVCRT__isctype( c
, MSVCRT__ALPHA
| MSVCRT__DIGIT
);
134 /*********************************************************************
135 * _isalpha_l (MSVCRT.@)
137 int CDECL
MSVCRT__isalpha_l(int c
, MSVCRT__locale_t locale
)
139 return MSVCRT__isctype_l( c
, MSVCRT__ALPHA
, locale
);
142 /*********************************************************************
145 int CDECL
MSVCRT_isalpha(int c
)
147 return MSVCRT__isctype( c
, MSVCRT__ALPHA
);
150 /*********************************************************************
151 * _iscntrl_l (MSVCRT.@)
153 int CDECL
MSVCRT__iscntrl_l(int c
, MSVCRT__locale_t locale
)
155 return MSVCRT__isctype_l( c
, MSVCRT__CONTROL
, locale
);
158 /*********************************************************************
161 int CDECL
MSVCRT_iscntrl(int c
)
163 return MSVCRT__isctype( c
, MSVCRT__CONTROL
);
166 /*********************************************************************
167 * _isdigit_l (MSVCRT.@)
169 int CDECL
MSVCRT__isdigit_l(int c
, MSVCRT__locale_t locale
)
171 return MSVCRT__isctype_l( c
, MSVCRT__DIGIT
, locale
);
174 /*********************************************************************
177 int CDECL
MSVCRT_isdigit(int c
)
179 return MSVCRT__isctype( c
, MSVCRT__DIGIT
);
182 /*********************************************************************
183 * _isgraph_l (MSVCRT.@)
185 int CDECL
MSVCRT__isgraph_l(int c
, MSVCRT__locale_t locale
)
187 return MSVCRT__isctype_l( c
, MSVCRT__ALPHA
| MSVCRT__DIGIT
| MSVCRT__PUNCT
, locale
);
190 /*********************************************************************
193 int CDECL
MSVCRT_isgraph(int c
)
195 return MSVCRT__isctype( c
, MSVCRT__ALPHA
| MSVCRT__DIGIT
| MSVCRT__PUNCT
);
198 /*********************************************************************
199 * _isleadbyte_l (MSVCRT.@)
201 int CDECL
MSVCRT__isleadbyte_l(int c
, MSVCRT__locale_t locale
)
203 return MSVCRT__isctype_l( c
, MSVCRT__LEADBYTE
, locale
);
206 /*********************************************************************
207 * isleadbyte (MSVCRT.@)
209 int CDECL
MSVCRT_isleadbyte(int c
)
211 return MSVCRT__isctype( c
, MSVCRT__LEADBYTE
);
214 /*********************************************************************
215 * _islower_l (MSVCRT.@)
217 int CDECL
MSVCRT__islower_l(int c
, MSVCRT__locale_t locale
)
219 return MSVCRT__isctype_l( c
, MSVCRT__LOWER
, locale
);
222 /*********************************************************************
225 int CDECL
MSVCRT_islower(int c
)
227 return MSVCRT__isctype( c
, MSVCRT__LOWER
);
230 /*********************************************************************
231 * _isprint_l (MSVCRT.@)
233 int CDECL
MSVCRT__isprint_l(int c
, MSVCRT__locale_t locale
)
235 return MSVCRT__isctype_l( c
, MSVCRT__ALPHA
| MSVCRT__DIGIT
| MSVCRT__BLANK
| MSVCRT__PUNCT
, locale
);
238 /*********************************************************************
241 int CDECL
MSVCRT_isprint(int c
)
243 return MSVCRT__isctype( c
, MSVCRT__ALPHA
| MSVCRT__DIGIT
| MSVCRT__BLANK
| MSVCRT__PUNCT
);
246 /*********************************************************************
249 int CDECL
MSVCRT_ispunct(int c
)
251 return MSVCRT__isctype( c
, MSVCRT__PUNCT
);
254 /*********************************************************************
255 * _isspace_l (MSVCRT.@)
257 int CDECL
MSVCRT__isspace_l(int c
, MSVCRT__locale_t locale
)
259 return MSVCRT__isctype_l( c
, MSVCRT__SPACE
, locale
);
262 /*********************************************************************
265 int CDECL
MSVCRT_isspace(int c
)
267 return MSVCRT__isctype( c
, MSVCRT__SPACE
);
270 /*********************************************************************
271 * _isupper_l (MSVCRT.@)
273 int CDECL
MSVCRT__isupper_l(int c
, MSVCRT__locale_t locale
)
275 return MSVCRT__isctype_l( c
, MSVCRT__UPPER
, locale
);
278 /*********************************************************************
281 int CDECL
MSVCRT_isupper(int c
)
283 return MSVCRT__isctype( c
, MSVCRT__UPPER
);
286 /*********************************************************************
287 * _isxdigit_l (MSVCRT.@)
289 int CDECL
MSVCRT__isxdigit_l(int c
, MSVCRT__locale_t locale
)
291 return MSVCRT__isctype_l( c
, MSVCRT__HEX
, locale
);
294 /*********************************************************************
295 * isxdigit (MSVCRT.@)
297 int CDECL
MSVCRT_isxdigit(int c
)
299 return MSVCRT__isctype( c
, MSVCRT__HEX
);
302 /*********************************************************************
303 * __isascii (MSVCRT.@)
305 int CDECL
MSVCRT___isascii(int c
)
307 return isascii((unsigned)c
);
310 /*********************************************************************
311 * __toascii (MSVCRT.@)
313 int CDECL
MSVCRT___toascii(int c
)
315 return (unsigned)c
& 0x7f;
318 /*********************************************************************
319 * iswascii (MSVCRT.@)
322 int CDECL
MSVCRT_iswascii(MSVCRT_wchar_t c
)
324 return ((unsigned)c
< 0x80);
327 /*********************************************************************
328 * __iscsym (MSVCRT.@)
330 int CDECL
MSVCRT___iscsym(int c
)
332 return (c
< 127 && (isalnum(c
) || c
== '_'));
335 /*********************************************************************
336 * __iscsymf (MSVCRT.@)
338 int CDECL
MSVCRT___iscsymf(int c
)
340 return (c
< 127 && (isalpha(c
) || c
== '_'));
343 /*********************************************************************
344 * _toupper_l (MSVCRT.@)
346 int CDECL
MSVCRT__toupper_l(int c
, MSVCRT__locale_t locale
)
348 MSVCRT_pthreadlocinfo locinfo
;
351 locinfo
= get_locinfo();
353 locinfo
= locale
->locinfo
;
356 return locinfo
->pcumap
[(unsigned char)c
];
358 if(locinfo
->pctype
[(c
>>8)&255] & MSVCRT__LEADBYTE
)
361 char str
[2], *p
= str
;
365 if(!MultiByteToWideChar(locinfo
->lc_codepage
,
366 MB_ERR_INVALID_CHARS
, str
, 2, &wide
, 1))
369 upper
= toupperW(wide
);
373 WideCharToMultiByte(locinfo
->lc_codepage
, 0,
374 &upper
, 1, str
, 2, NULL
, NULL
);
376 return str
[0] + (str
[1]<<8);
382 /*********************************************************************
385 int CDECL
MSVCRT_toupper(int c
)
387 return MSVCRT__toupper_l(c
, NULL
);
390 /*********************************************************************
391 * _toupper (MSVCRT.@)
393 int CDECL
MSVCRT__toupper(int c
)
395 return c
- 0x20; /* sic */
398 /*********************************************************************
399 * _tolower_l (MSVCRT.@)
401 int CDECL
MSVCRT__tolower_l(int c
, MSVCRT__locale_t locale
)
403 MSVCRT_pthreadlocinfo locinfo
;
406 locinfo
= get_locinfo();
408 locinfo
= locale
->locinfo
;
411 return locinfo
->pclmap
[(unsigned char)c
];
413 if(locinfo
->pctype
[(c
>>8)&255] & MSVCRT__LEADBYTE
)
416 char str
[2], *p
= str
;
420 if(!MultiByteToWideChar(locinfo
->lc_codepage
,
421 MB_ERR_INVALID_CHARS
, str
, 2, &wide
, 1))
424 upper
= tolowerW(wide
);
428 WideCharToMultiByte(locinfo
->lc_codepage
, 0,
429 &upper
, 1, str
, 2, NULL
, NULL
);
431 return str
[0] + (str
[1]<<8);
437 /*********************************************************************
440 int CDECL
MSVCRT_tolower(int c
)
442 return MSVCRT__tolower_l(c
, NULL
);
445 /*********************************************************************
446 * _tolower (MSVCRT.@)
448 int CDECL
MSVCRT__tolower(int c
)
450 return c
+ 0x20; /* sic */