codecvt 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // <codecvt> -*- C++ -*-
  2. // Copyright (C) 2015 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. #ifdef _GLIBCXX_USE_C99_STDINT_TR1
  33. namespace std _GLIBCXX_VISIBILITY(default)
  34. {
  35. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  36. enum codecvt_mode
  37. {
  38. consume_header = 4,
  39. generate_header = 2,
  40. little_endian = 1
  41. };
  42. template<typename _Elem, unsigned long _Maxcode = 0x10ffff,
  43. codecvt_mode _Mode = (codecvt_mode)0>
  44. class codecvt_utf8 : public codecvt<_Elem, char, mbstate_t>
  45. {
  46. public:
  47. explicit
  48. codecvt_utf8(size_t __refs = 0);
  49. ~codecvt_utf8();
  50. };
  51. template<typename _Elem, unsigned long _Maxcode = 0x10ffff,
  52. codecvt_mode _Mode = (codecvt_mode)0>
  53. class codecvt_utf16 : public codecvt<_Elem, char, mbstate_t>
  54. {
  55. public:
  56. explicit
  57. codecvt_utf16(size_t __refs = 0);
  58. ~codecvt_utf16();
  59. };
  60. template<typename _Elem, unsigned long _Maxcode = 0x10ffff,
  61. codecvt_mode _Mode = (codecvt_mode)0>
  62. class codecvt_utf8_utf16 : public codecvt<_Elem, char, mbstate_t>
  63. {
  64. public:
  65. explicit
  66. codecvt_utf8_utf16(size_t __refs = 0);
  67. ~codecvt_utf8_utf16();
  68. };
  69. #define _GLIBCXX_CODECVT_SPECIALIZATION2(_NAME, _ELEM) \
  70. template<> \
  71. class _NAME<_ELEM> \
  72. : public codecvt<_ELEM, char, mbstate_t> \
  73. { \
  74. public: \
  75. typedef _ELEM intern_type; \
  76. typedef char extern_type; \
  77. typedef mbstate_t state_type; \
  78. \
  79. protected: \
  80. _NAME(unsigned long __maxcode, codecvt_mode __mode, size_t __refs) \
  81. : codecvt(__refs), _M_maxcode(__maxcode), _M_mode(__mode) { } \
  82. \
  83. virtual \
  84. ~_NAME(); \
  85. \
  86. virtual result \
  87. do_out(state_type& __state, const intern_type* __from, \
  88. const intern_type* __from_end, const intern_type*& __from_next, \
  89. extern_type* __to, extern_type* __to_end, \
  90. extern_type*& __to_next) const; \
  91. \
  92. virtual result \
  93. do_unshift(state_type& __state, \
  94. extern_type* __to, extern_type* __to_end, \
  95. extern_type*& __to_next) const; \
  96. \
  97. virtual result \
  98. do_in(state_type& __state, \
  99. const extern_type* __from, const extern_type* __from_end, \
  100. const extern_type*& __from_next, \
  101. intern_type* __to, intern_type* __to_end, \
  102. intern_type*& __to_next) const; \
  103. \
  104. virtual \
  105. int do_encoding() const throw(); \
  106. \
  107. virtual \
  108. bool do_always_noconv() const throw(); \
  109. \
  110. virtual \
  111. int do_length(state_type&, const extern_type* __from, \
  112. const extern_type* __end, size_t __max) const; \
  113. \
  114. virtual int \
  115. do_max_length() const throw(); \
  116. \
  117. private: \
  118. unsigned long _M_maxcode; \
  119. codecvt_mode _M_mode; \
  120. }
  121. #define _GLIBCXX_CODECVT_SPECIALIZATION(_NAME, _ELEM) \
  122. _GLIBCXX_CODECVT_SPECIALIZATION2(__ ## _NAME ## _base, _ELEM); \
  123. template<unsigned long _Maxcode, codecvt_mode _Mode> \
  124. class _NAME<_ELEM, _Maxcode, _Mode> \
  125. : public __ ## _NAME ## _base<_ELEM> \
  126. { \
  127. public: \
  128. explicit \
  129. _NAME(size_t __refs = 0) \
  130. : __ ## _NAME ## _base<_ELEM>(std::min(_Maxcode, 0x10fffful), \
  131. _Mode, __refs) \
  132. { } \
  133. }
  134. template<typename _Elem> class __codecvt_utf8_base;
  135. template<typename _Elem> class __codecvt_utf16_base;
  136. template<typename _Elem> class __codecvt_utf8_utf16_base;
  137. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, char16_t);
  138. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, char16_t);
  139. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, char16_t);
  140. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, char32_t);
  141. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, char32_t);
  142. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, char32_t);
  143. #ifdef _GLIBCXX_USE_WCHAR_T
  144. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, wchar_t);
  145. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, wchar_t);
  146. _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, wchar_t);
  147. #endif
  148. _GLIBCXX_END_NAMESPACE_VERSION
  149. } // namespace
  150. #endif // _GLIBCXX_USE_C99_STDINT_TR1
  151. #endif
  152. #endif /* _GLIBCXX_CODECVT */