Merging r37048, r37051, r37052, r37055 from the-real-msvc branch
[reactos.git] / reactos / lib / sdk / crt / string / ctype.c
1 #include <string.h>
2 #undef __MINGW_IMPORT
3 #define __MINGW_IMPORT
4 #include <ctype.h>
5
6 #undef _pctype
7
8 /* MS's CRT header defines all that, and we actually implement that */
9 #undef iswalnum
10 #undef __isascii
11 #undef iswascii
12 #undef __iscsym
13 #undef __iscsymf
14 #undef iswalpha
15 #undef iswcntrl
16 #undef iswdigit
17 #undef iswgraph
18 #undef iswprint
19 #undef iswpunct
20 #undef iswlower
21 #undef iswupper
22 #undef iswspace
23 #undef iswxdigit
24 #undef __toascii
25
26 #define upalpha ('A' - 'a')
27
28
29 unsigned short _ctype[] = {
30 0, /* <EOF>, 0xFFFF */
31 _CONTROL, /* CTRL+@, 0x00 */
32 _CONTROL, /* CTRL+A, 0x01 */
33 _CONTROL, /* CTRL+B, 0x02 */
34 _CONTROL, /* CTRL+C, 0x03 */
35 _CONTROL, /* CTRL+D, 0x04 */
36 _CONTROL, /* CTRL+E, 0x05 */
37 _CONTROL, /* CTRL+F, 0x06 */
38 _CONTROL, /* CTRL+G, 0x07 */
39 _CONTROL, /* CTRL+H, 0x08 */
40 _CONTROL | _SPACE, /* CTRL+I, 0x09 */
41 _CONTROL | _SPACE, /* CTRL+J, 0x0a */
42 _CONTROL | _SPACE, /* CTRL+K, 0x0b */
43 _CONTROL | _SPACE, /* CTRL+L, 0x0c */
44 _CONTROL | _SPACE, /* CTRL+M, 0x0d */
45 _CONTROL, /* CTRL+N, 0x0e */
46 _CONTROL, /* CTRL+O, 0x0f */
47 _CONTROL, /* CTRL+P, 0x10 */
48 _CONTROL, /* CTRL+Q, 0x11 */
49 _CONTROL, /* CTRL+R, 0x12 */
50 _CONTROL, /* CTRL+S, 0x13 */
51 _CONTROL, /* CTRL+T, 0x14 */
52 _CONTROL, /* CTRL+U, 0x15 */
53 _CONTROL, /* CTRL+V, 0x16 */
54 _CONTROL, /* CTRL+W, 0x17 */
55 _CONTROL, /* CTRL+X, 0x18 */
56 _CONTROL, /* CTRL+Y, 0x19 */
57 _CONTROL, /* CTRL+Z, 0x1a */
58 _CONTROL, /* CTRL+[, 0x1b */
59 _CONTROL, /* CTRL+\, 0x1c */
60 _CONTROL, /* CTRL+], 0x1d */
61 _CONTROL, /* CTRL+^, 0x1e */
62 _CONTROL, /* CTRL+_, 0x1f */
63 _SPACE | _BLANK, /* ` ', 0x20 */
64 _PUNCT, /* `!', 0x21 */
65 _PUNCT, /* 0x22 */
66 _PUNCT, /* `#', 0x23 */
67 _PUNCT, /* `$', 0x24 */
68 _PUNCT, /* `%', 0x25 */
69 _PUNCT, /* `&', 0x26 */
70 _PUNCT, /* 0x27 */
71 _PUNCT, /* `(', 0x28 */
72 _PUNCT, /* `)', 0x29 */
73 _PUNCT, /* `*', 0x2a */
74 _PUNCT, /* `+', 0x2b */
75 _PUNCT, /* `,', 0x2c */
76 _PUNCT, /* `-', 0x2d */
77 _PUNCT, /* `.', 0x2e */
78 _PUNCT, /* `/', 0x2f */
79 _DIGIT | _HEX, /* `0', 0x30 */
80 _DIGIT | _HEX, /* `1', 0x31 */
81 _DIGIT | _HEX, /* `2', 0x32 */
82 _DIGIT | _HEX, /* `3', 0x33 */
83 _DIGIT | _HEX, /* `4', 0x34 */
84 _DIGIT | _HEX, /* `5', 0x35 */
85 _DIGIT | _HEX, /* `6', 0x36 */
86 _DIGIT | _HEX, /* `7', 0x37 */
87 _DIGIT | _HEX, /* `8', 0x38 */
88 _DIGIT | _HEX, /* `9', 0x39 */
89 _PUNCT, /* `:', 0x3a */
90 _PUNCT, /* `;', 0x3b */
91 _PUNCT, /* `<', 0x3c */
92 _PUNCT, /* `=', 0x3d */
93 _PUNCT, /* `>', 0x3e */
94 _PUNCT, /* `?', 0x3f */
95 _PUNCT, /* `@', 0x40 */
96 _UPPER | _HEX, /* `A', 0x41 */
97 _UPPER | _HEX, /* `B', 0x42 */
98 _UPPER | _HEX, /* `C', 0x43 */
99 _UPPER | _HEX, /* `D', 0x44 */
100 _UPPER | _HEX, /* `E', 0x45 */
101 _UPPER | _HEX, /* `F', 0x46 */
102 _UPPER, /* `G', 0x47 */
103 _UPPER, /* `H', 0x48 */
104 _UPPER, /* `I', 0x49 */
105 _UPPER, /* `J', 0x4a */
106 _UPPER, /* `K', 0x4b */
107 _UPPER, /* `L', 0x4c */
108 _UPPER, /* `M', 0x4d */
109 _UPPER, /* `N', 0x4e */
110 _UPPER, /* `O', 0x4f */
111 _UPPER, /* `P', 0x50 */
112 _UPPER, /* `Q', 0x51 */
113 _UPPER, /* `R', 0x52 */
114 _UPPER, /* `S', 0x53 */
115 _UPPER, /* `T', 0x54 */
116 _UPPER, /* `U', 0x55 */
117 _UPPER, /* `V', 0x56 */
118 _UPPER, /* `W', 0x57 */
119 _UPPER, /* `X', 0x58 */
120 _UPPER, /* `Y', 0x59 */
121 _UPPER, /* `Z', 0x5a */
122 _PUNCT, /* `[', 0x5b */
123 _PUNCT, /* 0x5c */
124 _PUNCT, /* `]', 0x5d */
125 _PUNCT, /* `^', 0x5e */
126 _PUNCT, /* `_', 0x5f */
127 _PUNCT, /* 0x60 */
128 _LOWER | _HEX, /* `a', 0x61 */
129 _LOWER | _HEX, /* `b', 0x62 */
130 _LOWER | _HEX, /* `c', 0x63 */
131 _LOWER | _HEX, /* `d', 0x64 */
132 _LOWER | _HEX, /* `e', 0x65 */
133 _LOWER | _HEX, /* `f', 0x66 */
134 _LOWER, /* `g', 0x67 */
135 _LOWER, /* `h', 0x68 */
136 _LOWER, /* `i', 0x69 */
137 _LOWER, /* `j', 0x6a */
138 _LOWER, /* `k', 0x6b */
139 _LOWER, /* `l', 0x6c */
140 _LOWER, /* `m', 0x6d */
141 _LOWER, /* `n', 0x6e */
142 _LOWER, /* `o', 0x6f */
143 _LOWER, /* `p', 0x70 */
144 _LOWER, /* `q', 0x71 */
145 _LOWER, /* `r', 0x72 */
146 _LOWER, /* `s', 0x73 */
147 _LOWER, /* `t', 0x74 */
148 _LOWER, /* `u', 0x75 */
149 _LOWER, /* `v', 0x76 */
150 _LOWER, /* `w', 0x77 */
151 _LOWER, /* `x', 0x78 */
152 _LOWER, /* `y', 0x79 */
153 _LOWER, /* `z', 0x7a */
154 _PUNCT, /* `{', 0x7b */
155 _PUNCT, /* `|', 0x7c */
156 _PUNCT, /* `}', 0x7d */
157 _PUNCT, /* `~', 0x7e */
158 _CONTROL, /* 0x7f */
159 0, /* 0x80 */
160 0, /* 0x81 */
161 0, /* 0x82 */
162 0, /* 0x83 */
163 0, /* 0x84 */
164 0, /* 0x85 */
165 0, /* 0x86 */
166 0, /* 0x87 */
167 0, /* 0x88 */
168 0, /* 0x89 */
169 0, /* 0x8a */
170 0, /* 0x8b */
171 0, /* 0x8c */
172 0, /* 0x8d */
173 0, /* 0x8e */
174 0, /* 0x8f */
175 0, /* 0x90 */
176 0, /* 0x91 */
177 0, /* 0x92 */
178 0, /* 0x93 */
179 0, /* 0x94 */
180 0, /* 0x95 */
181 0, /* 0x96 */
182 0, /* 0x97 */
183 0, /* 0x98 */
184 0, /* 0x99 */
185 0, /* 0x9a */
186 0, /* 0x9b */
187 0, /* 0x9c */
188 0, /* 0x9d */
189 0, /* 0x9e */
190 0, /* 0x9f */
191 0, /* 0xa0 */
192 0, /* 0xa1 */
193 0, /* 0xa2 */
194 0, /* 0xa3 */
195 0, /* 0xa4 */
196 0, /* 0xa5 */
197 0, /* 0xa6 */
198 0, /* 0xa7 */
199 0, /* 0xa8 */
200 0, /* 0xa9 */
201 0, /* 0xaa */
202 0, /* 0xab */
203 0, /* 0xac */
204 0, /* 0xad */
205 0, /* 0xae */
206 0, /* 0xaf */
207 0, /* 0xb0 */
208 0, /* 0xb1 */
209 0, /* 0xb2 */
210 0, /* 0xb3 */
211 0, /* 0xb4 */
212 0, /* 0xb5 */
213 0, /* 0xb6 */
214 0, /* 0xb7 */
215 0, /* 0xb8 */
216 0, /* 0xb9 */
217 0, /* 0xba */
218 0, /* 0xbb */
219 0, /* 0xbc */
220 0, /* 0xbd */
221 0, /* 0xbe */
222 0, /* 0xbf */
223 0, /* 0xc0 */
224 0, /* 0xc1 */
225 0, /* 0xc2 */
226 0, /* 0xc3 */
227 0, /* 0xc4 */
228 0, /* 0xc5 */
229 0, /* 0xc6 */
230 0, /* 0xc7 */
231 0, /* 0xc8 */
232 0, /* 0xc9 */
233 0, /* 0xca */
234 0, /* 0xcb */
235 0, /* 0xcc */
236 0, /* 0xcd */
237 0, /* 0xce */
238 0, /* 0xcf */
239 0, /* 0xd0 */
240 0, /* 0xd1 */
241 0, /* 0xd2 */
242 0, /* 0xd3 */
243 0, /* 0xd4 */
244 0, /* 0xd5 */
245 0, /* 0xd6 */
246 0, /* 0xd7 */
247 0, /* 0xd8 */
248 0, /* 0xd9 */
249 0, /* 0xda */
250 0, /* 0xdb */
251 0, /* 0xdc */
252 0, /* 0xdd */
253 0, /* 0xde */
254 0, /* 0xdf */
255 0, /* 0xe0 */
256 0, /* 0xe1 */
257 0, /* 0xe2 */
258 0, /* 0xe3 */
259 0, /* 0xe4 */
260 0, /* 0xe5 */
261 0, /* 0xe6 */
262 0, /* 0xe7 */
263 0, /* 0xe8 */
264 0, /* 0xe9 */
265 0, /* 0xea */
266 0, /* 0xeb */
267 0, /* 0xec */
268 0, /* 0xed */
269 0, /* 0xee */
270 0, /* 0xef */
271 0, /* 0xf0 */
272 0, /* 0xf1 */
273 0, /* 0xf2 */
274 0, /* 0xf3 */
275 0, /* 0xf4 */
276 0, /* 0xf5 */
277 0, /* 0xf6 */
278 0, /* 0xf7 */
279 0, /* 0xf8 */
280 0, /* 0xf9 */
281 0, /* 0xfa */
282 0, /* 0xfb */
283 0, /* 0xfc */
284 0, /* 0xfd */
285 0, /* 0xfe */
286 0 /* 0xff */
287 };
288
289 const unsigned short *_pctype = _ctype + 1;
290 const unsigned short *_pwctype = _ctype + 1;
291
292 /*
293 * @implemented
294 */
295 const unsigned short **__p__pctype(void)
296 {
297 return &_pctype;
298 }
299
300 /*
301 * @implemented
302 */
303 const unsigned short **__p__pwctype(void)
304 {
305 return &_pwctype;
306 }
307
308 int _isctype (int c, int ctypeFlags)
309 {
310 return (_pctype[(unsigned char)(c & 0xFF)] & ctypeFlags);
311 }
312
313 /*
314 * @implemented
315 */
316 int iswctype(wint_t wc, wctype_t wctypeFlags)
317 {
318 return (_pwctype[(unsigned char)(wc & 0xFF)] & wctypeFlags);
319 }
320
321 /*
322 * obsolete
323 *
324 * @implemented
325 */
326 int is_wctype(wint_t wc, wctype_t wctypeFlags)
327 {
328 return (_pwctype[(unsigned char)(wc & 0xFF)] & wctypeFlags);
329 }
330
331 /*
332 * @implemented
333 */
334 int isalpha(int c)
335 {
336 return(_isctype(c, _ALPHA));
337 }
338
339 /*
340 * @implemented
341 */
342 int isalnum(int c)
343 {
344 return(_isctype(c, _ALPHA | _DIGIT));
345 }
346
347 /*
348 * @implemented
349 */
350 int iswalnum(wint_t c)
351 {
352 return iswctype(c, _ALPHA | _DIGIT);
353 }
354
355 /*
356 * @implemented
357 */
358 int __isascii(int c)
359 {
360 return ((unsigned char)c <= 0x7f);
361 }
362
363 /*
364 * @implemented
365 */
366 int iswascii(wint_t c)
367 {
368 return __isascii(c);
369 }
370
371 /*
372 * @implemented
373 */
374 int iscntrl(int c)
375 {
376 return(_isctype(c, _CONTROL));
377 }
378
379 /*
380 * @implemented
381 */
382 int __iscsym(int c)
383 {
384 return (c < 127 && (isalnum(c) || (c == '_')));
385 }
386
387 /*
388 * @implemented
389 */
390 int __iscsymf(int c)
391 {
392 return (c < 127 && (isalpha(c) || (c == '_')));
393 }
394
395 /*
396 * @implemented
397 */
398 int isdigit(int c)
399 {
400 return(_isctype(c, _DIGIT));
401 }
402
403 /*
404 * @implemented
405 */
406 int isgraph(int c)
407 {
408 return (_isctype (c, _PUNCT | _ALPHA | _DIGIT));
409 }
410
411 /*
412 * @implemented
413 */
414 int islower(int c)
415 {
416 return (_isctype (c, _LOWER));
417 }
418
419 /*
420 * @implemented
421 */
422 int isprint(int c)
423 {
424 return (_isctype (c, _BLANK | _PUNCT | _ALPHA | _DIGIT));
425 }
426
427 /*
428 * @implemented
429 */
430 int ispunct(int c)
431 {
432 return (_isctype (c, _PUNCT));
433 }
434
435 /*
436 * @implemented
437 */
438 int isspace(int c)
439 {
440 return (_isctype (c, _SPACE));
441 }
442
443 /*
444 * @implemented
445 */
446 int isupper(int c)
447 {
448 return (_isctype (c, _UPPER));
449 }
450
451 /*
452 * @implemented
453 */
454 int isxdigit(int c)
455 {
456 return (_isctype (c, _HEX));
457 }
458
459
460 /*
461 * @implemented
462 */
463 int iswalpha(wint_t c)
464 {
465 return (iswctype (c, _ALPHA));
466 }
467
468 /*
469 * @implemented
470 */
471 int iswcntrl(wint_t c)
472 {
473 return iswctype(c, _CONTROL);
474 }
475
476 /*
477 * @implemented
478 */
479 int iswdigit(wint_t c)
480 {
481 return (iswctype (c, _DIGIT));
482 }
483
484 /*
485 * @implemented
486 */
487 int iswgraph(wint_t c)
488 {
489 return iswctype(c,_PUNCT | _ALPHA | _DIGIT);
490 }
491
492 /*
493 * @implemented
494 */
495 int iswprint(wint_t c)
496 {
497 return iswctype((unsigned short)c,_BLANK | _PUNCT | _ALPHA | _DIGIT);
498 }
499
500
501 /*
502 * @implemented
503 */
504 int iswpunct(wint_t c)
505 {
506 return iswctype(c, _PUNCT);
507 }
508
509 /*
510 * @implemented
511 */
512 int iswlower(wint_t c)
513 {
514 return (iswctype (c, _LOWER));
515 }
516
517 /*
518 * @implemented
519 */
520 int iswupper(wint_t c)
521 {
522 return iswctype(c, _UPPER);
523 }
524
525
526 /*
527 * @implemented
528 */
529 int iswspace(wint_t c)
530 {
531 return (iswctype (c, _SPACE));
532 }
533
534 /*
535 * @implemented
536 */
537 int iswxdigit(wint_t c)
538 {
539 return (iswctype (c, _HEX));
540 }
541
542
543 /*
544 * @implemented
545 */
546 int __toascii(int c)
547 {
548 return((unsigned)(c) & 0x7f);
549 }
550
551 /*
552 * @implemented
553 */
554 int _tolower(int c)
555 {
556 if (_isctype (c, _UPPER))
557 return (c - upalpha);
558 return(c);
559 }
560
561 /*
562 * @implemented
563 */
564 int _toupper(int c)
565 {
566 if (_isctype (c, _LOWER))
567 return (c + upalpha);
568 return(c);
569 }
570
571 /*
572 * @implemented
573 */
574 int tolower(int c)
575 {
576 if (_isctype (c, _UPPER))
577 return (c - upalpha);
578 return(c);
579 }
580
581 /*
582 * @implemented
583 */
584 int toupper(int c)
585 {
586 if (_isctype (c, _LOWER))
587 return (c + upalpha);
588 return(c);
589 }
590
591 /*
592 * @implemented
593 */
594 wint_t towlower(wint_t c)
595 {
596 if (iswctype (c, _UPPER))
597 return (c - upalpha);
598 return(c);
599 }
600
601 /*
602 * @implemented
603 */
604 wint_t towupper(wint_t c)
605 {
606 if (iswctype (c, _LOWER))
607 return (c + upalpha);
608 return(c);
609 }
610
611 /* EOF */