3 // Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
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
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // 22.2.1.3.2 ctype<char> members
34 #include <testsuite_hooks.h>
36 // XXX This test (test02) is not working for non-glibc locale models.
37 // { dg-do run { xfail *-*-* } }
39 class gnu_ctype: public std::ctype<char> { };
44 const char strlit00[] = "manilla, cebu, tandag PHILIPPINES";
45 const char strlit01[] = "MANILLA, CEBU, TANDAG PHILIPPINES";
46 const char strlit02[] = "manilla, cebu, tandag philippines";
59 int len = std::char_traits<char>::length(strlit00);
60 char c_array[len + 1];
62 // sanity check ctype_base::mask members
63 int i01 = std::ctype_base::space;
64 int i02 = std::ctype_base::upper;
65 int i03 = std::ctype_base::lower;
66 int i04 = std::ctype_base::digit;
67 int i05 = std::ctype_base::punct;
68 int i06 = std::ctype_base::alpha;
69 int i07 = std::ctype_base::xdigit;
70 int i08 = std::ctype_base::alnum;
71 int i09 = std::ctype_base::graph;
72 int i10 = std::ctype_base::print;
73 int i11 = std::ctype_base::cntrl;
74 int i12 = sizeof(std::ctype_base::mask);
87 // bool is(mask m, char c) const;
88 VERIFY( gctype.is(std::ctype_base::space, c30) );
89 VERIFY( gctype.is(std::ctype_base::upper, c00) );
90 VERIFY( gctype.is(std::ctype_base::lower, c10) );
91 VERIFY( gctype.is(std::ctype_base::digit, c20) );
92 VERIFY( gctype.is(std::ctype_base::punct, c40) );
93 VERIFY( gctype.is(std::ctype_base::alpha, c50) );
94 VERIFY( gctype.is(std::ctype_base::alpha, c60) );
95 VERIFY( gctype.is(std::ctype_base::xdigit, c20) );
96 VERIFY( !gctype.is(std::ctype_base::xdigit, c80) );
97 VERIFY( gctype.is(std::ctype_base::alnum, c50) );
98 VERIFY( gctype.is(std::ctype_base::alnum, c20) );
99 VERIFY( gctype.is(std::ctype_base::graph, c40) );
100 VERIFY( gctype.is(std::ctype_base::graph, c20) );
102 // const char* is(const char* low, const char* high, mask* vec) const
103 std::ctype_base::mask m00 = static_cast<std::ctype_base::mask>(0);
104 std::ctype_base::mask m01[3];
105 std::ctype_base::mask m02[13];
106 const char* cc0 = strlit00;
107 const char* cc1 = NULL;
108 const char* cc2 = NULL;
114 cc1 = gctype.is(cc0, cc0, m01);
115 VERIFY( cc1 == strlit00 );
116 VERIFY( m01[0] == m00 );
117 VERIFY( m01[1] == m00 );
118 VERIFY( m01[2] == m00 );
124 cc2 = gctype.is(cc0, cc0 + 3, m01);
125 VERIFY( cc2 == strlit00 + 3);
126 VERIFY( m01[0] != m00 );
127 VERIFY( m01[1] != m00 );
128 VERIFY( m01[2] != m00 );
129 VERIFY( gctype.is(m01[0], cc0[0]) );
130 VERIFY( gctype.is(m01[1], cc0[1]) );
131 VERIFY( gctype.is(m01[2], cc0[2]) );
134 cc1 = gctype.is(cc0, cc0 + 13, m02);
135 VERIFY( cc1 == strlit01 + 13);
136 VERIFY( m02[6] != m00 );
137 VERIFY( m02[7] != m00 );
138 VERIFY( m02[8] != m00 );
139 VERIFY( m02[8] != m02[6] );
140 VERIFY( m02[6] != m02[7] );
141 VERIFY( static_cast<bool>(m02[6] & std::ctype_base::alnum) );
142 VERIFY( static_cast<bool>(m02[6] & std::ctype_base::upper) );
143 VERIFY( static_cast<bool>(m02[6] & std::ctype_base::alpha) );
144 VERIFY( static_cast<bool>(m02[7] & std::ctype_base::punct) );
145 VERIFY( static_cast<bool>(m02[8] & std::ctype_base::space) );
146 VERIFY( gctype.is(m02[6], cc0[6]) );
147 VERIFY( gctype.is(m02[7], cc0[7]) );
148 VERIFY( gctype.is(m02[8], cc0[8]) );
150 // char toupper(char c) const
151 c100 = gctype.toupper(c10);
152 VERIFY( c100 == c00 );
154 // char tolower(char c) const
155 c100 = gctype.tolower(c00);
156 VERIFY( c100 == c10 );
158 // char toupper(char* low, const char* hi) const
159 std::char_traits<char>::copy(c_array, strlit02, len + 1);
160 gctype.toupper(c_array, c_array + len);
161 VERIFY( !std::char_traits<char>::compare(c_array, strlit01, len - 1) );
163 // char tolower(char* low, const char* hi) const
164 std::char_traits<char>::copy(c_array, strlit01, len + 1);
165 gctype.tolower(c_array, c_array + len);
166 VERIFY( !std::char_traits<char>::compare(c_array, strlit02, len - 1) );
174 // libstdc++/4456, libstdc++/4457, libstdc++/4458
178 typedef ctype_base::mask mask;
179 typedef vector<mask> vector_type;
183 // const int max = numeric_limits<char>::max();
185 const int ctype_mask_max = 10;
186 vector_type v_c(max);
187 vector_type v_de(max);
190 locale loc_c = locale::classic();
191 const ctype<char>& ctype_c = use_facet<ctype<char> >(loc_c);
192 for (int i = 0; i < max; ++i)
194 char c = static_cast<char>(i);
195 mask mask_test = static_cast<mask>(0);
196 mask mask_is = static_cast<mask>(0);
197 for (int j = 0; j <= ctype_mask_max; ++j)
199 mask_test = static_cast<mask>(1 << j);
200 if (ctype_c.is(mask_test, c))
201 mask_is |= mask_test;
207 locale loc_de("de_DE");
208 const ctype<char>& ctype_de = use_facet<ctype<char> >(loc_de);
209 for (int i = 0; i < max; ++i)
211 char c = static_cast<char>(i);
212 mask mask_test = static_cast<mask>(0);
213 mask mask_is = static_cast<mask>(0);
214 for (int j = 0; j <= ctype_mask_max; ++j)
216 mask_test = static_cast<mask>(1 << j);
217 if (ctype_de.is(mask_test, c))
218 mask_is |= mask_test;
223 #if QUANNUM_VERBOSE_LYRICALLY_ADEPT_BAY_AREA_MCS_MODE
224 for (int i = 0; i < max; ++i)
226 char mark = v_c[i] == v_de[i] ? ' ' : '-';
227 cout << i << ' ' << mark << ' ' << static_cast<char>(i) << '\t' ;
228 cout << "v_c: " << setw(4) << v_c[i] << '\t';
229 cout << "v_de: " << setw(4) << v_de[i] << endl;
231 cout << (v_c == v_de) << endl;
234 VERIFY( v_c != v_de );
237 // Dietmar Kühl via Peter Schmid
238 class comma_ctype: public std::ctype<char>
241 comma_ctype(): std::ctype<char>() { }
242 static void get_table()
246 // Per Liboriussen <liborius@stofanet.dk>
250 std::ctype_base::mask maskdata[256];
251 for (int i = 0; i < 256; ++i)
252 maskdata[i] = std::ctype_base::alpha;
253 std::ctype<char>* f = new std::ctype<char>(maskdata);
255 std::locale loc(global, f);
256 for (int i = 0; i < 256; ++i)
259 VERIFY( std::isalpha(ch, loc) );
266 #ifdef _GLIBCPP_HAVE_SETENV
267 // Set the global locale to non-"C".
268 std::locale loc_de("de_DE");
269 std::locale::global(loc_de);
271 // Set LANG environment variable to de_DE.
272 const char* oldLANG = getenv("LANG");
273 if (!setenv("LANG", "de_DE", 1))
278 setenv("LANG", oldLANG ? oldLANG : "", 1);