2 //===-------------------------- codecvt -----------------------------------===//
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();
60 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
61 #pragma GCC system_header
64 _LIBCPP_BEGIN_NAMESPACE_STD
75 template <class _Elem> class __codecvt_utf8;
78 class _LIBCPP_TYPE_VIS __codecvt_utf8<wchar_t>
79 : public codecvt<wchar_t, char, mbstate_t>
81 unsigned long _Maxcode_;
84 typedef wchar_t intern_type;
85 typedef char extern_type;
86 typedef mbstate_t state_type;
88 _LIBCPP_INLINE_VISIBILITY
89 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
91 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
95 do_out(state_type& __st,
96 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
97 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
99 do_in(state_type& __st,
100 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
101 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
103 do_unshift(state_type& __st,
104 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
105 virtual int do_encoding() const _NOEXCEPT;
106 virtual bool do_always_noconv() const _NOEXCEPT;
107 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
109 virtual int do_max_length() const _NOEXCEPT;
113 class _LIBCPP_TYPE_VIS __codecvt_utf8<char16_t>
114 : public codecvt<char16_t, char, mbstate_t>
116 unsigned long _Maxcode_;
119 typedef char16_t intern_type;
120 typedef char extern_type;
121 typedef mbstate_t state_type;
123 _LIBCPP_INLINE_VISIBILITY
124 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
126 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
130 do_out(state_type& __st,
131 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
132 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
134 do_in(state_type& __st,
135 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
136 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
138 do_unshift(state_type& __st,
139 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
140 virtual int do_encoding() const _NOEXCEPT;
141 virtual bool do_always_noconv() const _NOEXCEPT;
142 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
144 virtual int do_max_length() const _NOEXCEPT;
148 class _LIBCPP_TYPE_VIS __codecvt_utf8<char32_t>
149 : public codecvt<char32_t, char, mbstate_t>
151 unsigned long _Maxcode_;
154 typedef char32_t intern_type;
155 typedef char extern_type;
156 typedef mbstate_t state_type;
158 _LIBCPP_INLINE_VISIBILITY
159 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
161 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
165 do_out(state_type& __st,
166 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
167 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
169 do_in(state_type& __st,
170 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
171 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
173 do_unshift(state_type& __st,
174 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
175 virtual int do_encoding() const _NOEXCEPT;
176 virtual bool do_always_noconv() const _NOEXCEPT;
177 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
179 virtual int do_max_length() const _NOEXCEPT;
182 template <class _Elem, unsigned long _Maxcode = 0x10ffff,
183 codecvt_mode _Mode = (codecvt_mode)0>
184 class _LIBCPP_TEMPLATE_VIS codecvt_utf8
185 : public __codecvt_utf8<_Elem>
188 _LIBCPP_INLINE_VISIBILITY
189 explicit codecvt_utf8(size_t __refs = 0)
190 : __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) {}
192 _LIBCPP_INLINE_VISIBILITY
198 template <class _Elem, bool _LittleEndian> class __codecvt_utf16;
201 class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, false>
202 : public codecvt<wchar_t, char, mbstate_t>
204 unsigned long _Maxcode_;
207 typedef wchar_t intern_type;
208 typedef char extern_type;
209 typedef mbstate_t state_type;
211 _LIBCPP_INLINE_VISIBILITY
212 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
214 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
218 do_out(state_type& __st,
219 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
220 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
222 do_in(state_type& __st,
223 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
224 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
226 do_unshift(state_type& __st,
227 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
228 virtual int do_encoding() const _NOEXCEPT;
229 virtual bool do_always_noconv() const _NOEXCEPT;
230 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
232 virtual int do_max_length() const _NOEXCEPT;
236 class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, true>
237 : public codecvt<wchar_t, char, mbstate_t>
239 unsigned long _Maxcode_;
242 typedef wchar_t intern_type;
243 typedef char extern_type;
244 typedef mbstate_t state_type;
246 _LIBCPP_INLINE_VISIBILITY
247 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
249 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
253 do_out(state_type& __st,
254 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
255 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
257 do_in(state_type& __st,
258 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
259 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
261 do_unshift(state_type& __st,
262 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
263 virtual int do_encoding() const _NOEXCEPT;
264 virtual bool do_always_noconv() const _NOEXCEPT;
265 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
267 virtual int do_max_length() const _NOEXCEPT;
271 class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, false>
272 : public codecvt<char16_t, char, mbstate_t>
274 unsigned long _Maxcode_;
277 typedef char16_t intern_type;
278 typedef char extern_type;
279 typedef mbstate_t state_type;
281 _LIBCPP_INLINE_VISIBILITY
282 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
284 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
288 do_out(state_type& __st,
289 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
290 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
292 do_in(state_type& __st,
293 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
294 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
296 do_unshift(state_type& __st,
297 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
298 virtual int do_encoding() const _NOEXCEPT;
299 virtual bool do_always_noconv() const _NOEXCEPT;
300 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
302 virtual int do_max_length() const _NOEXCEPT;
306 class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, true>
307 : public codecvt<char16_t, char, mbstate_t>
309 unsigned long _Maxcode_;
312 typedef char16_t intern_type;
313 typedef char extern_type;
314 typedef mbstate_t state_type;
316 _LIBCPP_INLINE_VISIBILITY
317 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
319 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
323 do_out(state_type& __st,
324 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
325 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
327 do_in(state_type& __st,
328 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
329 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
331 do_unshift(state_type& __st,
332 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
333 virtual int do_encoding() const _NOEXCEPT;
334 virtual bool do_always_noconv() const _NOEXCEPT;
335 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
337 virtual int do_max_length() const _NOEXCEPT;
341 class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, false>
342 : public codecvt<char32_t, char, mbstate_t>
344 unsigned long _Maxcode_;
347 typedef char32_t intern_type;
348 typedef char extern_type;
349 typedef mbstate_t state_type;
351 _LIBCPP_INLINE_VISIBILITY
352 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
354 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
358 do_out(state_type& __st,
359 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
360 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
362 do_in(state_type& __st,
363 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
364 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
366 do_unshift(state_type& __st,
367 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
368 virtual int do_encoding() const _NOEXCEPT;
369 virtual bool do_always_noconv() const _NOEXCEPT;
370 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
372 virtual int do_max_length() const _NOEXCEPT;
376 class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, true>
377 : public codecvt<char32_t, char, mbstate_t>
379 unsigned long _Maxcode_;
382 typedef char32_t intern_type;
383 typedef char extern_type;
384 typedef mbstate_t state_type;
386 _LIBCPP_INLINE_VISIBILITY
387 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
389 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
393 do_out(state_type& __st,
394 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
395 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
397 do_in(state_type& __st,
398 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
399 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
401 do_unshift(state_type& __st,
402 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
403 virtual int do_encoding() const _NOEXCEPT;
404 virtual bool do_always_noconv() const _NOEXCEPT;
405 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
407 virtual int do_max_length() const _NOEXCEPT;
410 template <class _Elem, unsigned long _Maxcode = 0x10ffff,
411 codecvt_mode _Mode = (codecvt_mode)0>
412 class _LIBCPP_TEMPLATE_VIS codecvt_utf16
413 : public __codecvt_utf16<_Elem, _Mode & little_endian>
416 _LIBCPP_INLINE_VISIBILITY
417 explicit codecvt_utf16(size_t __refs = 0)
418 : __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) {}
420 _LIBCPP_INLINE_VISIBILITY
424 // codecvt_utf8_utf16
426 template <class _Elem> class __codecvt_utf8_utf16;
429 class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<wchar_t>
430 : public codecvt<wchar_t, char, mbstate_t>
432 unsigned long _Maxcode_;
435 typedef wchar_t intern_type;
436 typedef char extern_type;
437 typedef mbstate_t state_type;
439 _LIBCPP_INLINE_VISIBILITY
440 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
442 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
446 do_out(state_type& __st,
447 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
448 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
450 do_in(state_type& __st,
451 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
452 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
454 do_unshift(state_type& __st,
455 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
456 virtual int do_encoding() const _NOEXCEPT;
457 virtual bool do_always_noconv() const _NOEXCEPT;
458 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
460 virtual int do_max_length() const _NOEXCEPT;
464 class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char32_t>
465 : public codecvt<char32_t, char, mbstate_t>
467 unsigned long _Maxcode_;
470 typedef char32_t intern_type;
471 typedef char extern_type;
472 typedef mbstate_t state_type;
474 _LIBCPP_INLINE_VISIBILITY
475 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
477 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
481 do_out(state_type& __st,
482 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
483 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
485 do_in(state_type& __st,
486 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
487 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
489 do_unshift(state_type& __st,
490 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
491 virtual int do_encoding() const _NOEXCEPT;
492 virtual bool do_always_noconv() const _NOEXCEPT;
493 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
495 virtual int do_max_length() const _NOEXCEPT;
499 class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char16_t>
500 : public codecvt<char16_t, char, mbstate_t>
502 unsigned long _Maxcode_;
505 typedef char16_t intern_type;
506 typedef char extern_type;
507 typedef mbstate_t state_type;
509 _LIBCPP_INLINE_VISIBILITY
510 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
512 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
516 do_out(state_type& __st,
517 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
518 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
520 do_in(state_type& __st,
521 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
522 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
524 do_unshift(state_type& __st,
525 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
526 virtual int do_encoding() const _NOEXCEPT;
527 virtual bool do_always_noconv() const _NOEXCEPT;
528 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
530 virtual int do_max_length() const _NOEXCEPT;
533 template <class _Elem, unsigned long _Maxcode = 0x10ffff,
534 codecvt_mode _Mode = (codecvt_mode)0>
535 class _LIBCPP_TEMPLATE_VIS codecvt_utf8_utf16
536 : public __codecvt_utf8_utf16<_Elem>
539 _LIBCPP_INLINE_VISIBILITY
540 explicit codecvt_utf8_utf16(size_t __refs = 0)
541 : __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) {}
543 _LIBCPP_INLINE_VISIBILITY
544 ~codecvt_utf8_utf16() {}
547 _LIBCPP_END_NAMESPACE_STD
549 #endif // _LIBCPP_CODECVT