testsuite_character.cc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // -*- C++ -*-
  2. // Utility subroutines for the C++ library testsuite.
  3. //
  4. // Copyright (C) 2002-2022 Free Software Foundation, Inc.
  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 3, 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 COPYING3. If not see
  19. // <http://www.gnu.org/licenses/>.
  20. //
  21. #include <testsuite_character.h>
  22. namespace std
  23. {
  24. locale::id
  25. codecvt<__gnu_test::pod_uchar, char, __gnu_test::pod_state>::id;
  26. locale::id
  27. ctype<__gnu_test::pod_uchar>::id;
  28. locale::id
  29. numpunct<__gnu_test::pod_uint>::id;
  30. locale::id
  31. moneypunct<__gnu_test::pod_uint>::id;
  32. // Member specializations for the existing facet classes.
  33. // NB: This isn't especially portable. Perhaps a better way would be
  34. // to just specialize all of numpunct and ctype.
  35. using __gnu_test::pod_ushort;
  36. typedef pod_ushort::value_type value_type;
  37. template<>
  38. bool
  39. ctype<pod_ushort>::
  40. do_is(mask, char_type) const { return true; }
  41. template<>
  42. const pod_ushort*
  43. ctype<pod_ushort>::
  44. do_is(const char_type* __lo, const char_type*, mask*) const
  45. { return __lo; }
  46. template<>
  47. const pod_ushort*
  48. ctype<pod_ushort>::
  49. do_scan_is(mask, const char_type* __lo, const char_type*) const
  50. { return __lo; }
  51. template<>
  52. const pod_ushort*
  53. ctype<pod_ushort>::
  54. do_scan_not(mask, const char_type* __lo, const char_type*) const
  55. { return __lo; }
  56. template<>
  57. pod_ushort
  58. ctype<pod_ushort>::
  59. do_toupper(char_type __c) const
  60. { return __c; }
  61. template<>
  62. const pod_ushort*
  63. ctype<pod_ushort>::
  64. do_toupper(char_type*, const char_type* __hi) const
  65. { return __hi; }
  66. template<>
  67. pod_ushort
  68. ctype<pod_ushort>::
  69. do_tolower(char_type __c) const
  70. { return __c; }
  71. template<>
  72. const pod_ushort*
  73. ctype<pod_ushort>::
  74. do_tolower(char_type*, const char_type* __hi) const
  75. { return __hi; }
  76. template<>
  77. pod_ushort
  78. ctype<pod_ushort>::
  79. do_widen(char __c) const
  80. {
  81. char_type ret = { value_type(__c) };
  82. return ret;
  83. }
  84. template<>
  85. const char*
  86. ctype<pod_ushort>::
  87. do_widen(const char* __lo, const char* __hi, char_type* __dest) const
  88. {
  89. while (__lo < __hi)
  90. {
  91. *__dest = this->do_widen(*__lo);
  92. ++__lo;
  93. ++__dest;
  94. }
  95. return __hi;
  96. }
  97. template<>
  98. char
  99. ctype<pod_ushort>::
  100. do_narrow(char_type __wc, char) const
  101. { return static_cast<char>(__wc.value); }
  102. template<>
  103. const pod_ushort*
  104. ctype<pod_ushort>::
  105. do_narrow(const pod_ushort* __lo, const pod_ushort* __hi,
  106. char, char* __dest) const
  107. {
  108. while (__lo < __hi)
  109. {
  110. *__dest = this->do_narrow(*__lo, char());
  111. ++__lo;
  112. ++__dest;
  113. }
  114. return __hi;
  115. }
  116. template<>
  117. ctype<pod_ushort>::~ctype() { }
  118. template<>
  119. void
  120. numpunct<pod_ushort>::_M_initialize_numpunct(__c_locale)
  121. {
  122. if (!_M_data)
  123. _M_data = new __numpunct_cache<pod_ushort>;
  124. _M_data->_M_grouping = "";
  125. _M_data->_M_use_grouping = false;
  126. _M_data->_M_decimal_point.value = value_type('.');
  127. _M_data->_M_thousands_sep.value = value_type(',');
  128. for (size_t i = 0; i < __num_base::_S_oend; ++i)
  129. {
  130. value_type v = __num_base::_S_atoms_out[i];
  131. _M_data->_M_atoms_out[i].value = v;
  132. }
  133. for (size_t j = 0; j < __num_base::_S_iend; ++j)
  134. _M_data->_M_atoms_in[j].value = value_type(__num_base::_S_atoms_in[j]);
  135. // "true"
  136. pod_ushort* __truename = new pod_ushort[4 + 1];
  137. __truename[0].value = value_type('t');
  138. __truename[1].value = value_type('r');
  139. __truename[2].value = value_type('u');
  140. __truename[3].value = value_type('e');
  141. __truename[4] = pod_ushort();
  142. _M_data->_M_truename = __truename;
  143. // "false"
  144. pod_ushort* __falsename = new pod_ushort[5 + 1];
  145. __falsename[0].value = value_type('f');
  146. __falsename[1].value = value_type('a');
  147. __falsename[2].value = value_type('l');
  148. __falsename[3].value = value_type('s');
  149. __falsename[4].value = value_type('e');
  150. __falsename[5] = pod_ushort();
  151. _M_data->_M_falsename = __falsename;
  152. }
  153. template<>
  154. numpunct<pod_ushort>::~numpunct()
  155. { delete _M_data; }
  156. } // namespace std