1 // <codecvt> -*- C++ -*-
3 // Copyright (C) 2015-2017 Free Software Foundation, Inc.
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)
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.
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.
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/>.
25 // ISO C++ 14882: 22.5 Standard code conversion facets
27 /** @file include/codecvt
28 * This is a Standard C++ Library header.
31 #ifndef _GLIBCXX_CODECVT
32 #define _GLIBCXX_CODECVT 1
34 #pragma GCC system_header
36 #if __cplusplus < 201103L
37 # include <bits/c++0x_warning.h>
40 #include <bits/locale_classes.h>
41 #include <bits/codecvt.h>
43 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
45 namespace std _GLIBCXX_VISIBILITY(default)
47 _GLIBCXX_BEGIN_NAMESPACE_VERSION
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>
62 codecvt_utf8(size_t __refs = 0);
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>
73 codecvt_utf16(size_t __refs = 0);
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>
84 codecvt_utf8_utf16(size_t __refs = 0);
86 ~codecvt_utf8_utf16();
89 #define _GLIBCXX_CODECVT_SPECIALIZATION2(_NAME, _ELEM) \
92 : public codecvt<_ELEM, char, mbstate_t> \
95 typedef _ELEM intern_type; \
96 typedef char extern_type; \
97 typedef mbstate_t state_type; \
100 _NAME(unsigned long __maxcode, codecvt_mode __mode, size_t __refs) \
101 : codecvt(__refs), _M_maxcode(__maxcode), _M_mode(__mode) { } \
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; \
113 do_unshift(state_type& __state, \
114 extern_type* __to, extern_type* __to_end, \
115 extern_type*& __to_next) const; \
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; \
125 int do_encoding() const throw(); \
128 bool do_always_noconv() const throw(); \
131 int do_length(state_type&, const extern_type* __from, \
132 const extern_type* __end, size_t __max) const; \
135 do_max_length() const throw(); \
138 unsigned long _M_maxcode; \
139 codecvt_mode _M_mode; \
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> \
150 _NAME(size_t __refs = 0) \
151 : __ ## _NAME ## _base<_ELEM>(std::min(_Maxcode, 0x10fffful), \
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;
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);
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);
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);
174 _GLIBCXX_END_NAMESPACE_VERSION
177 #endif // _GLIBCXX_USE_C99_STDINT_TR1
181 #endif /* _GLIBCXX_CODECVT */