kernel32/tests: Add a test to check some fields in fake dlls.
[wine.git] / dlls / msvcrt / ctype.c
blob3b037aa8de2606eaafb719aabd049bf870923890
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 * _isblank_l (MSVCRT.@)
298 int CDECL MSVCRT__isblank_l(int c, MSVCRT__locale_t locale)
300 return c == '\t' || MSVCRT__isctype_l( c, MSVCRT__BLANK, locale );
303 /*********************************************************************
304 * isblank (MSVCRT.@)
306 int CDECL MSVCRT_isblank(int c)
308 return c == '\t' || MSVCRT__isctype( c, MSVCRT__BLANK );
311 /*********************************************************************
312 * __isascii (MSVCRT.@)
314 int CDECL MSVCRT___isascii(int c)
316 return isascii((unsigned)c);
319 /*********************************************************************
320 * __toascii (MSVCRT.@)
322 int CDECL MSVCRT___toascii(int c)
324 return (unsigned)c & 0x7f;
327 /*********************************************************************
328 * iswascii (MSVCRT.@)
331 int CDECL MSVCRT_iswascii(MSVCRT_wchar_t c)
333 return ((unsigned)c < 0x80);
336 /*********************************************************************
337 * __iscsym (MSVCRT.@)
339 int CDECL MSVCRT___iscsym(int c)
341 return (c < 127 && (isalnum(c) || c == '_'));
344 /*********************************************************************
345 * __iscsymf (MSVCRT.@)
347 int CDECL MSVCRT___iscsymf(int c)
349 return (c < 127 && (isalpha(c) || c == '_'));
352 /*********************************************************************
353 * _toupper_l (MSVCRT.@)
355 int CDECL MSVCRT__toupper_l(int c, MSVCRT__locale_t locale)
357 MSVCRT_pthreadlocinfo locinfo;
358 unsigned char str[2], *p = str;
359 WCHAR wide, upper;
361 if(!locale)
362 locinfo = get_locinfo();
363 else
364 locinfo = locale->locinfo;
366 if((unsigned)c < 256)
367 return locinfo->pcumap[c];
369 if(locinfo->pctype[(c>>8)&255] & MSVCRT__LEADBYTE)
370 *p++ = (c>>8) & 255;
371 else {
372 *MSVCRT__errno() = MSVCRT_EILSEQ;
373 str[1] = 0;
375 *p++ = c & 255;
377 if(!MultiByteToWideChar(locinfo->lc_codepage,
378 MB_ERR_INVALID_CHARS, (char*)str, p-str, &wide, 1))
379 return c;
381 upper = toupperW(wide);
382 if(upper == wide)
383 return str[0] + (str[1]<<8);
385 switch(WideCharToMultiByte(locinfo->lc_codepage, 0,
386 &upper, 1, (char*)str, 2, NULL, NULL)) {
387 case 0:
388 return c;
389 case 1:
390 return str[0];
391 default:
392 return str[0] + (str[1]<<8);
396 /*********************************************************************
397 * toupper (MSVCRT.@)
399 int CDECL MSVCRT_toupper(int c)
401 if(initial_locale)
402 return c>='a' && c<='z' ? c-'a'+'A' : c;
403 return MSVCRT__toupper_l(c, NULL);
406 /*********************************************************************
407 * _toupper (MSVCRT.@)
409 int CDECL MSVCRT__toupper(int c)
411 return c - 0x20; /* sic */
414 /*********************************************************************
415 * _tolower_l (MSVCRT.@)
417 int CDECL MSVCRT__tolower_l(int c, MSVCRT__locale_t locale)
419 MSVCRT_pthreadlocinfo locinfo;
420 unsigned char str[2], *p = str;
421 WCHAR wide, lower;
423 if(!locale)
424 locinfo = get_locinfo();
425 else
426 locinfo = locale->locinfo;
428 if((unsigned)c < 256)
429 return locinfo->pclmap[c];
431 if(locinfo->pctype[(c>>8)&255] & MSVCRT__LEADBYTE)
432 *p++ = (c>>8) & 255;
433 else {
434 *MSVCRT__errno() = MSVCRT_EILSEQ;
435 str[1] = 0;
437 *p++ = c & 255;
439 if(!MultiByteToWideChar(locinfo->lc_codepage,
440 MB_ERR_INVALID_CHARS, (char*)str, p-str, &wide, 1))
441 return c;
443 lower = tolowerW(wide);
444 if(lower == wide)
445 return str[0] + (str[1]<<8);
447 switch(WideCharToMultiByte(locinfo->lc_codepage, 0,
448 &lower, 1, (char*)str, 2, NULL, NULL)) {
449 case 0:
450 return c;
451 case 1:
452 return str[0];
453 default:
454 return str[0] + (str[1]<<8);
458 /*********************************************************************
459 * tolower (MSVCRT.@)
461 int CDECL MSVCRT_tolower(int c)
463 if(initial_locale)
464 return c>='A' && c<='Z' ? c-'A'+'a' : c;
465 return MSVCRT__tolower_l(c, NULL);
468 /*********************************************************************
469 * _tolower (MSVCRT.@)
471 int CDECL MSVCRT__tolower(int c)
473 return c + 0x20; /* sic */
476 #if _MSVCR_VER>=120
477 /*********************************************************************
478 * wctype (MSVCR120.@)
480 unsigned short __cdecl wctype(const char *property)
482 static const struct {
483 const char *name;
484 unsigned short mask;
485 } properties[] = {
486 { "alnum", MSVCRT__DIGIT|MSVCRT__ALPHA },
487 { "alpha", MSVCRT__ALPHA },
488 { "cntrl", MSVCRT__CONTROL },
489 { "digit", MSVCRT__DIGIT },
490 { "graph", MSVCRT__DIGIT|MSVCRT__PUNCT|MSVCRT__ALPHA },
491 { "lower", MSVCRT__LOWER },
492 { "print", MSVCRT__DIGIT|MSVCRT__PUNCT|MSVCRT__BLANK|MSVCRT__ALPHA },
493 { "punct", MSVCRT__PUNCT },
494 { "space", MSVCRT__SPACE },
495 { "upper", MSVCRT__UPPER },
496 { "xdigit", MSVCRT__HEX }
498 unsigned int i;
500 for(i=0; i<ARRAY_SIZE(properties); i++)
501 if(!strcmp(property, properties[i].name))
502 return properties[i].mask;
504 return 0;
506 #endif