blob: 60d3db882c03128d6d122ca150a30c39e24ebaa4 [file] [log] [blame]
Howard Hinnant7282c5a2010-05-30 21:39:41 +00001// -*- C++ -*-
Louis Dionne9bd93882021-11-17 16:25:01 -05002//===----------------------------------------------------------------------===//
Howard Hinnant7282c5a2010-05-30 21:39:41 +00003//
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
Louis Dionne89258142021-08-23 15:32:36 -040077#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnant7282c5a2010-05-30 21:39:41 +000078template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +000079class _LIBCPP_TYPE_VIS __codecvt_utf8<wchar_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +000080 : public codecvt<wchar_t, char, mbstate_t>
81{
82 unsigned long _Maxcode_;
83 codecvt_mode _Mode_;
84public:
85 typedef wchar_t intern_type;
86 typedef char extern_type;
87 typedef mbstate_t state_type;
88
Louis Dionne16fe2952018-07-11 23:14:33 +000089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +000090 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
91 codecvt_mode _Mode)
92 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
93 _Mode_(_Mode) {}
94protected:
95 virtual result
96 do_out(state_type& __st,
97 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
98 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
99 virtual result
100 do_in(state_type& __st,
101 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
102 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
103 virtual result
104 do_unshift(state_type& __st,
105 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100106 virtual int do_encoding() const _NOEXCEPT;
107 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000108 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
109 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100110 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000111};
Louis Dionne89258142021-08-23 15:32:36 -0400112#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000113
Marek Kurdej718b62c2020-12-02 08:57:02 +0100114_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000115template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000116class _LIBCPP_TYPE_VIS __codecvt_utf8<char16_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000117 : public codecvt<char16_t, char, mbstate_t>
118{
119 unsigned long _Maxcode_;
120 codecvt_mode _Mode_;
121public:
122 typedef char16_t intern_type;
123 typedef char extern_type;
124 typedef mbstate_t state_type;
125
Louis Dionne16fe2952018-07-11 23:14:33 +0000126 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000127 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
128 codecvt_mode _Mode)
129 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
130 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100131_LIBCPP_SUPPRESS_DEPRECATED_POP
132
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000133protected:
134 virtual result
135 do_out(state_type& __st,
136 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
137 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
138 virtual result
139 do_in(state_type& __st,
140 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
141 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
142 virtual result
143 do_unshift(state_type& __st,
144 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100145 virtual int do_encoding() const _NOEXCEPT;
146 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000147 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
148 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100149 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000150};
151
Marek Kurdej718b62c2020-12-02 08:57:02 +0100152_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000153template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000154class _LIBCPP_TYPE_VIS __codecvt_utf8<char32_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000155 : public codecvt<char32_t, char, mbstate_t>
156{
157 unsigned long _Maxcode_;
158 codecvt_mode _Mode_;
159public:
160 typedef char32_t intern_type;
161 typedef char extern_type;
162 typedef mbstate_t state_type;
163
Louis Dionne16fe2952018-07-11 23:14:33 +0000164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000165 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
166 codecvt_mode _Mode)
167 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
168 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100169_LIBCPP_SUPPRESS_DEPRECATED_POP
170
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000171protected:
172 virtual result
173 do_out(state_type& __st,
174 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
175 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
176 virtual result
177 do_in(state_type& __st,
178 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
179 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
180 virtual result
181 do_unshift(state_type& __st,
182 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100183 virtual int do_encoding() const _NOEXCEPT;
184 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000185 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
186 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100187 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000188};
189
190template <class _Elem, unsigned long _Maxcode = 0x10ffff,
191 codecvt_mode _Mode = (codecvt_mode)0>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000192class _LIBCPP_TEMPLATE_VIS codecvt_utf8
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000193 : public __codecvt_utf8<_Elem>
194{
195public:
Louis Dionne16fe2952018-07-11 23:14:33 +0000196 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000197 explicit codecvt_utf8(size_t __refs = 0)
198 : __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) {}
199
Louis Dionne16fe2952018-07-11 23:14:33 +0000200 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000201 ~codecvt_utf8() {}
202};
203
204// codecvt_utf16
205
206template <class _Elem, bool _LittleEndian> class __codecvt_utf16;
207
Louis Dionne89258142021-08-23 15:32:36 -0400208#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000209template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000210class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, false>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000211 : public codecvt<wchar_t, char, mbstate_t>
212{
213 unsigned long _Maxcode_;
214 codecvt_mode _Mode_;
215public:
216 typedef wchar_t intern_type;
217 typedef char extern_type;
218 typedef mbstate_t state_type;
219
Louis Dionne16fe2952018-07-11 23:14:33 +0000220 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000221 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
222 codecvt_mode _Mode)
223 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
224 _Mode_(_Mode) {}
225protected:
226 virtual result
227 do_out(state_type& __st,
228 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
229 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
230 virtual result
231 do_in(state_type& __st,
232 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
233 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
234 virtual result
235 do_unshift(state_type& __st,
236 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100237 virtual int do_encoding() const _NOEXCEPT;
238 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000239 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
240 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100241 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000242};
243
244template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000245class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, true>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000246 : public codecvt<wchar_t, char, mbstate_t>
247{
248 unsigned long _Maxcode_;
249 codecvt_mode _Mode_;
250public:
251 typedef wchar_t intern_type;
252 typedef char extern_type;
253 typedef mbstate_t state_type;
254
Louis Dionne16fe2952018-07-11 23:14:33 +0000255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000256 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
257 codecvt_mode _Mode)
258 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
259 _Mode_(_Mode) {}
260protected:
261 virtual result
262 do_out(state_type& __st,
263 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
264 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
265 virtual result
266 do_in(state_type& __st,
267 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
268 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
269 virtual result
270 do_unshift(state_type& __st,
271 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100272 virtual int do_encoding() const _NOEXCEPT;
273 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000274 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
275 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100276 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000277};
Louis Dionne89258142021-08-23 15:32:36 -0400278#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000279
Marek Kurdej718b62c2020-12-02 08:57:02 +0100280_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000281template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000282class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, false>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000283 : public codecvt<char16_t, char, mbstate_t>
284{
285 unsigned long _Maxcode_;
286 codecvt_mode _Mode_;
287public:
288 typedef char16_t intern_type;
289 typedef char extern_type;
290 typedef mbstate_t state_type;
291
Louis Dionne16fe2952018-07-11 23:14:33 +0000292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000293 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
294 codecvt_mode _Mode)
295 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
296 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100297_LIBCPP_SUPPRESS_DEPRECATED_POP
298
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000299protected:
300 virtual result
301 do_out(state_type& __st,
302 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
303 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
304 virtual result
305 do_in(state_type& __st,
306 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
307 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
308 virtual result
309 do_unshift(state_type& __st,
310 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100311 virtual int do_encoding() const _NOEXCEPT;
312 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000313 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
314 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100315 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000316};
317
Marek Kurdej718b62c2020-12-02 08:57:02 +0100318_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000319template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000320class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, true>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000321 : public codecvt<char16_t, char, mbstate_t>
322{
323 unsigned long _Maxcode_;
324 codecvt_mode _Mode_;
325public:
326 typedef char16_t intern_type;
327 typedef char extern_type;
328 typedef mbstate_t state_type;
329
Louis Dionne16fe2952018-07-11 23:14:33 +0000330 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000331 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
332 codecvt_mode _Mode)
333 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
334 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100335_LIBCPP_SUPPRESS_DEPRECATED_POP
336
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000337protected:
338 virtual result
339 do_out(state_type& __st,
340 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
341 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
342 virtual result
343 do_in(state_type& __st,
344 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
345 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
346 virtual result
347 do_unshift(state_type& __st,
348 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100349 virtual int do_encoding() const _NOEXCEPT;
350 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000351 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
352 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100353 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000354};
355
Marek Kurdej718b62c2020-12-02 08:57:02 +0100356_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000357template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000358class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, false>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000359 : public codecvt<char32_t, char, mbstate_t>
360{
361 unsigned long _Maxcode_;
362 codecvt_mode _Mode_;
363public:
364 typedef char32_t intern_type;
365 typedef char extern_type;
366 typedef mbstate_t state_type;
367
Louis Dionne16fe2952018-07-11 23:14:33 +0000368 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000369 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
370 codecvt_mode _Mode)
371 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
372 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100373_LIBCPP_SUPPRESS_DEPRECATED_POP
374
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000375protected:
376 virtual result
377 do_out(state_type& __st,
378 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
379 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
380 virtual result
381 do_in(state_type& __st,
382 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
383 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
384 virtual result
385 do_unshift(state_type& __st,
386 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100387 virtual int do_encoding() const _NOEXCEPT;
388 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000389 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
390 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100391 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000392};
393
Marek Kurdej718b62c2020-12-02 08:57:02 +0100394_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000395template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000396class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, true>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000397 : public codecvt<char32_t, char, mbstate_t>
398{
399 unsigned long _Maxcode_;
400 codecvt_mode _Mode_;
401public:
402 typedef char32_t intern_type;
403 typedef char extern_type;
404 typedef mbstate_t state_type;
405
Louis Dionne16fe2952018-07-11 23:14:33 +0000406 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000407 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
408 codecvt_mode _Mode)
409 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
410 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100411_LIBCPP_SUPPRESS_DEPRECATED_POP
412
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000413protected:
414 virtual result
415 do_out(state_type& __st,
416 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
417 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
418 virtual result
419 do_in(state_type& __st,
420 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
421 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
422 virtual result
423 do_unshift(state_type& __st,
424 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100425 virtual int do_encoding() const _NOEXCEPT;
426 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000427 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
428 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100429 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000430};
431
432template <class _Elem, unsigned long _Maxcode = 0x10ffff,
433 codecvt_mode _Mode = (codecvt_mode)0>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000434class _LIBCPP_TEMPLATE_VIS codecvt_utf16
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000435 : public __codecvt_utf16<_Elem, _Mode & little_endian>
436{
437public:
Louis Dionne16fe2952018-07-11 23:14:33 +0000438 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000439 explicit codecvt_utf16(size_t __refs = 0)
440 : __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) {}
441
Louis Dionne16fe2952018-07-11 23:14:33 +0000442 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000443 ~codecvt_utf16() {}
444};
445
446// codecvt_utf8_utf16
447
448template <class _Elem> class __codecvt_utf8_utf16;
449
Louis Dionne89258142021-08-23 15:32:36 -0400450#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000451template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000452class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<wchar_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000453 : public codecvt<wchar_t, char, mbstate_t>
454{
455 unsigned long _Maxcode_;
456 codecvt_mode _Mode_;
457public:
458 typedef wchar_t intern_type;
459 typedef char extern_type;
460 typedef mbstate_t state_type;
461
Louis Dionne16fe2952018-07-11 23:14:33 +0000462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000463 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
464 codecvt_mode _Mode)
465 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
466 _Mode_(_Mode) {}
467protected:
468 virtual result
469 do_out(state_type& __st,
470 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
471 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
472 virtual result
473 do_in(state_type& __st,
474 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
475 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
476 virtual result
477 do_unshift(state_type& __st,
478 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100479 virtual int do_encoding() const _NOEXCEPT;
480 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000481 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
482 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100483 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000484};
Louis Dionne89258142021-08-23 15:32:36 -0400485#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000486
Marek Kurdej718b62c2020-12-02 08:57:02 +0100487_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000488template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000489class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char32_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000490 : public codecvt<char32_t, char, mbstate_t>
491{
492 unsigned long _Maxcode_;
493 codecvt_mode _Mode_;
494public:
495 typedef char32_t intern_type;
496 typedef char extern_type;
497 typedef mbstate_t state_type;
498
Louis Dionne16fe2952018-07-11 23:14:33 +0000499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000500 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
501 codecvt_mode _Mode)
502 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
503 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100504_LIBCPP_SUPPRESS_DEPRECATED_POP
505
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000506protected:
507 virtual result
508 do_out(state_type& __st,
509 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
510 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
511 virtual result
512 do_in(state_type& __st,
513 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
514 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
515 virtual result
516 do_unshift(state_type& __st,
517 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100518 virtual int do_encoding() const _NOEXCEPT;
519 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000520 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
521 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100522 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000523};
524
Marek Kurdej718b62c2020-12-02 08:57:02 +0100525_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000526template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000527class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char16_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000528 : public codecvt<char16_t, char, mbstate_t>
529{
530 unsigned long _Maxcode_;
531 codecvt_mode _Mode_;
532public:
533 typedef char16_t intern_type;
534 typedef char extern_type;
535 typedef mbstate_t state_type;
536
Louis Dionne16fe2952018-07-11 23:14:33 +0000537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000538 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
539 codecvt_mode _Mode)
540 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
541 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100542_LIBCPP_SUPPRESS_DEPRECATED_POP
543
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000544protected:
545 virtual result
546 do_out(state_type& __st,
547 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
548 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
549 virtual result
550 do_in(state_type& __st,
551 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
552 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
553 virtual result
554 do_unshift(state_type& __st,
555 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100556 virtual int do_encoding() const _NOEXCEPT;
557 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000558 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
559 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100560 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000561};
562
563template <class _Elem, unsigned long _Maxcode = 0x10ffff,
564 codecvt_mode _Mode = (codecvt_mode)0>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000565class _LIBCPP_TEMPLATE_VIS codecvt_utf8_utf16
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000566 : public __codecvt_utf8_utf16<_Elem>
567{
568public:
Louis Dionne16fe2952018-07-11 23:14:33 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000570 explicit codecvt_utf8_utf16(size_t __refs = 0)
571 : __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) {}
572
Louis Dionne16fe2952018-07-11 23:14:33 +0000573 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000574 ~codecvt_utf8_utf16() {}
575};
576
577_LIBCPP_END_NAMESPACE_STD
578
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400579#endif // _LIBCPP_CODECVT