]>
Commit | Line | Data |
---|---|---|
5f8d36fe | 1 | // { dg-do compile } |
b2dad0e3 BK |
2 | // 1999-08-24 bkoz |
3 | ||
5f8d36fe | 4 | // Copyright (C) 1999, 2000, 2003 Free Software Foundation |
b2dad0e3 BK |
5 | // |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 2, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING. If not, write to the Free | |
19 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
20 | // USA. | |
21 | ||
dbb27f26 BK |
22 | // 22.2.1 The ctype category |
23 | ||
b2dad0e3 BK |
24 | // 1: Test that the locale headers are picking up the correct declaration |
25 | // of the internal type `ctype_base::mask'. | |
26 | int mask (); | |
27 | ||
28 | #include <locale> | |
29 | ||
30 | // 2: Should be able to instantiate this for other types besides char, wchar_t | |
205c6f17 BK |
31 | typedef std::ctype<char> cctype; |
32 | ||
33 | class gnu_ctype: public std::ctype<unsigned char> | |
34 | { | |
35 | private: | |
36 | const cctype& _M_cctype; | |
37 | ||
38 | public: | |
39 | explicit | |
40 | gnu_ctype(size_t __refs = 0) | |
41 | : std::ctype<unsigned char>(__refs), | |
42 | _M_cctype(std::use_facet<cctype>(std::locale::classic())) | |
43 | { } | |
44 | ||
45 | ~gnu_ctype(); | |
46 | ||
47 | protected: | |
48 | virtual bool | |
49 | do_is(mask __m, char_type __c) const | |
50 | { return _M_cctype.is(__m, __c); } | |
51 | ||
52 | virtual const char_type* | |
53 | do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const | |
54 | { | |
55 | const char* __c = _M_cctype.is(reinterpret_cast<const char*>(__lo), | |
56 | reinterpret_cast<const char*>(__hi), __vec); | |
57 | return reinterpret_cast<const char_type*>(__c); | |
58 | } | |
59 | ||
60 | virtual const char_type* | |
61 | do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const | |
62 | { | |
63 | const char* __c = _M_cctype.scan_is(__m, | |
64 | reinterpret_cast<const char*>(__lo), | |
65 | reinterpret_cast<const char*>(__hi)); | |
66 | return reinterpret_cast<const char_type*>(__c); | |
67 | } | |
68 | ||
69 | virtual const char_type* | |
70 | do_scan_not(mask __m, const char_type* __lo, const char_type* __hi) const | |
71 | { | |
72 | const char* __c = _M_cctype.scan_is(__m, | |
73 | reinterpret_cast<const char*>(__lo), | |
74 | reinterpret_cast<const char*>(__hi)); | |
75 | return reinterpret_cast<const char_type*>(__c); | |
76 | } | |
77 | ||
78 | virtual char_type | |
79 | do_toupper(char_type __c) const | |
80 | { return _M_cctype.toupper(__c); } | |
81 | ||
82 | virtual const char_type* | |
83 | do_toupper(char_type* __lo, const char_type* __hi) const | |
84 | { | |
85 | const char* __c = _M_cctype.toupper(reinterpret_cast<char*>(__lo), | |
86 | reinterpret_cast<const char*>(__hi)); | |
87 | return reinterpret_cast<const char_type*>(__c); | |
88 | } | |
89 | ||
90 | virtual char_type | |
91 | do_tolower(char_type __c) const | |
92 | { return _M_cctype.tolower(__c); } | |
93 | ||
94 | virtual const char_type* | |
95 | do_tolower(char_type* __lo, const char_type* __hi) const | |
96 | { | |
97 | const char* __c = _M_cctype.toupper(reinterpret_cast<char*>(__lo), | |
98 | reinterpret_cast<const char*>(__hi)); | |
99 | return reinterpret_cast<const char_type*>(__c); | |
100 | } | |
101 | ||
102 | virtual char_type | |
103 | do_widen(char __c) const | |
104 | { return _M_cctype.widen(__c); } | |
105 | ||
106 | virtual const char* | |
107 | do_widen(const char* __lo, const char* __hi, char_type* __dest) const | |
108 | { | |
109 | const char* __c = _M_cctype.widen(reinterpret_cast<const char*>(__lo), | |
110 | reinterpret_cast<const char*>(__hi), | |
111 | reinterpret_cast<char*>(__dest)); | |
112 | return __c; | |
113 | } | |
114 | ||
115 | virtual char | |
116 | do_narrow(char_type __c, char __dfault) const | |
117 | { return _M_cctype.narrow(__c, __dfault); } | |
118 | ||
119 | virtual const char_type* | |
120 | do_narrow(const char_type* __lo, const char_type* __hi, char __dfault, | |
121 | char* __dest) const | |
122 | { | |
123 | const char* __c = _M_cctype.narrow(reinterpret_cast<const char*>(__lo), | |
124 | reinterpret_cast<const char*>(__hi), | |
125 | __dfault, | |
126 | reinterpret_cast<char*>(__dest)); | |
127 | return reinterpret_cast<const char_type*>(__c); | |
128 | } | |
129 | ||
130 | }; | |
131 | ||
132 | gnu_ctype::~gnu_ctype() { } | |
133 | ||
b2dad0e3 BK |
134 | gnu_ctype facet01; |
135 | ||
d9ab8adb BK |
136 | // 3: Sanity check ctype_base::mask bitmask requirements |
137 | void | |
138 | test01() | |
139 | { | |
140 | using namespace std; | |
141 | ||
142 | ctype_base::mask m01; | |
143 | ctype_base::mask m02; | |
144 | ||
145 | m01 = ctype_base::space; | |
146 | m02 = ctype_base::xdigit; | |
147 | ||
148 | m01 & m02; | |
149 | m01 | m02; | |
150 | m01 ^ m02; | |
205c6f17 | 151 | ~m01; |
d9ab8adb BK |
152 | m01 &= m02; |
153 | m01 |= m02; | |
154 | m01 ^= m02; | |
155 | } | |
156 | ||
157 | int main() | |
158 | { | |
159 | test01(); | |
160 | return 0; | |
161 | } |