]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/ctype_is_char.cc
1 // Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
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
6 // Free Software Foundation; either version 2, or (at your option)
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.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction. Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License. This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
28 // 22.2.1.3.2 ctype<char> members
32 #include <testsuite_hooks.h>
34 // XXX This test (test02) is not working for non-glibc locale models.
35 // { dg-do run { xfail *-*-* } }
37 typedef char char_type
;
38 class gnu_ctype
: public std::ctype
<char_type
> { };
43 const char_type strlit00
[] = "manilla, cebu, tandag PHILIPPINES";
44 const char_type strlit01
[] = "MANILLA, CEBU, TANDAG PHILIPPINES";
45 const char_type strlit02
[] = "manilla, cebu, tandag philippines";
46 const char_type c00
= 'S';
47 const char_type c10
= 's';
48 const char_type c20
= '9';
49 const char_type c30
= ' ';
50 const char_type c40
= '!';
51 const char_type c50
= 'F';
52 const char_type c60
= 'f';
53 const char_type c70
= 'X';
54 const char_type c80
= 'x';
58 int len
= std::char_traits
<char_type
>::length(strlit00
);
59 char_type c_array
[len
+ 1];
61 // sanity check ctype_base::mask members
62 int i01
= std::ctype_base::space
;
63 int i02
= std::ctype_base::upper
;
64 int i03
= std::ctype_base::lower
;
65 int i04
= std::ctype_base::digit
;
66 int i05
= std::ctype_base::punct
;
67 int i06
= std::ctype_base::alpha
;
68 int i07
= std::ctype_base::xdigit
;
69 int i08
= std::ctype_base::alnum
;
70 int i09
= std::ctype_base::graph
;
71 int i10
= std::ctype_base::print
;
72 int i11
= std::ctype_base::cntrl
;
73 int i12
= sizeof(std::ctype_base::mask
);
86 // bool is(mask m, char_type c) const;
87 VERIFY( gctype
.is(std::ctype_base::space
, c30
) );
88 VERIFY( gctype
.is(std::ctype_base::upper
, c00
) );
89 VERIFY( gctype
.is(std::ctype_base::lower
, c10
) );
90 VERIFY( gctype
.is(std::ctype_base::digit
, c20
) );
91 VERIFY( gctype
.is(std::ctype_base::punct
, c40
) );
92 VERIFY( gctype
.is(std::ctype_base::alpha
, c50
) );
93 VERIFY( gctype
.is(std::ctype_base::alpha
, c60
) );
94 VERIFY( gctype
.is(std::ctype_base::xdigit
, c20
) );
95 VERIFY( !gctype
.is(std::ctype_base::xdigit
, c80
) );
96 VERIFY( gctype
.is(std::ctype_base::alnum
, c50
) );
97 VERIFY( gctype
.is(std::ctype_base::alnum
, c20
) );
98 VERIFY( gctype
.is(std::ctype_base::graph
, c40
) );
99 VERIFY( gctype
.is(std::ctype_base::graph
, c20
) );
101 // const char* is(const char* low, const char* high, mask* vec) const
102 std::ctype_base::mask m00
= static_cast<std::ctype_base::mask
>(0);
103 std::ctype_base::mask m01
[3];
104 std::ctype_base::mask m02
[13];
105 const char_type
* cc0
= strlit00
;
106 const char_type
* cc1
= NULL
;
107 const char_type
* cc2
= NULL
;
113 cc1
= gctype
.is(cc0
, cc0
, m01
);
114 VERIFY( cc1
== strlit00
);
115 VERIFY( m01
[0] == m00
);
116 VERIFY( m01
[1] == m00
);
117 VERIFY( m01
[2] == m00
);
123 cc2
= gctype
.is(cc0
, cc0
+ 3, m01
);
124 VERIFY( cc2
== strlit00
+ 3);
125 VERIFY( m01
[0] != m00
);
126 VERIFY( m01
[1] != m00
);
127 VERIFY( m01
[2] != m00
);
128 VERIFY( gctype
.is(m01
[0], cc0
[0]) );
129 VERIFY( gctype
.is(m01
[1], cc0
[1]) );
130 VERIFY( gctype
.is(m01
[2], cc0
[2]) );
133 cc1
= gctype
.is(cc0
, cc0
+ 13, m02
);
134 VERIFY( cc1
== strlit01
+ 13);
135 VERIFY( m02
[6] != m00
);
136 VERIFY( m02
[7] != m00
);
137 VERIFY( m02
[8] != m00
);
138 VERIFY( m02
[8] != m02
[6] );
139 VERIFY( m02
[6] != m02
[7] );
140 VERIFY( static_cast<bool>(m02
[6] & std::ctype_base::alnum
) );
141 VERIFY( static_cast<bool>(m02
[6] & std::ctype_base::upper
) );
142 VERIFY( static_cast<bool>(m02
[6] & std::ctype_base::alpha
) );
143 VERIFY( static_cast<bool>(m02
[7] & std::ctype_base::punct
) );
144 VERIFY( static_cast<bool>(m02
[8] & std::ctype_base::space
) );
145 VERIFY( gctype
.is(m02
[6], cc0
[6]) );
146 VERIFY( gctype
.is(m02
[7], cc0
[7]) );
147 VERIFY( gctype
.is(m02
[8], cc0
[8]) );
150 // libstdc++/4456, libstdc++/4457, libstdc++/4458
154 typedef ctype_base::mask mask
;
155 typedef vector
<mask
> vector_type
;
159 // const int max = numeric_limits<char>::max();
161 const int ctype_mask_max
= 10;
162 vector_type
v_c(max
);
163 vector_type
v_de(max
);
166 locale loc_c
= locale::classic();
167 const ctype
<char>& ctype_c
= use_facet
<ctype
<char> >(loc_c
);
168 for (int i
= 0; i
< max
; ++i
)
170 char_type c
= static_cast<char>(i
);
171 mask mask_test
= static_cast<mask
>(0);
172 mask mask_is
= static_cast<mask
>(0);
173 for (int j
= 0; j
<= ctype_mask_max
; ++j
)
175 mask_test
= static_cast<mask
>(1 << j
);
176 if (ctype_c
.is(mask_test
, c
))
177 mask_is
|= mask_test
;
183 locale
loc_de("de_DE");
184 const ctype
<char>& ctype_de
= use_facet
<ctype
<char> >(loc_de
);
185 for (int i
= 0; i
< max
; ++i
)
187 char_type c
= static_cast<char>(i
);
188 mask mask_test
= static_cast<mask
>(0);
189 mask mask_is
= static_cast<mask
>(0);
190 for (int j
= 0; j
<= ctype_mask_max
; ++j
)
192 mask_test
= static_cast<mask
>(1 << j
);
193 if (ctype_de
.is(mask_test
, c
))
194 mask_is
|= mask_test
;
199 #if QUANNUM_VERBOSE_LYRICALLY_ADEPT_BAY_AREA_MCS_MODE
200 for (int i
= 0; i
< max
; ++i
)
202 char_type mark
= v_c
[i
] == v_de
[i
] ? ' ' : '-';
203 cout
<< i
<< ' ' << mark
<< ' ' << static_cast<char>(i
) << '\t' ;
204 cout
<< "v_c: " << setw(4) << v_c
[i
] << '\t';
205 cout
<< "v_de: " << setw(4) << v_de
[i
] << endl
;
207 cout
<< (v_c
== v_de
) << endl
;
210 VERIFY( v_c
!= v_de
);
213 // Per Liboriussen <liborius@stofanet.dk>
217 std::ctype_base::mask maskdata
[256];
218 for (int i
= 0; i
< 256; ++i
)
219 maskdata
[i
] = std::ctype_base::alpha
;
220 std::ctype
<char>* f
= new std::ctype
<char>(maskdata
);
222 std::locale
loc(global
, f
);
223 for (int i
= 0; i
< 256; ++i
)
226 VERIFY( std::isalpha(ch
, loc
) );
233 #ifdef _GLIBCPP_HAVE_SETENV
234 // Set the global locale to non-"C".
235 std::locale
loc_de("de_DE");
236 std::locale::global(loc_de
);
238 // Set LANG environment variable to de_DE.
239 const char* oldLANG
= getenv("LANG");
240 if (!setenv("LANG", "de_DE", 1))
245 setenv("LANG", oldLANG
? oldLANG
: "", 1);
250 // http://gcc.gnu.org/ml/libstdc++/2002-05/msg00038.html
255 const char* tentLANG
= std::setlocale(LC_ALL
, "ja_JP.eucjp");
256 if (tentLANG
!= NULL
)
258 std::string preLANG
= tentLANG
;
262 std::string postLANG
= std::setlocale(LC_ALL
, NULL
);
263 VERIFY( preLANG
== postLANG
);