blob: ec7d4a7809582bf39346e65e29abd84b5124c6e0 [file] [log] [blame]
Howard Hinnant7282c5a2010-05-30 21:39:41 +00001// -*- C++ -*-
2//===-------------------------- codecvt -----------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnant7282c5a2010-05-30 21:39:41 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_CODECVT
11#define _LIBCPP_CODECVT
12
13/*
14 codecvt synopsis
15
16namespace std
17{
18
19enum codecvt_mode
20{
21 consume_header = 4,
22 generate_header = 2,
23 little_endian = 1
24};
25
26template <class Elem, unsigned long Maxcode = 0x10ffff,
27 codecvt_mode Mode = (codecvt_mode)0>
28class codecvt_utf8
29 : public codecvt<Elem, char, mbstate_t>
30{
Marshall Clowd594d202013-08-27 14:22:13 +000031 explicit codecvt_utf8(size_t refs = 0);
32 ~codecvt_utf8();
Howard Hinnant7282c5a2010-05-30 21:39:41 +000033};
34
35template <class Elem, unsigned long Maxcode = 0x10ffff,
36 codecvt_mode Mode = (codecvt_mode)0>
37class codecvt_utf16
38 : public codecvt<Elem, char, mbstate_t>
39{
Marshall Clowd594d202013-08-27 14:22:13 +000040 explicit codecvt_utf16(size_t refs = 0);
41 ~codecvt_utf16();
Howard Hinnant7282c5a2010-05-30 21:39:41 +000042};
43
44template <class Elem, unsigned long Maxcode = 0x10ffff,
45 codecvt_mode Mode = (codecvt_mode)0>
46class codecvt_utf8_utf16
47 : public codecvt<Elem, char, mbstate_t>
48{
Marshall Clowd594d202013-08-27 14:22:13 +000049 explicit codecvt_utf8_utf16(size_t refs = 0);
50 ~codecvt_utf8_utf16();
Howard Hinnant7282c5a2010-05-30 21:39:41 +000051};
52
53} // std
54
55*/
56
57#include <__config>
58#include <__locale>
59
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000060#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant7282c5a2010-05-30 21:39:41 +000061#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000062#endif
Howard Hinnant7282c5a2010-05-30 21:39:41 +000063
64_LIBCPP_BEGIN_NAMESPACE_STD
65
66enum codecvt_mode
67{
68 consume_header = 4,
69 generate_header = 2,
70 little_endian = 1
71};
72
73// codecvt_utf8
74
75template <class _Elem> class __codecvt_utf8;
76
77template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +000078class _LIBCPP_TYPE_VIS __codecvt_utf8<wchar_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +000079 : public codecvt<wchar_t, char, mbstate_t>
80{
81 unsigned long _Maxcode_;
82 codecvt_mode _Mode_;
83public:
84 typedef wchar_t intern_type;
85 typedef char extern_type;
86 typedef mbstate_t state_type;
87
Louis Dionne16fe2952018-07-11 23:14:33 +000088 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +000089 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
90 codecvt_mode _Mode)
91 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
92 _Mode_(_Mode) {}
93protected:
94 virtual result
95 do_out(state_type& __st,
96 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
97 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
98 virtual result
99 do_in(state_type& __st,
100 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
101 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
102 virtual result
103 do_unshift(state_type& __st,
104 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100105 virtual int do_encoding() const _NOEXCEPT;
106 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000107 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
108 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100109 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000110};
111
Marek Kurdej718b62c2020-12-02 08:57:02 +0100112_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000113template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000114class _LIBCPP_TYPE_VIS __codecvt_utf8<char16_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000115 : public codecvt<char16_t, char, mbstate_t>
116{
117 unsigned long _Maxcode_;
118 codecvt_mode _Mode_;
119public:
120 typedef char16_t intern_type;
121 typedef char extern_type;
122 typedef mbstate_t state_type;
123
Louis Dionne16fe2952018-07-11 23:14:33 +0000124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000125 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
126 codecvt_mode _Mode)
127 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
128 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100129_LIBCPP_SUPPRESS_DEPRECATED_POP
130
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000131protected:
132 virtual result
133 do_out(state_type& __st,
134 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
135 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
136 virtual result
137 do_in(state_type& __st,
138 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
139 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
140 virtual result
141 do_unshift(state_type& __st,
142 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100143 virtual int do_encoding() const _NOEXCEPT;
144 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000145 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
146 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100147 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000148};
149
Marek Kurdej718b62c2020-12-02 08:57:02 +0100150_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000151template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000152class _LIBCPP_TYPE_VIS __codecvt_utf8<char32_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000153 : public codecvt<char32_t, char, mbstate_t>
154{
155 unsigned long _Maxcode_;
156 codecvt_mode _Mode_;
157public:
158 typedef char32_t intern_type;
159 typedef char extern_type;
160 typedef mbstate_t state_type;
161
Louis Dionne16fe2952018-07-11 23:14:33 +0000162 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000163 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
164 codecvt_mode _Mode)
165 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
166 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100167_LIBCPP_SUPPRESS_DEPRECATED_POP
168
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000169protected:
170 virtual result
171 do_out(state_type& __st,
172 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
173 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
174 virtual result
175 do_in(state_type& __st,
176 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
177 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
178 virtual result
179 do_unshift(state_type& __st,
180 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100181 virtual int do_encoding() const _NOEXCEPT;
182 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000183 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
184 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100185 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000186};
187
188template <class _Elem, unsigned long _Maxcode = 0x10ffff,
189 codecvt_mode _Mode = (codecvt_mode)0>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000190class _LIBCPP_TEMPLATE_VIS codecvt_utf8
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000191 : public __codecvt_utf8<_Elem>
192{
193public:
Louis Dionne16fe2952018-07-11 23:14:33 +0000194 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000195 explicit codecvt_utf8(size_t __refs = 0)
196 : __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) {}
197
Louis Dionne16fe2952018-07-11 23:14:33 +0000198 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000199 ~codecvt_utf8() {}
200};
201
202// codecvt_utf16
203
204template <class _Elem, bool _LittleEndian> class __codecvt_utf16;
205
206template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000207class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, false>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000208 : public codecvt<wchar_t, char, mbstate_t>
209{
210 unsigned long _Maxcode_;
211 codecvt_mode _Mode_;
212public:
213 typedef wchar_t intern_type;
214 typedef char extern_type;
215 typedef mbstate_t state_type;
216
Louis Dionne16fe2952018-07-11 23:14:33 +0000217 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000218 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
219 codecvt_mode _Mode)
220 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
221 _Mode_(_Mode) {}
222protected:
223 virtual result
224 do_out(state_type& __st,
225 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
226 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
227 virtual result
228 do_in(state_type& __st,
229 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
230 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
231 virtual result
232 do_unshift(state_type& __st,
233 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100234 virtual int do_encoding() const _NOEXCEPT;
235 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000236 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
237 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100238 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000239};
240
241template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000242class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, true>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000243 : public codecvt<wchar_t, char, mbstate_t>
244{
245 unsigned long _Maxcode_;
246 codecvt_mode _Mode_;
247public:
248 typedef wchar_t intern_type;
249 typedef char extern_type;
250 typedef mbstate_t state_type;
251
Louis Dionne16fe2952018-07-11 23:14:33 +0000252 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000253 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
254 codecvt_mode _Mode)
255 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
256 _Mode_(_Mode) {}
257protected:
258 virtual result
259 do_out(state_type& __st,
260 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
261 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
262 virtual result
263 do_in(state_type& __st,
264 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
265 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
266 virtual result
267 do_unshift(state_type& __st,
268 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100269 virtual int do_encoding() const _NOEXCEPT;
270 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000271 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
272 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100273 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000274};
275
Marek Kurdej718b62c2020-12-02 08:57:02 +0100276_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000277template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000278class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, false>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000279 : public codecvt<char16_t, char, mbstate_t>
280{
281 unsigned long _Maxcode_;
282 codecvt_mode _Mode_;
283public:
284 typedef char16_t intern_type;
285 typedef char extern_type;
286 typedef mbstate_t state_type;
287
Louis Dionne16fe2952018-07-11 23:14:33 +0000288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000289 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
290 codecvt_mode _Mode)
291 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
292 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100293_LIBCPP_SUPPRESS_DEPRECATED_POP
294
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000295protected:
296 virtual result
297 do_out(state_type& __st,
298 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
299 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
300 virtual result
301 do_in(state_type& __st,
302 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
303 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
304 virtual result
305 do_unshift(state_type& __st,
306 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100307 virtual int do_encoding() const _NOEXCEPT;
308 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000309 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
310 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100311 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000312};
313
Marek Kurdej718b62c2020-12-02 08:57:02 +0100314_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000315template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000316class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, true>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000317 : public codecvt<char16_t, char, mbstate_t>
318{
319 unsigned long _Maxcode_;
320 codecvt_mode _Mode_;
321public:
322 typedef char16_t intern_type;
323 typedef char extern_type;
324 typedef mbstate_t state_type;
325
Louis Dionne16fe2952018-07-11 23:14:33 +0000326 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000327 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
328 codecvt_mode _Mode)
329 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
330 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100331_LIBCPP_SUPPRESS_DEPRECATED_POP
332
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000333protected:
334 virtual result
335 do_out(state_type& __st,
336 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
337 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
338 virtual result
339 do_in(state_type& __st,
340 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
341 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
342 virtual result
343 do_unshift(state_type& __st,
344 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100345 virtual int do_encoding() const _NOEXCEPT;
346 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000347 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
348 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100349 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000350};
351
Marek Kurdej718b62c2020-12-02 08:57:02 +0100352_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000353template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000354class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, false>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000355 : public codecvt<char32_t, char, mbstate_t>
356{
357 unsigned long _Maxcode_;
358 codecvt_mode _Mode_;
359public:
360 typedef char32_t intern_type;
361 typedef char extern_type;
362 typedef mbstate_t state_type;
363
Louis Dionne16fe2952018-07-11 23:14:33 +0000364 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000365 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
366 codecvt_mode _Mode)
367 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
368 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100369_LIBCPP_SUPPRESS_DEPRECATED_POP
370
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000371protected:
372 virtual result
373 do_out(state_type& __st,
374 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
375 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
376 virtual result
377 do_in(state_type& __st,
378 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
379 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
380 virtual result
381 do_unshift(state_type& __st,
382 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100383 virtual int do_encoding() const _NOEXCEPT;
384 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000385 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
386 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100387 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000388};
389
Marek Kurdej718b62c2020-12-02 08:57:02 +0100390_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000391template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000392class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, true>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000393 : public codecvt<char32_t, char, mbstate_t>
394{
395 unsigned long _Maxcode_;
396 codecvt_mode _Mode_;
397public:
398 typedef char32_t intern_type;
399 typedef char extern_type;
400 typedef mbstate_t state_type;
401
Louis Dionne16fe2952018-07-11 23:14:33 +0000402 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000403 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
404 codecvt_mode _Mode)
405 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
406 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100407_LIBCPP_SUPPRESS_DEPRECATED_POP
408
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000409protected:
410 virtual result
411 do_out(state_type& __st,
412 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
413 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
414 virtual result
415 do_in(state_type& __st,
416 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
417 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
418 virtual result
419 do_unshift(state_type& __st,
420 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100421 virtual int do_encoding() const _NOEXCEPT;
422 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000423 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
424 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100425 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000426};
427
428template <class _Elem, unsigned long _Maxcode = 0x10ffff,
429 codecvt_mode _Mode = (codecvt_mode)0>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000430class _LIBCPP_TEMPLATE_VIS codecvt_utf16
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000431 : public __codecvt_utf16<_Elem, _Mode & little_endian>
432{
433public:
Louis Dionne16fe2952018-07-11 23:14:33 +0000434 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000435 explicit codecvt_utf16(size_t __refs = 0)
436 : __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) {}
437
Louis Dionne16fe2952018-07-11 23:14:33 +0000438 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000439 ~codecvt_utf16() {}
440};
441
442// codecvt_utf8_utf16
443
444template <class _Elem> class __codecvt_utf8_utf16;
445
446template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000447class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<wchar_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000448 : public codecvt<wchar_t, char, mbstate_t>
449{
450 unsigned long _Maxcode_;
451 codecvt_mode _Mode_;
452public:
453 typedef wchar_t intern_type;
454 typedef char extern_type;
455 typedef mbstate_t state_type;
456
Louis Dionne16fe2952018-07-11 23:14:33 +0000457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000458 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
459 codecvt_mode _Mode)
460 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
461 _Mode_(_Mode) {}
462protected:
463 virtual result
464 do_out(state_type& __st,
465 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
466 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
467 virtual result
468 do_in(state_type& __st,
469 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
470 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
471 virtual result
472 do_unshift(state_type& __st,
473 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100474 virtual int do_encoding() const _NOEXCEPT;
475 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000476 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
477 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100478 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000479};
480
Marek Kurdej718b62c2020-12-02 08:57:02 +0100481_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000482template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000483class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char32_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000484 : public codecvt<char32_t, char, mbstate_t>
485{
486 unsigned long _Maxcode_;
487 codecvt_mode _Mode_;
488public:
489 typedef char32_t intern_type;
490 typedef char extern_type;
491 typedef mbstate_t state_type;
492
Louis Dionne16fe2952018-07-11 23:14:33 +0000493 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000494 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
495 codecvt_mode _Mode)
496 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
497 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100498_LIBCPP_SUPPRESS_DEPRECATED_POP
499
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000500protected:
501 virtual result
502 do_out(state_type& __st,
503 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
504 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
505 virtual result
506 do_in(state_type& __st,
507 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
508 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
509 virtual result
510 do_unshift(state_type& __st,
511 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100512 virtual int do_encoding() const _NOEXCEPT;
513 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000514 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
515 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100516 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000517};
518
Marek Kurdej718b62c2020-12-02 08:57:02 +0100519_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000520template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000521class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char16_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000522 : public codecvt<char16_t, char, mbstate_t>
523{
524 unsigned long _Maxcode_;
525 codecvt_mode _Mode_;
526public:
527 typedef char16_t intern_type;
528 typedef char extern_type;
529 typedef mbstate_t state_type;
530
Louis Dionne16fe2952018-07-11 23:14:33 +0000531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000532 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
533 codecvt_mode _Mode)
534 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
535 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100536_LIBCPP_SUPPRESS_DEPRECATED_POP
537
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000538protected:
539 virtual result
540 do_out(state_type& __st,
541 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
542 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
543 virtual result
544 do_in(state_type& __st,
545 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
546 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
547 virtual result
548 do_unshift(state_type& __st,
549 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100550 virtual int do_encoding() const _NOEXCEPT;
551 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000552 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
553 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100554 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000555};
556
557template <class _Elem, unsigned long _Maxcode = 0x10ffff,
558 codecvt_mode _Mode = (codecvt_mode)0>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000559class _LIBCPP_TEMPLATE_VIS codecvt_utf8_utf16
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000560 : public __codecvt_utf8_utf16<_Elem>
561{
562public:
Louis Dionne16fe2952018-07-11 23:14:33 +0000563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000564 explicit codecvt_utf8_utf16(size_t __refs = 0)
565 : __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) {}
566
Louis Dionne16fe2952018-07-11 23:14:33 +0000567 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000568 ~codecvt_utf8_utf16() {}
569};
570
571_LIBCPP_END_NAMESPACE_STD
572
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400573#endif // _LIBCPP_CODECVT