d3dx9/tests: Add tests for D3DXLoadMeshHierarchyFromXInMemory.
[wine.git] / dlls / msvcrt / ctype.c
blob2805afb30ccaccb8e8b8d9b7d7e2e5434d00f61f
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 /* 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 * __pctype_func (MSVCRT.@)
64 const unsigned short* CDECL MSVCRT___pctype_func(void)
66 return get_locinfo()->pctype;
69 /*********************************************************************
70 * _isctype_l (MSVCRT.@)
72 int CDECL MSVCRT__isctype_l(int c, int type, MSVCRT__locale_t locale)
74 MSVCRT_pthreadlocinfo locinfo;
76 if(!locale)
77 locinfo = get_locinfo();
78 else
79 locinfo = locale->locinfo;
81 if (c >= -1 && c <= 255)
82 return locinfo->pctype[c] & type;
84 if (locinfo->mb_cur_max != 1 && c > 0)
86 /* FIXME: Is there a faster way to do this? */
87 WORD typeInfo;
88 char convert[3], *pconv = convert;
90 if (locinfo->pctype[(UINT)c >> 8] & MSVCRT__LEADBYTE)
91 *pconv++ = (UINT)c >> 8;
92 *pconv++ = c & 0xff;
93 *pconv = 0;
95 if (GetStringTypeExA(locinfo->lc_handle[MSVCRT_LC_CTYPE],
96 CT_CTYPE1, convert, convert[1] ? 2 : 1, &typeInfo))
97 return typeInfo & type;
99 return 0;
102 /*********************************************************************
103 * _isctype (MSVCRT.@)
105 int CDECL MSVCRT__isctype(int c, int type)
107 return MSVCRT__isctype_l(c, type, NULL);
110 /*********************************************************************
111 * _isalnum_l (MSVCRT.@)
113 int CDECL MSVCRT__isalnum_l(int c, MSVCRT__locale_t locale)
115 return MSVCRT__isctype_l( c, MSVCRT__ALPHA | MSVCRT__DIGIT, locale );
118 /*********************************************************************
119 * isalnum (MSVCRT.@)
121 int CDECL MSVCRT_isalnum(int c)
123 return MSVCRT__isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT );
126 /*********************************************************************
127 * _isalpha_l (MSVCRT.@)
129 int CDECL MSVCRT__isalpha_l(int c, MSVCRT__locale_t locale)
131 return MSVCRT__isctype_l( c, MSVCRT__ALPHA, locale );
134 /*********************************************************************
135 * isalpha (MSVCRT.@)
137 int CDECL MSVCRT_isalpha(int c)
139 return MSVCRT__isctype( c, MSVCRT__ALPHA );
142 /*********************************************************************
143 * _iscntrl_l (MSVCRT.@)
145 int CDECL MSVCRT__iscntrl_l(int c, MSVCRT__locale_t locale)
147 return MSVCRT__isctype_l( c, MSVCRT__CONTROL, locale );
150 /*********************************************************************
151 * iscntrl (MSVCRT.@)
153 int CDECL MSVCRT_iscntrl(int c)
155 return MSVCRT__isctype( c, MSVCRT__CONTROL );
158 /*********************************************************************
159 * _isdigit_l (MSVCRT.@)
161 int CDECL MSVCRT__isdigit_l(int c, MSVCRT__locale_t locale)
163 return MSVCRT__isctype_l( c, MSVCRT__DIGIT, locale );
166 /*********************************************************************
167 * isdigit (MSVCRT.@)
169 int CDECL MSVCRT_isdigit(int c)
171 return MSVCRT__isctype( c, MSVCRT__DIGIT );
174 /*********************************************************************
175 * _isgraph_l (MSVCRT.@)
177 int CDECL MSVCRT__isgraph_l(int c, MSVCRT__locale_t locale)
179 return MSVCRT__isctype_l( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__PUNCT, locale );
182 /*********************************************************************
183 * isgraph (MSVCRT.@)
185 int CDECL MSVCRT_isgraph(int c)
187 return MSVCRT__isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__PUNCT );
190 /*********************************************************************
191 * _isleadbyte_l (MSVCRT.@)
193 int CDECL MSVCRT__isleadbyte_l(int c, MSVCRT__locale_t locale)
195 return MSVCRT__isctype_l( c, MSVCRT__LEADBYTE, locale );
198 /*********************************************************************
199 * isleadbyte (MSVCRT.@)
201 int CDECL MSVCRT_isleadbyte(int c)
203 return MSVCRT__isctype( c, MSVCRT__LEADBYTE );
206 /*********************************************************************
207 * _islower_l (MSVCRT.@)
209 int CDECL MSVCRT__islower_l(int c, MSVCRT__locale_t locale)
211 return MSVCRT__isctype_l( c, MSVCRT__LOWER, locale );
214 /*********************************************************************
215 * islower (MSVCRT.@)
217 int CDECL MSVCRT_islower(int c)
219 return MSVCRT__isctype( c, MSVCRT__LOWER );
222 /*********************************************************************
223 * _isprint_l (MSVCRT.@)
225 int CDECL MSVCRT__isprint_l(int c, MSVCRT__locale_t locale)
227 return MSVCRT__isctype_l( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__BLANK | MSVCRT__PUNCT, locale );
230 /*********************************************************************
231 * isprint (MSVCRT.@)
233 int CDECL MSVCRT_isprint(int c)
235 return MSVCRT__isctype( c, MSVCRT__ALPHA | MSVCRT__DIGIT | MSVCRT__BLANK | MSVCRT__PUNCT );
238 /*********************************************************************
239 * ispunct (MSVCRT.@)
241 int CDECL MSVCRT_ispunct(int c)
243 return MSVCRT__isctype( c, MSVCRT__PUNCT );
246 /*********************************************************************
247 * _isspace_l (MSVCRT.@)
249 int CDECL MSVCRT__isspace_l(int c, MSVCRT__locale_t locale)
251 return MSVCRT__isctype_l( c, MSVCRT__SPACE, locale );
254 /*********************************************************************
255 * isspace (MSVCRT.@)
257 int CDECL MSVCRT_isspace(int c)
259 return MSVCRT__isctype( c, MSVCRT__SPACE );
262 /*********************************************************************
263 * _isupper_l (MSVCRT.@)
265 int CDECL MSVCRT__isupper_l(int c, MSVCRT__locale_t locale)
267 return MSVCRT__isctype_l( c, MSVCRT__UPPER, locale );
270 /*********************************************************************
271 * isupper (MSVCRT.@)
273 int CDECL MSVCRT_isupper(int c)
275 return MSVCRT__isctype( c, MSVCRT__UPPER );
278 /*********************************************************************
279 * _isxdigit_l (MSVCRT.@)
281 int CDECL MSVCRT__isxdigit_l(int c, MSVCRT__locale_t locale)
283 return MSVCRT__isctype_l( c, MSVCRT__HEX, locale );
286 /*********************************************************************
287 * isxdigit (MSVCRT.@)
289 int CDECL MSVCRT_isxdigit(int c)
291 return MSVCRT__isctype( c, MSVCRT__HEX );
294 /*********************************************************************
295 * __isascii (MSVCRT.@)
297 int CDECL MSVCRT___isascii(int c)
299 return isascii((unsigned)c);
302 /*********************************************************************
303 * __toascii (MSVCRT.@)
305 int CDECL MSVCRT___toascii(int c)
307 return (unsigned)c & 0x7f;
310 /*********************************************************************
311 * iswascii (MSVCRT.@)
314 int CDECL MSVCRT_iswascii(MSVCRT_wchar_t c)
316 return ((unsigned)c < 0x80);
319 /*********************************************************************
320 * __iscsym (MSVCRT.@)
322 int CDECL MSVCRT___iscsym(int c)
324 return (c < 127 && (isalnum(c) || c == '_'));
327 /*********************************************************************
328 * __iscsymf (MSVCRT.@)
330 int CDECL MSVCRT___iscsymf(int c)
332 return (c < 127 && (isalpha(c) || c == '_'));
335 /*********************************************************************
336 * _toupper_l (MSVCRT.@)
338 int CDECL MSVCRT__toupper_l(int c, MSVCRT__locale_t locale)
340 MSVCRT_pthreadlocinfo locinfo;
342 if(!locale)
343 locinfo = get_locinfo();
344 else
345 locinfo = locale->locinfo;
347 if(c < 256)
348 return locinfo->pcumap[(unsigned char)c];
350 if(locinfo->pctype[(c>>8)&255] & MSVCRT__LEADBYTE)
352 WCHAR wide, upper;
353 char str[2], *p = str;
354 *p++ = (c>>8) & 255;
355 *p++ = c & 255;
357 if(!MultiByteToWideChar(locinfo->lc_codepage,
358 MB_ERR_INVALID_CHARS, str, 2, &wide, 1))
359 return c;
361 upper = toupperW(wide);
362 if(upper == wide)
363 return c;
365 WideCharToMultiByte(locinfo->lc_codepage, 0,
366 &upper, 1, str, 2, NULL, NULL);
368 return str[0] + (str[1]<<8);
371 return c;
374 /*********************************************************************
375 * toupper (MSVCRT.@)
377 int CDECL MSVCRT_toupper(int c)
379 return MSVCRT__toupper_l(c, NULL);
382 /*********************************************************************
383 * _toupper (MSVCRT.@)
385 int CDECL MSVCRT__toupper(int c)
387 return c - 0x20; /* sic */
390 /*********************************************************************
391 * _tolower_l (MSVCRT.@)
393 int CDECL MSVCRT__tolower_l(int c, MSVCRT__locale_t locale)
395 MSVCRT_pthreadlocinfo locinfo;
397 if(!locale)
398 locinfo = get_locinfo();
399 else
400 locinfo = locale->locinfo;
402 if(c < 256)
403 return locinfo->pclmap[(unsigned char)c];
405 if(locinfo->pctype[(c>>8)&255] & MSVCRT__LEADBYTE)
407 WCHAR wide, upper;
408 char str[2], *p = str;
409 *p++ = (c>>8) & 255;
410 *p++ = c & 255;
412 if(!MultiByteToWideChar(locinfo->lc_codepage,
413 MB_ERR_INVALID_CHARS, str, 2, &wide, 1))
414 return c;
416 upper = tolowerW(wide);
417 if(upper == wide)
418 return c;
420 WideCharToMultiByte(locinfo->lc_codepage, 0,
421 &upper, 1, str, 2, NULL, NULL);
423 return str[0] + (str[1]<<8);
426 return c;
429 /*********************************************************************
430 * tolower (MSVCRT.@)
432 int CDECL MSVCRT_tolower(int c)
434 return MSVCRT__tolower_l(c, NULL);
437 /*********************************************************************
438 * _tolower (MSVCRT.@)
440 int CDECL MSVCRT__tolower(int c)
442 return c + 0x20; /* sic */