]>
Commit | Line | Data |
---|---|---|
83ffe9cd | 1 | // Copyright (C) 2000-2023 Free Software Foundation, Inc. |
f64ce6c6 BK |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
748086b7 | 6 | // Free Software Foundation; either version 3, or (at your option) |
f64ce6c6 BK |
7 | // any later version. |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
748086b7 JJ |
15 | // with this library; see the file COPYING3. If not see |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
f64ce6c6 BK |
18 | |
19 | // 22.2.1.3.2 ctype<char> members | |
20 | ||
21 | #include <locale> | |
f64ce6c6 BK |
22 | #include <testsuite_hooks.h> |
23 | ||
f64ce6c6 BK |
24 | typedef wchar_t char_type; |
25 | class gnu_ctype: public std::ctype<char_type> { }; | |
26 | ||
27 | void test01() | |
28 | { | |
f64ce6c6 BK |
29 | const char_type strlit00[] = L"manilla, cebu, tandag PHILIPPINES"; |
30 | const char_type strlit01[] = L"MANILLA, CEBU, TANDAG PHILIPPINES"; | |
f64ce6c6 BK |
31 | const char_type c00 = L'S'; |
32 | const char_type c10 = L's'; | |
33 | const char_type c20 = L'9'; | |
34 | const char_type c30 = L' '; | |
35 | const char_type c40 = L'!'; | |
36 | const char_type c50 = L'F'; | |
37 | const char_type c60 = L'f'; | |
f64ce6c6 BK |
38 | const char_type c80 = L'x'; |
39 | ||
40 | gnu_ctype gctype; | |
f64ce6c6 BK |
41 | |
42 | // sanity check ctype_base::mask members | |
43 | int i01 = std::ctype_base::space; | |
44 | int i02 = std::ctype_base::upper; | |
45 | int i03 = std::ctype_base::lower; | |
46 | int i04 = std::ctype_base::digit; | |
47 | int i05 = std::ctype_base::punct; | |
48 | int i06 = std::ctype_base::alpha; | |
49 | int i07 = std::ctype_base::xdigit; | |
50 | int i08 = std::ctype_base::alnum; | |
51 | int i09 = std::ctype_base::graph; | |
52 | int i10 = std::ctype_base::print; | |
53 | int i11 = std::ctype_base::cntrl; | |
f64ce6c6 BK |
54 | VERIFY ( i01 != i02); |
55 | VERIFY ( i02 != i03); | |
56 | VERIFY ( i03 != i04); | |
57 | VERIFY ( i04 != i05); | |
58 | VERIFY ( i05 != i06); | |
59 | VERIFY ( i06 != i07); | |
60 | VERIFY ( i07 != i08); | |
61 | VERIFY ( i08 != i09); | |
62 | VERIFY ( i09 != i10); | |
63 | VERIFY ( i10 != i11); | |
64 | VERIFY ( i11 != i01); | |
65 | ||
66 | // bool is(mask m, char_type c) const; | |
67 | VERIFY( gctype.is(std::ctype_base::space, c30) ); | |
68 | VERIFY( gctype.is(std::ctype_base::upper, c00) ); | |
69 | VERIFY( gctype.is(std::ctype_base::lower, c10) ); | |
70 | VERIFY( gctype.is(std::ctype_base::digit, c20) ); | |
71 | VERIFY( gctype.is(std::ctype_base::punct, c40) ); | |
72 | VERIFY( gctype.is(std::ctype_base::alpha, c50) ); | |
73 | VERIFY( gctype.is(std::ctype_base::alpha, c60) ); | |
74 | VERIFY( gctype.is(std::ctype_base::xdigit, c20) ); | |
75 | VERIFY( !gctype.is(std::ctype_base::xdigit, c80) ); | |
76 | VERIFY( gctype.is(std::ctype_base::alnum, c50) ); | |
77 | VERIFY( gctype.is(std::ctype_base::alnum, c20) ); | |
78 | VERIFY( gctype.is(std::ctype_base::graph, c40) ); | |
79 | VERIFY( gctype.is(std::ctype_base::graph, c20) ); | |
80 | ||
81 | // const char* is(const char* low, const char* high, mask* vec) const | |
82 | std::ctype_base::mask m00 = static_cast<std::ctype_base::mask>(0); | |
83 | std::ctype_base::mask m01[3]; | |
84 | std::ctype_base::mask m02[13]; | |
85 | const char_type* cc0 = strlit00; | |
8fc81078 PC |
86 | const char_type* cc1 = 0; |
87 | const char_type* cc2 = 0; | |
f64ce6c6 BK |
88 | |
89 | cc0 = strlit00; | |
465ad0c7 BK |
90 | for (std::size_t i = 0; i < 3; ++i) |
91 | m01[i] = m00; | |
f64ce6c6 BK |
92 | cc1 = gctype.is(cc0, cc0, m01); |
93 | VERIFY( cc1 == strlit00 ); | |
94 | VERIFY( m01[0] == m00 ); | |
95 | VERIFY( m01[1] == m00 ); | |
96 | VERIFY( m01[2] == m00 ); | |
97 | ||
465ad0c7 BK |
98 | cc0 = strlit00; |
99 | for (std::size_t i = 0; i < 3; ++i) | |
100 | m01[i] = m00; | |
101 | cc2 = gctype.is(cc0, cc0 + 3, m01); | |
102 | VERIFY( cc2 == strlit00 + 3); | |
f64ce6c6 BK |
103 | VERIFY( m01[0] != m00 ); |
104 | VERIFY( m01[1] != m00 ); | |
105 | VERIFY( m01[2] != m00 ); | |
106 | VERIFY( gctype.is(m01[0], cc0[0]) ); | |
107 | VERIFY( gctype.is(m01[1], cc0[1]) ); | |
108 | VERIFY( gctype.is(m01[2], cc0[2]) ); | |
f64ce6c6 BK |
109 | |
110 | cc0 = strlit01; | |
465ad0c7 BK |
111 | for (std::size_t i = 0; i < 13; ++i) |
112 | m02[i] = m00; | |
f64ce6c6 BK |
113 | cc1 = gctype.is(cc0, cc0 + 13, m02); |
114 | VERIFY( cc1 == strlit01 + 13); | |
f64ce6c6 BK |
115 | VERIFY( m02[6] != m00 ); |
116 | VERIFY( m02[7] != m00 ); | |
117 | VERIFY( m02[8] != m00 ); | |
118 | VERIFY( m02[8] != m02[6] ); | |
119 | VERIFY( m02[6] != m02[7] ); | |
120 | VERIFY( static_cast<bool>(m02[6] & std::ctype_base::alnum) ); | |
121 | VERIFY( static_cast<bool>(m02[6] & std::ctype_base::upper) ); | |
122 | VERIFY( static_cast<bool>(m02[6] & std::ctype_base::alpha) ); | |
123 | VERIFY( static_cast<bool>(m02[7] & std::ctype_base::punct) ); | |
124 | VERIFY( static_cast<bool>(m02[8] & std::ctype_base::space) ); | |
125 | VERIFY( gctype.is(m02[6], cc0[6]) ); | |
126 | VERIFY( gctype.is(m02[7], cc0[7]) ); | |
127 | VERIFY( gctype.is(m02[8], cc0[8]) ); | |
f64ce6c6 BK |
128 | } |
129 | ||
f64ce6c6 BK |
130 | int main() |
131 | { | |
132 | test01(); | |
f64ce6c6 BK |
133 | return 0; |
134 | } |