1// <codecvt> -*- C++ -*-
3// Copyright (C) 2015-2021 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>
43namespace std _GLIBCXX_VISIBILITY(default)
45_GLIBCXX_BEGIN_NAMESPACE_VERSION
54 template<typename _Elem, unsigned long _Maxcode = 0x10ffff,
55 codecvt_mode _Mode = (codecvt_mode)0>
56 class codecvt_utf8 : public codecvt<_Elem, char, mbstate_t>
60 codecvt_utf8(size_t __refs = 0);
65 template<typename _Elem, unsigned long _Maxcode = 0x10ffff,
66 codecvt_mode _Mode = (codecvt_mode)0>
67 class codecvt_utf16 : public codecvt<_Elem, char, mbstate_t>
71 codecvt_utf16(size_t __refs = 0);
76 template<typename _Elem, unsigned long _Maxcode = 0x10ffff,
77 codecvt_mode _Mode = (codecvt_mode)0>
78 class codecvt_utf8_utf16 : public codecvt<_Elem, char, mbstate_t>
82 codecvt_utf8_utf16(size_t __refs = 0);
84 ~codecvt_utf8_utf16();
87#define _GLIBCXX_CODECVT_SPECIALIZATION2(_NAME, _ELEM) \
90 : public codecvt<_ELEM, char, mbstate_t> \
93 typedef _ELEM intern_type; \
94 typedef char extern_type; \
95 typedef mbstate_t state_type; \
98 _NAME(unsigned long __maxcode, codecvt_mode __mode, size_t __refs) \
99 : codecvt(__refs), _M_maxcode(__maxcode), _M_mode(__mode) { } \
105 do_out(state_type& __state, const intern_type* __from, \
106 const intern_type* __from_end, const intern_type*& __from_next, \
107 extern_type* __to, extern_type* __to_end, \
108 extern_type*& __to_next) const; \
111 do_unshift(state_type& __state, \
112 extern_type* __to, extern_type* __to_end, \
113 extern_type*& __to_next) const; \
116 do_in(state_type& __state, \
117 const extern_type* __from, const extern_type* __from_end, \
118 const extern_type*& __from_next, \
119 intern_type* __to, intern_type* __to_end, \
120 intern_type*& __to_next) const; \
123 int do_encoding() const throw(); \
126 bool do_always_noconv() const throw(); \
129 int do_length(state_type&, const extern_type* __from, \
130 const extern_type* __end, size_t __max) const; \
133 do_max_length() const throw(); \
136 unsigned long _M_maxcode; \
137 codecvt_mode _M_mode; \
140#define _GLIBCXX_CODECVT_SPECIALIZATION(_NAME, _ELEM) \
141 _GLIBCXX_CODECVT_SPECIALIZATION2(__ ## _NAME ## _base, _ELEM); \
142 template<unsigned long _Maxcode, codecvt_mode _Mode> \
143 class _NAME<_ELEM, _Maxcode, _Mode> \
144 : public __ ## _NAME ## _base<_ELEM> \
148 _NAME(size_t __refs = 0) \
149 : __ ## _NAME ## _base<_ELEM>(std::min(_Maxcode, 0x10fffful), \
154 template<typename _Elem> class __codecvt_utf8_base;
155 template<typename _Elem> class __codecvt_utf16_base;
156 template<typename _Elem> class __codecvt_utf8_utf16_base;
158 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, char16_t);
159 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, char16_t);
160 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, char16_t);
162 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, char32_t);
163 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, char32_t);
164 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, char32_t);
166#ifdef _GLIBCXX_USE_WCHAR_T
167 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, wchar_t);
168 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, wchar_t);
169 _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, wchar_t);
172_GLIBCXX_END_NAMESPACE_VERSION
177#endif /* _GLIBCXX_CODECVT */