2 //===-------------------------- codecvt -----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_CODECVT
12 #define _LIBCPP_CODECVT
27 template <class Elem, unsigned long Maxcode = 0x10ffff,
28 codecvt_mode Mode = (codecvt_mode)0>
30 : public codecvt<Elem, char, mbstate_t>
32 explicit codecvt_utf8(size_t refs = 0);
36 template <class Elem, unsigned long Maxcode = 0x10ffff,
37 codecvt_mode Mode = (codecvt_mode)0>
39 : public codecvt<Elem, char, mbstate_t>
41 explicit codecvt_utf16(size_t refs = 0);
45 template <class Elem, unsigned long Maxcode = 0x10ffff,
46 codecvt_mode Mode = (codecvt_mode)0>
47 class codecvt_utf8_utf16
48 : public codecvt<Elem, char, mbstate_t>
50 explicit codecvt_utf8_utf16(size_t refs = 0);
51 ~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;
79 class _LIBCPP_TYPE_VIS __codecvt_utf8<wchar_t>
80 : public codecvt<wchar_t, char, mbstate_t>
82 unsigned long _Maxcode_;
85 typedef wchar_t intern_type;
86 typedef char extern_type;
87 typedef mbstate_t state_type;
90 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
92 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
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;
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;
104 do_unshift(state_type& __st,
105 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
106 virtual int do_encoding() const throw();
107 virtual bool do_always_noconv() const throw();
108 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
110 virtual int do_max_length() const throw();
114 class _LIBCPP_TYPE_VIS __codecvt_utf8<char16_t>
115 : public codecvt<char16_t, char, mbstate_t>
117 unsigned long _Maxcode_;
120 typedef char16_t intern_type;
121 typedef char extern_type;
122 typedef mbstate_t state_type;
124 _LIBCPP_ALWAYS_INLINE
125 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
127 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
131 do_out(state_type& __st,
132 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
133 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
135 do_in(state_type& __st,
136 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
137 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
139 do_unshift(state_type& __st,
140 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
141 virtual int do_encoding() const throw();
142 virtual bool do_always_noconv() const throw();
143 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
145 virtual int do_max_length() const throw();
149 class _LIBCPP_TYPE_VIS __codecvt_utf8<char32_t>
150 : public codecvt<char32_t, char, mbstate_t>
152 unsigned long _Maxcode_;
155 typedef char32_t intern_type;
156 typedef char extern_type;
157 typedef mbstate_t state_type;
159 _LIBCPP_ALWAYS_INLINE
160 explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
162 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
166 do_out(state_type& __st,
167 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
168 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
170 do_in(state_type& __st,
171 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
172 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
174 do_unshift(state_type& __st,
175 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
176 virtual int do_encoding() const throw();
177 virtual bool do_always_noconv() const throw();
178 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
180 virtual int do_max_length() const throw();
183 template <class _Elem, unsigned long _Maxcode = 0x10ffff,
184 codecvt_mode _Mode = (codecvt_mode)0>
185 class _LIBCPP_TYPE_VIS_ONLY codecvt_utf8
186 : public __codecvt_utf8<_Elem>
189 _LIBCPP_ALWAYS_INLINE
190 explicit codecvt_utf8(size_t __refs = 0)
191 : __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) {}
193 _LIBCPP_ALWAYS_INLINE
199 template <class _Elem, bool _LittleEndian> class __codecvt_utf16;
202 class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, false>
203 : public codecvt<wchar_t, char, mbstate_t>
205 unsigned long _Maxcode_;
208 typedef wchar_t intern_type;
209 typedef char extern_type;
210 typedef mbstate_t state_type;
212 _LIBCPP_ALWAYS_INLINE
213 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
215 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
219 do_out(state_type& __st,
220 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
221 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
223 do_in(state_type& __st,
224 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
225 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
227 do_unshift(state_type& __st,
228 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
229 virtual int do_encoding() const throw();
230 virtual bool do_always_noconv() const throw();
231 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
233 virtual int do_max_length() const throw();
237 class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, true>
238 : public codecvt<wchar_t, char, mbstate_t>
240 unsigned long _Maxcode_;
243 typedef wchar_t intern_type;
244 typedef char extern_type;
245 typedef mbstate_t state_type;
247 _LIBCPP_ALWAYS_INLINE
248 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
250 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
254 do_out(state_type& __st,
255 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
256 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
258 do_in(state_type& __st,
259 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
260 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
262 do_unshift(state_type& __st,
263 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
264 virtual int do_encoding() const throw();
265 virtual bool do_always_noconv() const throw();
266 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
268 virtual int do_max_length() const throw();
272 class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, false>
273 : public codecvt<char16_t, char, mbstate_t>
275 unsigned long _Maxcode_;
278 typedef char16_t intern_type;
279 typedef char extern_type;
280 typedef mbstate_t state_type;
282 _LIBCPP_ALWAYS_INLINE
283 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
285 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
289 do_out(state_type& __st,
290 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
291 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
293 do_in(state_type& __st,
294 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
295 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
297 do_unshift(state_type& __st,
298 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
299 virtual int do_encoding() const throw();
300 virtual bool do_always_noconv() const throw();
301 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
303 virtual int do_max_length() const throw();
307 class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, true>
308 : public codecvt<char16_t, char, mbstate_t>
310 unsigned long _Maxcode_;
313 typedef char16_t intern_type;
314 typedef char extern_type;
315 typedef mbstate_t state_type;
317 _LIBCPP_ALWAYS_INLINE
318 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
320 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
324 do_out(state_type& __st,
325 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
326 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
328 do_in(state_type& __st,
329 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
330 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
332 do_unshift(state_type& __st,
333 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
334 virtual int do_encoding() const throw();
335 virtual bool do_always_noconv() const throw();
336 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
338 virtual int do_max_length() const throw();
342 class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, false>
343 : public codecvt<char32_t, char, mbstate_t>
345 unsigned long _Maxcode_;
348 typedef char32_t intern_type;
349 typedef char extern_type;
350 typedef mbstate_t state_type;
352 _LIBCPP_ALWAYS_INLINE
353 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
355 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
359 do_out(state_type& __st,
360 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
361 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
363 do_in(state_type& __st,
364 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
365 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
367 do_unshift(state_type& __st,
368 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
369 virtual int do_encoding() const throw();
370 virtual bool do_always_noconv() const throw();
371 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
373 virtual int do_max_length() const throw();
377 class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, true>
378 : public codecvt<char32_t, char, mbstate_t>
380 unsigned long _Maxcode_;
383 typedef char32_t intern_type;
384 typedef char extern_type;
385 typedef mbstate_t state_type;
387 _LIBCPP_ALWAYS_INLINE
388 explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
390 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
394 do_out(state_type& __st,
395 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
396 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
398 do_in(state_type& __st,
399 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
400 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
402 do_unshift(state_type& __st,
403 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
404 virtual int do_encoding() const throw();
405 virtual bool do_always_noconv() const throw();
406 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
408 virtual int do_max_length() const throw();
411 template <class _Elem, unsigned long _Maxcode = 0x10ffff,
412 codecvt_mode _Mode = (codecvt_mode)0>
413 class _LIBCPP_TYPE_VIS_ONLY codecvt_utf16
414 : public __codecvt_utf16<_Elem, _Mode & little_endian>
417 _LIBCPP_ALWAYS_INLINE
418 explicit codecvt_utf16(size_t __refs = 0)
419 : __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) {}
421 _LIBCPP_ALWAYS_INLINE
425 // codecvt_utf8_utf16
427 template <class _Elem> class __codecvt_utf8_utf16;
430 class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<wchar_t>
431 : public codecvt<wchar_t, char, mbstate_t>
433 unsigned long _Maxcode_;
436 typedef wchar_t intern_type;
437 typedef char extern_type;
438 typedef mbstate_t state_type;
440 _LIBCPP_ALWAYS_INLINE
441 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
443 : codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
447 do_out(state_type& __st,
448 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
449 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
451 do_in(state_type& __st,
452 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
453 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
455 do_unshift(state_type& __st,
456 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
457 virtual int do_encoding() const throw();
458 virtual bool do_always_noconv() const throw();
459 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
461 virtual int do_max_length() const throw();
465 class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char32_t>
466 : public codecvt<char32_t, char, mbstate_t>
468 unsigned long _Maxcode_;
471 typedef char32_t intern_type;
472 typedef char extern_type;
473 typedef mbstate_t state_type;
475 _LIBCPP_ALWAYS_INLINE
476 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
478 : codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
482 do_out(state_type& __st,
483 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
484 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
486 do_in(state_type& __st,
487 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
488 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
490 do_unshift(state_type& __st,
491 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
492 virtual int do_encoding() const throw();
493 virtual bool do_always_noconv() const throw();
494 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
496 virtual int do_max_length() const throw();
500 class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char16_t>
501 : public codecvt<char16_t, char, mbstate_t>
503 unsigned long _Maxcode_;
506 typedef char16_t intern_type;
507 typedef char extern_type;
508 typedef mbstate_t state_type;
510 _LIBCPP_ALWAYS_INLINE
511 explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
513 : codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
517 do_out(state_type& __st,
518 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
519 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
521 do_in(state_type& __st,
522 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
523 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
525 do_unshift(state_type& __st,
526 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
527 virtual int do_encoding() const throw();
528 virtual bool do_always_noconv() const throw();
529 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
531 virtual int do_max_length() const throw();
534 template <class _Elem, unsigned long _Maxcode = 0x10ffff,
535 codecvt_mode _Mode = (codecvt_mode)0>
536 class _LIBCPP_TYPE_VIS_ONLY codecvt_utf8_utf16
537 : public __codecvt_utf8_utf16<_Elem>
540 _LIBCPP_ALWAYS_INLINE
541 explicit codecvt_utf8_utf16(size_t __refs = 0)
542 : __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) {}
544 _LIBCPP_ALWAYS_INLINE
545 ~codecvt_utf8_utf16() {}
548 _LIBCPP_END_NAMESPACE_STD
550 #endif // _LIBCPP_CODECVT