msvcrt: Don't include MSVC 8.0+ string functions in SOs for older DLLs.
[wine.git] / dlls / msvcrt / ctype.c
blob2c39a566867d5646561c48a04c8284980ec4d092
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 return MSVCRT__toupper_l(c, NULL);
404 /*********************************************************************
405 * _toupper (MSVCRT.@)
407 int CDECL MSVCRT__toupper(int c)
409 return c - 0x20; /* sic */
412 /*********************************************************************
413 * _tolower_l (MSVCRT.@)
415 int CDECL MSVCRT__tolower_l(int c, MSVCRT__locale_t locale)
417 MSVCRT_pthreadlocinfo locinfo;
418 unsigned char str[2], *p = str;
419 WCHAR wide, lower;
421 if(!locale)
422 locinfo = get_locinfo();
423 else
424 locinfo = locale->locinfo;
426 if((unsigned)c < 256)
427 return locinfo->pclmap[c];
429 if(locinfo->pctype[(c>>8)&255] & MSVCRT__LEADBYTE)
430 *p++ = (c>>8) & 255;
431 else {
432 *MSVCRT__errno() = MSVCRT_EILSEQ;
433 str[1] = 0;
435 *p++ = c & 255;
437 if(!MultiByteToWideChar(locinfo->lc_codepage,
438 MB_ERR_INVALID_CHARS, (char*)str, p-str, &wide, 1))
439 return c;
441 lower = tolowerW(wide);
442 if(lower == wide)
443 return str[0] + (str[1]<<8);
445 switch(WideCharToMultiByte(locinfo->lc_codepage, 0,
446 &lower, 1, (char*)str, 2, NULL, NULL)) {
447 case 0:
448 return c;
449 case 1:
450 return str[0];
451 default:
452 return str[0] + (str[1]<<8);
456 /*********************************************************************
457 * tolower (MSVCRT.@)
459 int CDECL MSVCRT_tolower(int c)
461 return MSVCRT__tolower_l(c, NULL);
464 /*********************************************************************
465 * _tolower (MSVCRT.@)
467 int CDECL MSVCRT__tolower(int c)
469 return c + 0x20; /* sic */
472 #if _MSVCR_VER>=120
473 /*********************************************************************
474 * wctype (MSVCR120.@)
476 unsigned short __cdecl wctype(const char *property)
478 static const struct {
479 const char *name;
480 unsigned short mask;
481 } properties[] = {
482 { "alnum", MSVCRT__DIGIT|MSVCRT__ALPHA },
483 { "alpha", MSVCRT__ALPHA },
484 { "cntrl", MSVCRT__CONTROL },
485 { "digit", MSVCRT__DIGIT },
486 { "graph", MSVCRT__DIGIT|MSVCRT__PUNCT|MSVCRT__ALPHA },
487 { "lower", MSVCRT__LOWER },
488 { "print", MSVCRT__DIGIT|MSVCRT__PUNCT|MSVCRT__BLANK|MSVCRT__ALPHA },
489 { "punct", MSVCRT__PUNCT },
490 { "space", MSVCRT__SPACE },
491 { "upper", MSVCRT__UPPER },
492 { "xdigit", MSVCRT__HEX }
494 unsigned int i;
496 for(i=0; i<sizeof(properties)/sizeof(properties[0]); i++)
497 if(!strcmp(property, properties[i].name))
498 return properties[i].mask;
500 return 0;
502 #endif