ebea4031e3bbaee86b9e9dd2858f45578b5bab38
3 // Copyright (C) 2000 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
33 // NB: Don't include any other headers in this file.
34 #include <debug_assert.h>
36 class gnu_ctype
: public std::ctype
<char> { };
41 const char strlit00
[] = "manilla, cebu, tandag PHILIPPINES";
42 const char strlit01
[] = "MANILLA, CEBU, TANDAG PHILIPPINES";
43 const char strlit02
[] = "manilla, cebu, tandag philippines";
56 int len
= std::char_traits
<char>::length(strlit00
);
57 char c_array
[len
+ 1];
59 // sanity check ctype_base::mask members
60 int i01
= std::ctype_base::space
;
61 int i02
= std::ctype_base::upper
;
62 int i03
= std::ctype_base::lower
;
63 int i04
= std::ctype_base::digit
;
64 int i05
= std::ctype_base::punct
;
65 int i06
= std::ctype_base::alpha
;
66 int i07
= std::ctype_base::xdigit
;
67 int i08
= std::ctype_base::alnum
;
68 int i09
= std::ctype_base::graph
;
69 int i10
= std::ctype_base::print
;
70 int i11
= std::ctype_base::cntrl
;
71 int i12
= sizeof(std::ctype_base::mask
);
84 // bool is(mask m, char c) const;
85 VERIFY( gctype
.is(std::ctype_base::space
, c30
) );
86 VERIFY( gctype
.is(std::ctype_base::upper
, c00
) );
87 VERIFY( gctype
.is(std::ctype_base::lower
, c10
) );
88 VERIFY( gctype
.is(std::ctype_base::digit
, c20
) );
89 VERIFY( gctype
.is(std::ctype_base::punct
, c40
) );
90 VERIFY( gctype
.is(std::ctype_base::alpha
, c50
) );
91 VERIFY( gctype
.is(std::ctype_base::alpha
, c60
) );
92 VERIFY( gctype
.is(std::ctype_base::xdigit
, c20
) );
93 VERIFY( !gctype
.is(std::ctype_base::xdigit
, c80
) );
94 VERIFY( gctype
.is(std::ctype_base::alnum
, c50
) );
95 VERIFY( gctype
.is(std::ctype_base::alnum
, c20
) );
96 VERIFY( gctype
.is(std::ctype_base::graph
, c40
) );
97 VERIFY( gctype
.is(std::ctype_base::graph
, c20
) );
99 // const char* is(const char* low, const char* high, mask* vec) const
100 std::ctype_base::mask m00
= static_cast<std::ctype_base::mask
>(0);
101 std::ctype_base::mask m01
[3];
102 std::ctype_base::mask m02
[13];
103 const char* cc0
= strlit00
;
104 const char* cc1
= NULL
;
105 const char* cc2
= NULL
;
111 cc1
= gctype
.is(cc0
, cc0
, m01
);
112 VERIFY( cc1
== strlit00
);
113 VERIFY( m01
[0] == m00
);
114 VERIFY( m01
[1] == m00
);
115 VERIFY( m01
[2] == m00
);
121 cc2
= gctype
.is(cc0
, cc0
+ 3, m01
);
122 VERIFY( cc2
== strlit00
+ 3);
123 VERIFY( m01
[0] != m00
);
124 VERIFY( m01
[1] != m00
);
125 VERIFY( m01
[2] != m00
);
126 VERIFY( gctype
.is(m01
[0], cc0
[0]) );
127 VERIFY( gctype
.is(m01
[1], cc0
[1]) );
128 VERIFY( gctype
.is(m01
[2], cc0
[2]) );
131 cc1
= gctype
.is(cc0
, cc0
+ 13, m02
);
132 VERIFY( cc1
== strlit01
+ 13);
133 VERIFY( m02
[6] != m00
);
134 VERIFY( m02
[7] != m00
);
135 VERIFY( m02
[8] != m00
);
136 VERIFY( m02
[8] != m02
[6] );
137 VERIFY( m02
[6] != m02
[7] );
138 VERIFY( static_cast<bool>(m02
[6] & std::ctype_base::alnum
) );
139 VERIFY( static_cast<bool>(m02
[6] & std::ctype_base::upper
) );
140 VERIFY( static_cast<bool>(m02
[6] & std::ctype_base::alpha
) );
141 VERIFY( static_cast<bool>(m02
[7] & std::ctype_base::punct
) );
142 VERIFY( static_cast<bool>(m02
[8] & std::ctype_base::space
) );
143 VERIFY( gctype
.is(m02
[6], cc0
[6]) );
144 VERIFY( gctype
.is(m02
[7], cc0
[7]) );
145 VERIFY( gctype
.is(m02
[8], cc0
[8]) );
147 // char toupper(char c) const
148 c100
= gctype
.toupper(c10
);
149 VERIFY( c100
== c00
);
151 // char tolower(char c) const
152 c100
= gctype
.tolower(c00
);
153 VERIFY( c100
== c10
);
155 // char toupper(char* low, const char* hi) const
156 std::char_traits
<char>::copy(c_array
, strlit02
, len
+ 1);
157 gctype
.toupper(c_array
, c_array
+ len
);
158 VERIFY( !std::char_traits
<char>::compare(c_array
, strlit01
, len
- 1) );
160 // char tolower(char* low, const char* hi) const
161 std::char_traits
<char>::copy(c_array
, strlit01
, len
+ 1);
162 gctype
.tolower(c_array
, c_array
+ len
);
163 VERIFY( !std::char_traits
<char>::compare(c_array
, strlit02
, len
- 1) );