| 1 |
// -*- C++ -*- |
| 2 |
|
| 3 |
// Utility subroutines for the C++ library testsuite. |
| 4 |
// |
| 5 |
// Copyright (C) 2002-2025 Free Software Foundation, Inc. |
| 6 |
// |
| 7 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 8 |
// software; you can redistribute it and/or modify it under the |
| 9 |
// terms of the GNU General Public License as published by the |
| 10 |
// Free Software Foundation; either version 3, or (at your option) |
| 11 |
// any later version. |
| 12 |
// |
| 13 |
// This library is distributed in the hope that it will be useful, |
| 14 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
// GNU General Public License for more details. |
| 17 |
// |
| 18 |
// You should have received a copy of the GNU General Public License along |
| 19 |
// with this library; see the file COPYING3. If not see |
| 20 |
// <http://www.gnu.org/licenses/>. |
| 21 |
// |
| 22 |
|
| 23 |
#include <testsuite_character.h> |
| 24 |
|
| 25 |
namespace std |
| 26 |
{ |
| 27 |
locale::id |
| 28 |
codecvt<__gnu_test::pod_uchar, char, __gnu_test::pod_state>::id; |
| 29 |
|
| 30 |
locale::id |
| 31 |
ctype<__gnu_test::pod_uchar>::id; |
| 32 |
|
| 33 |
locale::id |
| 34 |
numpunct<__gnu_test::pod_uint>::id; |
| 35 |
|
| 36 |
locale::id |
| 37 |
moneypunct<__gnu_test::pod_uint>::id; |
| 38 |
|
| 39 |
// Member specializations for the existing facet classes. |
| 40 |
// NB: This isn't especially portable. Perhaps a better way would be |
| 41 |
// to just specialize all of numpunct and ctype. |
| 42 |
using __gnu_test::pod_ushort; |
| 43 |
typedef pod_ushort::value_type value_type; |
| 44 |
|
| 45 |
template<> |
| 46 |
bool |
| 47 |
ctype<pod_ushort>:: |
| 48 |
do_is(mask, char_type) const { return true; } |
| 49 |
|
| 50 |
template<> |
| 51 |
const pod_ushort* |
| 52 |
ctype<pod_ushort>:: |
| 53 |
do_is(const char_type* __lo, const char_type*, mask*) const |
| 54 |
{ return __lo; } |
| 55 |
|
| 56 |
template<> |
| 57 |
const pod_ushort* |
| 58 |
ctype<pod_ushort>:: |
| 59 |
do_scan_is(mask, const char_type* __lo, const char_type*) const |
| 60 |
{ return __lo; } |
| 61 |
|
| 62 |
template<> |
| 63 |
const pod_ushort* |
| 64 |
ctype<pod_ushort>:: |
| 65 |
do_scan_not(mask, const char_type* __lo, const char_type*) const |
| 66 |
{ return __lo; } |
| 67 |
|
| 68 |
template<> |
| 69 |
pod_ushort |
| 70 |
ctype<pod_ushort>:: |
| 71 |
do_toupper(char_type __c) const |
| 72 |
{ return __c; } |
| 73 |
|
| 74 |
template<> |
| 75 |
const pod_ushort* |
| 76 |
ctype<pod_ushort>:: |
| 77 |
do_toupper(char_type*, const char_type* __hi) const |
| 78 |
{ return __hi; } |
| 79 |
|
| 80 |
template<> |
| 81 |
pod_ushort |
| 82 |
ctype<pod_ushort>:: |
| 83 |
do_tolower(char_type __c) const |
| 84 |
{ return __c; } |
| 85 |
|
| 86 |
template<> |
| 87 |
const pod_ushort* |
| 88 |
ctype<pod_ushort>:: |
| 89 |
do_tolower(char_type*, const char_type* __hi) const |
| 90 |
{ return __hi; } |
| 91 |
|
| 92 |
template<> |
| 93 |
pod_ushort |
| 94 |
ctype<pod_ushort>:: |
| 95 |
do_widen(char __c) const |
| 96 |
{ |
| 97 |
char_type ret = { value_type(__c) }; |
| 98 |
return ret; |
| 99 |
} |
| 100 |
|
| 101 |
template<> |
| 102 |
const char* |
| 103 |
ctype<pod_ushort>:: |
| 104 |
do_widen(const char* __lo, const char* __hi, char_type* __dest) const |
| 105 |
{ |
| 106 |
while (__lo < __hi) |
| 107 |
{ |
| 108 |
*__dest = this->do_widen(*__lo); |
| 109 |
++__lo; |
| 110 |
++__dest; |
| 111 |
} |
| 112 |
return __hi; |
| 113 |
} |
| 114 |
|
| 115 |
template<> |
| 116 |
char |
| 117 |
ctype<pod_ushort>:: |
| 118 |
do_narrow(char_type __wc, char) const |
| 119 |
{ return static_cast<char>(__wc.value); } |
| 120 |
|
| 121 |
template<> |
| 122 |
const pod_ushort* |
| 123 |
ctype<pod_ushort>:: |
| 124 |
do_narrow(const pod_ushort* __lo, const pod_ushort* __hi, |
| 125 |
char, char* __dest) const |
| 126 |
{ |
| 127 |
while (__lo < __hi) |
| 128 |
{ |
| 129 |
*__dest = this->do_narrow(*__lo, char()); |
| 130 |
++__lo; |
| 131 |
++__dest; |
| 132 |
} |
| 133 |
return __hi; |
| 134 |
} |
| 135 |
|
| 136 |
template<> |
| 137 |
ctype<pod_ushort>::~ctype() { } |
| 138 |
|
| 139 |
template<> |
| 140 |
void |
| 141 |
numpunct<pod_ushort>::_M_initialize_numpunct(__c_locale) |
| 142 |
{ |
| 143 |
if (!_M_data) |
| 144 |
_M_data = new __numpunct_cache<pod_ushort>; |
| 145 |
|
| 146 |
_M_data->_M_grouping = ""; |
| 147 |
_M_data->_M_use_grouping = false; |
| 148 |
|
| 149 |
_M_data->_M_decimal_point.value = value_type('.'); |
| 150 |
_M_data->_M_thousands_sep.value = value_type(','); |
| 151 |
|
| 152 |
for (size_t i = 0; i < __num_base::_S_oend; ++i) |
| 153 |
{ |
| 154 |
value_type v = __num_base::_S_atoms_out[i]; |
| 155 |
_M_data->_M_atoms_out[i].value = v; |
| 156 |
} |
| 157 |
|
| 158 |
for (size_t j = 0; j < __num_base::_S_iend; ++j) |
| 159 |
_M_data->_M_atoms_in[j].value = value_type(__num_base::_S_atoms_in[j]); |
| 160 |
|
| 161 |
// "true" |
| 162 |
pod_ushort* __truename = new pod_ushort[4 + 1]; |
| 163 |
__truename[0].value = value_type('t'); |
| 164 |
__truename[1].value = value_type('r'); |
| 165 |
__truename[2].value = value_type('u'); |
| 166 |
__truename[3].value = value_type('e'); |
| 167 |
__truename[4] = pod_ushort(); |
| 168 |
_M_data->_M_truename = __truename; |
| 169 |
|
| 170 |
// "false" |
| 171 |
pod_ushort* __falsename = new pod_ushort[5 + 1]; |
| 172 |
__falsename[0].value = value_type('f'); |
| 173 |
__falsename[1].value = value_type('a'); |
| 174 |
__falsename[2].value = value_type('l'); |
| 175 |
__falsename[3].value = value_type('s'); |
| 176 |
__falsename[4].value = value_type('e'); |
| 177 |
__falsename[5] = pod_ushort(); |
| 178 |
_M_data->_M_falsename = __falsename; |
| 179 |
} |
| 180 |
|
| 181 |
template<> |
| 182 |
numpunct<pod_ushort>::~numpunct() |
| 183 |
{ delete _M_data; } |
| 184 |
} // namespace std |