1 |
19 |
jlechner |
// Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
|
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
|
6 |
|
|
// Free Software Foundation; either version 2, or (at your option)
|
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
|
15 |
|
|
// with this library; see the file COPYING. If not, write to the Free
|
16 |
|
|
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
17 |
|
|
// USA.
|
18 |
|
|
|
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.
|
27 |
|
|
|
28 |
|
|
// 22.2.1.3.2 ctype<char> members
|
29 |
|
|
|
30 |
|
|
#include <locale>
|
31 |
|
|
#include <testsuite_hooks.h>
|
32 |
|
|
|
33 |
|
|
typedef wchar_t char_type;
|
34 |
|
|
class gnu_ctype: public std::ctype<char_type> { };
|
35 |
|
|
|
36 |
|
|
void test01()
|
37 |
|
|
{
|
38 |
|
|
bool test __attribute__((unused)) = true;
|
39 |
|
|
const char_type strlit00[] = L"manilla, cebu, tandag PHILIPPINES";
|
40 |
|
|
const char_type strlit01[] = L"MANILLA, CEBU, TANDAG PHILIPPINES";
|
41 |
|
|
const char_type c00 = L'S';
|
42 |
|
|
const char_type c10 = L's';
|
43 |
|
|
const char_type c20 = L'9';
|
44 |
|
|
const char_type c30 = L' ';
|
45 |
|
|
const char_type c40 = L'!';
|
46 |
|
|
const char_type c50 = L'F';
|
47 |
|
|
const char_type c60 = L'f';
|
48 |
|
|
const char_type c80 = L'x';
|
49 |
|
|
|
50 |
|
|
gnu_ctype gctype;
|
51 |
|
|
|
52 |
|
|
// sanity check ctype_base::mask members
|
53 |
|
|
int i01 = std::ctype_base::space;
|
54 |
|
|
int i02 = std::ctype_base::upper;
|
55 |
|
|
int i03 = std::ctype_base::lower;
|
56 |
|
|
int i04 = std::ctype_base::digit;
|
57 |
|
|
int i05 = std::ctype_base::punct;
|
58 |
|
|
int i06 = std::ctype_base::alpha;
|
59 |
|
|
int i07 = std::ctype_base::xdigit;
|
60 |
|
|
int i08 = std::ctype_base::alnum;
|
61 |
|
|
int i09 = std::ctype_base::graph;
|
62 |
|
|
int i10 = std::ctype_base::print;
|
63 |
|
|
int i11 = std::ctype_base::cntrl;
|
64 |
|
|
VERIFY ( i01 != i02);
|
65 |
|
|
VERIFY ( i02 != i03);
|
66 |
|
|
VERIFY ( i03 != i04);
|
67 |
|
|
VERIFY ( i04 != i05);
|
68 |
|
|
VERIFY ( i05 != i06);
|
69 |
|
|
VERIFY ( i06 != i07);
|
70 |
|
|
VERIFY ( i07 != i08);
|
71 |
|
|
VERIFY ( i08 != i09);
|
72 |
|
|
VERIFY ( i09 != i10);
|
73 |
|
|
VERIFY ( i10 != i11);
|
74 |
|
|
VERIFY ( i11 != i01);
|
75 |
|
|
|
76 |
|
|
// bool is(mask m, char_type c) const;
|
77 |
|
|
VERIFY( gctype.is(std::ctype_base::space, c30) );
|
78 |
|
|
VERIFY( gctype.is(std::ctype_base::upper, c00) );
|
79 |
|
|
VERIFY( gctype.is(std::ctype_base::lower, c10) );
|
80 |
|
|
VERIFY( gctype.is(std::ctype_base::digit, c20) );
|
81 |
|
|
VERIFY( gctype.is(std::ctype_base::punct, c40) );
|
82 |
|
|
VERIFY( gctype.is(std::ctype_base::alpha, c50) );
|
83 |
|
|
VERIFY( gctype.is(std::ctype_base::alpha, c60) );
|
84 |
|
|
VERIFY( gctype.is(std::ctype_base::xdigit, c20) );
|
85 |
|
|
VERIFY( !gctype.is(std::ctype_base::xdigit, c80) );
|
86 |
|
|
VERIFY( gctype.is(std::ctype_base::alnum, c50) );
|
87 |
|
|
VERIFY( gctype.is(std::ctype_base::alnum, c20) );
|
88 |
|
|
VERIFY( gctype.is(std::ctype_base::graph, c40) );
|
89 |
|
|
VERIFY( gctype.is(std::ctype_base::graph, c20) );
|
90 |
|
|
|
91 |
|
|
// const char* is(const char* low, const char* high, mask* vec) const
|
92 |
|
|
std::ctype_base::mask m00 = static_cast<std::ctype_base::mask>(0);
|
93 |
|
|
std::ctype_base::mask m01[3];
|
94 |
|
|
std::ctype_base::mask m02[13];
|
95 |
|
|
const char_type* cc0 = strlit00;
|
96 |
|
|
const char_type* cc1 = NULL;
|
97 |
|
|
const char_type* cc2 = NULL;
|
98 |
|
|
|
99 |
|
|
cc0 = strlit00;
|
100 |
|
|
for (std::size_t i = 0; i < 3; ++i)
|
101 |
|
|
m01[i] = m00;
|
102 |
|
|
cc1 = gctype.is(cc0, cc0, m01);
|
103 |
|
|
VERIFY( cc1 == strlit00 );
|
104 |
|
|
VERIFY( m01[0] == m00 );
|
105 |
|
|
VERIFY( m01[1] == m00 );
|
106 |
|
|
VERIFY( m01[2] == m00 );
|
107 |
|
|
|
108 |
|
|
cc0 = strlit00;
|
109 |
|
|
for (std::size_t i = 0; i < 3; ++i)
|
110 |
|
|
m01[i] = m00;
|
111 |
|
|
cc2 = gctype.is(cc0, cc0 + 3, m01);
|
112 |
|
|
VERIFY( cc2 == strlit00 + 3);
|
113 |
|
|
VERIFY( m01[0] != m00 );
|
114 |
|
|
VERIFY( m01[1] != m00 );
|
115 |
|
|
VERIFY( m01[2] != m00 );
|
116 |
|
|
VERIFY( gctype.is(m01[0], cc0[0]) );
|
117 |
|
|
VERIFY( gctype.is(m01[1], cc0[1]) );
|
118 |
|
|
VERIFY( gctype.is(m01[2], cc0[2]) );
|
119 |
|
|
|
120 |
|
|
cc0 = strlit01;
|
121 |
|
|
for (std::size_t i = 0; i < 13; ++i)
|
122 |
|
|
m02[i] = m00;
|
123 |
|
|
cc1 = gctype.is(cc0, cc0 + 13, m02);
|
124 |
|
|
VERIFY( cc1 == strlit01 + 13);
|
125 |
|
|
VERIFY( m02[6] != m00 );
|
126 |
|
|
VERIFY( m02[7] != m00 );
|
127 |
|
|
VERIFY( m02[8] != m00 );
|
128 |
|
|
VERIFY( m02[8] != m02[6] );
|
129 |
|
|
VERIFY( m02[6] != m02[7] );
|
130 |
|
|
VERIFY( static_cast<bool>(m02[6] & std::ctype_base::alnum) );
|
131 |
|
|
VERIFY( static_cast<bool>(m02[6] & std::ctype_base::upper) );
|
132 |
|
|
VERIFY( static_cast<bool>(m02[6] & std::ctype_base::alpha) );
|
133 |
|
|
VERIFY( static_cast<bool>(m02[7] & std::ctype_base::punct) );
|
134 |
|
|
VERIFY( static_cast<bool>(m02[8] & std::ctype_base::space) );
|
135 |
|
|
VERIFY( gctype.is(m02[6], cc0[6]) );
|
136 |
|
|
VERIFY( gctype.is(m02[7], cc0[7]) );
|
137 |
|
|
VERIFY( gctype.is(m02[8], cc0[8]) );
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
int main()
|
141 |
|
|
{
|
142 |
|
|
test01();
|
143 |
|
|
return 0;
|
144 |
|
|
}
|