blob: b9b38b3834237a8eb992503361ca2a309855f6ec [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>
Mark de Weverce8f12c2021-12-22 18:14:14 +010059#include <version>
Howard Hinnant7282c5a2010-05-30 21:39:41 +000060
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000061#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -050062# pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000063#endif
Howard Hinnant7282c5a2010-05-30 21:39:41 +000064
65_LIBCPP_BEGIN_NAMESPACE_STD
66
67enum codecvt_mode
68{
69 consume_header = 4,
70 generate_header = 2,
71 little_endian = 1
72};
73
74// codecvt_utf8
75
76template <class _Elem> class __codecvt_utf8;
77
Louis Dionne89258142021-08-23 15:32:36 -040078#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnant7282c5a2010-05-30 21:39:41 +000079template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +000080class _LIBCPP_TYPE_VIS __codecvt_utf8<wchar_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +000081 : public codecvt<wchar_t, char, mbstate_t>
82{
83 unsigned long _Maxcode_;
84 codecvt_mode _Mode_;
85public:
86 typedef wchar_t intern_type;
87 typedef char extern_type;
88 typedef mbstate_t state_type;
89
Louis Dionne16fe2952018-07-11 23:14:33 +000090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +000091 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
92 codecvt_mode _Mode)
93 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
94 _Mode_(_Mode) {}
95protected:
96 virtual result
97 do_out(state_type& __st,
98 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
99 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
100 virtual result
101 do_in(state_type& __st,
102 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
103 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
104 virtual result
105 do_unshift(state_type& __st,
106 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100107 virtual int do_encoding() const _NOEXCEPT;
108 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000109 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
110 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100111 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000112};
Louis Dionne89258142021-08-23 15:32:36 -0400113#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000114
Marek Kurdej718b62c2020-12-02 08:57:02 +0100115_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000116template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000117class _LIBCPP_TYPE_VIS __codecvt_utf8<char16_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000118 : public codecvt<char16_t, char, mbstate_t>
119{
120 unsigned long _Maxcode_;
121 codecvt_mode _Mode_;
122public:
123 typedef char16_t intern_type;
124 typedef char extern_type;
125 typedef mbstate_t state_type;
126
Louis Dionne16fe2952018-07-11 23:14:33 +0000127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000128 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
129 codecvt_mode _Mode)
130 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
131 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100132_LIBCPP_SUPPRESS_DEPRECATED_POP
133
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000134protected:
135 virtual result
136 do_out(state_type& __st,
137 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
138 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
139 virtual result
140 do_in(state_type& __st,
141 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
142 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
143 virtual result
144 do_unshift(state_type& __st,
145 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100146 virtual int do_encoding() const _NOEXCEPT;
147 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000148 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
149 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100150 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000151};
152
Marek Kurdej718b62c2020-12-02 08:57:02 +0100153_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000154template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000155class _LIBCPP_TYPE_VIS __codecvt_utf8<char32_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000156 : public codecvt<char32_t, char, mbstate_t>
157{
158 unsigned long _Maxcode_;
159 codecvt_mode _Mode_;
160public:
161 typedef char32_t intern_type;
162 typedef char extern_type;
163 typedef mbstate_t state_type;
164
Louis Dionne16fe2952018-07-11 23:14:33 +0000165 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000166 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
167 codecvt_mode _Mode)
168 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
169 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100170_LIBCPP_SUPPRESS_DEPRECATED_POP
171
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000172protected:
173 virtual result
174 do_out(state_type& __st,
175 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
176 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
177 virtual result
178 do_in(state_type& __st,
179 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
180 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
181 virtual result
182 do_unshift(state_type& __st,
183 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100184 virtual int do_encoding() const _NOEXCEPT;
185 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000186 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
187 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100188 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000189};
190
191template <class _Elem, unsigned long _Maxcode = 0x10ffff,
192 codecvt_mode _Mode = (codecvt_mode)0>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000193class _LIBCPP_TEMPLATE_VIS codecvt_utf8
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000194 : public __codecvt_utf8<_Elem>
195{
196public:
Louis Dionne16fe2952018-07-11 23:14:33 +0000197 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000198 explicit codecvt_utf8(size_t __refs = 0)
199 : __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) {}
200
Louis Dionne16fe2952018-07-11 23:14:33 +0000201 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000202 ~codecvt_utf8() {}
203};
204
205// codecvt_utf16
206
207template <class _Elem, bool _LittleEndian> class __codecvt_utf16;
208
Louis Dionne89258142021-08-23 15:32:36 -0400209#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000210template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000211class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, false>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000212 : public codecvt<wchar_t, char, mbstate_t>
213{
214 unsigned long _Maxcode_;
215 codecvt_mode _Mode_;
216public:
217 typedef wchar_t intern_type;
218 typedef char extern_type;
219 typedef mbstate_t state_type;
220
Louis Dionne16fe2952018-07-11 23:14:33 +0000221 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000222 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
223 codecvt_mode _Mode)
224 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
225 _Mode_(_Mode) {}
226protected:
227 virtual result
228 do_out(state_type& __st,
229 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
230 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
231 virtual result
232 do_in(state_type& __st,
233 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
234 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
235 virtual result
236 do_unshift(state_type& __st,
237 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100238 virtual int do_encoding() const _NOEXCEPT;
239 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000240 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
241 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100242 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000243};
244
245template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000246class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, true>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000247 : public codecvt<wchar_t, char, mbstate_t>
248{
249 unsigned long _Maxcode_;
250 codecvt_mode _Mode_;
251public:
252 typedef wchar_t intern_type;
253 typedef char extern_type;
254 typedef mbstate_t state_type;
255
Louis Dionne16fe2952018-07-11 23:14:33 +0000256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000257 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
258 codecvt_mode _Mode)
259 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
260 _Mode_(_Mode) {}
261protected:
262 virtual result
263 do_out(state_type& __st,
264 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
265 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
266 virtual result
267 do_in(state_type& __st,
268 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
269 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
270 virtual result
271 do_unshift(state_type& __st,
272 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100273 virtual int do_encoding() const _NOEXCEPT;
274 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000275 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
276 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100277 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000278};
Louis Dionne89258142021-08-23 15:32:36 -0400279#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000280
Marek Kurdej718b62c2020-12-02 08:57:02 +0100281_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000282template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000283class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, false>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000284 : public codecvt<char16_t, char, mbstate_t>
285{
286 unsigned long _Maxcode_;
287 codecvt_mode _Mode_;
288public:
289 typedef char16_t intern_type;
290 typedef char extern_type;
291 typedef mbstate_t state_type;
292
Louis Dionne16fe2952018-07-11 23:14:33 +0000293 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000294 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
295 codecvt_mode _Mode)
296 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
297 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100298_LIBCPP_SUPPRESS_DEPRECATED_POP
299
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000300protected:
301 virtual result
302 do_out(state_type& __st,
303 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
304 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
305 virtual result
306 do_in(state_type& __st,
307 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
308 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
309 virtual result
310 do_unshift(state_type& __st,
311 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100312 virtual int do_encoding() const _NOEXCEPT;
313 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000314 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
315 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100316 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000317};
318
Marek Kurdej718b62c2020-12-02 08:57:02 +0100319_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000320template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000321class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, true>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000322 : public codecvt<char16_t, char, mbstate_t>
323{
324 unsigned long _Maxcode_;
325 codecvt_mode _Mode_;
326public:
327 typedef char16_t intern_type;
328 typedef char extern_type;
329 typedef mbstate_t state_type;
330
Louis Dionne16fe2952018-07-11 23:14:33 +0000331 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000332 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
333 codecvt_mode _Mode)
334 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
335 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100336_LIBCPP_SUPPRESS_DEPRECATED_POP
337
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000338protected:
339 virtual result
340 do_out(state_type& __st,
341 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
342 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
343 virtual result
344 do_in(state_type& __st,
345 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
346 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
347 virtual result
348 do_unshift(state_type& __st,
349 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100350 virtual int do_encoding() const _NOEXCEPT;
351 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000352 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
353 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100354 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000355};
356
Marek Kurdej718b62c2020-12-02 08:57:02 +0100357_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000358template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000359class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, false>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000360 : public codecvt<char32_t, char, mbstate_t>
361{
362 unsigned long _Maxcode_;
363 codecvt_mode _Mode_;
364public:
365 typedef char32_t intern_type;
366 typedef char extern_type;
367 typedef mbstate_t state_type;
368
Louis Dionne16fe2952018-07-11 23:14:33 +0000369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000370 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
371 codecvt_mode _Mode)
372 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
373 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100374_LIBCPP_SUPPRESS_DEPRECATED_POP
375
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000376protected:
377 virtual result
378 do_out(state_type& __st,
379 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
380 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
381 virtual result
382 do_in(state_type& __st,
383 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
384 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
385 virtual result
386 do_unshift(state_type& __st,
387 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100388 virtual int do_encoding() const _NOEXCEPT;
389 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000390 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
391 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100392 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000393};
394
Marek Kurdej718b62c2020-12-02 08:57:02 +0100395_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000396template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000397class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, true>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000398 : public codecvt<char32_t, char, mbstate_t>
399{
400 unsigned long _Maxcode_;
401 codecvt_mode _Mode_;
402public:
403 typedef char32_t intern_type;
404 typedef char extern_type;
405 typedef mbstate_t state_type;
406
Louis Dionne16fe2952018-07-11 23:14:33 +0000407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000408 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
409 codecvt_mode _Mode)
410 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
411 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100412_LIBCPP_SUPPRESS_DEPRECATED_POP
413
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000414protected:
415 virtual result
416 do_out(state_type& __st,
417 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
418 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
419 virtual result
420 do_in(state_type& __st,
421 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
422 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
423 virtual result
424 do_unshift(state_type& __st,
425 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100426 virtual int do_encoding() const _NOEXCEPT;
427 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000428 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
429 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100430 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000431};
432
433template <class _Elem, unsigned long _Maxcode = 0x10ffff,
434 codecvt_mode _Mode = (codecvt_mode)0>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000435class _LIBCPP_TEMPLATE_VIS codecvt_utf16
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000436 : public __codecvt_utf16<_Elem, _Mode & little_endian>
437{
438public:
Louis Dionne16fe2952018-07-11 23:14:33 +0000439 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000440 explicit codecvt_utf16(size_t __refs = 0)
441 : __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) {}
442
Louis Dionne16fe2952018-07-11 23:14:33 +0000443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000444 ~codecvt_utf16() {}
445};
446
447// codecvt_utf8_utf16
448
449template <class _Elem> class __codecvt_utf8_utf16;
450
Louis Dionne89258142021-08-23 15:32:36 -0400451#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000452template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000453class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<wchar_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000454 : public codecvt<wchar_t, char, mbstate_t>
455{
456 unsigned long _Maxcode_;
457 codecvt_mode _Mode_;
458public:
459 typedef wchar_t intern_type;
460 typedef char extern_type;
461 typedef mbstate_t state_type;
462
Louis Dionne16fe2952018-07-11 23:14:33 +0000463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000464 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
465 codecvt_mode _Mode)
466 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
467 _Mode_(_Mode) {}
468protected:
469 virtual result
470 do_out(state_type& __st,
471 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
472 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
473 virtual result
474 do_in(state_type& __st,
475 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
476 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
477 virtual result
478 do_unshift(state_type& __st,
479 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100480 virtual int do_encoding() const _NOEXCEPT;
481 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000482 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
483 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100484 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000485};
Louis Dionne89258142021-08-23 15:32:36 -0400486#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000487
Marek Kurdej718b62c2020-12-02 08:57:02 +0100488_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000489template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000490class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char32_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000491 : public codecvt<char32_t, char, mbstate_t>
492{
493 unsigned long _Maxcode_;
494 codecvt_mode _Mode_;
495public:
496 typedef char32_t intern_type;
497 typedef char extern_type;
498 typedef mbstate_t state_type;
499
Louis Dionne16fe2952018-07-11 23:14:33 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000501 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
502 codecvt_mode _Mode)
503 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
504 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100505_LIBCPP_SUPPRESS_DEPRECATED_POP
506
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000507protected:
508 virtual result
509 do_out(state_type& __st,
510 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
511 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
512 virtual result
513 do_in(state_type& __st,
514 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
515 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
516 virtual result
517 do_unshift(state_type& __st,
518 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100519 virtual int do_encoding() const _NOEXCEPT;
520 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000521 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
522 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100523 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000524};
525
Marek Kurdej718b62c2020-12-02 08:57:02 +0100526_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000527template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000528class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char16_t>
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000529 : public codecvt<char16_t, char, mbstate_t>
530{
531 unsigned long _Maxcode_;
532 codecvt_mode _Mode_;
533public:
534 typedef char16_t intern_type;
535 typedef char extern_type;
536 typedef mbstate_t state_type;
537
Louis Dionne16fe2952018-07-11 23:14:33 +0000538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000539 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
540 codecvt_mode _Mode)
541 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
542 _Mode_(_Mode) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +0100543_LIBCPP_SUPPRESS_DEPRECATED_POP
544
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000545protected:
546 virtual result
547 do_out(state_type& __st,
548 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
549 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
550 virtual result
551 do_in(state_type& __st,
552 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
553 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
554 virtual result
555 do_unshift(state_type& __st,
556 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100557 virtual int do_encoding() const _NOEXCEPT;
558 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000559 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
560 size_t __mx) const;
Dimitry Andric47269ce2020-03-13 19:36:26 +0100561 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000562};
563
564template <class _Elem, unsigned long _Maxcode = 0x10ffff,
565 codecvt_mode _Mode = (codecvt_mode)0>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000566class _LIBCPP_TEMPLATE_VIS codecvt_utf8_utf16
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000567 : public __codecvt_utf8_utf16<_Elem>
568{
569public:
Louis Dionne16fe2952018-07-11 23:14:33 +0000570 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000571 explicit codecvt_utf8_utf16(size_t __refs = 0)
572 : __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) {}
573
Louis Dionne16fe2952018-07-11 23:14:33 +0000574 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7282c5a2010-05-30 21:39:41 +0000575 ~codecvt_utf8_utf16() {}
576};
577
578_LIBCPP_END_NAMESPACE_STD
579
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400580#endif // _LIBCPP_CODECVT