2 * msvcrt.dll ctype functions
4 * Copyright 2000 Jon Griffiths
8 DEFAULT_DEBUG_CHANNEL(msvcrt
);
10 /* ASCII char classification table - binary compatible */
11 #define MSVCRT_UPPER C1_UPPER
12 #define MSVCRT_LOWER C1_LOWER
13 #define MSVCRT_DIGIT C1_DIGIT
14 #define MSVCRT_SPACE C1_SPACE
15 #define MSVCRT_PUNCT C1_PUNCT
16 #define MSVCRT_CONTROL C1_CNTRL
17 #define MSVCRT_BLANK C1_BLANK
18 #define MSVCRT_HEX C1_XDIGIT
19 #define MSVCRT_LEADBYTE 0x8000
20 #define MSVCRT_ALPHA (C1_ALPHA|MSVCRT_UPPER|MSVCRT_LOWER)
22 #define _C_ MSVCRT_CONTROL
23 #define _S_ MSVCRT_SPACE
24 #define _P_ MSVCRT_PUNCT
25 #define _D_ MSVCRT_DIGIT
26 #define _H_ MSVCRT_HEX
27 #define _U_ MSVCRT_UPPER
28 #define _L_ MSVCRT_LOWER
30 WORD MSVCRT__ctype
[257] = {
31 0, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _S_
|_C_
, _S_
|_C_
,
32 _S_
|_C_
, _S_
|_C_
, _S_
|_C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
,
33 _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _C_
, _S_
|MSVCRT_BLANK
,
34 _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
,
35 _P_
, _D_
|_H_
, _D_
|_H_
, _D_
|_H_
, _D_
|_H_
, _D_
|_H_
, _D_
|_H_
, _D_
|_H_
,
36 _D_
|_H_
, _D_
|_H_
, _D_
|_H_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _U_
|_H_
,
37 _U_
|_H_
, _U_
|_H_
, _U_
|_H_
, _U_
|_H_
, _U_
|_H_
, _U_
, _U_
, _U_
, _U_
, _U_
,
38 _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
, _U_
,
39 _U_
, _P_
, _P_
, _P_
, _P_
, _P_
, _P_
, _L_
|_H_
, _L_
|_H_
, _L_
|_H_
, _L_
|_H_
,
40 _L_
|_H_
, _L_
|_H_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
,
41 _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _L_
, _P_
, _P_
, _P_
, _P_
,
42 _C_
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46 0, 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
50 /* Internal: Current ctype table for locale */
51 WORD MSVCRT_current_ctype
[257];
53 /* pctype is used by macros in the Win32 headers. It must point
54 * To a table of flags exactly like ctype. To allow locale
55 * changes to affect ctypes (i.e. isleadbyte), we use a second table
56 * and update its flags whenever the current locale changes.
58 WORD
* MSVCRT__pctype
= MSVCRT_current_ctype
+ 1;
61 extern int MSVCRT___mb_cur_max
;
62 extern LCID MSVCRT_current_lc_all_lcid
;
64 /*********************************************************************
65 * MSVCRT___p__pctype (MSVCRT.@)
67 WORD
** MSVCRT___p__pctype(void)
69 return &MSVCRT__pctype
;
72 /*********************************************************************
75 int __cdecl
MSVCRT__isctype(int c
, int type
)
77 if (c
>= -1 && c
<= 255)
78 return MSVCRT__pctype
[c
] & type
;
80 if (MSVCRT___mb_cur_max
!= 1 && c
> 0)
82 /* FIXME: Is there a faster way to do this? */
84 char convert
[3], *pconv
= convert
;
86 if (MSVCRT__pctype
[(UINT
)c
>> 8] & MSVCRT_LEADBYTE
)
87 *pconv
++ = (UINT
)c
>> 8;
90 /* FIXME: Use ctype LCID, not lc_all */
91 if (GetStringTypeExA(MSVCRT_current_lc_all_lcid
, CT_CTYPE1
,
92 convert
, convert
[1] ? 2 : 1, &typeInfo
))
93 return typeInfo
& type
;
98 /*********************************************************************
101 int __cdecl
MSVCRT_isalnum(int c
)
103 return MSVCRT__isctype( c
,MSVCRT_ALPHA
| MSVCRT_DIGIT
);
106 /*********************************************************************
109 int __cdecl
MSVCRT_isalpha(int c
)
111 return MSVCRT__isctype( c
, MSVCRT_ALPHA
);
114 /*********************************************************************
117 int __cdecl
MSVCRT_iscntrl(int c
)
119 return MSVCRT__isctype( c
, MSVCRT_CONTROL
);
122 /*********************************************************************
125 int __cdecl
MSVCRT_isdigit(int c
)
127 return MSVCRT__isctype( c
, MSVCRT_DIGIT
);
130 /*********************************************************************
133 int __cdecl
MSVCRT_isgraph(int c
)
135 return MSVCRT__isctype( c
, MSVCRT_ALPHA
| MSVCRT_DIGIT
| MSVCRT_PUNCT
);
138 /*********************************************************************
139 * isleadbyte (MSVCRT.@)
141 int __cdecl
MSVCRT_isleadbyte(int c
)
143 return MSVCRT__isctype( c
, MSVCRT_LEADBYTE
);
146 /*********************************************************************
149 int __cdecl
MSVCRT_islower(int c
)
151 return MSVCRT__isctype( c
, MSVCRT_LOWER
);
154 /*********************************************************************
157 int __cdecl
MSVCRT_isprint(int c
)
159 return MSVCRT__isctype( c
, MSVCRT_ALPHA
| MSVCRT_DIGIT
|
160 MSVCRT_BLANK
| MSVCRT_PUNCT
);
163 /*********************************************************************
166 int __cdecl
MSVCRT_ispunct(int c
)
168 return MSVCRT__isctype( c
, MSVCRT_PUNCT
);
171 /*********************************************************************
174 int __cdecl
MSVCRT_isspace(int c
)
176 return MSVCRT__isctype( c
, MSVCRT_SPACE
);
179 /*********************************************************************
182 int __cdecl
MSVCRT_isupper(int c
)
184 return MSVCRT__isctype( c
, MSVCRT_UPPER
);
187 /*********************************************************************
188 * isxdigit (MSVCRT.@)
190 int __cdecl
MSVCRT_isxdigit(int c
)
192 return MSVCRT__isctype( c
, MSVCRT_HEX
);
195 /*********************************************************************
196 * __isascii (MSVCRT.@)
198 int __cdecl
MSVCRT___isascii(int c
)
200 return isascii((unsigned)c
);
203 /*********************************************************************
204 * __toascii (MSVCRT.@)
206 int __cdecl
MSVCRT___toascii(int c
)
208 return (unsigned)c
& 0x7f;
211 /*********************************************************************
212 * iswascii (MSVCRT.@)
215 int __cdecl
MSVCRT_iswascii(WCHAR c
)
217 return ((unsigned)c
< 0x80);
220 /*********************************************************************
221 * __iscsym (MSVCRT.@)
223 int __cdecl
MSVCRT___iscsym(int c
)
225 return (c
< 127 && (isalnum(c
) || c
== '_'));
228 /*********************************************************************
229 * __iscsymf (MSVCRT.@)
231 int __cdecl
MSVCRT___iscsymf(int c
)
233 return (c
< 127 && (isalpha(c
) || c
== '_'));
236 /*********************************************************************
237 * _toupper (MSVCRT.@)
239 int __cdecl
MSVCRT__toupper(int c
)
241 return c
- 0x20; /* sic */
244 /*********************************************************************
245 * _tolower (MSVCRT.@)
247 int __cdecl
MSVCRT__tolower(int c
)
249 return c
+ 0x20; /* sic */