You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
5.2KB

  1. // <codecvt> -*- C++ -*-
  2. // Copyright (C) 2015-2020 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. // ISO C++ 14882: 22.5 Standard code conversion facets
  21. /** @file include/codecvt
  22. * This is a Standard C++ Library header.
  23. */
  24. #ifndef _GLIBCXX_CODECVT
  25. #define _GLIBCXX_CODECVT 1
  26. #pragma GCC system_header
  27. #if __cplusplus < 201103L
  28. # include <bits/c++0x_warning.h>
  29. #else
  30. #include <bits/locale_classes.h>
  31. #include <bits/codecvt.h>
  32. namespace std _GLIBCXX_VISIBILITY(default)
  33. {
  34. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  35. enum codecvt_mode
  36. {
  37. consume_header = 4,
  38. generate_header = 2,
  39. little_endian = 1
  40. };
  41. template<typename _Elem, unsigned long _Maxcode = 0x10ffff,
  42. codecvt_mode _Mode = (codecvt_mode)0>
  43. class codecvt_utf8 : public codecvt<_Elem, char, mbstate_t>
  44. {
  45. public:
  46. explicit
  47. codecvt_utf8(size_t __refs = 0);
  48. ~codecvt_utf8();
  49. };
  50. template<typename _Elem, unsigned long _Maxcode = 0x10ffff,
  51. codecvt_mode _Mode = (codecvt_mode)0>
  52. class codecvt_utf16 : public codecvt<_Elem, char, mbstate_t>
  53. {
  54. public:
  55. explicit
  56. codecvt_utf16(size_t __refs = 0);
  57. ~codecvt_utf16();
  58. };
  59. template<typename _Elem, unsigned long _Maxcode = 0x10ffff,
  60. codecvt_mode _Mode = (codecvt_mode)0>
  61. class codecvt_utf8_utf16 : public codecvt<_Elem, char, mbstate_t>
  62. {
  63. public:
  64. explicit
  65. codecvt_utf8_utf16(size_t __refs = 0);
  66. ~codecvt_utf8_utf16();
  67. };
  68. #define _GLIBCXX_CODECVT_SPECIALIZATION2(_NAME, _ELEM) \
  69. template<> \
  70. class _NAME<_ELEM> \
  71. : public codecvt<_ELEM, char, mbstate_t> \
  72. { \
  73. public: \
  74. typedef _ELEM intern_type; \
  75. typedef char extern_type; \
  76. typedef mbstate_t state_type; \
  77. \
  78. protected: \
  79. _NAME(unsigned long __maxcode, codecvt_mode __mode, size_t __refs) \
  80. : codecvt(__refs), _M_maxcode(__maxcode), _M_mode(__mode) { } \
  81. \
  82. virtual \
  83. ~_NAME(); \
  84. \
  85. virtual result \
  86. do_out(state_type& __state, const intern_type* __from, \
  87. const intern_type* __from_end, const intern_type*& __from_next, \
  88. extern_type* __to, extern_type* __to_end, \
  89. extern_type*& __to_next) const; \
  90. \
  91. virtual result \
  92. do_unshift(state_type& __state, \
  93. extern_type* __to, extern_type* __to_end, \
  94. extern_type*& __to_next) const; \
  95. \
  96. virtual result \
  97. do_in(state_type& __state, \
  98. const extern_type* __from, const extern_type* __from_end, \
  99. const extern_type*& __from_next, \
  100. intern_type* __to, intern_type* __to_end, \
  101. intern_type*& __to_next) const; \
  102. \
  103. virtual \
  104. int do_encoding() const throw(); \
  105. \
  106. virtual \
  107. bool do_always_noconv() const throw(); \
  108. \
  109. virtual \
  110. int do_length(state_type&, const extern_type* __from, \
  111. const extern_type* __end, size_t __max) const; \
  112. \
  113. virtual int \
  114. do_max_length() const throw(); \
  115. \
  116. private: \
  117. unsigned long _M_maxcode; \
  118. codecvt_mode _M_mode; \
  119. }
  120. #define _GLIBCXX_CODECVT_SPECIALIZATION(_NAME, _ELEM) \
  121. _GLIBCXX_CODECVT_SPECIALIZATION2(__ ## _NAME ## _base, _ELEM); \
  122. template<unsigned long _Maxcode, codecvt_mode _Mode> \
  123. class _NAME<_ELEM, _Maxcode, _Mode> \
  124. : public __ ## _NAME ## _base<_ELEM> \
  125. { \
  126. public: \
  127. explicit \
  128. _NAME(size_t __refs = 0) \
  129. : __ ## _NAME ## _base<_ELEM>(std::min(_Maxcode, 0x10fffful), \
  130. _Mode, __refs) \
  131. { } \
  132. }
  133. template<typename _Elem> class __codecvt_utf8_base;
  134. template<typename _Elem> class __codecvt_utf16_base;
  135. template<typename _Elem> class __codecvt_utf8_utf16_base;
  136. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, char16_t);
  137. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, char16_t);
  138. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, char16_t);
  139. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, char32_t);
  140. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, char32_t);
  141. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, char32_t);
  142. #ifdef _GLIBCXX_USE_WCHAR_T
  143. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, wchar_t);
  144. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, wchar_t);
  145. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, wchar_t);
  146. #endif
  147. _GLIBCXX_END_NAMESPACE_VERSION
  148. } // namespace
  149. #endif // C++11
  150. #endif /* _GLIBCXX_CODECVT */