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>
35
template <class Elem, unsigned long Maxcode = 0x10ffff,
36
codecvt_mode Mode = (codecvt_mode)0>
38
: public codecvt<Elem, char, mbstate_t>
43
template <class Elem, unsigned long Maxcode = 0x10ffff,
44
codecvt_mode Mode = (codecvt_mode)0>
45
class codecvt_utf8_utf16
46
: public codecvt<Elem, char, mbstate_t>
58
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
59
#pragma GCC system_header
62
_LIBCPP_BEGIN_NAMESPACE_STD
73
template <class _Elem> class __codecvt_utf8;
76
class __codecvt_utf8<wchar_t>
77
: public codecvt<wchar_t, char, mbstate_t>
79
unsigned long _Maxcode_;
82
typedef wchar_t intern_type;
83
typedef char extern_type;
84
typedef mbstate_t state_type;
87
explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
89
: codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
93
do_out(state_type& __st,
94
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
95
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
97
do_in(state_type& __st,
98
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
99
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
101
do_unshift(state_type& __st,
102
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
103
virtual int do_encoding() const throw();
104
virtual bool do_always_noconv() const throw();
105
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
107
virtual int do_max_length() const throw();
111
class __codecvt_utf8<char16_t>
112
: public codecvt<char16_t, char, mbstate_t>
114
unsigned long _Maxcode_;
117
typedef char16_t intern_type;
118
typedef char extern_type;
119
typedef mbstate_t state_type;
121
_LIBCPP_ALWAYS_INLINE
122
explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
124
: codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
128
do_out(state_type& __st,
129
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
130
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
132
do_in(state_type& __st,
133
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
134
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
136
do_unshift(state_type& __st,
137
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
138
virtual int do_encoding() const throw();
139
virtual bool do_always_noconv() const throw();
140
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
142
virtual int do_max_length() const throw();
146
class __codecvt_utf8<char32_t>
147
: public codecvt<char32_t, char, mbstate_t>
149
unsigned long _Maxcode_;
152
typedef char32_t intern_type;
153
typedef char extern_type;
154
typedef mbstate_t state_type;
156
_LIBCPP_ALWAYS_INLINE
157
explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
159
: codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
163
do_out(state_type& __st,
164
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
165
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
167
do_in(state_type& __st,
168
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
169
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
171
do_unshift(state_type& __st,
172
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
173
virtual int do_encoding() const throw();
174
virtual bool do_always_noconv() const throw();
175
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
177
virtual int do_max_length() const throw();
180
template <class _Elem, unsigned long _Maxcode = 0x10ffff,
181
codecvt_mode _Mode = (codecvt_mode)0>
182
class _LIBCPP_TYPE_VIS codecvt_utf8
183
: public __codecvt_utf8<_Elem>
186
_LIBCPP_ALWAYS_INLINE
187
explicit codecvt_utf8(size_t __refs = 0)
188
: __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) {}
190
_LIBCPP_ALWAYS_INLINE
196
template <class _Elem, bool _LittleEndian> class __codecvt_utf16;
199
class __codecvt_utf16<wchar_t, false>
200
: public codecvt<wchar_t, char, mbstate_t>
202
unsigned long _Maxcode_;
205
typedef wchar_t intern_type;
206
typedef char extern_type;
207
typedef mbstate_t state_type;
209
_LIBCPP_ALWAYS_INLINE
210
explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
212
: codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
216
do_out(state_type& __st,
217
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
218
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
220
do_in(state_type& __st,
221
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
222
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
224
do_unshift(state_type& __st,
225
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
226
virtual int do_encoding() const throw();
227
virtual bool do_always_noconv() const throw();
228
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
230
virtual int do_max_length() const throw();
234
class __codecvt_utf16<wchar_t, true>
235
: public codecvt<wchar_t, char, mbstate_t>
237
unsigned long _Maxcode_;
240
typedef wchar_t intern_type;
241
typedef char extern_type;
242
typedef mbstate_t state_type;
244
_LIBCPP_ALWAYS_INLINE
245
explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
247
: codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
251
do_out(state_type& __st,
252
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
253
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
255
do_in(state_type& __st,
256
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
257
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
259
do_unshift(state_type& __st,
260
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
261
virtual int do_encoding() const throw();
262
virtual bool do_always_noconv() const throw();
263
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
265
virtual int do_max_length() const throw();
269
class __codecvt_utf16<char16_t, false>
270
: public codecvt<char16_t, char, mbstate_t>
272
unsigned long _Maxcode_;
275
typedef char16_t intern_type;
276
typedef char extern_type;
277
typedef mbstate_t state_type;
279
_LIBCPP_ALWAYS_INLINE
280
explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
282
: codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
286
do_out(state_type& __st,
287
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
288
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
290
do_in(state_type& __st,
291
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
292
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
294
do_unshift(state_type& __st,
295
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
296
virtual int do_encoding() const throw();
297
virtual bool do_always_noconv() const throw();
298
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
300
virtual int do_max_length() const throw();
304
class __codecvt_utf16<char16_t, true>
305
: public codecvt<char16_t, char, mbstate_t>
307
unsigned long _Maxcode_;
310
typedef char16_t intern_type;
311
typedef char extern_type;
312
typedef mbstate_t state_type;
314
_LIBCPP_ALWAYS_INLINE
315
explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
317
: codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
321
do_out(state_type& __st,
322
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
323
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
325
do_in(state_type& __st,
326
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
327
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
329
do_unshift(state_type& __st,
330
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
331
virtual int do_encoding() const throw();
332
virtual bool do_always_noconv() const throw();
333
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
335
virtual int do_max_length() const throw();
339
class __codecvt_utf16<char32_t, false>
340
: public codecvt<char32_t, char, mbstate_t>
342
unsigned long _Maxcode_;
345
typedef char32_t intern_type;
346
typedef char extern_type;
347
typedef mbstate_t state_type;
349
_LIBCPP_ALWAYS_INLINE
350
explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
352
: codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
356
do_out(state_type& __st,
357
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
358
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
360
do_in(state_type& __st,
361
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
362
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
364
do_unshift(state_type& __st,
365
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
366
virtual int do_encoding() const throw();
367
virtual bool do_always_noconv() const throw();
368
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
370
virtual int do_max_length() const throw();
374
class __codecvt_utf16<char32_t, true>
375
: public codecvt<char32_t, char, mbstate_t>
377
unsigned long _Maxcode_;
380
typedef char32_t intern_type;
381
typedef char extern_type;
382
typedef mbstate_t state_type;
384
_LIBCPP_ALWAYS_INLINE
385
explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
387
: codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
391
do_out(state_type& __st,
392
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
393
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
395
do_in(state_type& __st,
396
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
397
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
399
do_unshift(state_type& __st,
400
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
401
virtual int do_encoding() const throw();
402
virtual bool do_always_noconv() const throw();
403
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
405
virtual int do_max_length() const throw();
408
template <class _Elem, unsigned long _Maxcode = 0x10ffff,
409
codecvt_mode _Mode = (codecvt_mode)0>
410
class _LIBCPP_TYPE_VIS codecvt_utf16
411
: public __codecvt_utf16<_Elem, _Mode & little_endian>
414
_LIBCPP_ALWAYS_INLINE
415
explicit codecvt_utf16(size_t __refs = 0)
416
: __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) {}
418
_LIBCPP_ALWAYS_INLINE
422
// codecvt_utf8_utf16
424
template <class _Elem> class __codecvt_utf8_utf16;
427
class __codecvt_utf8_utf16<wchar_t>
428
: public codecvt<wchar_t, char, mbstate_t>
430
unsigned long _Maxcode_;
433
typedef wchar_t intern_type;
434
typedef char extern_type;
435
typedef mbstate_t state_type;
437
_LIBCPP_ALWAYS_INLINE
438
explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
440
: codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
444
do_out(state_type& __st,
445
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
446
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
448
do_in(state_type& __st,
449
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
450
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
452
do_unshift(state_type& __st,
453
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
454
virtual int do_encoding() const throw();
455
virtual bool do_always_noconv() const throw();
456
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
458
virtual int do_max_length() const throw();
462
class __codecvt_utf8_utf16<char32_t>
463
: public codecvt<char32_t, char, mbstate_t>
465
unsigned long _Maxcode_;
468
typedef char32_t intern_type;
469
typedef char extern_type;
470
typedef mbstate_t state_type;
472
_LIBCPP_ALWAYS_INLINE
473
explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
475
: codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
479
do_out(state_type& __st,
480
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
481
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
483
do_in(state_type& __st,
484
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
485
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
487
do_unshift(state_type& __st,
488
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
489
virtual int do_encoding() const throw();
490
virtual bool do_always_noconv() const throw();
491
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
493
virtual int do_max_length() const throw();
497
class __codecvt_utf8_utf16<char16_t>
498
: public codecvt<char16_t, char, mbstate_t>
500
unsigned long _Maxcode_;
503
typedef char16_t intern_type;
504
typedef char extern_type;
505
typedef mbstate_t state_type;
507
_LIBCPP_ALWAYS_INLINE
508
explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
510
: codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
514
do_out(state_type& __st,
515
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
516
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
518
do_in(state_type& __st,
519
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
520
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
522
do_unshift(state_type& __st,
523
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
524
virtual int do_encoding() const throw();
525
virtual bool do_always_noconv() const throw();
526
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
528
virtual int do_max_length() const throw();
531
template <class _Elem, unsigned long _Maxcode = 0x10ffff,
532
codecvt_mode _Mode = (codecvt_mode)0>
533
class _LIBCPP_TYPE_VIS codecvt_utf8_utf16
534
: public __codecvt_utf8_utf16<_Elem>
537
_LIBCPP_ALWAYS_INLINE
538
explicit codecvt_utf8_utf16(size_t __refs = 0)
539
: __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) {}
541
_LIBCPP_ALWAYS_INLINE
542
~codecvt_utf8_utf16() {}
545
_LIBCPP_END_NAMESPACE_STD
547
#endif // _LIBCPP_CODECVT