2 //===----------------------------------------------------------------------===//
4 // 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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_CODECVT
11 #define _LIBCPP_CODECVT
26 template <class Elem, unsigned long Maxcode = 0x10ffff,
27 codecvt_mode Mode = (codecvt_mode)0>
29 : public codecvt<Elem, char, mbstate_t>
31 explicit codecvt_utf8(size_t refs = 0);
35 template <class Elem, unsigned long Maxcode = 0x10ffff,
36 codecvt_mode Mode = (codecvt_mode)0>
38 : public codecvt<Elem, char, mbstate_t>
40 explicit codecvt_utf16(size_t refs = 0);
44 template <class Elem, unsigned long Maxcode = 0x10ffff,
45 codecvt_mode Mode = (codecvt_mode)0>
46 class codecvt_utf8_utf16
47 : public codecvt<Elem, char, mbstate_t>
49 explicit codecvt_utf8_utf16(size_t refs = 0);
50 ~codecvt_utf8_utf16();
57 #include <__assert> // all public C++ headers provide the assertion handler
62 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
63 # pragma GCC system_header
66 _LIBCPP_BEGIN_NAMESPACE_STD
68 enum _LIBCPP_DEPRECATED_IN_CXX17 codecvt_mode
77 template <class _Elem> class __codecvt_utf8;
79 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
81 class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8<wchar_t>
82 : public codecvt<wchar_t, char, mbstate_t>
84 unsigned long __maxcode_;
85 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
87 _LIBCPP_SUPPRESS_DEPRECATED_POP
89 typedef wchar_t intern_type;
90 typedef char extern_type;
91 typedef mbstate_t state_type;
93 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
94 _LIBCPP_INLINE_VISIBILITY
95 explicit __codecvt_utf8(size_t __refs, unsigned long __maxcode,
97 : codecvt<wchar_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
99 _LIBCPP_SUPPRESS_DEPRECATED_POP
101 result do_out(state_type& __st,
102 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
103 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
104 result do_in(state_type& __st,
105 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
106 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
107 result do_unshift(state_type& __st,
108 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
109 int do_encoding() const _NOEXCEPT override;
110 bool do_always_noconv() const _NOEXCEPT override;
111 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
112 int do_max_length() const _NOEXCEPT override;
114 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
116 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
118 class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8<char16_t>
119 : public codecvt<char16_t, char, mbstate_t>
121 unsigned long __maxcode_;
122 codecvt_mode __mode_;
124 typedef char16_t intern_type;
125 typedef char extern_type;
126 typedef mbstate_t state_type;
128 _LIBCPP_INLINE_VISIBILITY
129 explicit __codecvt_utf8(size_t __refs, unsigned long __maxcode,
131 : codecvt<char16_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
133 _LIBCPP_SUPPRESS_DEPRECATED_POP
136 result 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 override;
139 result 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 override;
142 result do_unshift(state_type& __st,
143 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
144 int do_encoding() const _NOEXCEPT override;
145 bool do_always_noconv() const _NOEXCEPT override;
146 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
147 int do_max_length() const _NOEXCEPT override;
150 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
152 class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8<char32_t>
153 : public codecvt<char32_t, char, mbstate_t>
155 unsigned long __maxcode_;
156 codecvt_mode __mode_;
158 typedef char32_t intern_type;
159 typedef char extern_type;
160 typedef mbstate_t state_type;
162 _LIBCPP_INLINE_VISIBILITY
163 explicit __codecvt_utf8(size_t __refs, unsigned long __maxcode,
165 : codecvt<char32_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
167 _LIBCPP_SUPPRESS_DEPRECATED_POP
170 result do_out(state_type& __st,
171 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
172 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
173 result do_in(state_type& __st,
174 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
175 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
176 result do_unshift(state_type& __st,
177 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
178 int do_encoding() const _NOEXCEPT override;
179 bool do_always_noconv() const _NOEXCEPT override;
180 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
181 int do_max_length() const _NOEXCEPT override;
184 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
185 template <class _Elem, unsigned long _Maxcode = 0x10ffff,
186 codecvt_mode _Mode = (codecvt_mode)0>
187 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 codecvt_utf8
188 : public __codecvt_utf8<_Elem>
191 _LIBCPP_INLINE_VISIBILITY
192 explicit codecvt_utf8(size_t __refs = 0)
193 : __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) {}
195 _LIBCPP_INLINE_VISIBILITY
198 _LIBCPP_SUPPRESS_DEPRECATED_POP
202 template <class _Elem, bool _LittleEndian> class __codecvt_utf16;
204 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
206 class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf16<wchar_t, false>
207 : public codecvt<wchar_t, char, mbstate_t>
209 unsigned long __maxcode_;
210 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
211 codecvt_mode __mode_;
212 _LIBCPP_SUPPRESS_DEPRECATED_POP
214 typedef wchar_t intern_type;
215 typedef char extern_type;
216 typedef mbstate_t state_type;
218 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
219 _LIBCPP_INLINE_VISIBILITY
220 explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
222 : codecvt<wchar_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
224 _LIBCPP_SUPPRESS_DEPRECATED_POP
226 result do_out(state_type& __st,
227 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
228 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
229 result do_in(state_type& __st,
230 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
231 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
232 result do_unshift(state_type& __st,
233 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
234 int do_encoding() const _NOEXCEPT override;
235 bool do_always_noconv() const _NOEXCEPT override;
236 int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
237 size_t __mx) const override;
238 int do_max_length() const _NOEXCEPT override;
242 class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf16<wchar_t, true>
243 : public codecvt<wchar_t, char, mbstate_t>
245 unsigned long __maxcode_;
246 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
247 codecvt_mode __mode_;
248 _LIBCPP_SUPPRESS_DEPRECATED_POP
250 typedef wchar_t intern_type;
251 typedef char extern_type;
252 typedef mbstate_t state_type;
254 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
255 _LIBCPP_INLINE_VISIBILITY
256 explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
258 : codecvt<wchar_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
260 _LIBCPP_SUPPRESS_DEPRECATED_POP
262 result 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 override;
265 result do_in(state_type& __st,
266 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
267 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
268 result do_unshift(state_type& __st,
269 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
270 int do_encoding() const _NOEXCEPT override;
271 bool do_always_noconv() const _NOEXCEPT override;
272 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
273 int do_max_length() const _NOEXCEPT override;
275 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
277 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
279 class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf16<char16_t, false>
280 : public codecvt<char16_t, char, mbstate_t>
282 unsigned long __maxcode_;
283 codecvt_mode __mode_;
285 typedef char16_t intern_type;
286 typedef char extern_type;
287 typedef mbstate_t state_type;
289 _LIBCPP_INLINE_VISIBILITY
290 explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
292 : codecvt<char16_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
294 _LIBCPP_SUPPRESS_DEPRECATED_POP
297 result 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 override;
300 result do_in(state_type& __st,
301 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
302 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
303 result do_unshift(state_type& __st,
304 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
305 int do_encoding() const _NOEXCEPT override;
306 bool do_always_noconv() const _NOEXCEPT override;
307 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
308 int do_max_length() const _NOEXCEPT override;
311 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
313 class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf16<char16_t, true>
314 : public codecvt<char16_t, char, mbstate_t>
316 unsigned long __maxcode_;
317 codecvt_mode __mode_;
319 typedef char16_t intern_type;
320 typedef char extern_type;
321 typedef mbstate_t state_type;
323 _LIBCPP_INLINE_VISIBILITY
324 explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
326 : codecvt<char16_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
328 _LIBCPP_SUPPRESS_DEPRECATED_POP
331 result do_out(state_type& __st,
332 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
333 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
334 result do_in(state_type& __st,
335 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
336 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
337 result do_unshift(state_type& __st,
338 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
339 int do_encoding() const _NOEXCEPT override;
340 bool do_always_noconv() const _NOEXCEPT override;
341 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
342 int do_max_length() const _NOEXCEPT override;
345 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
347 class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf16<char32_t, false>
348 : public codecvt<char32_t, char, mbstate_t>
350 unsigned long __maxcode_;
351 codecvt_mode __mode_;
353 typedef char32_t intern_type;
354 typedef char extern_type;
355 typedef mbstate_t state_type;
357 _LIBCPP_INLINE_VISIBILITY
358 explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
360 : codecvt<char32_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
362 _LIBCPP_SUPPRESS_DEPRECATED_POP
365 result do_out(state_type& __st,
366 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
367 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
368 result do_in(state_type& __st,
369 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
370 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
371 result do_unshift(state_type& __st,
372 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
373 int do_encoding() const _NOEXCEPT override;
374 bool do_always_noconv() const _NOEXCEPT override;
375 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
376 int do_max_length() const _NOEXCEPT override;
379 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
381 class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf16<char32_t, true>
382 : public codecvt<char32_t, char, mbstate_t>
384 unsigned long __maxcode_;
385 codecvt_mode __mode_;
387 typedef char32_t intern_type;
388 typedef char extern_type;
389 typedef mbstate_t state_type;
391 _LIBCPP_INLINE_VISIBILITY
392 explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
394 : codecvt<char32_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
396 _LIBCPP_SUPPRESS_DEPRECATED_POP
399 result do_out(state_type& __st,
400 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
401 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
402 result do_in(state_type& __st,
403 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
404 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
405 result do_unshift(state_type& __st,
406 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
407 int do_encoding() const _NOEXCEPT override;
408 bool do_always_noconv() const _NOEXCEPT override;
409 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
410 int do_max_length() const _NOEXCEPT override;
413 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
414 template <class _Elem, unsigned long _Maxcode = 0x10ffff,
415 codecvt_mode _Mode = (codecvt_mode)0>
416 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 codecvt_utf16
417 : public __codecvt_utf16<_Elem, _Mode & little_endian>
420 _LIBCPP_INLINE_VISIBILITY
421 explicit codecvt_utf16(size_t __refs = 0)
422 : __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) {}
424 _LIBCPP_INLINE_VISIBILITY
427 _LIBCPP_SUPPRESS_DEPRECATED_POP
429 // codecvt_utf8_utf16
431 template <class _Elem> class __codecvt_utf8_utf16;
433 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
435 class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8_utf16<wchar_t>
436 : public codecvt<wchar_t, char, mbstate_t>
438 unsigned long __maxcode_;
439 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
440 codecvt_mode __mode_;
441 _LIBCPP_SUPPRESS_DEPRECATED_POP
443 typedef wchar_t intern_type;
444 typedef char extern_type;
445 typedef mbstate_t state_type;
447 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
448 _LIBCPP_INLINE_VISIBILITY
449 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long __maxcode,
451 : codecvt<wchar_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
453 _LIBCPP_SUPPRESS_DEPRECATED_POP
455 result do_out(state_type& __st,
456 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
457 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
458 result do_in(state_type& __st,
459 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
460 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
461 result do_unshift(state_type& __st,
462 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
463 int do_encoding() const _NOEXCEPT override;
464 bool do_always_noconv() const _NOEXCEPT override;
465 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
466 int do_max_length() const _NOEXCEPT override;
468 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
470 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
472 class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8_utf16<char32_t>
473 : public codecvt<char32_t, char, mbstate_t>
475 unsigned long __maxcode_;
476 codecvt_mode __mode_;
478 typedef char32_t intern_type;
479 typedef char extern_type;
480 typedef mbstate_t state_type;
482 _LIBCPP_INLINE_VISIBILITY
483 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long __maxcode,
485 : codecvt<char32_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
487 _LIBCPP_SUPPRESS_DEPRECATED_POP
490 result do_out(state_type& __st,
491 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
492 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
493 result do_in(state_type& __st,
494 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
495 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
496 result do_unshift(state_type& __st,
497 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
498 int do_encoding() const _NOEXCEPT override;
499 bool do_always_noconv() const _NOEXCEPT override;
500 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
501 int do_max_length() const _NOEXCEPT override;
504 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
506 class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8_utf16<char16_t>
507 : public codecvt<char16_t, char, mbstate_t>
509 unsigned long __maxcode_;
510 codecvt_mode __mode_;
512 typedef char16_t intern_type;
513 typedef char extern_type;
514 typedef mbstate_t state_type;
516 _LIBCPP_INLINE_VISIBILITY
517 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long __maxcode,
519 : codecvt<char16_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
521 _LIBCPP_SUPPRESS_DEPRECATED_POP
524 result do_out(state_type& __st,
525 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
526 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
527 result do_in(state_type& __st,
528 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
529 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
530 result do_unshift(state_type& __st,
531 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
532 int do_encoding() const _NOEXCEPT override;
533 bool do_always_noconv() const _NOEXCEPT override;
534 int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
535 int do_max_length() const _NOEXCEPT override;
538 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
539 template <class _Elem, unsigned long _Maxcode = 0x10ffff,
540 codecvt_mode _Mode = (codecvt_mode)0>
541 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 codecvt_utf8_utf16
542 : public __codecvt_utf8_utf16<_Elem>
545 _LIBCPP_INLINE_VISIBILITY
546 explicit codecvt_utf8_utf16(size_t __refs = 0)
547 : __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) {}
549 _LIBCPP_INLINE_VISIBILITY
550 ~codecvt_utf8_utf16() {}
552 _LIBCPP_SUPPRESS_DEPRECATED_POP
554 _LIBCPP_END_NAMESPACE_STD
556 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
562 # include <initializer_list>
567 # include <stdexcept>
568 # include <type_traits>
572 #endif // _LIBCPP_CODECVT