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();
61 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
62 #pragma GCC system_header
65 _LIBCPP_BEGIN_NAMESPACE_STD
76 template <class _Elem> class __codecvt_utf8;
78 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
80 class _LIBCPP_TYPE_VIS __codecvt_utf8<wchar_t>
81 : public codecvt<wchar_t, char, mbstate_t>
83 unsigned long _Maxcode_;
86 typedef wchar_t intern_type;
87 typedef char extern_type;
88 typedef mbstate_t state_type;
90 _LIBCPP_INLINE_VISIBILITY
91 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
93 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
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;
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;
105 do_unshift(state_type& __st,
106 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
107 virtual int do_encoding() const _NOEXCEPT;
108 virtual bool do_always_noconv() const _NOEXCEPT;
109 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
111 virtual int do_max_length() const _NOEXCEPT;
113 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
115 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
117 class _LIBCPP_TYPE_VIS __codecvt_utf8<char16_t>
118 : public codecvt<char16_t, char, mbstate_t>
120 unsigned long _Maxcode_;
123 typedef char16_t intern_type;
124 typedef char extern_type;
125 typedef mbstate_t state_type;
127 _LIBCPP_INLINE_VISIBILITY
128 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
130 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
132 _LIBCPP_SUPPRESS_DEPRECATED_POP
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;
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;
144 do_unshift(state_type& __st,
145 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
146 virtual int do_encoding() const _NOEXCEPT;
147 virtual bool do_always_noconv() const _NOEXCEPT;
148 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
150 virtual int do_max_length() const _NOEXCEPT;
153 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
155 class _LIBCPP_TYPE_VIS __codecvt_utf8<char32_t>
156 : public codecvt<char32_t, char, mbstate_t>
158 unsigned long _Maxcode_;
161 typedef char32_t intern_type;
162 typedef char extern_type;
163 typedef mbstate_t state_type;
165 _LIBCPP_INLINE_VISIBILITY
166 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
168 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
170 _LIBCPP_SUPPRESS_DEPRECATED_POP
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;
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;
182 do_unshift(state_type& __st,
183 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
184 virtual int do_encoding() const _NOEXCEPT;
185 virtual bool do_always_noconv() const _NOEXCEPT;
186 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
188 virtual int do_max_length() const _NOEXCEPT;
191 template <class _Elem, unsigned long _Maxcode = 0x10ffff,
192 codecvt_mode _Mode = (codecvt_mode)0>
193 class _LIBCPP_TEMPLATE_VIS codecvt_utf8
194 : public __codecvt_utf8<_Elem>
197 _LIBCPP_INLINE_VISIBILITY
198 explicit codecvt_utf8(size_t __refs = 0)
199 : __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) {}
201 _LIBCPP_INLINE_VISIBILITY
207 template <class _Elem, bool _LittleEndian> class __codecvt_utf16;
209 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
211 class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, false>
212 : public codecvt<wchar_t, char, mbstate_t>
214 unsigned long _Maxcode_;
217 typedef wchar_t intern_type;
218 typedef char extern_type;
219 typedef mbstate_t state_type;
221 _LIBCPP_INLINE_VISIBILITY
222 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
224 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
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;
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;
236 do_unshift(state_type& __st,
237 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
238 virtual int do_encoding() const _NOEXCEPT;
239 virtual bool do_always_noconv() const _NOEXCEPT;
240 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
242 virtual int do_max_length() const _NOEXCEPT;
246 class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, true>
247 : public codecvt<wchar_t, char, mbstate_t>
249 unsigned long _Maxcode_;
252 typedef wchar_t intern_type;
253 typedef char extern_type;
254 typedef mbstate_t state_type;
256 _LIBCPP_INLINE_VISIBILITY
257 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
259 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
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;
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;
271 do_unshift(state_type& __st,
272 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
273 virtual int do_encoding() const _NOEXCEPT;
274 virtual bool do_always_noconv() const _NOEXCEPT;
275 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
277 virtual int do_max_length() const _NOEXCEPT;
279 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
281 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
283 class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, false>
284 : public codecvt<char16_t, char, mbstate_t>
286 unsigned long _Maxcode_;
289 typedef char16_t intern_type;
290 typedef char extern_type;
291 typedef mbstate_t state_type;
293 _LIBCPP_INLINE_VISIBILITY
294 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
296 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
298 _LIBCPP_SUPPRESS_DEPRECATED_POP
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;
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;
310 do_unshift(state_type& __st,
311 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
312 virtual int do_encoding() const _NOEXCEPT;
313 virtual bool do_always_noconv() const _NOEXCEPT;
314 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
316 virtual int do_max_length() const _NOEXCEPT;
319 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
321 class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, true>
322 : public codecvt<char16_t, char, mbstate_t>
324 unsigned long _Maxcode_;
327 typedef char16_t intern_type;
328 typedef char extern_type;
329 typedef mbstate_t state_type;
331 _LIBCPP_INLINE_VISIBILITY
332 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
334 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
336 _LIBCPP_SUPPRESS_DEPRECATED_POP
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;
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;
348 do_unshift(state_type& __st,
349 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
350 virtual int do_encoding() const _NOEXCEPT;
351 virtual bool do_always_noconv() const _NOEXCEPT;
352 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
354 virtual int do_max_length() const _NOEXCEPT;
357 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
359 class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, false>
360 : public codecvt<char32_t, char, mbstate_t>
362 unsigned long _Maxcode_;
365 typedef char32_t intern_type;
366 typedef char extern_type;
367 typedef mbstate_t state_type;
369 _LIBCPP_INLINE_VISIBILITY
370 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
372 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
374 _LIBCPP_SUPPRESS_DEPRECATED_POP
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;
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;
386 do_unshift(state_type& __st,
387 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
388 virtual int do_encoding() const _NOEXCEPT;
389 virtual bool do_always_noconv() const _NOEXCEPT;
390 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
392 virtual int do_max_length() const _NOEXCEPT;
395 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
397 class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, true>
398 : public codecvt<char32_t, char, mbstate_t>
400 unsigned long _Maxcode_;
403 typedef char32_t intern_type;
404 typedef char extern_type;
405 typedef mbstate_t state_type;
407 _LIBCPP_INLINE_VISIBILITY
408 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
410 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
412 _LIBCPP_SUPPRESS_DEPRECATED_POP
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;
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;
424 do_unshift(state_type& __st,
425 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
426 virtual int do_encoding() const _NOEXCEPT;
427 virtual bool do_always_noconv() const _NOEXCEPT;
428 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
430 virtual int do_max_length() const _NOEXCEPT;
433 template <class _Elem, unsigned long _Maxcode = 0x10ffff,
434 codecvt_mode _Mode = (codecvt_mode)0>
435 class _LIBCPP_TEMPLATE_VIS codecvt_utf16
436 : public __codecvt_utf16<_Elem, _Mode & little_endian>
439 _LIBCPP_INLINE_VISIBILITY
440 explicit codecvt_utf16(size_t __refs = 0)
441 : __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) {}
443 _LIBCPP_INLINE_VISIBILITY
447 // codecvt_utf8_utf16
449 template <class _Elem> class __codecvt_utf8_utf16;
451 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
453 class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<wchar_t>
454 : public codecvt<wchar_t, char, mbstate_t>
456 unsigned long _Maxcode_;
459 typedef wchar_t intern_type;
460 typedef char extern_type;
461 typedef mbstate_t state_type;
463 _LIBCPP_INLINE_VISIBILITY
464 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
466 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
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;
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;
478 do_unshift(state_type& __st,
479 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
480 virtual int do_encoding() const _NOEXCEPT;
481 virtual bool do_always_noconv() const _NOEXCEPT;
482 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
484 virtual int do_max_length() const _NOEXCEPT;
486 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
488 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
490 class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char32_t>
491 : public codecvt<char32_t, char, mbstate_t>
493 unsigned long _Maxcode_;
496 typedef char32_t intern_type;
497 typedef char extern_type;
498 typedef mbstate_t state_type;
500 _LIBCPP_INLINE_VISIBILITY
501 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
503 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
505 _LIBCPP_SUPPRESS_DEPRECATED_POP
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;
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;
517 do_unshift(state_type& __st,
518 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
519 virtual int do_encoding() const _NOEXCEPT;
520 virtual bool do_always_noconv() const _NOEXCEPT;
521 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
523 virtual int do_max_length() const _NOEXCEPT;
526 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
528 class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char16_t>
529 : public codecvt<char16_t, char, mbstate_t>
531 unsigned long _Maxcode_;
534 typedef char16_t intern_type;
535 typedef char extern_type;
536 typedef mbstate_t state_type;
538 _LIBCPP_INLINE_VISIBILITY
539 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
541 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
543 _LIBCPP_SUPPRESS_DEPRECATED_POP
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;
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;
555 do_unshift(state_type& __st,
556 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
557 virtual int do_encoding() const _NOEXCEPT;
558 virtual bool do_always_noconv() const _NOEXCEPT;
559 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
561 virtual int do_max_length() const _NOEXCEPT;
564 template <class _Elem, unsigned long _Maxcode = 0x10ffff,
565 codecvt_mode _Mode = (codecvt_mode)0>
566 class _LIBCPP_TEMPLATE_VIS codecvt_utf8_utf16
567 : public __codecvt_utf8_utf16<_Elem>
570 _LIBCPP_INLINE_VISIBILITY
571 explicit codecvt_utf8_utf16(size_t __refs = 0)
572 : __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) {}
574 _LIBCPP_INLINE_VISIBILITY
575 ~codecvt_utf8_utf16() {}
578 _LIBCPP_END_NAMESPACE_STD
580 #endif // _LIBCPP_CODECVT