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