Implement ClearCustData.
[wine] / dlls / msvcrt / ctype.c
1 /*
2  * msvcrt.dll ctype functions
3  *
4  * Copyright 2000 Jon Griffiths
5  *
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.
10  *
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.
15  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 #include "msvcrt.h"
21
22 #include "msvcrt/ctype.h"
23
24 #include "wine/debug.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
27
28 /* Some abbreviations to make the following table readable */
29 #define _C_ _CONTROL
30 #define _S_ _SPACE
31 #define _P_ _PUNCT
32 #define _D_ _DIGIT
33 #define _H_ _HEX
34 #define _U_ _UPPER
35 #define _L_ _LOWER
36
37 WORD MSVCRT__ctype [257] = {
38   0, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|_C_, _S_|_C_,
39   _S_|_C_, _S_|_C_, _S_|_C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_,
40   _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _C_, _S_|_BLANK,
41   _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _P_,
42   _P_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_, _D_|_H_,
43   _D_|_H_, _D_|_H_, _D_|_H_, _P_, _P_, _P_, _P_, _P_, _P_, _P_, _U_|_H_,
44   _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_|_H_, _U_, _U_, _U_, _U_, _U_,
45   _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_, _U_,
46   _U_, _P_, _P_, _P_, _P_, _P_, _P_, _L_|_H_, _L_|_H_, _L_|_H_, _L_|_H_,
47   _L_|_H_, _L_|_H_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_,
48   _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _L_, _P_, _P_, _P_, _P_,
49   _C_, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
54   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
55 };
56
57 /* Internal: Current ctype table for locale */
58 WORD MSVCRT_current_ctype[257];
59
60 /* pctype is used by macros in the Win32 headers. It must point
61  * To a table of flags exactly like ctype. To allow locale
62  * changes to affect ctypes (i.e. isleadbyte), we use a second table
63  * and update its flags whenever the current locale changes.
64  */
65 WORD* MSVCRT__pctype = MSVCRT_current_ctype + 1;
66
67 /* mbctype data */
68 extern int MSVCRT___mb_cur_max;
69 extern LCID MSVCRT_current_lc_all_lcid;
70
71 /*********************************************************************
72  *              __p__pctype (MSVCRT.@)
73  */
74 WORD** __p__pctype(void)
75 {
76   return &MSVCRT__pctype;
77 }
78
79 /*********************************************************************
80  *              _isctype (MSVCRT.@)
81  */
82 int _isctype(int c, int type)
83 {
84   if (c >= -1 && c <= 255)
85     return MSVCRT__pctype[c] & type;
86
87   if (MSVCRT___mb_cur_max != 1 && c > 0)
88   {
89     /* FIXME: Is there a faster way to do this? */
90     WORD typeInfo;
91     char convert[3], *pconv = convert;
92
93     if (MSVCRT__pctype[(UINT)c >> 8] & _LEADBYTE)
94       *pconv++ = (UINT)c >> 8;
95     *pconv++ = c & 0xff;
96     *pconv = 0;
97     /* FIXME: Use ctype LCID, not lc_all */
98     if (GetStringTypeExA(MSVCRT_current_lc_all_lcid, CT_CTYPE1,
99                          convert, convert[1] ? 2 : 1, &typeInfo))
100       return typeInfo & type;
101   }
102   return 0;
103 }
104
105 /*********************************************************************
106  *              isalnum (MSVCRT.@)
107  */
108 int MSVCRT_isalnum(int c)
109 {
110   return _isctype( c, _ALPHA | _DIGIT );
111 }
112
113 /*********************************************************************
114  *              isalpha (MSVCRT.@)
115  */
116 int MSVCRT_isalpha(int c)
117 {
118   return _isctype( c, _ALPHA );
119 }
120
121 /*********************************************************************
122  *              iscntrl (MSVCRT.@)
123  */
124 int MSVCRT_iscntrl(int c)
125 {
126   return _isctype( c, _CONTROL );
127 }
128
129 /*********************************************************************
130  *              isdigit (MSVCRT.@)
131  */
132 int MSVCRT_isdigit(int c)
133 {
134   return _isctype( c, _DIGIT );
135 }
136
137 /*********************************************************************
138  *              isgraph (MSVCRT.@)
139  */
140 int MSVCRT_isgraph(int c)
141 {
142   return _isctype( c, _ALPHA | _DIGIT | _PUNCT );
143 }
144
145 /*********************************************************************
146  *              isleadbyte (MSVCRT.@)
147  */
148 int MSVCRT_isleadbyte(int c)
149 {
150   return _isctype( c, _LEADBYTE );
151 }
152
153 /*********************************************************************
154  *              islower (MSVCRT.@)
155  */
156 int MSVCRT_islower(int c)
157 {
158   return _isctype( c, _LOWER );
159 }
160
161 /*********************************************************************
162  *              isprint (MSVCRT.@)
163  */
164 int MSVCRT_isprint(int c)
165 {
166   return _isctype( c, _ALPHA | _DIGIT | _BLANK | _PUNCT );
167 }
168
169 /*********************************************************************
170  *              ispunct (MSVCRT.@)
171  */
172 int MSVCRT_ispunct(int c)
173 {
174   return _isctype( c, _PUNCT );
175 }
176
177 /*********************************************************************
178  *              isspace (MSVCRT.@)
179  */
180 int MSVCRT_isspace(int c)
181 {
182   return _isctype( c, _SPACE );
183 }
184
185 /*********************************************************************
186  *              isupper (MSVCRT.@)
187  */
188 int MSVCRT_isupper(int c)
189 {
190   return _isctype( c, _UPPER );
191 }
192
193 /*********************************************************************
194  *              isxdigit (MSVCRT.@)
195  */
196 int MSVCRT_isxdigit(int c)
197 {
198   return _isctype( c, _HEX );
199 }
200
201 /*********************************************************************
202  *              __isascii (MSVCRT.@)
203  */
204 int MSVCRT___isascii(int c)
205 {
206   return isascii((unsigned)c);
207 }
208
209 /*********************************************************************
210  *              __toascii (MSVCRT.@)
211  */
212 int MSVCRT___toascii(int c)
213 {
214   return (unsigned)c & 0x7f;
215 }
216
217 /*********************************************************************
218  *              iswascii (MSVCRT.@)
219  *
220  */
221 int MSVCRT_iswascii(MSVCRT_wchar_t c)
222 {
223   return ((unsigned)c < 0x80);
224 }
225
226 /*********************************************************************
227  *              __iscsym (MSVCRT.@)
228  */
229 int MSVCRT___iscsym(int c)
230 {
231   return (c < 127 && (isalnum(c) || c == '_'));
232 }
233
234 /*********************************************************************
235  *              __iscsymf (MSVCRT.@)
236  */
237 int MSVCRT___iscsymf(int c)
238 {
239   return (c < 127 && (isalpha(c) || c == '_'));
240 }
241
242 /*********************************************************************
243  *              _toupper (MSVCRT.@)
244  */
245 int MSVCRT__toupper(int c)
246 {
247     return c - 0x20;  /* sic */
248 }
249
250 /*********************************************************************
251  *              _tolower (MSVCRT.@)
252  */
253 int MSVCRT__tolower(int c)
254 {
255     return c + 0x20;  /* sic */
256 }