aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/22_locale/ctype.cc
blob: 54a6a4e2e03e40d72cc57461abda30f05ebaf14a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// 1999-08-24 bkoz

// Copyright (C) 2000, 1999 Free Software Foundation
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.

// 22.2.1 the ctype category

// 1: Test that the locale headers are picking up the correct declaration
// of the internal type `ctype_base::mask'.
int mask ();

#include <locale>

// 2: Should be able to instantiate this for other types besides char, wchar_t
typedef std::ctype<char> cctype;

class gnu_ctype: public std::ctype<unsigned char> 
{ 
private:
  const cctype& _M_cctype;

public:
  explicit 
  gnu_ctype(size_t __refs = 0) 
  : std::ctype<unsigned char>(__refs), 
    _M_cctype(std::use_facet<cctype>(std::locale::classic())) 
  { }

  ~gnu_ctype();

protected:
  virtual bool 
  do_is(mask __m, char_type __c) const
  { return _M_cctype.is(__m, __c); }

  virtual const char_type*
  do_is(const char_type* __lo, const char_type* __hi, mask* __vec) const
  { 
    const char* __c = _M_cctype.is(reinterpret_cast<const char*>(__lo), 
				   reinterpret_cast<const char*>(__hi), __vec);
    return reinterpret_cast<const char_type*>(__c);
  }
  
  virtual const char_type*
  do_scan_is(mask __m, const char_type* __lo, const char_type* __hi) const
  {
    const char* __c = _M_cctype.scan_is(__m, 
					reinterpret_cast<const char*>(__lo), 
					reinterpret_cast<const char*>(__hi));
    return reinterpret_cast<const char_type*>(__c);
  }

  virtual const char_type*
  do_scan_not(mask __m, const char_type* __lo, const char_type* __hi) const
  {
    const char* __c = _M_cctype.scan_is(__m, 
					reinterpret_cast<const char*>(__lo), 
					reinterpret_cast<const char*>(__hi));
    return reinterpret_cast<const char_type*>(__c);
  }

  virtual char_type 
  do_toupper(char_type __c) const
  { return _M_cctype.toupper(__c); }

  virtual const char_type*
  do_toupper(char_type* __lo, const char_type* __hi) const
  {
    const char* __c = _M_cctype.toupper(reinterpret_cast<char*>(__lo), 
					reinterpret_cast<const char*>(__hi));
    return reinterpret_cast<const char_type*>(__c);
  }

  virtual char_type 
  do_tolower(char_type __c) const
  { return _M_cctype.tolower(__c); }

  virtual const char_type*
  do_tolower(char_type* __lo, const char_type* __hi) const
  {
    const char* __c = _M_cctype.toupper(reinterpret_cast<char*>(__lo), 
					reinterpret_cast<const char*>(__hi));
    return reinterpret_cast<const char_type*>(__c);
  }

  virtual char_type 
  do_widen(char __c) const
  { return _M_cctype.widen(__c); }

  virtual const char*
  do_widen(const char* __lo, const char* __hi, char_type* __dest) const
  {
    const char* __c = _M_cctype.widen(reinterpret_cast<const char*>(__lo), 
				      reinterpret_cast<const char*>(__hi),
				      reinterpret_cast<char*>(__dest));
    return __c;
  }

  virtual char 
  do_narrow(char_type __c, char __dfault) const
  { return _M_cctype.narrow(__c, __dfault); }

  virtual const char_type*
  do_narrow(const char_type* __lo, const char_type* __hi, char __dfault, 
	    char* __dest) const
  {
    const char* __c = _M_cctype.narrow(reinterpret_cast<const char*>(__lo), 
				       reinterpret_cast<const char*>(__hi),
				       __dfault,
				       reinterpret_cast<char*>(__dest));
    return reinterpret_cast<const char_type*>(__c);
  }

};

gnu_ctype::~gnu_ctype() { }

gnu_ctype facet01;

// 3: Sanity check ctype_base::mask bitmask requirements
void
test01()
{
  using namespace std;

  ctype_base::mask m01;
  ctype_base::mask m02;
  
  m01 = ctype_base::space;
  m02 = ctype_base::xdigit;

  m01 & m02;
  m01 | m02;
  m01 ^ m02;
  ~m01;
  m01 &= m02;
  m01 |= m02;
  m01 ^= m02;
}

class gnu_obj 
{ };

class gnu_ctype2: public std::ctype<gnu_obj> 
{ };

// libstdc++/3017
void test02()
{
  gnu_ctype2 obj;
}

int main() 
{ 
  test01();
  test02();
  return 0;
}