include: Define _WIN64 on sparc/powerpc64.
[wine.git] / dlls / msvcrt / ctype.c
blobca8b5fdae38efee2cf2735081d8b7403530f9784
1 /*
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
21 #include "msvcrt.h"
22 #include "winnls.h"
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 /*********************************************************************
55 * __p__pctype (MSVCRT.@)
57 unsigned short** CDECL MSVCRT___p__pctype(void)
59 return &get_locinfo()->pctype;
62 /*********************************************************************
63 * __pctype_func (MSVCRT.@)
65 const unsigned short* CDECL MSVCRT___pctype_func(void)
67 return get_locinfo()->pctype;
70 /*********************************************************************
71 * _isctype_l (MSVCRT.@)
73 int CDECL MSVCRT__isctype_l(int c, int type, MSVCRT__locale_t locale)
75 MSVCRT_pthreadlocinfo locinfo;
77 if(!locale)
78 locinfo = get_locinfo();
79 else
80 locinfo = locale->locinfo;
82 if (c >= -1 && c <= 255)
83 return locinfo->pctype[c] & type;
85 if (locinfo->mb_cur_max != 1 && c > 0)
87 /* FIXME: Is there a faster way to do this? */
88 WORD typeInfo;
89 char convert[3], *pconv = convert;
91 if (locinfo->pctype[(UINT)c >> 8] & MSVCRT__LEADBYTE)
92 *pconv++ = (UINT)c >> 8;
93 *pconv++ = c & 0xff;
94 *pconv = 0;
96 if (GetStringTypeExA(locinfo->lc_handle[MSVCRT_LC_CTYPE],
97 CT_CTYPE1, convert, convert[1] ? 2 : 1, &typeInfo))
98 return typeInfo & type;
100 return 0;
103 /*********************************************************************
104 * _isctype (MSVCRT.@)
106 int CDECL MSVCRT__isctype(int c, int type)
108 return MSVCRT__isctype_l(c, type, NULL);
111 /*********************************************************************
112 * _isalnum_l (MSVCRT.@)
114 int CDECL MSVCRT__isalnum_l(int c, MSVCRT__locale_t locale)
116 return MSVCRT__isctype_l( c, MSVCRT__ALPHA | MSVCRT__DIGIT, locale );
119 /*********************************************************************
120 * isalnum (MSVCRT.@)
122 int CDECL MSVCRT_isalnum(int c)
124 return MSVCRT__isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT );
127 /*********************************************************************
128 * _isalpha_l (MSVCRT.@)
130 int CDECL MSVCRT__isalpha_l(int c, MSVCRT__locale_t locale)
132 return MSVCRT__isctype_l( c, MSVCRT__ALPHA, locale );
135 /*********************************************************************
136 * isalpha (MSVCRT.@)
138 int CDECL MSVCRT_isalpha(int c)
140 return MSVCRT__isctype( c, MSVCRT__ALPHA );
143 /*********************************************************************
144 * _iscntrl_l (MSVCRT.@)
146 int CDECL MSVCRT__iscntrl_l(int c, MSVCRT__locale_t locale)
148 return MSVCRT__isctype_l( c, MSVCRT__CONTROL, locale );
151 /*********************************************************************
152 * iscntrl (MSVCRT.@)
154 int CDECL MSVCRT_iscntrl(int c)
156 return MSVCRT__isctype( c, MSVCRT__CONTROL );
159 /*********************************************************************
160 * _isdigit_l (MSVCRT.@)
162 int CDECL MSVCRT__isdigit_l(int c, MSVCRT__locale_t locale)
164 return MSVCRT__isctype_l( c, MSVCRT__DIGIT, locale );
167 /*********************************************************************
168 * isdigit (MSVCRT.@)
170 int CDECL MSVCRT_isdigit(int c)
172 return MSVCRT__isctype( c, MSVCRT__DIGIT );
175 /*********************************************************************
176 * _isgraph_l (MSVCRT.@)
178 int CDECL MSVCRT__isgraph_l(int c, MSVCRT__locale_t locale)
180 return MSVCRT__isctype_l( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__PUNCT, locale );
183 /*********************************************************************
184 * isgraph (MSVCRT.@)
186 int CDECL MSVCRT_isgraph(int c)
188 return MSVCRT__isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__PUNCT );
191 /*********************************************************************
192 * _isleadbyte_l (MSVCRT.@)
194 int CDECL MSVCRT__isleadbyte_l(int c, MSVCRT__locale_t locale)
196 return MSVCRT__isctype_l( c, MSVCRT__LEADBYTE, locale );
199 /*********************************************************************
200 * isleadbyte (MSVCRT.@)
202 int CDECL MSVCRT_isleadbyte(int c)
204 return MSVCRT__isctype( c, MSVCRT__LEADBYTE );
207 /*********************************************************************
208 * _islower_l (MSVCRT.@)
210 int CDECL MSVCRT__islower_l(int c, MSVCRT__locale_t locale)
212 return MSVCRT__isctype_l( c, MSVCRT__LOWER, locale );
215 /*********************************************************************
216 * islower (MSVCRT.@)
218 int CDECL MSVCRT_islower(int c)
220 return MSVCRT__isctype( c, MSVCRT__LOWER );
223 /*********************************************************************
224 * _isprint_l (MSVCRT.@)
226 int CDECL MSVCRT__isprint_l(int c, MSVCRT__locale_t locale)
228 return MSVCRT__isctype_l( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__BLANK | MSVCRT__PUNCT, locale );
231 /*********************************************************************
232 * isprint (MSVCRT.@)
234 int CDECL MSVCRT_isprint(int c)
236 return MSVCRT__isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__BLANK | MSVCRT__PUNCT );
239 /*********************************************************************
240 * ispunct (MSVCRT.@)
242 int CDECL MSVCRT_ispunct(int c)
244 return MSVCRT__isctype( c, MSVCRT__PUNCT );
247 /*********************************************************************
248 * _isspace_l (MSVCRT.@)
250 int CDECL MSVCRT__isspace_l(int c, MSVCRT__locale_t locale)
252 return MSVCRT__isctype_l( c, MSVCRT__SPACE, locale );
255 /*********************************************************************
256 * isspace (MSVCRT.@)
258 int CDECL MSVCRT_isspace(int c)
260 return MSVCRT__isctype( c, MSVCRT__SPACE );
263 /*********************************************************************
264 * _isupper_l (MSVCRT.@)
266 int CDECL MSVCRT__isupper_l(int c, MSVCRT__locale_t locale)
268 return MSVCRT__isctype_l( c, MSVCRT__UPPER, locale );
271 /*********************************************************************
272 * isupper (MSVCRT.@)
274 int CDECL MSVCRT_isupper(int c)
276 return MSVCRT__isctype( c, MSVCRT__UPPER );
279 /*********************************************************************
280 * _isxdigit_l (MSVCRT.@)
282 int CDECL MSVCRT__isxdigit_l(int c, MSVCRT__locale_t locale)
284 return MSVCRT__isctype_l( c, MSVCRT__HEX, locale );
287 /*********************************************************************
288 * isxdigit (MSVCRT.@)
290 int CDECL MSVCRT_isxdigit(int c)
292 return MSVCRT__isctype( c, MSVCRT__HEX );
295 /*********************************************************************
296 * __isascii (MSVCRT.@)
298 int CDECL MSVCRT___isascii(int c)
300 return isascii((unsigned)c);
303 /*********************************************************************
304 * __toascii (MSVCRT.@)
306 int CDECL MSVCRT___toascii(int c)
308 return (unsigned)c & 0x7f;
311 /*********************************************************************
312 * iswascii (MSVCRT.@)
315 int CDECL MSVCRT_iswascii(MSVCRT_wchar_t c)
317 return ((unsigned)c < 0x80);
320 /*********************************************************************
321 * __iscsym (MSVCRT.@)
323 int CDECL MSVCRT___iscsym(int c)
325 return (c < 127 && (isalnum(c) || c == '_'));
328 /*********************************************************************
329 * __iscsymf (MSVCRT.@)
331 int CDECL MSVCRT___iscsymf(int c)
333 return (c < 127 && (isalpha(c) || c == '_'));
336 /*********************************************************************
337 * _toupper_l (MSVCRT.@)
339 int CDECL MSVCRT__toupper_l(int c, MSVCRT__locale_t locale)
341 MSVCRT_pthreadlocinfo locinfo;
343 if(!locale)
344 locinfo = get_locinfo();
345 else
346 locinfo = locale->locinfo;
348 if(c < 256)
349 return locinfo->pcumap[(unsigned char)c];
351 if(locinfo->pctype[(c>>8)&255] & MSVCRT__LEADBYTE)
353 WCHAR wide, upper;
354 char str[2], *p = str;
355 *p++ = (c>>8) & 255;
356 *p++ = c & 255;
358 if(!MultiByteToWideChar(locinfo->lc_codepage,
359 MB_ERR_INVALID_CHARS, str, 2, &wide, 1))
360 return c;
362 upper = toupperW(wide);
363 if(upper == wide)
364 return c;
366 WideCharToMultiByte(locinfo->lc_codepage, 0,
367 &upper, 1, str, 2, NULL, NULL);
369 return str[0] + (str[1]<<8);
372 return c;
375 /*********************************************************************
376 * toupper (MSVCRT.@)
378 int CDECL MSVCRT_toupper(int c)
380 return MSVCRT__toupper_l(c, NULL);
383 /*********************************************************************
384 * _toupper (MSVCRT.@)
386 int CDECL MSVCRT__toupper(int c)
388 return c - 0x20; /* sic */
391 /*********************************************************************
392 * _tolower_l (MSVCRT.@)
394 int CDECL MSVCRT__tolower_l(int c, MSVCRT__locale_t locale)
396 MSVCRT_pthreadlocinfo locinfo;
398 if(!locale)
399 locinfo = get_locinfo();
400 else
401 locinfo = locale->locinfo;
403 if(c < 256)
404 return locinfo->pclmap[(unsigned char)c];
406 if(locinfo->pctype[(c>>8)&255] & MSVCRT__LEADBYTE)
408 WCHAR wide, upper;
409 char str[2], *p = str;
410 *p++ = (c>>8) & 255;
411 *p++ = c & 255;
413 if(!MultiByteToWideChar(locinfo->lc_codepage,
414 MB_ERR_INVALID_CHARS, str, 2, &wide, 1))
415 return c;
417 upper = tolowerW(wide);
418 if(upper == wide)
419 return c;
421 WideCharToMultiByte(locinfo->lc_codepage, 0,
422 &upper, 1, str, 2, NULL, NULL);
424 return str[0] + (str[1]<<8);
427 return c;
430 /*********************************************************************
431 * tolower (MSVCRT.@)
433 int CDECL MSVCRT_tolower(int c)
435 return MSVCRT__tolower_l(c, NULL);
438 /*********************************************************************
439 * _tolower (MSVCRT.@)
441 int CDECL MSVCRT__tolower(int c)
443 return c + 0x20; /* sic */