Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
21.cwctype.cpp
Go to the documentation of this file.
1
30#include <cwctype>
31
32#include <rw_driver.h>
33
34
36// detect masking macros
37const char* const cwctype_macros [] = {
38
39#ifdef iswalnum
40# undef iswalnum
41 "iswalnum",
42#else
43 "",
44#endif
45
46#ifdef iswalpha
47# undef iswalpha
48 "iswalpha",
49#else
50 "",
51#endif
52
53#ifdef iswcntrl
54# undef iswcntrl
55 "iswcntrl",
56#else
57 "",
58#endif
59
60#ifdef iswctype
61# undef iswctype
62 "iswctype",
63#else
64 "",
65#endif
66
67#ifdef iswdigit
68# undef iswdigit
69 "iswdigit",
70#else
71 "",
72#endif
73
74#ifdef iswgraph
75# undef iswgraph
76 "iswgraph",
77#else
78 "",
79#endif
80
81#ifdef iswlower
82# undef iswlower
83 "iswlower",
84#else
85 "",
86#endif
87
88#ifdef iswprint
89# undef iswprint
90 "iswprint",
91#else
92 "",
93#endif
94
95#ifdef iswpunct
96# undef iswpunct
97 "iswpunct",
98#else
99 "",
100#endif
101
102#ifdef iswspace
103# undef iswspace
104 "iswspace",
105#else
106 "",
107#endif
108
109#ifdef iswupper
110# undef iswupper
111 "iswupper",
112#else
113 "",
114#endif
115
116#ifdef iswxdigit
117# undef iswxdigit
118 "iswxdigit",
119#else
120 "",
121#endif
122
123#ifdef tolower
124# undef tolower
125 "tolower",
126#else
127 "",
128#endif
129
130#ifdef toupper
131# undef toupper
132 "toupper",
133#else
134 "",
135#endif
136
137#ifdef towctrans
138# undef towctrans
139 "towctrans",
140#else
141 "",
142#endif
143
144#ifdef wctrans
145# undef wctrans
146 "wctrans",
147#else
148 "",
149#endif
150
151#ifdef wctype
152# undef wctype
153 "wctype",
154#else
155 "",
156#endif
157
158 0
159};
160
161
163#ifndef _RWSTD_NO_NAMESPACE
164
165// check types
166
167namespace Fallback {
168
169struct wint_t {
170 int i_;
171 char dummy_ [256]; // make sure we're bigger than the real thing
172
173 // this (fake) wint_t emulates a scalar type
174 wint_t (int i): i_ (i) { }
175 operator int () const { return i_; }
176};
177
178struct wctype_t {
179 int i_;
180 char dummy_ [256]; // make sure we're bigger than the real thing
181
182 // this (fake) wctype_t emulates a scalar type
183 wctype_t (int i): i_ (i) { }
184 operator int () const { return i_; }
185};
186
187struct wctrans_t {
188 int i_;
189 char dummy_ [256]; // make sure we're bigger than the real thing
190
191 // this (fake) wctrans_t emulates a scalar type
192 wctrans_t (int i): i_ (i) { }
193 operator int () const { return i_; }
194};
195
196} // Namespace Fallback
197
198namespace std {
199
200// define test functions in namespace std to detect the presece
201// or absence of the required types
202
203namespace Nested {
204
205using namespace Fallback;
206
207// each test_xxx_t typedef aliases std::xxx_t if the corresponding
208// type is defined in namespace std, or Fallback::xxx_t otherwise
209typedef wint_t test_wint_t;
212
213} // namespace Nested
214
215} // namespace std
216
217typedef std::Nested::test_wint_t test_wint_t;
218typedef std::Nested::test_wctrans_t test_wctrans_t;
219typedef std::Nested::test_wctype_t test_wctype_t;
220
221const char std_name[] = "std";
222
223static void
224test_types ()
225{
226 rw_info (0, 0, 0,
227 "types %s::wint_t, %1$s::wctrans_t, and %1$s::wctype_t",
228 std_name);
229
230 rw_assert (sizeof (test_wint_t) != sizeof (Fallback::wint_t), 0, 0,
231 "%s::wint_t not defined", std_name);
232
233 // TO DO: exercise wint_t requirements
234
235 rw_assert (sizeof (test_wctrans_t) != sizeof (Fallback::wctrans_t), 0, 0,
236 "%s::wctrans_t not defined", std_name);
237
238 // TO DO: exercise wctrans_t requirements (must be a scalar type)
239
240 rw_assert (sizeof (test_wctype_t) != sizeof (Fallback::wctype_t), 0, 0,
241 "%s::wctype_t not defined", std_name);
242
243 // TO DO: exercise wctype_t requirements (must be a scalar type)
244}
245
246#else // if defined (_RWSTD_NO_NAMESPACE)
247
248const char std_name[] = "";
249
250static void
251test_types ()
252{
253 rw_info (0, 0, 0,
254 "types %s::wint_t, %1s::wctrans_t, and %1s::wctype_t", std_name);
255
256 rw_note (0, 0, 0, "_RWSTD_NO_NAMESPACE defined, cannot test");
257}
258
259#endif // _RWSTD_NO_NAMESPACE
260
261
263enum {
264 // character classification/function missing bits
276
277 // function missing bits
278 bit_towctrans = 1 << 11,
279 bit_towlower = 1 << 12,
280 bit_towupper = 1 << 13,
281 bit_iswctype = 1 << 14,
282 bit_wctrans = 1 << 16,
283 bit_wctype = 1 << 17
285
286// each bit is set to 1 if and only if the corresponding function
287// is determined to be missing (not declared) in <cwctype>
288/* extern */ int missing_set;
289
290// define function template overloads for the <cctype> functions with
291// the same name to detect whether the C versions are declared or not
292#define TEST_FUNCTION(name, ret) \
293 template <class T> ret name (T) { \
294 missing_set |= bit_ ## name; \
295 return -1; \
296 } typedef void rw_unused_typedef
297
299
300TEST_FUNCTION (iswalnum, int);
301TEST_FUNCTION (iswalpha, int);
302TEST_FUNCTION (iswcntrl, int);
303TEST_FUNCTION (iswdigit, int);
304TEST_FUNCTION (iswgraph, int);
305TEST_FUNCTION (iswlower, int);
306TEST_FUNCTION (iswprint, int);
307TEST_FUNCTION (iswpunct, int);
308TEST_FUNCTION (iswspace, int);
309TEST_FUNCTION (iswupper, int);
310TEST_FUNCTION (iswxdigit, int);
311TEST_FUNCTION (towlower, wchar_t);
312TEST_FUNCTION (towupper, wchar_t);
313TEST_FUNCTION (wctrans, wctrans_t);
314TEST_FUNCTION (wctype, wctype_t);
315
316template <class T, class U>
317int iswctype (T, U) { missing_set |= bit_iswctype; return -1; }
318
319template <class T, class U>
320wint_t towctrans (T, U) { missing_set |= bit_towctrans; return -1; }
321
322} // namespace std
323
324
326static char*
327get_bitmask (int mask, char *str)
328{
329 char *str_save = str;
330
331#define APPEND(bit) \
332 if (mask & bit_ ## bit) { \
333 for (const char *s = #bit; *s; ++s, ++str) \
334 *str = *s; \
335 *str++ = '|'; \
336 } else (void)0
337
338 APPEND (alnum);
339 APPEND (alpha);
340 APPEND (cntrl);
341 APPEND (digit);
342 APPEND (graph);
343 APPEND (lower);
344 APPEND (print);
345 APPEND (punct);
346 APPEND (space);
347 APPEND (upper);
348 APPEND (xdigit);
349
350 if (str == str_save)
351 *str = '\0';
352 else
353 str [-1] = '\0';
354
355 return str_save;
356}
357
358
359static const int
360char_mask [256] = {
361
362#undef LETTER
363#define LETTER(bits) bit_alpha | bit_alnum | bit_print | bit_graph | bits
364
365#if 'A' == 0x41
366
367 /* 0x00 */ bit_cntrl,
368 /* 0x01 */ bit_cntrl,
369 /* 0x02 */ bit_cntrl,
370 /* 0x03 */ bit_cntrl,
371 /* 0x04 */ bit_cntrl,
372 /* 0x05 */ bit_cntrl,
373 /* 0x06 */ bit_cntrl,
374 /* 0x07 */ bit_cntrl,
375 /* 0x08 */ bit_cntrl,
376 /* 0x09 */ bit_space | bit_cntrl,
377 /* 0x0a */ bit_space | bit_cntrl,
378 /* 0x0b */ bit_space | bit_cntrl,
379 /* 0x0c */ bit_space | bit_cntrl,
380 /* 0x0d */ bit_space | bit_cntrl,
381 /* 0x0e */ bit_cntrl,
382 /* 0x0f */ bit_cntrl,
383 /* 0x10 */ bit_cntrl,
384 /* 0x11 */ bit_cntrl,
385 /* 0x12 */ bit_cntrl,
386 /* 0x13 */ bit_cntrl,
387 /* 0x14 */ bit_cntrl,
388 /* 0x15 */ bit_cntrl,
389 /* 0x16 */ bit_cntrl,
390 /* 0x17 */ bit_cntrl,
391 /* 0x18 */ bit_cntrl,
392 /* 0x19 */ bit_cntrl,
393 /* 0x1a */ bit_cntrl,
394 /* 0x1b */ bit_cntrl,
395 /* 0x1c */ bit_cntrl,
396 /* 0x1d */ bit_cntrl,
397 /* 0x1e */ bit_cntrl,
398 /* 0x1f */ bit_cntrl,
399 /* ' ' */ bit_space | bit_print,
400 /* '!' */ bit_print | bit_punct | bit_graph,
401 /* '"' */ bit_print | bit_punct | bit_graph,
402 /* '#' */ bit_print | bit_punct | bit_graph,
403 /* '$' */ bit_print | bit_punct | bit_graph,
404 /* '%' */ bit_print | bit_punct | bit_graph,
405 /* '&' */ bit_print | bit_punct | bit_graph,
406 /* '\'' */ bit_print | bit_punct | bit_graph,
407 /* '(' */ bit_print | bit_punct | bit_graph,
408 /* ')' */ bit_print | bit_punct | bit_graph,
409 /* '*' */ bit_print | bit_punct | bit_graph,
410 /* '+' */ bit_print | bit_punct | bit_graph,
411 /* ',' */ bit_print | bit_punct | bit_graph,
412 /* '-' */ bit_print | bit_punct | bit_graph,
413 /* '.' */ bit_print | bit_punct | bit_graph,
414 /* '/' */ bit_print | bit_punct | bit_graph,
425 /* ':' */ bit_print | bit_punct | bit_graph,
426 /* ';' */ bit_print | bit_punct | bit_graph,
427 /* '<' */ bit_print | bit_punct | bit_graph,
428 /* '=' */ bit_print | bit_punct | bit_graph,
429 /* '>' */ bit_print | bit_punct | bit_graph,
430 /* '?' */ bit_print | bit_punct | bit_graph,
431 /* '@' */ bit_print | bit_punct | bit_graph,
432
433 /* 'A' */ LETTER (bit_upper | bit_xdigit),
434 /* 'B' */ LETTER (bit_upper | bit_xdigit),
435 /* 'C' */ LETTER (bit_upper | bit_xdigit),
436 /* 'D' */ LETTER (bit_upper | bit_xdigit),
437 /* 'E' */ LETTER (bit_upper | bit_xdigit),
438 /* 'F' */ LETTER (bit_upper | bit_xdigit),
439 /* 'G' */ LETTER (bit_upper),
440 /* 'H' */ LETTER (bit_upper),
441 /* 'I' */ LETTER (bit_upper),
442 /* 'J' */ LETTER (bit_upper),
443 /* 'K' */ LETTER (bit_upper),
444 /* 'L' */ LETTER (bit_upper),
445 /* 'M' */ LETTER (bit_upper),
446 /* 'N' */ LETTER (bit_upper),
447 /* 'O' */ LETTER (bit_upper),
448 /* 'P' */ LETTER (bit_upper),
449 /* 'Q' */ LETTER (bit_upper),
450 /* 'R' */ LETTER (bit_upper),
451 /* 'S' */ LETTER (bit_upper),
452 /* 'T' */ LETTER (bit_upper),
453 /* 'U' */ LETTER (bit_upper),
454 /* 'V' */ LETTER (bit_upper),
455 /* 'W' */ LETTER (bit_upper),
456 /* 'X' */ LETTER (bit_upper),
457 /* 'Y' */ LETTER (bit_upper),
458 /* 'Z' */ LETTER (bit_upper),
459 /* '[' */ bit_print | bit_punct | bit_graph,
460 /* '\\' */ bit_print | bit_punct | bit_graph,
461 /* ']' */ bit_print | bit_punct | bit_graph,
462 /* '^' */ bit_print | bit_punct | bit_graph,
463 /* '_' */ bit_print | bit_punct | bit_graph,
464 /* '`' */ bit_print | bit_punct | bit_graph,
465 /* 'a' */ LETTER (bit_lower | bit_xdigit),
466 /* 'b' */ LETTER (bit_lower | bit_xdigit),
467 /* 'c' */ LETTER (bit_lower | bit_xdigit),
468 /* 'd' */ LETTER (bit_lower | bit_xdigit),
469 /* 'e' */ LETTER (bit_lower | bit_xdigit),
470 /* 'f' */ LETTER (bit_lower | bit_xdigit),
471 /* 'g' */ LETTER (bit_lower),
472 /* 'h' */ LETTER (bit_lower),
473 /* 'i' */ LETTER (bit_lower),
474 /* 'j' */ LETTER (bit_lower),
475 /* 'k' */ LETTER (bit_lower),
476 /* 'l' */ LETTER (bit_lower),
477 /* 'm' */ LETTER (bit_lower),
478 /* 'n' */ LETTER (bit_lower),
479 /* 'o' */ LETTER (bit_lower),
480 /* 'p' */ LETTER (bit_lower),
481 /* 'q' */ LETTER (bit_lower),
482 /* 'r' */ LETTER (bit_lower),
483 /* 's' */ LETTER (bit_lower),
484 /* 't' */ LETTER (bit_lower),
485 /* 'u' */ LETTER (bit_lower),
486 /* 'v' */ LETTER (bit_lower),
487 /* 'w' */ LETTER (bit_lower),
488 /* 'x' */ LETTER (bit_lower),
489 /* 'y' */ LETTER (bit_lower),
490 /* 'z' */ LETTER (bit_lower),
491 /* '{' */ bit_print | bit_punct | bit_graph,
492 /* '|' */ bit_print | bit_punct | bit_graph,
493 /* '}' */ bit_print | bit_punct | bit_graph,
494 /* '~' */ bit_print | bit_punct | bit_graph,
495 /* 0x7f */ bit_cntrl
496
497#elif 'A' == 0xc1
498
499 /* NUL */ bit_cntrl,
500 /* SOH */ bit_cntrl,
501 /* STX */ bit_cntrl,
502 /* ETX */ bit_cntrl,
503 /* PF */ bit_cntrl,
504 /* HT */ bit_cntrl,
505 /* LC */ bit_cntrl,
506 /* DEL */ bit_cntrl,
507 /* */ 0,
508 /* */ 0,
509 /* SMM */ bit_cntrl,
510 /* VT */ bit_cntrl,
511 /* FF */ bit_cntrl,
512 /* CR */ bit_cntrl,
513 /* SO */ bit_cntrl,
514 /* SI */ bit_cntrl,
515 /* DLE */ bit_cntrl,
516 /* DC1 */ bit_cntrl,
517 /* DC2 */ bit_cntrl,
518 /* TM */ bit_cntrl,
519 /* RES */ bit_cntrl,
520 /* NL */ bit_cntrl,
521 /* BS */ bit_cntrl,
522 /* IL */ bit_cntrl,
523 /* CAN */ bit_cntrl,
524 /* EM */ bit_cntrl,
525 /* CC */ bit_cntrl,
526 /* CU1 */ bit_cntrl,
527 /* IFS */ bit_cntrl,
528 /* IGS */ bit_cntrl,
529 /* IRS */ bit_cntrl,
530 /* IUS */ bit_cntrl,
531 /* DS */ bit_cntrl,
532 /* SOS */ bit_cntrl,
533 /* FS */ bit_cntrl,
534 /* */ 0,
535 /* BYP */ bit_cntrl,
536 /* LF */ bit_cntrl,
537 /* ETB */ bit_cntrl,
538 /* ESC */ bit_cntrl,
539 /* */ 0,
540 /* */ 0,
541 /* SM */ bit_cntrl,
542 /* CU2 */ bit_cntrl,
543 /* */ 0,
544 /* ENQ */ bit_cntrl,
545 /* ACK */ bit_cntrl,
546 /* BEL */ bit_cntrl,
547 /* */ 0,
548 /* */ 0,
549 /* SYN */ bit_cntrl,
550 /* */ 0,
551 /* PN */ bit_cntrl,
552 /* RS */ bit_cntrl,
553 /* UC */ bit_cntrl,
554 /* EOT */ bit_cntrl,
555 /* */ 0,
556 /* */ 0,
557 /* */ 0,
558 /* CU3 */ bit_cntrl,
559 /* DC4 */ bit_cntrl,
560 /* NAK */ bit_cntrl,
561 /* */ 0,
562 /* SUB */ bit_cntrl,
563 /* SP */ bit_cntrl,
564 /* */ 0,
565 /* */ 0,
566 /* */ 0,
567 /* */ 0,
568 /* */ 0,
569 /* */ 0,
570 /* */ 0,
571 /* */ 0,
572 /* */ 0,
573 /* ct. */ bit_print | bit_punct | bit_graph,
574 /* '.' */ bit_print | bit_punct | bit_graph,
575 /* '<' */ bit_print | bit_punct | bit_graph,
576 /* '(' */ bit_print | bit_punct | bit_graph,
577 /* '+' */ bit_print | bit_punct | bit_graph,
578 /* '|' */ bit_print | bit_punct | bit_graph,
579 /* '&' */ bit_print | bit_punct | bit_graph,
580 /* */ 0,
581 /* */ 0,
582 /* */ 0,
583 /* */ 0,
584 /* */ 0,
585 /* */ 0,
586 /* */ 0,
587 /* */ 0,
588 /* */ 0,
589 /* '!' */ bit_print | bit_punct | bit_graph,
590 /* '$' */ bit_print | bit_punct | bit_graph,
591 /* '*' */ bit_print | bit_punct | bit_graph,
592 /* ')' */ bit_print | bit_punct | bit_graph,
593 /* ';' */ bit_print | bit_punct | bit_graph,
594 /* '~' */ bit_print | bit_punct | bit_graph,
595 /* '-' */ bit_print | bit_punct | bit_graph,
596 /* '/' */ bit_print | bit_punct | bit_graph,
597 /* */ 0,
598 /* */ 0,
599 /* */ 0,
600 /* */ 0,
601 /* */ 0,
602 /* */ 0,
603 /* */ 0,
604 /* */ 0,
605 /* */ 0,
606 /* ',' */ bit_print | bit_punct | bit_graph,
607 /* '%' */ bit_print | bit_punct | bit_graph,
608 /* '_' */ bit_print | bit_punct | bit_graph,
609 /* '>' */ bit_print | bit_punct | bit_graph,
610 /* '?' */ bit_print | bit_punct | bit_graph,
611 /* */ 0,
612 /* */ 0,
613 /* */ 0,
614 /* */ 0,
615 /* */ 0,
616 /* */ 0,
617 /* */ 0,
618 /* */ 0,
619 /* */ 0,
620 /* */ 0,
621 /* ':' */ bit_print | bit_punct | bit_graph,
622 /* '#' */ bit_print | bit_punct | bit_graph,
623 /* '@' */ bit_print | bit_punct | bit_graph,
624 /* ''' */ bit_print | bit_punct | bit_graph,
625 /* '=' */ bit_print | bit_punct | bit_graph,
626 /* '"' */ bit_print | bit_punct | bit_graph,
627 /* */ 0,
628 /* 'a' */ LETTER (bit_lower | bit_xdigit),
629 /* 'b' */ LETTER (bit_lower | bit_xdigit),
630 /* 'c' */ LETTER (bit_lower | bit_xdigit),
631 /* 'd' */ LETTER (bit_lower | bit_xdigit),
632 /* 'e' */ LETTER (bit_lower | bit_xdigit),
633 /* 'f' */ LETTER (bit_lower | bit_xdigit),
634 /* 'g' */ LETTER (bit_lower),
635 /* 'h' */ LETTER (bit_lower),
636 /* 'i' */ LETTER (bit_lower),
637 /* */ 0,
638 /* */ 0,
639 /* */ 0,
640 /* */ 0,
641 /* */ 0,
642 /* */ 0,
643 /* */ 0,
644 /* 'j' */ LETTER (bit_lower),
645 /* 'k' */ LETTER (bit_lower),
646 /* 'l' */ LETTER (bit_lower),
647 /* 'm' */ LETTER (bit_lower),
648 /* 'n' */ LETTER (bit_lower),
649 /* 'o' */ LETTER (bit_lower),
650 /* 'p' */ LETTER (bit_lower),
651 /* 'q' */ LETTER (bit_lower),
652 /* 'r' */ LETTER (bit_lower),
653 /* */ 0,
654 /* */ 0,
655 /* */ 0,
656 /* */ 0,
657 /* */ 0,
658 /* */ 0,
659 /* */ 0,
660 /* */ 0,
661 /* 's' */ LETTER (bit_lower),
662 /* 't' */ LETTER (bit_lower),
663 /* 'u' */ LETTER (bit_lower),
664 /* 'v' */ LETTER (bit_lower),
665 /* 'w' */ LETTER (bit_lower),
666 /* 'x' */ LETTER (bit_lower),
667 /* 'y' */ LETTER (bit_lower),
668 /* 'z' */ LETTER (bit_lower),
669 /* */ 0,
670 /* */ 0,
671 /* */ 0,
672 /* */ 0,
673 /* */ 0,
674 /* */ 0,
675 /* */ 0,
676 /* */ 0,
677 /* */ 0,
678 /* */ 0,
679 /* */ 0,
680 /* */ 0,
681 /* */ 0,
682 /* */ 0,
683 /* */ 0,
684 /* '`' */ 0,
685 /* */ 0,
686 /* */ 0,
687 /* */ 0,
688 /* */ 0,
689 /* */ 0,
690 /* */ 0,
691 /* 'A' */ LETTER (bit_upper | bit_xdigit),
692 /* 'B' */ LETTER (bit_upper | bit_xdigit),
693 /* 'C' */ LETTER (bit_upper | bit_xdigit),
694 /* 'D' */ LETTER (bit_upper | bit_xdigit),
695 /* 'E' */ LETTER (bit_upper | bit_xdigit),
696 /* 'F' */ LETTER (bit_upper | bit_xdigit),
697 /* 'G' */ LETTER (bit_upper),
698 /* 'H' */ LETTER (bit_upper),
699 /* 'I' */ LETTER (bit_upper),
700 /* */ 0,
701 /* */ 0,
702 /* */ 0,
703 /* */ 0,
704 /* */ 0,
705 /* */ 0,
706 /* */ 0,
707 /* 'J' */ LETTER (bit_upper),
708 /* 'K' */ LETTER (bit_upper),
709 /* 'L' */ LETTER (bit_upper),
710 /* 'M' */ LETTER (bit_upper),
711 /* 'N' */ LETTER (bit_upper),
712 /* 'O' */ LETTER (bit_upper),
713 /* 'P' */ LETTER (bit_upper),
714 /* 'Q' */ LETTER (bit_upper),
715 /* 'R' */ LETTER (bit_upper),
716 /* */ 0,
717 /* */ 0,
718 /* */ 0,
719 /* */ 0,
720 /* */ 0,
721 /* */ 0,
722 /* */ 0,
723 /* */ 0,
724 /* 'S' */ LETTER (bit_upper),
725 /* 'T' */ LETTER (bit_upper),
726 /* 'U' */ LETTER (bit_upper),
727 /* 'V' */ LETTER (bit_upper),
728 /* 'W' */ LETTER (bit_upper),
729 /* 'X' */ LETTER (bit_upper),
730 /* 'Y' */ LETTER (bit_upper),
731 /* 'Z' */ LETTER (bit_upper),
732 /* */ 0,
733 /* */ 0,
734 /* */ 0,
735 /* */ 0,
736 /* */ 0,
737 /* */ 0,
738 /* '0' */ bit_print | bit_digit | bit_graph | bit_xdigit,
739 /* '1' */ bit_print | bit_digit | bit_graph | bit_xdigit,
740 /* '2' */ bit_print | bit_digit | bit_graph | bit_xdigit,
741 /* '3' */ bit_print | bit_digit | bit_graph | bit_xdigit,
742 /* '4' */ bit_print | bit_digit | bit_graph | bit_xdigit,
743 /* '5' */ bit_print | bit_digit | bit_graph | bit_xdigit,
744 /* '6' */ bit_print | bit_digit | bit_graph | bit_xdigit,
745 /* '7' */ bit_print | bit_digit | bit_graph | bit_xdigit,
746 /* '8' */ bit_print | bit_digit | bit_graph | bit_xdigit,
747 /* '9' */ bit_print | bit_digit | bit_graph | bit_xdigit,
748 /* */ 0,
749 /* */ 0,
750 /* */ 0,
751 /* */ 0,
752 /* */ 0,
753 /* */ 0
754
755#else // 'A' != 0x41 && 'A' != 0xc1
756# error unknown character set (neither ASCII nor EBCDIC)
757#endif // ASCII or EBCDIC
758
759};
760
761static void
762test_behavior ()
763{
764 rw_info (0, 0, 0, "behavior of <cwctype> functions in the \"C\" locale");
765
766 char missing_str [80];
767
768 for (int i = 0; i != 256; ++i) {
769
770 const test_wint_t c = i;
771
772 int mask = 0;
773
774// invoke each function that is found to be declared in the header
775// and exercise its return value; avoid testing functions that are
776// not found to be declared in the header to prevent unnecessary
777// noise
778#define SET_MASK_BIT(bitno) \
779 if (bit_ ## bitno & missing_set) \
780 mask |= char_mask [i] & bit_ ## bitno; \
781 else \
782 mask |= std::isw ## bitno (c) ? bit_ ## bitno : 0; \
783
784 SET_MASK_BIT (alnum);
785 SET_MASK_BIT (alpha);
787 SET_MASK_BIT (digit);
792 SET_MASK_BIT (space);
794 SET_MASK_BIT (xdigit);
795
796 // C99 standard (7.25.2.1 p2) implicitly allows
797 // defining the extra bits in iswxxx()
798 const int missing_bits = ~mask & char_mask [i];
799
800 rw_assert (0 == missing_bits, 0, 0,
801 "%#c mask missing bits %s (%#x)",
802 i, get_bitmask (missing_bits, missing_str), missing_bits);
803 }
804}
805
806
808static int rw_opt_no_behavior; // for --no-behavior
809
810static int
811run_test (int, char**)
812{
813#ifdef _RWSTD_STRICT_ANSI
814# define RW_DIAG rw_assert
815#else
816# define RW_DIAG rw_warn
817#endif
818
820 rw_info (0, 0, 0, "checking for the absence of masking macros");
821
822 // verify the shadow macros are not #defined (explicitly
823 // disallowed by 17.4.1.2, p6 and Footnote 159 of C++ '03)
824 for (unsigned i = 0; cwctype_macros [i]; ++i) {
825 RW_DIAG ('\0' == cwctype_macros [i][0], 0, 0,
826 "macro %s unexpectedly #defined", cwctype_macros [i]);
827 }
828
830#ifndef WEOF
831 const int weof_defined = 0;
832#else // if defined (WEOF)
833 const int weof_defined = 1;
834#endif // WEOF
835
836 rw_assert (weof_defined, 0, 0, "macro WEOF unexpectedly not #defined");
837
839 test_types ();
840
842 // verify that each function is defined
843
844#define TEST(function) \
845 do { \
846 rw_info (0, 0, 0, "%s::%s (%s::wint_t) definition", \
847 std_name, #function, std_name); \
848 const int result = std::function (test_wint_t ('a')); \
849 RW_DIAG (-1 != result && !(missing_set & bit_ ## function), \
850 0, __LINE__, "%s::%s (%s::wint_t) not defined", \
851 std_name, #function, std_name); \
852 } while (0)
853
854 TEST (iswalnum);
855 TEST (iswalpha);
856 TEST (iswcntrl);
857 TEST (iswdigit);
858 TEST (iswgraph);
859 TEST (iswlower);
860 TEST (iswprint);
861 TEST (iswspace);
862 TEST (iswpunct);
863 TEST (iswupper);
864 TEST (iswxdigit);
865 TEST (towlower);
866 TEST (towupper);
867
868 // exercise std::wctype(const char*)
869 rw_info (0, 0, 0,
870 "%s::wctype (const char*) definition", std_name);
871
872 int result = std::wctype ("");
873
874 RW_DIAG (-1 != result && !(missing_set & bit_wctype), 0, __LINE__,
875 "%s::wctype (const char*) not defined", std_name);
876
877
878 // exercise std::iswctype(std::wint_t, std::wctype_t)
879 rw_info (0, 0, 0,
880 "%s::iswctype (%1$s::wint_t, %1$s::wctype_t) definition",
881 std_name);
882
883 const test_wint_t wc = 0;
884 const test_wctype_t desc = 0;
885
886 result = std::iswctype (wc, desc);
887
888 RW_DIAG (-1 != result && !(missing_set & bit_iswctype), 0, __LINE__,
889 "%s::iswctype (%1$s::wint_t, %1$s::wctype_t) not defined",
890 std_name);
891
892 // exercise std::wctrans(const char*)
893 rw_info (0, 0, 0,
894 "%s::wctrans (const char*) definition", std_name);
895
896 // cast wctrans() result to ptrdiff_t in case it's a pointer
897 // such as in GNU glibc
898 result = (int)(_RWSTD_PTRDIFF_T)std::wctrans ("");
899
900 RW_DIAG (-1 != result && !(missing_set & bit_wctrans), 0, __LINE__,
901 "%s::wctrans (const char*) not defined", std_name);
902
903 // exercise std::towctrans(wint_t, wctrans_t)
904 rw_info (0, 0, 0,
905 "%s::towctrans(wint_t, wctrans_t) definition", std_name);
906
907 const test_wctrans_t category = 0;
908 result = std::towctrans (wc, category);
909
910 RW_DIAG (-1 != result && !(missing_set & bit_towctrans), 0, __LINE__,
911 "%s::towctrans(wint_t, wctrans_t) not defined", std_name);
912
914 if (rw_opt_no_behavior)
915 rw_note (0, 0, 0, "behavior test disabled (use --test-behavior)");
916 else
917 test_behavior ();
918
919 return 0;
920}
921
922
924int main (int argc, char *argv[])
925{
926 return rw_test (argc, argv, __FILE__,
927 "lib.c.strings",
928 "header <cwctype>",
929 run_test,
930 "|-no-behavior#0-1 ",
931 &rw_opt_no_behavior);
932}
const char lower[]
const char graph[]
const char upper[]
const char cntrl[]
const char print[]
const char punct[]
#define i
Definition 17.names.cpp:126
#define T
Definition 17.names.cpp:163
#define c
Definition 17.names.cpp:111
#define U
Definition 17.names.cpp:164
volatile int result
std::Nested::test_wint_t test_wint_t
#define APPEND(bit)
std::Nested::test_wctype_t test_wctype_t
const char *const cwctype_macros[]
#define LETTER(bits)
int missing_set
#define TEST(function)
#define RW_DIAG
#define SET_MASK_BIT(bitno)
std::Nested::test_wint_t test_wint_t
@ bit_iswalpha
@ bit_iswspace
@ bit_iswlower
@ bit_graph
@ bit_iswpunct
@ bit_towlower
@ bit_iswcntrl
@ bit_iswupper
@ bit_cntrl
@ bit_iswgraph
@ bit_upper
@ bit_towupper
@ bit_digit
@ bit_alpha
@ bit_alnum
@ bit_xdigit
@ bit_wctrans
@ bit_lower
@ bit_iswxdigit
@ bit_print
@ bit_space
@ bit_iswalnum
@ bit_iswdigit
@ bit_wctype
@ bit_punct
@ bit_iswctype
@ bit_iswprint
@ bit_towctrans
std::Nested::test_wctrans_t test_wctrans_t
const char std_name[]
#define TEST_FUNCTION(name, ret)
void test_types(Vector *, T *, Allocator)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define main
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
const char * str
Definition exec.cpp:170
Definition json.h:5363
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
Definition driver.cpp:1681
_TEST_EXPORT int rw_note(int, const char *, int, const char *,...)
Definition driver.cpp:1664
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
Definition driver.cpp:1630