1
//===------------------------- locale.cpp ---------------------------------===//
3
// The LLVM Compiler Infrastructure
5
// This file is dual licensed under the MIT and the University of Illinois Open
6
// Source Licenses. See LICENSE.TXT for details.
8
//===----------------------------------------------------------------------===//
10
// On Solaris, we need to define something to make the C99 parts of localeconv
23
#include "type_traits"
27
#include "__sso_allocator"
29
#include <support/win32/locale_win32.h>
35
// On Linux, wint_t and wchar_t have different signed-ness, and this causes
36
// lots of noise in the build log, but no bugs that I know of.
37
#pragma clang diagnostic ignored "-Wsign-conversion"
39
_LIBCPP_BEGIN_NAMESPACE_STD
43
// In theory this could create a race condition. In practice
44
// the race condition is non-fatal since it will just create
45
// a little resource leak. Better approach would be appreciated.
46
static locale_t result = newlocale(LC_ALL_MASK, "C", 0);
49
#endif // __cloc_defined
55
void operator()(locale::facet* p) {p->__release_shared();}
58
template <class T, class A0>
63
static typename aligned_storage<sizeof(T)>::type buf;
68
template <class T, class A0, class A1>
73
static typename aligned_storage<sizeof(T)>::type buf;
74
::new (&buf) T(a0, a1);
78
template <class T, class A0, class A1, class A2>
81
make(A0 a0, A1 a1, A2 a2)
83
static typename aligned_storage<sizeof(T)>::type buf;
84
::new (&buf) T(a0, a1, a2);
88
template <typename T, size_t N>
92
countof(const T (&)[N])
101
countof(const T * const begin, const T * const end)
103
return static_cast<size_t>(end - begin);
108
const locale::category locale::none;
109
const locale::category locale::collate;
110
const locale::category locale::ctype;
111
const locale::category locale::monetary;
112
const locale::category locale::numeric;
113
const locale::category locale::time;
114
const locale::category locale::messages;
115
const locale::category locale::all;
117
#pragma clang diagnostic push
118
#pragma clang diagnostic ignored "-Wpadded"
120
class _LIBCPP_HIDDEN locale::__imp
124
vector<facet*, __sso_allocator<facet*, N> > facets_;
127
explicit __imp(size_t refs = 0);
128
explicit __imp(const string& name, size_t refs = 0);
130
__imp(const __imp&, const string&, locale::category c);
131
__imp(const __imp& other, const __imp& one, locale::category c);
132
__imp(const __imp&, facet* f, long id);
135
const string& name() const {return name_;}
136
bool has_facet(long id) const
137
{return static_cast<size_t>(id) < facets_.size() && facets_[static_cast<size_t>(id)];}
138
const locale::facet* use_facet(long id) const;
140
static const locale& make_classic();
141
static locale& make_global();
143
void install(facet* f, long id);
144
template <class F> void install(F* f) {install(f, f->id.__get());}
145
template <class F> void install_from(const __imp& other);
148
#pragma clang diagnostic pop
150
locale::__imp::__imp(size_t refs)
156
install(&make<_VSTD::collate<char> >(1u));
157
install(&make<_VSTD::collate<wchar_t> >(1u));
158
install(&make<_VSTD::ctype<char> >((ctype_base::mask*)0, false, 1u));
159
install(&make<_VSTD::ctype<wchar_t> >(1u));
160
install(&make<codecvt<char, char, mbstate_t> >(1u));
161
install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));
162
install(&make<codecvt<char16_t, char, mbstate_t> >(1u));
163
install(&make<codecvt<char32_t, char, mbstate_t> >(1u));
164
install(&make<numpunct<char> >(1u));
165
install(&make<numpunct<wchar_t> >(1u));
166
install(&make<num_get<char> >(1u));
167
install(&make<num_get<wchar_t> >(1u));
168
install(&make<num_put<char> >(1u));
169
install(&make<num_put<wchar_t> >(1u));
170
install(&make<moneypunct<char, false> >(1u));
171
install(&make<moneypunct<char, true> >(1u));
172
install(&make<moneypunct<wchar_t, false> >(1u));
173
install(&make<moneypunct<wchar_t, true> >(1u));
174
install(&make<money_get<char> >(1u));
175
install(&make<money_get<wchar_t> >(1u));
176
install(&make<money_put<char> >(1u));
177
install(&make<money_put<wchar_t> >(1u));
178
install(&make<time_get<char> >(1u));
179
install(&make<time_get<wchar_t> >(1u));
180
install(&make<time_put<char> >(1u));
181
install(&make<time_put<wchar_t> >(1u));
182
install(&make<_VSTD::messages<char> >(1u));
183
install(&make<_VSTD::messages<wchar_t> >(1u));
186
locale::__imp::__imp(const string& name, size_t refs)
191
#ifndef _LIBCPP_NO_EXCEPTIONS
194
#endif // _LIBCPP_NO_EXCEPTIONS
195
facets_ = locale::classic().__locale_->facets_;
196
for (unsigned i = 0; i < facets_.size(); ++i)
198
facets_[i]->__add_shared();
199
install(new collate_byname<char>(name_));
200
install(new collate_byname<wchar_t>(name_));
201
install(new ctype_byname<char>(name_));
202
install(new ctype_byname<wchar_t>(name_));
203
install(new codecvt_byname<char, char, mbstate_t>(name_));
204
install(new codecvt_byname<wchar_t, char, mbstate_t>(name_));
205
install(new codecvt_byname<char16_t, char, mbstate_t>(name_));
206
install(new codecvt_byname<char32_t, char, mbstate_t>(name_));
207
install(new numpunct_byname<char>(name_));
208
install(new numpunct_byname<wchar_t>(name_));
209
install(new moneypunct_byname<char, false>(name_));
210
install(new moneypunct_byname<char, true>(name_));
211
install(new moneypunct_byname<wchar_t, false>(name_));
212
install(new moneypunct_byname<wchar_t, true>(name_));
213
install(new time_get_byname<char>(name_));
214
install(new time_get_byname<wchar_t>(name_));
215
install(new time_put_byname<char>(name_));
216
install(new time_put_byname<wchar_t>(name_));
217
install(new messages_byname<char>(name_));
218
install(new messages_byname<wchar_t>(name_));
219
#ifndef _LIBCPP_NO_EXCEPTIONS
223
for (unsigned i = 0; i < facets_.size(); ++i)
225
facets_[i]->__release_shared();
228
#endif // _LIBCPP_NO_EXCEPTIONS
231
// NOTE avoid the `base class should be explicitly initialized in the
232
// copy constructor` warning emitted by GCC
233
#pragma GCC diagnostic push
234
#pragma GCC diagnostic ignored "-Wextra"
236
locale::__imp::__imp(const __imp& other)
237
: facets_(max<size_t>(N, other.facets_.size())),
240
facets_ = other.facets_;
241
for (unsigned i = 0; i < facets_.size(); ++i)
243
facets_[i]->__add_shared();
246
#pragma GCC diagnostic pop
248
locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
252
facets_ = other.facets_;
253
for (unsigned i = 0; i < facets_.size(); ++i)
255
facets_[i]->__add_shared();
256
#ifndef _LIBCPP_NO_EXCEPTIONS
259
#endif // _LIBCPP_NO_EXCEPTIONS
260
if (c & locale::collate)
262
install(new collate_byname<char>(name));
263
install(new collate_byname<wchar_t>(name));
265
if (c & locale::ctype)
267
install(new ctype_byname<char>(name));
268
install(new ctype_byname<wchar_t>(name));
269
install(new codecvt_byname<char, char, mbstate_t>(name));
270
install(new codecvt_byname<wchar_t, char, mbstate_t>(name));
271
install(new codecvt_byname<char16_t, char, mbstate_t>(name));
272
install(new codecvt_byname<char32_t, char, mbstate_t>(name));
274
if (c & locale::monetary)
276
install(new moneypunct_byname<char, false>(name));
277
install(new moneypunct_byname<char, true>(name));
278
install(new moneypunct_byname<wchar_t, false>(name));
279
install(new moneypunct_byname<wchar_t, true>(name));
281
if (c & locale::numeric)
283
install(new numpunct_byname<char>(name));
284
install(new numpunct_byname<wchar_t>(name));
286
if (c & locale::time)
288
install(new time_get_byname<char>(name));
289
install(new time_get_byname<wchar_t>(name));
290
install(new time_put_byname<char>(name));
291
install(new time_put_byname<wchar_t>(name));
293
if (c & locale::messages)
295
install(new messages_byname<char>(name));
296
install(new messages_byname<wchar_t>(name));
298
#ifndef _LIBCPP_NO_EXCEPTIONS
302
for (unsigned i = 0; i < facets_.size(); ++i)
304
facets_[i]->__release_shared();
307
#endif // _LIBCPP_NO_EXCEPTIONS
313
locale::__imp::install_from(const locale::__imp& one)
315
long id = F::id.__get();
316
install(const_cast<F*>(static_cast<const F*>(one.use_facet(id))), id);
319
locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)
323
facets_ = other.facets_;
324
for (unsigned i = 0; i < facets_.size(); ++i)
326
facets_[i]->__add_shared();
327
#ifndef _LIBCPP_NO_EXCEPTIONS
330
#endif // _LIBCPP_NO_EXCEPTIONS
331
if (c & locale::collate)
333
install_from<_VSTD::collate<char> >(one);
334
install_from<_VSTD::collate<wchar_t> >(one);
336
if (c & locale::ctype)
338
install_from<_VSTD::ctype<char> >(one);
339
install_from<_VSTD::ctype<wchar_t> >(one);
340
install_from<_VSTD::codecvt<char, char, mbstate_t> >(one);
341
install_from<_VSTD::codecvt<char16_t, char, mbstate_t> >(one);
342
install_from<_VSTD::codecvt<char32_t, char, mbstate_t> >(one);
343
install_from<_VSTD::codecvt<wchar_t, char, mbstate_t> >(one);
345
if (c & locale::monetary)
347
install_from<moneypunct<char, false> >(one);
348
install_from<moneypunct<char, true> >(one);
349
install_from<moneypunct<wchar_t, false> >(one);
350
install_from<moneypunct<wchar_t, true> >(one);
351
install_from<money_get<char> >(one);
352
install_from<money_get<wchar_t> >(one);
353
install_from<money_put<char> >(one);
354
install_from<money_put<wchar_t> >(one);
356
if (c & locale::numeric)
358
install_from<numpunct<char> >(one);
359
install_from<numpunct<wchar_t> >(one);
360
install_from<num_get<char> >(one);
361
install_from<num_get<wchar_t> >(one);
362
install_from<num_put<char> >(one);
363
install_from<num_put<wchar_t> >(one);
365
if (c & locale::time)
367
install_from<time_get<char> >(one);
368
install_from<time_get<wchar_t> >(one);
369
install_from<time_put<char> >(one);
370
install_from<time_put<wchar_t> >(one);
372
if (c & locale::messages)
374
install_from<_VSTD::messages<char> >(one);
375
install_from<_VSTD::messages<wchar_t> >(one);
377
#ifndef _LIBCPP_NO_EXCEPTIONS
381
for (unsigned i = 0; i < facets_.size(); ++i)
383
facets_[i]->__release_shared();
386
#endif // _LIBCPP_NO_EXCEPTIONS
389
locale::__imp::__imp(const __imp& other, facet* f, long id)
390
: facets_(max<size_t>(N, other.facets_.size()+1)),
394
unique_ptr<facet, release> hold(f);
395
facets_ = other.facets_;
396
for (unsigned i = 0; i < other.facets_.size(); ++i)
398
facets_[i]->__add_shared();
399
install(hold.get(), id);
402
locale::__imp::~__imp()
404
for (unsigned i = 0; i < facets_.size(); ++i)
406
facets_[i]->__release_shared();
410
locale::__imp::install(facet* f, long id)
413
unique_ptr<facet, release> hold(f);
414
if (static_cast<size_t>(id) >= facets_.size())
415
facets_.resize(static_cast<size_t>(id+1));
416
if (facets_[static_cast<size_t>(id)])
417
facets_[static_cast<size_t>(id)]->__release_shared();
418
facets_[static_cast<size_t>(id)] = hold.release();
422
locale::__imp::use_facet(long id) const
424
#ifndef _LIBCPP_NO_EXCEPTIONS
427
#endif // _LIBCPP_NO_EXCEPTIONS
428
return facets_[static_cast<size_t>(id)];
434
locale::__imp::make_classic()
436
// only one thread can get in here and it only gets in once
437
static aligned_storage<sizeof(locale)>::type buf;
438
locale* c = (locale*)&buf;
439
c->__locale_ = &make<__imp>(1u);
446
static const locale& c = __imp::make_classic();
451
locale::__imp::make_global()
453
// only one thread can get in here and it only gets in once
454
static aligned_storage<sizeof(locale)>::type buf;
455
::new (&buf) locale(locale::classic());
456
return *(locale*)&buf;
462
static locale& g = __imp::make_global();
466
locale::locale() _NOEXCEPT
467
: __locale_(__global().__locale_)
469
__locale_->__add_shared();
472
locale::locale(const locale& l) _NOEXCEPT
473
: __locale_(l.__locale_)
475
__locale_->__add_shared();
480
__locale_->__release_shared();
484
locale::operator=(const locale& other) _NOEXCEPT
486
other.__locale_->__add_shared();
487
__locale_->__release_shared();
488
__locale_ = other.__locale_;
492
locale::locale(const char* name)
493
#ifndef _LIBCPP_NO_EXCEPTIONS
494
: __locale_(name ? new __imp(name)
495
: throw runtime_error("locale constructed with null"))
496
#else // _LIBCPP_NO_EXCEPTIONS
497
: __locale_(new __imp(name))
500
__locale_->__add_shared();
503
locale::locale(const string& name)
504
: __locale_(new __imp(name))
506
__locale_->__add_shared();
509
locale::locale(const locale& other, const char* name, category c)
510
#ifndef _LIBCPP_NO_EXCEPTIONS
511
: __locale_(name ? new __imp(*other.__locale_, name, c)
512
: throw runtime_error("locale constructed with null"))
513
#else // _LIBCPP_NO_EXCEPTIONS
514
: __locale_(new __imp(*other.__locale_, name, c))
517
__locale_->__add_shared();
520
locale::locale(const locale& other, const string& name, category c)
521
: __locale_(new __imp(*other.__locale_, name, c))
523
__locale_->__add_shared();
526
locale::locale(const locale& other, const locale& one, category c)
527
: __locale_(new __imp(*other.__locale_, *one.__locale_, c))
529
__locale_->__add_shared();
535
return __locale_->name();
539
locale::__install_ctor(const locale& other, facet* f, long id)
542
__locale_ = new __imp(*other.__locale_, f, id);
544
__locale_ = other.__locale_;
545
__locale_->__add_shared();
549
locale::global(const locale& loc)
551
locale& g = __global();
555
setlocale(LC_ALL, g.name().c_str());
560
locale::has_facet(id& x) const
562
return __locale_->has_facet(x.__get());
566
locale::use_facet(id& x) const
568
return __locale_->use_facet(x.__get());
572
locale::operator==(const locale& y) const
574
return (__locale_ == y.__locale_)
575
|| (__locale_->name() != "*" && __locale_->name() == y.__locale_->name());
580
locale::facet::~facet()
585
locale::facet::__on_zero_shared() _NOEXCEPT
592
int32_t locale::id::__next_id = 0;
600
void (locale::id::* pmf_)();
602
__fake_bind(void (locale::id::* pmf)(), locale::id* id)
603
: id_(id), pmf_(pmf) {}
605
void operator()() const
616
call_once(__flag_, __fake_bind(&locale::id::__init, this));
623
__id_ = __sync_add_and_fetch(&__next_id, 1);
626
// template <> class collate_byname<char>
628
collate_byname<char>::collate_byname(const char* n, size_t refs)
629
: collate<char>(refs),
630
__l(newlocale(LC_ALL_MASK, n, 0))
632
#ifndef _LIBCPP_NO_EXCEPTIONS
634
throw runtime_error("collate_byname<char>::collate_byname"
635
" failed to construct for " + string(n));
636
#endif // _LIBCPP_NO_EXCEPTIONS
639
collate_byname<char>::collate_byname(const string& name, size_t refs)
640
: collate<char>(refs),
641
__l(newlocale(LC_ALL_MASK, name.c_str(), 0))
643
#ifndef _LIBCPP_NO_EXCEPTIONS
645
throw runtime_error("collate_byname<char>::collate_byname"
646
" failed to construct for " + name);
647
#endif // _LIBCPP_NO_EXCEPTIONS
650
collate_byname<char>::~collate_byname()
656
collate_byname<char>::do_compare(const char_type* __lo1, const char_type* __hi1,
657
const char_type* __lo2, const char_type* __hi2) const
659
string_type lhs(__lo1, __hi1);
660
string_type rhs(__lo2, __hi2);
661
int r = strcoll_l(lhs.c_str(), rhs.c_str(), __l);
669
collate_byname<char>::string_type
670
collate_byname<char>::do_transform(const char_type* lo, const char_type* hi) const
672
const string_type in(lo, hi);
673
string_type out(strxfrm_l(0, in.c_str(), 0, __l), char());
674
strxfrm_l(const_cast<char*>(out.c_str()), in.c_str(), out.size()+1, __l);
678
// template <> class collate_byname<wchar_t>
680
collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)
681
: collate<wchar_t>(refs),
682
__l(newlocale(LC_ALL_MASK, n, 0))
684
#ifndef _LIBCPP_NO_EXCEPTIONS
686
throw runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
687
" failed to construct for " + string(n));
688
#endif // _LIBCPP_NO_EXCEPTIONS
691
collate_byname<wchar_t>::collate_byname(const string& name, size_t refs)
692
: collate<wchar_t>(refs),
693
__l(newlocale(LC_ALL_MASK, name.c_str(), 0))
695
#ifndef _LIBCPP_NO_EXCEPTIONS
697
throw runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
698
" failed to construct for " + name);
699
#endif // _LIBCPP_NO_EXCEPTIONS
702
collate_byname<wchar_t>::~collate_byname()
708
collate_byname<wchar_t>::do_compare(const char_type* __lo1, const char_type* __hi1,
709
const char_type* __lo2, const char_type* __hi2) const
711
string_type lhs(__lo1, __hi1);
712
string_type rhs(__lo2, __hi2);
713
int r = wcscoll_l(lhs.c_str(), rhs.c_str(), __l);
721
collate_byname<wchar_t>::string_type
722
collate_byname<wchar_t>::do_transform(const char_type* lo, const char_type* hi) const
724
const string_type in(lo, hi);
725
string_type out(wcsxfrm_l(0, in.c_str(), 0, __l), wchar_t());
726
wcsxfrm_l(const_cast<wchar_t*>(out.c_str()), in.c_str(), out.size()+1, __l);
730
// template <> class ctype<wchar_t>;
732
const ctype_base::mask ctype_base::space;
733
const ctype_base::mask ctype_base::print;
734
const ctype_base::mask ctype_base::cntrl;
735
const ctype_base::mask ctype_base::upper;
736
const ctype_base::mask ctype_base::lower;
737
const ctype_base::mask ctype_base::alpha;
738
const ctype_base::mask ctype_base::digit;
739
const ctype_base::mask ctype_base::punct;
740
const ctype_base::mask ctype_base::xdigit;
741
const ctype_base::mask ctype_base::blank;
742
const ctype_base::mask ctype_base::alnum;
743
const ctype_base::mask ctype_base::graph;
745
locale::id ctype<wchar_t>::id;
747
ctype<wchar_t>::~ctype()
752
ctype<wchar_t>::do_is(mask m, char_type c) const
754
return isascii(c) ? ctype<char>::classic_table()[c] & m : false;
758
ctype<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const
760
for (; low != high; ++low, ++vec)
761
*vec = static_cast<mask>(isascii(*low) ?
762
ctype<char>::classic_table()[*low] : 0);
767
ctype<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const
769
for (; low != high; ++low)
770
if (isascii(*low) && (ctype<char>::classic_table()[*low] & m))
776
ctype<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
778
for (; low != high; ++low)
779
if (!(isascii(*low) && (ctype<char>::classic_table()[*low] & m)))
785
ctype<wchar_t>::do_toupper(char_type c) const
787
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
788
return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
789
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
790
return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
792
return (isascii(c) && iswlower_l(c, __cloc())) ? c-L'a'+L'A' : c;
797
ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
799
for (; low != high; ++low)
800
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
801
*low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
802
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
803
*low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
806
*low = (isascii(*low) && islower_l(*low, __cloc())) ? (*low-L'a'+L'A') : *low;
812
ctype<wchar_t>::do_tolower(char_type c) const
814
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
815
return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
816
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
817
return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
819
return (isascii(c) && isupper_l(c, __cloc())) ? c-L'A'+'a' : c;
824
ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const
826
for (; low != high; ++low)
827
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
828
*low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
829
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
830
*low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
833
*low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-L'A'+L'a' : *low;
839
ctype<wchar_t>::do_widen(char c) const
845
ctype<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
847
for (; low != high; ++low, ++dest)
853
ctype<wchar_t>::do_narrow(char_type c, char dfault) const
856
return static_cast<char>(c);
861
ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
863
for (; low != high; ++low, ++dest)
865
*dest = static_cast<char>(*low);
871
// template <> class ctype<char>;
873
locale::id ctype<char>::id;
875
ctype<char>::ctype(const mask* tab, bool del, size_t refs)
876
: locale::facet(refs),
881
__tab_ = classic_table();
884
ctype<char>::~ctype()
886
if (__tab_ && __del_)
891
ctype<char>::do_toupper(char_type c) const
893
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
895
static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
896
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
898
static_cast<char>(__classic_upper_table()[static_cast<size_t>(c)]) : c;
900
return (isascii(c) && islower_l(c, __cloc())) ? c-'a'+'A' : c;
905
ctype<char>::do_toupper(char_type* low, const char_type* high) const
907
for (; low != high; ++low)
908
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
909
*low = isascii(*low) ?
910
static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
911
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
912
*low = isascii(*low) ?
913
static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
915
*low = (isascii(*low) && islower_l(*low, __cloc())) ? *low-'a'+'A' : *low;
921
ctype<char>::do_tolower(char_type c) const
923
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
925
static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
926
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
928
static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
930
return (isascii(c) && isupper_l(c, __cloc())) ? c-'A'+'a' : c;
935
ctype<char>::do_tolower(char_type* low, const char_type* high) const
937
for (; low != high; ++low)
938
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
939
*low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;
940
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
941
*low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
943
*low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-'A'+'a' : *low;
949
ctype<char>::do_widen(char c) const
955
ctype<char>::do_widen(const char* low, const char* high, char_type* dest) const
957
for (; low != high; ++low, ++dest)
963
ctype<char>::do_narrow(char_type c, char dfault) const
966
return static_cast<char>(c);
971
ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
973
for (; low != high; ++low, ++dest)
982
extern "C" const unsigned short ** __ctype_b_loc();
983
extern "C" const int ** __ctype_tolower_loc();
984
extern "C" const int ** __ctype_toupper_loc();
987
const ctype<char>::mask*
988
ctype<char>::classic_table() _NOEXCEPT
990
#if defined(__APPLE__) || defined(__FreeBSD__)
991
return _DefaultRuneLocale.__runetype;
992
#elif defined(__GLIBC__)
993
return __cloc()->__ctype_b;
996
#elif defined(_WIN32)
997
return _ctype+1; // internal ctype mask table defined in msvcrt.dll
998
// This is assumed to be safe, which is a nonsense assumption because we're
999
// going to end up dereferencing it later...
1000
#elif defined(EMSCRIPTEN)
1001
return *__ctype_b_loc();
1003
// Platform not supported: abort so the person doing the port knows what to
1005
# warning ctype<char>::classic_table() is not implemented
1011
#if defined(__GLIBC__)
1013
ctype<char>::__classic_lower_table() _NOEXCEPT
1015
return __cloc()->__ctype_tolower;
1019
ctype<char>::__classic_upper_table() _NOEXCEPT
1021
return __cloc()->__ctype_toupper;
1025
#if defined(EMSCRIPTEN)
1027
ctype<char>::__classic_lower_table() _NOEXCEPT
1029
return *__ctype_tolower_loc();
1033
ctype<char>::__classic_upper_table() _NOEXCEPT
1035
return *__ctype_toupper_loc();
1037
#endif // EMSCRIPTEN
1039
// template <> class ctype_byname<char>
1041
ctype_byname<char>::ctype_byname(const char* name, size_t refs)
1042
: ctype<char>(0, false, refs),
1043
__l(newlocale(LC_ALL_MASK, name, 0))
1045
#ifndef _LIBCPP_NO_EXCEPTIONS
1047
throw runtime_error("ctype_byname<char>::ctype_byname"
1048
" failed to construct for " + string(name));
1049
#endif // _LIBCPP_NO_EXCEPTIONS
1052
ctype_byname<char>::ctype_byname(const string& name, size_t refs)
1053
: ctype<char>(0, false, refs),
1054
__l(newlocale(LC_ALL_MASK, name.c_str(), 0))
1056
#ifndef _LIBCPP_NO_EXCEPTIONS
1058
throw runtime_error("ctype_byname<char>::ctype_byname"
1059
" failed to construct for " + name);
1060
#endif // _LIBCPP_NO_EXCEPTIONS
1063
ctype_byname<char>::~ctype_byname()
1069
ctype_byname<char>::do_toupper(char_type c) const
1071
return static_cast<char>(toupper_l(c, __l));
1075
ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const
1077
for (; low != high; ++low)
1078
*low = static_cast<char>(toupper_l(*low, __l));
1083
ctype_byname<char>::do_tolower(char_type c) const
1085
return static_cast<char>(tolower_l(c, __l));
1089
ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
1091
for (; low != high; ++low)
1092
*low = static_cast<char>(tolower_l(*low, __l));
1096
// template <> class ctype_byname<wchar_t>
1098
ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
1099
: ctype<wchar_t>(refs),
1100
__l(newlocale(LC_ALL_MASK, name, 0))
1102
#ifndef _LIBCPP_NO_EXCEPTIONS
1104
throw runtime_error("ctype_byname<wchar_t>::ctype_byname"
1105
" failed to construct for " + string(name));
1106
#endif // _LIBCPP_NO_EXCEPTIONS
1109
ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)
1110
: ctype<wchar_t>(refs),
1111
__l(newlocale(LC_ALL_MASK, name.c_str(), 0))
1113
#ifndef _LIBCPP_NO_EXCEPTIONS
1115
throw runtime_error("ctype_byname<wchar_t>::ctype_byname"
1116
" failed to construct for " + name);
1117
#endif // _LIBCPP_NO_EXCEPTIONS
1120
ctype_byname<wchar_t>::~ctype_byname()
1126
ctype_byname<wchar_t>::do_is(mask m, char_type c) const
1128
#ifdef _LIBCPP_WCTYPE_IS_MASK
1129
return static_cast<bool>(iswctype_l(c, m, __l));
1131
bool result = false;
1132
wint_t ch = static_cast<wint_t>(c);
1133
if (m & space) result |= (iswspace_l(ch, __l) != 0);
1134
if (m & print) result |= (iswprint_l(ch, __l) != 0);
1135
if (m & cntrl) result |= (iswcntrl_l(ch, __l) != 0);
1136
if (m & upper) result |= (iswupper_l(ch, __l) != 0);
1137
if (m & lower) result |= (iswlower_l(ch, __l) != 0);
1138
if (m & alpha) result |= (iswalpha_l(ch, __l) != 0);
1139
if (m & digit) result |= (iswdigit_l(ch, __l) != 0);
1140
if (m & punct) result |= (iswpunct_l(ch, __l) != 0);
1141
if (m & xdigit) result |= (iswxdigit_l(ch, __l) != 0);
1142
if (m & blank) result |= (iswblank_l(ch, __l) != 0);
1148
ctype_byname<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const
1150
for (; low != high; ++low, ++vec)
1153
*vec = static_cast<mask>(ctype<char>::classic_table()[*low]);
1157
wint_t ch = static_cast<wint_t>(*low);
1158
if (iswspace_l(ch, __l))
1160
if (iswprint_l(ch, __l))
1162
if (iswcntrl_l(ch, __l))
1164
if (iswupper_l(ch, __l))
1166
if (iswlower_l(ch, __l))
1168
if (iswalpha_l(ch, __l))
1170
if (iswdigit_l(ch, __l))
1172
if (iswpunct_l(ch, __l))
1174
if (iswxdigit_l(ch, __l))
1182
ctype_byname<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const
1184
for (; low != high; ++low)
1186
#ifdef _LIBCPP_WCTYPE_IS_MASK
1187
if (iswctype_l(*low, m, __l))
1190
wint_t ch = static_cast<wint_t>(*low);
1191
if (m & space && iswspace_l(ch, __l)) break;
1192
if (m & print && iswprint_l(ch, __l)) break;
1193
if (m & cntrl && iswcntrl_l(ch, __l)) break;
1194
if (m & upper && iswupper_l(ch, __l)) break;
1195
if (m & lower && iswlower_l(ch, __l)) break;
1196
if (m & alpha && iswalpha_l(ch, __l)) break;
1197
if (m & digit && iswdigit_l(ch, __l)) break;
1198
if (m & punct && iswpunct_l(ch, __l)) break;
1199
if (m & xdigit && iswxdigit_l(ch, __l)) break;
1200
if (m & blank && iswblank_l(ch, __l)) break;
1207
ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
1209
for (; low != high; ++low)
1211
#ifdef _LIBCPP_WCTYPE_IS_MASK
1212
if (!iswctype_l(*low, m, __l))
1215
wint_t ch = static_cast<wint_t>(*low);
1216
if (m & space && iswspace_l(ch, __l)) continue;
1217
if (m & print && iswprint_l(ch, __l)) continue;
1218
if (m & cntrl && iswcntrl_l(ch, __l)) continue;
1219
if (m & upper && iswupper_l(ch, __l)) continue;
1220
if (m & lower && iswlower_l(ch, __l)) continue;
1221
if (m & alpha && iswalpha_l(ch, __l)) continue;
1222
if (m & digit && iswdigit_l(ch, __l)) continue;
1223
if (m & punct && iswpunct_l(ch, __l)) continue;
1224
if (m & xdigit && iswxdigit_l(ch, __l)) continue;
1225
if (m & blank && iswblank_l(ch, __l)) continue;
1233
ctype_byname<wchar_t>::do_toupper(char_type c) const
1235
return towupper_l(c, __l);
1239
ctype_byname<wchar_t>::do_toupper(char_type* low, const char_type* high) const
1241
for (; low != high; ++low)
1242
*low = towupper_l(*low, __l);
1247
ctype_byname<wchar_t>::do_tolower(char_type c) const
1249
return towlower_l(c, __l);
1253
ctype_byname<wchar_t>::do_tolower(char_type* low, const char_type* high) const
1255
for (; low != high; ++low)
1256
*low = towlower_l(*low, __l);
1261
ctype_byname<wchar_t>::do_widen(char c) const
1263
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1264
return btowc_l(c, __l);
1266
return __btowc_l(c, __l);
1271
ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
1273
for (; low != high; ++low, ++dest)
1274
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1275
*dest = btowc_l(*low, __l);
1277
*dest = __btowc_l(*low, __l);
1283
ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const
1285
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1286
int r = wctob_l(c, __l);
1288
int r = __wctob_l(c, __l);
1290
return r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
1294
ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
1296
for (; low != high; ++low, ++dest)
1298
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1299
int r = wctob_l(*low, __l);
1301
int r = __wctob_l(*low, __l);
1303
*dest = r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
1308
// template <> class codecvt<char, char, mbstate_t>
1310
locale::id codecvt<char, char, mbstate_t>::id;
1312
codecvt<char, char, mbstate_t>::~codecvt()
1316
codecvt<char, char, mbstate_t>::result
1317
codecvt<char, char, mbstate_t>::do_out(state_type&,
1318
const intern_type* frm, const intern_type*, const intern_type*& frm_nxt,
1319
extern_type* to, extern_type*, extern_type*& to_nxt) const
1326
codecvt<char, char, mbstate_t>::result
1327
codecvt<char, char, mbstate_t>::do_in(state_type&,
1328
const extern_type* frm, const extern_type*, const extern_type*& frm_nxt,
1329
intern_type* to, intern_type*, intern_type*& to_nxt) const
1336
codecvt<char, char, mbstate_t>::result
1337
codecvt<char, char, mbstate_t>::do_unshift(state_type&,
1338
extern_type* to, extern_type*, extern_type*& to_nxt) const
1345
codecvt<char, char, mbstate_t>::do_encoding() const _NOEXCEPT
1351
codecvt<char, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
1357
codecvt<char, char, mbstate_t>::do_length(state_type&,
1358
const extern_type* frm, const extern_type* end, size_t mx) const
1360
return static_cast<int>(min<size_t>(mx, static_cast<size_t>(end-frm)));
1364
codecvt<char, char, mbstate_t>::do_max_length() const _NOEXCEPT
1369
// template <> class codecvt<wchar_t, char, mbstate_t>
1371
locale::id codecvt<wchar_t, char, mbstate_t>::id;
1373
codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs)
1374
: locale::facet(refs),
1379
codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs)
1380
: locale::facet(refs),
1381
__l(newlocale(LC_ALL_MASK, nm, 0))
1383
#ifndef _LIBCPP_NO_EXCEPTIONS
1385
throw runtime_error("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname"
1386
" failed to construct for " + string(nm));
1387
#endif // _LIBCPP_NO_EXCEPTIONS
1390
codecvt<wchar_t, char, mbstate_t>::~codecvt()
1396
codecvt<wchar_t, char, mbstate_t>::result
1397
codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
1398
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
1399
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
1401
// look for first internal null in frm
1402
const intern_type* fend = frm;
1403
for (; fend != frm_end; ++fend)
1406
// loop over all null-terminated sequences in frm
1408
for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
1410
// save state in case needed to reover to_nxt on error
1411
mbstate_t save_state = st;
1412
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1413
size_t n = wcsnrtombs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
1414
static_cast<size_t>(to_end-to), &st, __l);
1416
size_t n = __wcsnrtombs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
1418
if (n == size_t(-1))
1420
// need to recover to_nxt
1421
for (to_nxt = to; frm != frm_nxt; ++frm)
1423
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1424
n = wcrtomb_l(to_nxt, *frm, &save_state, __l);
1426
n = __wcrtomb_l(to_nxt, *frm, &save_state, __l);
1428
if (n == size_t(-1))
1438
if (to_nxt == to_end)
1440
if (fend != frm_end) // set up next null terminated sequence
1442
// Try to write the terminating null
1443
extern_type tmp[MB_LEN_MAX];
1444
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1445
n = wcrtomb_l(tmp, intern_type(), &st, __l);
1447
n = __wcrtomb_l(tmp, intern_type(), &st, __l);
1449
if (n == size_t(-1)) // on error
1451
if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
1453
for (extern_type* p = tmp; n; --n) // write it
1456
// look for next null in frm
1457
for (fend = frm_nxt; fend != frm_end; ++fend)
1462
return frm_nxt == frm_end ? ok : partial;
1465
codecvt<wchar_t, char, mbstate_t>::result
1466
codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
1467
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
1468
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
1470
// look for first internal null in frm
1471
const extern_type* fend = frm;
1472
for (; fend != frm_end; ++fend)
1475
// loop over all null-terminated sequences in frm
1477
for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
1479
// save state in case needed to reover to_nxt on error
1480
mbstate_t save_state = st;
1481
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1482
size_t n = mbsnrtowcs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
1483
static_cast<size_t>(to_end-to), &st, __l);
1485
size_t n = __mbsnrtowcs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
1487
if (n == size_t(-1))
1489
// need to recover to_nxt
1490
for (to_nxt = to; frm != frm_nxt; ++to_nxt)
1492
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1493
n = mbrtowc_l(to_nxt, frm, static_cast<size_t>(fend-frm),
1496
n = __mbrtowc_l(to_nxt, frm, fend-frm, &save_state, __l);
1515
return frm_nxt == frm_end ? ok : partial;
1520
if (to_nxt == to_end)
1522
if (fend != frm_end) // set up next null terminated sequence
1524
// Try to write the terminating null
1525
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1526
n = mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l);
1528
n = __mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l);
1530
if (n != 0) // on error
1534
// look for next null in frm
1535
for (fend = frm_nxt; fend != frm_end; ++fend)
1540
return frm_nxt == frm_end ? ok : partial;
1543
codecvt<wchar_t, char, mbstate_t>::result
1544
codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st,
1545
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
1548
extern_type tmp[MB_LEN_MAX];
1549
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1550
size_t n = wcrtomb_l(tmp, intern_type(), &st, __l);
1552
size_t n = __wcrtomb_l(tmp, intern_type(), &st, __l);
1554
if (n == size_t(-1) || n == 0) // on error
1557
if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
1559
for (extern_type* p = tmp; n; --n) // write it
1565
codecvt<wchar_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
1567
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1568
if (mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
1570
if (__mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
1573
// stateless encoding
1574
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1575
if (__l == 0 || MB_CUR_MAX_L(__l) == 1) // there are no known constant length encodings
1577
if (__l == 0 || __mb_cur_max_l(__l) == 1) // there are no known constant length encodings
1579
return 1; // which take more than 1 char to form a wchar_t
1586
codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
1592
codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st,
1593
const extern_type* frm, const extern_type* frm_end, size_t mx) const
1596
for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t)
1598
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1599
size_t n = mbrlen_l(frm, static_cast<size_t>(frm_end-frm), &st, __l);
1601
size_t n = __mbrlen_l(frm, frm_end-frm, &st, __l);
1622
codecvt<wchar_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
1624
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1625
return __l == 0 ? 1 : static_cast<int>( MB_CUR_MAX_L(__l));
1627
return __l == 0 ? 1 : static_cast<int>(__mb_cur_max_l(__l));
1632
// UTF-32 UTF-16 UTF-8 # of code points
1633
// first second first second third fourth
1634
// 000000 - 00007F 0000 - 007F 00 - 7F 127
1635
// 000080 - 0007FF 0080 - 07FF C2 - DF, 80 - BF 1920
1636
// 000800 - 000FFF 0800 - 0FFF E0 - E0, A0 - BF, 80 - BF 2048
1637
// 001000 - 00CFFF 1000 - CFFF E1 - EC, 80 - BF, 80 - BF 49152
1638
// 00D000 - 00D7FF D000 - D7FF ED - ED, 80 - 9F, 80 - BF 2048
1639
// 00D800 - 00DFFF invalid
1640
// 00E000 - 00FFFF E000 - FFFF EE - EF, 80 - BF, 80 - BF 8192
1641
// 010000 - 03FFFF D800 - D8BF, DC00 - DFFF F0 - F0, 90 - BF, 80 - BF, 80 - BF 196608
1642
// 040000 - 0FFFFF D8C0 - DBBF, DC00 - DFFF F1 - F3, 80 - BF, 80 - BF, 80 - BF 786432
1643
// 100000 - 10FFFF DBC0 - DBFF, DC00 - DFFF F4 - F4, 80 - 8F, 80 - BF, 80 - BF 65536
1646
codecvt_base::result
1647
utf16_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
1648
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
1649
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1653
if (mode & generate_header)
1655
if (to_end-to_nxt < 3)
1656
return codecvt_base::partial;
1657
*to_nxt++ = static_cast<uint8_t>(0xEF);
1658
*to_nxt++ = static_cast<uint8_t>(0xBB);
1659
*to_nxt++ = static_cast<uint8_t>(0xBF);
1661
for (; frm_nxt < frm_end; ++frm_nxt)
1663
uint16_t wc1 = *frm_nxt;
1665
return codecvt_base::error;
1668
if (to_end-to_nxt < 1)
1669
return codecvt_base::partial;
1670
*to_nxt++ = static_cast<uint8_t>(wc1);
1672
else if (wc1 < 0x0800)
1674
if (to_end-to_nxt < 2)
1675
return codecvt_base::partial;
1676
*to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
1677
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
1679
else if (wc1 < 0xD800)
1681
if (to_end-to_nxt < 3)
1682
return codecvt_base::partial;
1683
*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1684
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1685
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1687
else if (wc1 < 0xDC00)
1689
if (frm_end-frm_nxt < 2)
1690
return codecvt_base::partial;
1691
uint16_t wc2 = frm_nxt[1];
1692
if ((wc2 & 0xFC00) != 0xDC00)
1693
return codecvt_base::error;
1694
if (to_end-to_nxt < 4)
1695
return codecvt_base::partial;
1696
if ((((((unsigned long)wc1 & 0x03C0) >> 6) + 1) << 16) +
1697
(((unsigned long)wc1 & 0x003F) << 10) + (wc2 & 0x03FF) > Maxcode)
1698
return codecvt_base::error;
1700
uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
1701
*to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
1702
*to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
1703
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
1704
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
1706
else if (wc1 < 0xE000)
1708
return codecvt_base::error;
1712
if (to_end-to_nxt < 3)
1713
return codecvt_base::partial;
1714
*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1715
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1716
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1719
return codecvt_base::ok;
1723
codecvt_base::result
1724
utf16_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
1725
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
1726
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1730
if (mode & generate_header)
1732
if (to_end-to_nxt < 3)
1733
return codecvt_base::partial;
1734
*to_nxt++ = static_cast<uint8_t>(0xEF);
1735
*to_nxt++ = static_cast<uint8_t>(0xBB);
1736
*to_nxt++ = static_cast<uint8_t>(0xBF);
1738
for (; frm_nxt < frm_end; ++frm_nxt)
1740
uint16_t wc1 = static_cast<uint16_t>(*frm_nxt);
1742
return codecvt_base::error;
1745
if (to_end-to_nxt < 1)
1746
return codecvt_base::partial;
1747
*to_nxt++ = static_cast<uint8_t>(wc1);
1749
else if (wc1 < 0x0800)
1751
if (to_end-to_nxt < 2)
1752
return codecvt_base::partial;
1753
*to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
1754
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
1756
else if (wc1 < 0xD800)
1758
if (to_end-to_nxt < 3)
1759
return codecvt_base::partial;
1760
*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1761
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1762
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1764
else if (wc1 < 0xDC00)
1766
if (frm_end-frm_nxt < 2)
1767
return codecvt_base::partial;
1768
uint16_t wc2 = static_cast<uint16_t>(frm_nxt[1]);
1769
if ((wc2 & 0xFC00) != 0xDC00)
1770
return codecvt_base::error;
1771
if (to_end-to_nxt < 4)
1772
return codecvt_base::partial;
1773
if ((((((unsigned long)wc1 & 0x03C0) >> 6) + 1) << 16) +
1774
(((unsigned long)wc1 & 0x003F) << 10) + (wc2 & 0x03FF) > Maxcode)
1775
return codecvt_base::error;
1777
uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
1778
*to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
1779
*to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
1780
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
1781
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
1783
else if (wc1 < 0xE000)
1785
return codecvt_base::error;
1789
if (to_end-to_nxt < 3)
1790
return codecvt_base::partial;
1791
*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1792
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1793
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1796
return codecvt_base::ok;
1800
codecvt_base::result
1801
utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
1802
uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
1803
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1807
if (mode & consume_header)
1809
if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
1813
for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
1815
uint8_t c1 = *frm_nxt;
1817
return codecvt_base::error;
1820
*to_nxt = static_cast<uint16_t>(c1);
1825
return codecvt_base::error;
1829
if (frm_end-frm_nxt < 2)
1830
return codecvt_base::partial;
1831
uint8_t c2 = frm_nxt[1];
1832
if ((c2 & 0xC0) != 0x80)
1833
return codecvt_base::error;
1834
uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
1836
return codecvt_base::error;
1842
if (frm_end-frm_nxt < 3)
1843
return codecvt_base::partial;
1844
uint8_t c2 = frm_nxt[1];
1845
uint8_t c3 = frm_nxt[2];
1849
if ((c2 & 0xE0) != 0xA0)
1850
return codecvt_base::error;
1853
if ((c2 & 0xE0) != 0x80)
1854
return codecvt_base::error;
1857
if ((c2 & 0xC0) != 0x80)
1858
return codecvt_base::error;
1861
if ((c3 & 0xC0) != 0x80)
1862
return codecvt_base::error;
1863
uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
1864
| ((c2 & 0x3F) << 6)
1867
return codecvt_base::error;
1873
if (frm_end-frm_nxt < 4)
1874
return codecvt_base::partial;
1875
uint8_t c2 = frm_nxt[1];
1876
uint8_t c3 = frm_nxt[2];
1877
uint8_t c4 = frm_nxt[3];
1881
if (!(0x90 <= c2 && c2 <= 0xBF))
1882
return codecvt_base::error;
1885
if ((c2 & 0xF0) != 0x80)
1886
return codecvt_base::error;
1889
if ((c2 & 0xC0) != 0x80)
1890
return codecvt_base::error;
1893
if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
1894
return codecvt_base::error;
1895
if (to_end-to_nxt < 2)
1896
return codecvt_base::partial;
1897
if (((((unsigned long)c1 & 7) << 18) +
1898
(((unsigned long)c2 & 0x3F) << 12) +
1899
(((unsigned long)c3 & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode)
1900
return codecvt_base::error;
1901
*to_nxt = static_cast<uint16_t>(
1903
| (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
1904
| ((c2 & 0x0F) << 2)
1905
| ((c3 & 0x30) >> 4));
1906
*++to_nxt = static_cast<uint16_t>(
1908
| ((c3 & 0x0F) << 6)
1914
return codecvt_base::error;
1917
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
1921
codecvt_base::result
1922
utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
1923
uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
1924
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1928
if (mode & consume_header)
1930
if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
1934
for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
1936
uint8_t c1 = *frm_nxt;
1938
return codecvt_base::error;
1941
*to_nxt = static_cast<uint32_t>(c1);
1946
return codecvt_base::error;
1950
if (frm_end-frm_nxt < 2)
1951
return codecvt_base::partial;
1952
uint8_t c2 = frm_nxt[1];
1953
if ((c2 & 0xC0) != 0x80)
1954
return codecvt_base::error;
1955
uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
1957
return codecvt_base::error;
1958
*to_nxt = static_cast<uint32_t>(t);
1963
if (frm_end-frm_nxt < 3)
1964
return codecvt_base::partial;
1965
uint8_t c2 = frm_nxt[1];
1966
uint8_t c3 = frm_nxt[2];
1970
if ((c2 & 0xE0) != 0xA0)
1971
return codecvt_base::error;
1974
if ((c2 & 0xE0) != 0x80)
1975
return codecvt_base::error;
1978
if ((c2 & 0xC0) != 0x80)
1979
return codecvt_base::error;
1982
if ((c3 & 0xC0) != 0x80)
1983
return codecvt_base::error;
1984
uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
1985
| ((c2 & 0x3F) << 6)
1988
return codecvt_base::error;
1989
*to_nxt = static_cast<uint32_t>(t);
1994
if (frm_end-frm_nxt < 4)
1995
return codecvt_base::partial;
1996
uint8_t c2 = frm_nxt[1];
1997
uint8_t c3 = frm_nxt[2];
1998
uint8_t c4 = frm_nxt[3];
2002
if (!(0x90 <= c2 && c2 <= 0xBF))
2003
return codecvt_base::error;
2006
if ((c2 & 0xF0) != 0x80)
2007
return codecvt_base::error;
2010
if ((c2 & 0xC0) != 0x80)
2011
return codecvt_base::error;
2014
if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2015
return codecvt_base::error;
2016
if (to_end-to_nxt < 2)
2017
return codecvt_base::partial;
2018
if (((((unsigned long)c1 & 7) << 18) +
2019
(((unsigned long)c2 & 0x3F) << 12) +
2020
(((unsigned long)c3 & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode)
2021
return codecvt_base::error;
2022
*to_nxt = static_cast<uint32_t>(
2024
| (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
2025
| ((c2 & 0x0F) << 2)
2026
| ((c3 & 0x30) >> 4));
2027
*++to_nxt = static_cast<uint32_t>(
2029
| ((c3 & 0x0F) << 6)
2035
return codecvt_base::error;
2038
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2043
utf8_to_utf16_length(const uint8_t* frm, const uint8_t* frm_end,
2044
size_t mx, unsigned long Maxcode = 0x10FFFF,
2045
codecvt_mode mode = codecvt_mode(0))
2047
const uint8_t* frm_nxt = frm;
2048
if (mode & consume_header)
2050
if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2054
for (size_t nchar16_t = 0; frm_nxt < frm_end && nchar16_t < mx; ++nchar16_t)
2056
uint8_t c1 = *frm_nxt;
2069
if ((frm_end-frm_nxt < 2) || (frm_nxt[1] & 0xC0) != 0x80)
2071
uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F));
2078
if (frm_end-frm_nxt < 3)
2080
uint8_t c2 = frm_nxt[1];
2081
uint8_t c3 = frm_nxt[2];
2085
if ((c2 & 0xE0) != 0xA0)
2086
return static_cast<int>(frm_nxt - frm);
2089
if ((c2 & 0xE0) != 0x80)
2090
return static_cast<int>(frm_nxt - frm);
2093
if ((c2 & 0xC0) != 0x80)
2094
return static_cast<int>(frm_nxt - frm);
2097
if ((c3 & 0xC0) != 0x80)
2099
if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
2105
if (frm_end-frm_nxt < 4 || mx-nchar16_t < 2)
2107
uint8_t c2 = frm_nxt[1];
2108
uint8_t c3 = frm_nxt[2];
2109
uint8_t c4 = frm_nxt[3];
2113
if (!(0x90 <= c2 && c2 <= 0xBF))
2114
return static_cast<int>(frm_nxt - frm);
2117
if ((c2 & 0xF0) != 0x80)
2118
return static_cast<int>(frm_nxt - frm);
2121
if ((c2 & 0xC0) != 0x80)
2122
return static_cast<int>(frm_nxt - frm);
2125
if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2127
if (((((unsigned long)c1 & 7) << 18) +
2128
(((unsigned long)c2 & 0x3F) << 12) +
2129
(((unsigned long)c3 & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode)
2139
return static_cast<int>(frm_nxt - frm);
2143
codecvt_base::result
2144
ucs4_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
2145
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2146
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2150
if (mode & generate_header)
2152
if (to_end-to_nxt < 3)
2153
return codecvt_base::partial;
2154
*to_nxt++ = static_cast<uint8_t>(0xEF);
2155
*to_nxt++ = static_cast<uint8_t>(0xBB);
2156
*to_nxt++ = static_cast<uint8_t>(0xBF);
2158
for (; frm_nxt < frm_end; ++frm_nxt)
2160
uint32_t wc = *frm_nxt;
2161
if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
2162
return codecvt_base::error;
2165
if (to_end-to_nxt < 1)
2166
return codecvt_base::partial;
2167
*to_nxt++ = static_cast<uint8_t>(wc);
2169
else if (wc < 0x000800)
2171
if (to_end-to_nxt < 2)
2172
return codecvt_base::partial;
2173
*to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
2174
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
2176
else if (wc < 0x010000)
2178
if (to_end-to_nxt < 3)
2179
return codecvt_base::partial;
2180
*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
2181
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
2182
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
2184
else // if (wc < 0x110000)
2186
if (to_end-to_nxt < 4)
2187
return codecvt_base::partial;
2188
*to_nxt++ = static_cast<uint8_t>(0xF0 | (wc >> 18));
2189
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x03F000) >> 12));
2190
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x000FC0) >> 6));
2191
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x00003F));
2194
return codecvt_base::ok;
2198
codecvt_base::result
2199
utf8_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2200
uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2201
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2205
if (mode & consume_header)
2207
if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2211
for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
2213
uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2217
return codecvt_base::error;
2218
*to_nxt = static_cast<uint32_t>(c1);
2223
return codecvt_base::error;
2227
if (frm_end-frm_nxt < 2)
2228
return codecvt_base::partial;
2229
uint8_t c2 = frm_nxt[1];
2230
if ((c2 & 0xC0) != 0x80)
2231
return codecvt_base::error;
2232
uint32_t t = static_cast<uint32_t>(((c1 & 0x1F) << 6)
2235
return codecvt_base::error;
2241
if (frm_end-frm_nxt < 3)
2242
return codecvt_base::partial;
2243
uint8_t c2 = frm_nxt[1];
2244
uint8_t c3 = frm_nxt[2];
2248
if ((c2 & 0xE0) != 0xA0)
2249
return codecvt_base::error;
2252
if ((c2 & 0xE0) != 0x80)
2253
return codecvt_base::error;
2256
if ((c2 & 0xC0) != 0x80)
2257
return codecvt_base::error;
2260
if ((c3 & 0xC0) != 0x80)
2261
return codecvt_base::error;
2262
uint32_t t = static_cast<uint32_t>(((c1 & 0x0F) << 12)
2263
| ((c2 & 0x3F) << 6)
2266
return codecvt_base::error;
2272
if (frm_end-frm_nxt < 4)
2273
return codecvt_base::partial;
2274
uint8_t c2 = frm_nxt[1];
2275
uint8_t c3 = frm_nxt[2];
2276
uint8_t c4 = frm_nxt[3];
2280
if (!(0x90 <= c2 && c2 <= 0xBF))
2281
return codecvt_base::error;
2284
if ((c2 & 0xF0) != 0x80)
2285
return codecvt_base::error;
2288
if ((c2 & 0xC0) != 0x80)
2289
return codecvt_base::error;
2292
if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2293
return codecvt_base::error;
2294
uint32_t t = static_cast<uint32_t>(((c1 & 0x07) << 18)
2295
| ((c2 & 0x3F) << 12)
2296
| ((c3 & 0x3F) << 6)
2299
return codecvt_base::error;
2305
return codecvt_base::error;
2308
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2313
utf8_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
2314
size_t mx, unsigned long Maxcode = 0x10FFFF,
2315
codecvt_mode mode = codecvt_mode(0))
2317
const uint8_t* frm_nxt = frm;
2318
if (mode & consume_header)
2320
if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2324
for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
2326
uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2339
if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
2341
if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
2347
if (frm_end-frm_nxt < 3)
2349
uint8_t c2 = frm_nxt[1];
2350
uint8_t c3 = frm_nxt[2];
2354
if ((c2 & 0xE0) != 0xA0)
2355
return static_cast<int>(frm_nxt - frm);
2358
if ((c2 & 0xE0) != 0x80)
2359
return static_cast<int>(frm_nxt - frm);
2362
if ((c2 & 0xC0) != 0x80)
2363
return static_cast<int>(frm_nxt - frm);
2366
if ((c3 & 0xC0) != 0x80)
2368
if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
2374
if (frm_end-frm_nxt < 4)
2376
uint8_t c2 = frm_nxt[1];
2377
uint8_t c3 = frm_nxt[2];
2378
uint8_t c4 = frm_nxt[3];
2382
if (!(0x90 <= c2 && c2 <= 0xBF))
2383
return static_cast<int>(frm_nxt - frm);
2386
if ((c2 & 0xF0) != 0x80)
2387
return static_cast<int>(frm_nxt - frm);
2390
if ((c2 & 0xC0) != 0x80)
2391
return static_cast<int>(frm_nxt - frm);
2394
if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2396
if ((((c1 & 0x07u) << 18) | ((c2 & 0x3Fu) << 12) |
2397
((c3 & 0x3Fu) << 6) | (c4 & 0x3Fu)) > Maxcode)
2406
return static_cast<int>(frm_nxt - frm);
2410
codecvt_base::result
2411
ucs2_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
2412
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2413
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2417
if (mode & generate_header)
2419
if (to_end-to_nxt < 3)
2420
return codecvt_base::partial;
2421
*to_nxt++ = static_cast<uint8_t>(0xEF);
2422
*to_nxt++ = static_cast<uint8_t>(0xBB);
2423
*to_nxt++ = static_cast<uint8_t>(0xBF);
2425
for (; frm_nxt < frm_end; ++frm_nxt)
2427
uint16_t wc = *frm_nxt;
2428
if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
2429
return codecvt_base::error;
2432
if (to_end-to_nxt < 1)
2433
return codecvt_base::partial;
2434
*to_nxt++ = static_cast<uint8_t>(wc);
2436
else if (wc < 0x0800)
2438
if (to_end-to_nxt < 2)
2439
return codecvt_base::partial;
2440
*to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
2441
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
2443
else // if (wc <= 0xFFFF)
2445
if (to_end-to_nxt < 3)
2446
return codecvt_base::partial;
2447
*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
2448
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
2449
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
2452
return codecvt_base::ok;
2456
codecvt_base::result
2457
utf8_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2458
uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
2459
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2463
if (mode & consume_header)
2465
if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2469
for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
2471
uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2475
return codecvt_base::error;
2476
*to_nxt = static_cast<uint16_t>(c1);
2481
return codecvt_base::error;
2485
if (frm_end-frm_nxt < 2)
2486
return codecvt_base::partial;
2487
uint8_t c2 = frm_nxt[1];
2488
if ((c2 & 0xC0) != 0x80)
2489
return codecvt_base::error;
2490
uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6)
2493
return codecvt_base::error;
2499
if (frm_end-frm_nxt < 3)
2500
return codecvt_base::partial;
2501
uint8_t c2 = frm_nxt[1];
2502
uint8_t c3 = frm_nxt[2];
2506
if ((c2 & 0xE0) != 0xA0)
2507
return codecvt_base::error;
2510
if ((c2 & 0xE0) != 0x80)
2511
return codecvt_base::error;
2514
if ((c2 & 0xC0) != 0x80)
2515
return codecvt_base::error;
2518
if ((c3 & 0xC0) != 0x80)
2519
return codecvt_base::error;
2520
uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
2521
| ((c2 & 0x3F) << 6)
2524
return codecvt_base::error;
2530
return codecvt_base::error;
2533
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2538
utf8_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
2539
size_t mx, unsigned long Maxcode = 0x10FFFF,
2540
codecvt_mode mode = codecvt_mode(0))
2542
const uint8_t* frm_nxt = frm;
2543
if (mode & consume_header)
2545
if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2549
for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
2551
uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2564
if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
2566
if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
2572
if (frm_end-frm_nxt < 3)
2574
uint8_t c2 = frm_nxt[1];
2575
uint8_t c3 = frm_nxt[2];
2579
if ((c2 & 0xE0) != 0xA0)
2580
return static_cast<int>(frm_nxt - frm);
2583
if ((c2 & 0xE0) != 0x80)
2584
return static_cast<int>(frm_nxt - frm);
2587
if ((c2 & 0xC0) != 0x80)
2588
return static_cast<int>(frm_nxt - frm);
2591
if ((c3 & 0xC0) != 0x80)
2593
if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
2602
return static_cast<int>(frm_nxt - frm);
2606
codecvt_base::result
2607
ucs4_to_utf16be(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
2608
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2609
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2613
if (mode & generate_header)
2615
if (to_end-to_nxt < 2)
2616
return codecvt_base::partial;
2617
*to_nxt++ = static_cast<uint8_t>(0xFE);
2618
*to_nxt++ = static_cast<uint8_t>(0xFF);
2620
for (; frm_nxt < frm_end; ++frm_nxt)
2622
uint32_t wc = *frm_nxt;
2623
if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
2624
return codecvt_base::error;
2627
if (to_end-to_nxt < 2)
2628
return codecvt_base::partial;
2629
*to_nxt++ = static_cast<uint8_t>(wc >> 8);
2630
*to_nxt++ = static_cast<uint8_t>(wc);
2634
if (to_end-to_nxt < 4)
2635
return codecvt_base::partial;
2636
uint16_t t = static_cast<uint16_t>(
2638
| ((((wc & 0x1F0000) >> 16) - 1) << 6)
2639
| ((wc & 0x00FC00) >> 10));
2640
*to_nxt++ = static_cast<uint8_t>(t >> 8);
2641
*to_nxt++ = static_cast<uint8_t>(t);
2642
t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
2643
*to_nxt++ = static_cast<uint8_t>(t >> 8);
2644
*to_nxt++ = static_cast<uint8_t>(t);
2647
return codecvt_base::ok;
2651
codecvt_base::result
2652
utf16be_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2653
uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2654
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2658
if (mode & consume_header)
2660
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2663
for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2665
uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2666
if ((c1 & 0xFC00) == 0xDC00)
2667
return codecvt_base::error;
2668
if ((c1 & 0xFC00) != 0xD800)
2671
return codecvt_base::error;
2672
*to_nxt = static_cast<uint32_t>(c1);
2677
if (frm_end-frm_nxt < 4)
2678
return codecvt_base::partial;
2679
uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
2680
if ((c2 & 0xFC00) != 0xDC00)
2681
return codecvt_base::error;
2682
uint32_t t = static_cast<uint32_t>(
2683
((((c1 & 0x03C0) >> 6) + 1) << 16)
2684
| ((c1 & 0x003F) << 10)
2687
return codecvt_base::error;
2692
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2697
utf16be_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
2698
size_t mx, unsigned long Maxcode = 0x10FFFF,
2699
codecvt_mode mode = codecvt_mode(0))
2701
const uint8_t* frm_nxt = frm;
2702
if (mode & consume_header)
2704
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2707
for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
2709
uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2710
if ((c1 & 0xFC00) == 0xDC00)
2712
if ((c1 & 0xFC00) != 0xD800)
2720
if (frm_end-frm_nxt < 4)
2722
uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
2723
if ((c2 & 0xFC00) != 0xDC00)
2725
uint32_t t = static_cast<uint32_t>(
2726
((((c1 & 0x03C0) >> 6) + 1) << 16)
2727
| ((c1 & 0x003F) << 10)
2734
return static_cast<int>(frm_nxt - frm);
2738
codecvt_base::result
2739
ucs4_to_utf16le(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
2740
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2741
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2745
if (mode & generate_header)
2747
if (to_end-to_nxt < 2)
2748
return codecvt_base::partial;
2749
*to_nxt++ = static_cast<uint8_t>(0xFF);
2750
*to_nxt++ = static_cast<uint8_t>(0xFE);
2752
for (; frm_nxt < frm_end; ++frm_nxt)
2754
uint32_t wc = *frm_nxt;
2755
if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
2756
return codecvt_base::error;
2759
if (to_end-to_nxt < 2)
2760
return codecvt_base::partial;
2761
*to_nxt++ = static_cast<uint8_t>(wc);
2762
*to_nxt++ = static_cast<uint8_t>(wc >> 8);
2766
if (to_end-to_nxt < 4)
2767
return codecvt_base::partial;
2768
uint16_t t = static_cast<uint16_t>(
2770
| ((((wc & 0x1F0000) >> 16) - 1) << 6)
2771
| ((wc & 0x00FC00) >> 10));
2772
*to_nxt++ = static_cast<uint8_t>(t);
2773
*to_nxt++ = static_cast<uint8_t>(t >> 8);
2774
t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
2775
*to_nxt++ = static_cast<uint8_t>(t);
2776
*to_nxt++ = static_cast<uint8_t>(t >> 8);
2779
return codecvt_base::ok;
2783
codecvt_base::result
2784
utf16le_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2785
uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2786
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2790
if (mode & consume_header)
2792
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
2795
for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2797
uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
2798
if ((c1 & 0xFC00) == 0xDC00)
2799
return codecvt_base::error;
2800
if ((c1 & 0xFC00) != 0xD800)
2803
return codecvt_base::error;
2804
*to_nxt = static_cast<uint32_t>(c1);
2809
if (frm_end-frm_nxt < 4)
2810
return codecvt_base::partial;
2811
uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
2812
if ((c2 & 0xFC00) != 0xDC00)
2813
return codecvt_base::error;
2814
uint32_t t = static_cast<uint32_t>(
2815
((((c1 & 0x03C0) >> 6) + 1) << 16)
2816
| ((c1 & 0x003F) << 10)
2819
return codecvt_base::error;
2824
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2829
utf16le_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
2830
size_t mx, unsigned long Maxcode = 0x10FFFF,
2831
codecvt_mode mode = codecvt_mode(0))
2833
const uint8_t* frm_nxt = frm;
2834
if (mode & consume_header)
2836
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
2839
for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
2841
uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
2842
if ((c1 & 0xFC00) == 0xDC00)
2844
if ((c1 & 0xFC00) != 0xD800)
2852
if (frm_end-frm_nxt < 4)
2854
uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
2855
if ((c2 & 0xFC00) != 0xDC00)
2857
uint32_t t = static_cast<uint32_t>(
2858
((((c1 & 0x03C0) >> 6) + 1) << 16)
2859
| ((c1 & 0x003F) << 10)
2866
return static_cast<int>(frm_nxt - frm);
2870
codecvt_base::result
2871
ucs2_to_utf16be(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
2872
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2873
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2877
if (mode & generate_header)
2879
if (to_end-to_nxt < 2)
2880
return codecvt_base::partial;
2881
*to_nxt++ = static_cast<uint8_t>(0xFE);
2882
*to_nxt++ = static_cast<uint8_t>(0xFF);
2884
for (; frm_nxt < frm_end; ++frm_nxt)
2886
uint16_t wc = *frm_nxt;
2887
if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
2888
return codecvt_base::error;
2889
if (to_end-to_nxt < 2)
2890
return codecvt_base::partial;
2891
*to_nxt++ = static_cast<uint8_t>(wc >> 8);
2892
*to_nxt++ = static_cast<uint8_t>(wc);
2894
return codecvt_base::ok;
2898
codecvt_base::result
2899
utf16be_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2900
uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
2901
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2905
if (mode & consume_header)
2907
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2910
for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2912
uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2913
if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
2914
return codecvt_base::error;
2918
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2923
utf16be_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
2924
size_t mx, unsigned long Maxcode = 0x10FFFF,
2925
codecvt_mode mode = codecvt_mode(0))
2927
const uint8_t* frm_nxt = frm;
2928
if (mode & consume_header)
2930
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2933
for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
2935
uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2936
if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
2940
return static_cast<int>(frm_nxt - frm);
2944
codecvt_base::result
2945
ucs2_to_utf16le(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
2946
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2947
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2951
if (mode & generate_header)
2953
if (to_end-to_nxt < 2)
2954
return codecvt_base::partial;
2955
*to_nxt++ = static_cast<uint8_t>(0xFF);
2956
*to_nxt++ = static_cast<uint8_t>(0xFE);
2958
for (; frm_nxt < frm_end; ++frm_nxt)
2960
uint16_t wc = *frm_nxt;
2961
if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
2962
return codecvt_base::error;
2963
if (to_end-to_nxt < 2)
2964
return codecvt_base::partial;
2965
*to_nxt++ = static_cast<uint8_t>(wc);
2966
*to_nxt++ = static_cast<uint8_t>(wc >> 8);
2968
return codecvt_base::ok;
2972
codecvt_base::result
2973
utf16le_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2974
uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
2975
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2979
if (mode & consume_header)
2981
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
2984
for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2986
uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
2987
if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
2988
return codecvt_base::error;
2992
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2997
utf16le_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
2998
size_t mx, unsigned long Maxcode = 0x10FFFF,
2999
codecvt_mode mode = codecvt_mode(0))
3001
const uint8_t* frm_nxt = frm;
3003
if (mode & consume_header)
3005
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
3008
for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
3010
uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
3011
if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
3015
return static_cast<int>(frm_nxt - frm);
3018
// template <> class codecvt<char16_t, char, mbstate_t>
3020
locale::id codecvt<char16_t, char, mbstate_t>::id;
3022
codecvt<char16_t, char, mbstate_t>::~codecvt()
3026
codecvt<char16_t, char, mbstate_t>::result
3027
codecvt<char16_t, char, mbstate_t>::do_out(state_type&,
3028
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3029
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3031
const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3032
const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3033
const uint16_t* _frm_nxt = _frm;
3034
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3035
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3036
uint8_t* _to_nxt = _to;
3037
result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3038
frm_nxt = frm + (_frm_nxt - _frm);
3039
to_nxt = to + (_to_nxt - _to);
3043
codecvt<char16_t, char, mbstate_t>::result
3044
codecvt<char16_t, char, mbstate_t>::do_in(state_type&,
3045
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3046
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3048
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3049
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3050
const uint8_t* _frm_nxt = _frm;
3051
uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3052
uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3053
uint16_t* _to_nxt = _to;
3054
result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3055
frm_nxt = frm + (_frm_nxt - _frm);
3056
to_nxt = to + (_to_nxt - _to);
3060
codecvt<char16_t, char, mbstate_t>::result
3061
codecvt<char16_t, char, mbstate_t>::do_unshift(state_type&,
3062
extern_type* to, extern_type*, extern_type*& to_nxt) const
3069
codecvt<char16_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
3075
codecvt<char16_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
3081
codecvt<char16_t, char, mbstate_t>::do_length(state_type&,
3082
const extern_type* frm, const extern_type* frm_end, size_t mx) const
3084
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3085
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3086
return utf8_to_utf16_length(_frm, _frm_end, mx);
3090
codecvt<char16_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
3095
// template <> class codecvt<char32_t, char, mbstate_t>
3097
locale::id codecvt<char32_t, char, mbstate_t>::id;
3099
codecvt<char32_t, char, mbstate_t>::~codecvt()
3103
codecvt<char32_t, char, mbstate_t>::result
3104
codecvt<char32_t, char, mbstate_t>::do_out(state_type&,
3105
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3106
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3108
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3109
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3110
const uint32_t* _frm_nxt = _frm;
3111
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3112
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3113
uint8_t* _to_nxt = _to;
3114
result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3115
frm_nxt = frm + (_frm_nxt - _frm);
3116
to_nxt = to + (_to_nxt - _to);
3120
codecvt<char32_t, char, mbstate_t>::result
3121
codecvt<char32_t, char, mbstate_t>::do_in(state_type&,
3122
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3123
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3125
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3126
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3127
const uint8_t* _frm_nxt = _frm;
3128
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3129
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3130
uint32_t* _to_nxt = _to;
3131
result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3132
frm_nxt = frm + (_frm_nxt - _frm);
3133
to_nxt = to + (_to_nxt - _to);
3137
codecvt<char32_t, char, mbstate_t>::result
3138
codecvt<char32_t, char, mbstate_t>::do_unshift(state_type&,
3139
extern_type* to, extern_type*, extern_type*& to_nxt) const
3146
codecvt<char32_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
3152
codecvt<char32_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
3158
codecvt<char32_t, char, mbstate_t>::do_length(state_type&,
3159
const extern_type* frm, const extern_type* frm_end, size_t mx) const
3161
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3162
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3163
return utf8_to_ucs4_length(_frm, _frm_end, mx);
3167
codecvt<char32_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
3172
// __codecvt_utf8<wchar_t>
3174
__codecvt_utf8<wchar_t>::result
3175
__codecvt_utf8<wchar_t>::do_out(state_type&,
3176
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3177
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3179
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3180
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3181
const uint32_t* _frm_nxt = _frm;
3182
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3183
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3184
uint8_t* _to_nxt = _to;
3185
result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3187
frm_nxt = frm + (_frm_nxt - _frm);
3188
to_nxt = to + (_to_nxt - _to);
3192
__codecvt_utf8<wchar_t>::result
3193
__codecvt_utf8<wchar_t>::do_in(state_type&,
3194
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3195
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3197
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3198
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3199
const uint8_t* _frm_nxt = _frm;
3200
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3201
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3202
uint32_t* _to_nxt = _to;
3203
result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3205
frm_nxt = frm + (_frm_nxt - _frm);
3206
to_nxt = to + (_to_nxt - _to);
3210
__codecvt_utf8<wchar_t>::result
3211
__codecvt_utf8<wchar_t>::do_unshift(state_type&,
3212
extern_type* to, extern_type*, extern_type*& to_nxt) const
3219
__codecvt_utf8<wchar_t>::do_encoding() const _NOEXCEPT
3225
__codecvt_utf8<wchar_t>::do_always_noconv() const _NOEXCEPT
3231
__codecvt_utf8<wchar_t>::do_length(state_type&,
3232
const extern_type* frm, const extern_type* frm_end, size_t mx) const
3234
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3235
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3236
return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3240
__codecvt_utf8<wchar_t>::do_max_length() const _NOEXCEPT
3242
if (_Mode_ & consume_header)
3247
// __codecvt_utf8<char16_t>
3249
__codecvt_utf8<char16_t>::result
3250
__codecvt_utf8<char16_t>::do_out(state_type&,
3251
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3252
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3254
const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3255
const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3256
const uint16_t* _frm_nxt = _frm;
3257
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3258
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3259
uint8_t* _to_nxt = _to;
3260
result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3262
frm_nxt = frm + (_frm_nxt - _frm);
3263
to_nxt = to + (_to_nxt - _to);
3267
__codecvt_utf8<char16_t>::result
3268
__codecvt_utf8<char16_t>::do_in(state_type&,
3269
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3270
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3272
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3273
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3274
const uint8_t* _frm_nxt = _frm;
3275
uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3276
uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3277
uint16_t* _to_nxt = _to;
3278
result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3280
frm_nxt = frm + (_frm_nxt - _frm);
3281
to_nxt = to + (_to_nxt - _to);
3285
__codecvt_utf8<char16_t>::result
3286
__codecvt_utf8<char16_t>::do_unshift(state_type&,
3287
extern_type* to, extern_type*, extern_type*& to_nxt) const
3294
__codecvt_utf8<char16_t>::do_encoding() const _NOEXCEPT
3300
__codecvt_utf8<char16_t>::do_always_noconv() const _NOEXCEPT
3306
__codecvt_utf8<char16_t>::do_length(state_type&,
3307
const extern_type* frm, const extern_type* frm_end, size_t mx) const
3309
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3310
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3311
return utf8_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3315
__codecvt_utf8<char16_t>::do_max_length() const _NOEXCEPT
3317
if (_Mode_ & consume_header)
3322
// __codecvt_utf8<char32_t>
3324
__codecvt_utf8<char32_t>::result
3325
__codecvt_utf8<char32_t>::do_out(state_type&,
3326
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3327
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3329
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3330
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3331
const uint32_t* _frm_nxt = _frm;
3332
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3333
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3334
uint8_t* _to_nxt = _to;
3335
result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3337
frm_nxt = frm + (_frm_nxt - _frm);
3338
to_nxt = to + (_to_nxt - _to);
3342
__codecvt_utf8<char32_t>::result
3343
__codecvt_utf8<char32_t>::do_in(state_type&,
3344
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3345
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3347
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3348
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3349
const uint8_t* _frm_nxt = _frm;
3350
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3351
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3352
uint32_t* _to_nxt = _to;
3353
result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3355
frm_nxt = frm + (_frm_nxt - _frm);
3356
to_nxt = to + (_to_nxt - _to);
3360
__codecvt_utf8<char32_t>::result
3361
__codecvt_utf8<char32_t>::do_unshift(state_type&,
3362
extern_type* to, extern_type*, extern_type*& to_nxt) const
3369
__codecvt_utf8<char32_t>::do_encoding() const _NOEXCEPT
3375
__codecvt_utf8<char32_t>::do_always_noconv() const _NOEXCEPT
3381
__codecvt_utf8<char32_t>::do_length(state_type&,
3382
const extern_type* frm, const extern_type* frm_end, size_t mx) const
3384
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3385
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3386
return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3390
__codecvt_utf8<char32_t>::do_max_length() const _NOEXCEPT
3392
if (_Mode_ & consume_header)
3397
// __codecvt_utf16<wchar_t, false>
3399
__codecvt_utf16<wchar_t, false>::result
3400
__codecvt_utf16<wchar_t, false>::do_out(state_type&,
3401
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3402
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3404
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3405
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3406
const uint32_t* _frm_nxt = _frm;
3407
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3408
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3409
uint8_t* _to_nxt = _to;
3410
result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3412
frm_nxt = frm + (_frm_nxt - _frm);
3413
to_nxt = to + (_to_nxt - _to);
3417
__codecvt_utf16<wchar_t, false>::result
3418
__codecvt_utf16<wchar_t, false>::do_in(state_type&,
3419
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3420
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3422
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3423
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3424
const uint8_t* _frm_nxt = _frm;
3425
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3426
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3427
uint32_t* _to_nxt = _to;
3428
result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3430
frm_nxt = frm + (_frm_nxt - _frm);
3431
to_nxt = to + (_to_nxt - _to);
3435
__codecvt_utf16<wchar_t, false>::result
3436
__codecvt_utf16<wchar_t, false>::do_unshift(state_type&,
3437
extern_type* to, extern_type*, extern_type*& to_nxt) const
3444
__codecvt_utf16<wchar_t, false>::do_encoding() const _NOEXCEPT
3450
__codecvt_utf16<wchar_t, false>::do_always_noconv() const _NOEXCEPT
3456
__codecvt_utf16<wchar_t, false>::do_length(state_type&,
3457
const extern_type* frm, const extern_type* frm_end, size_t mx) const
3459
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3460
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3461
return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3465
__codecvt_utf16<wchar_t, false>::do_max_length() const _NOEXCEPT
3467
if (_Mode_ & consume_header)
3472
// __codecvt_utf16<wchar_t, true>
3474
__codecvt_utf16<wchar_t, true>::result
3475
__codecvt_utf16<wchar_t, true>::do_out(state_type&,
3476
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3477
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3479
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3480
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3481
const uint32_t* _frm_nxt = _frm;
3482
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3483
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3484
uint8_t* _to_nxt = _to;
3485
result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3487
frm_nxt = frm + (_frm_nxt - _frm);
3488
to_nxt = to + (_to_nxt - _to);
3492
__codecvt_utf16<wchar_t, true>::result
3493
__codecvt_utf16<wchar_t, true>::do_in(state_type&,
3494
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3495
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3497
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3498
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3499
const uint8_t* _frm_nxt = _frm;
3500
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3501
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3502
uint32_t* _to_nxt = _to;
3503
result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3505
frm_nxt = frm + (_frm_nxt - _frm);
3506
to_nxt = to + (_to_nxt - _to);
3510
__codecvt_utf16<wchar_t, true>::result
3511
__codecvt_utf16<wchar_t, true>::do_unshift(state_type&,
3512
extern_type* to, extern_type*, extern_type*& to_nxt) const
3519
__codecvt_utf16<wchar_t, true>::do_encoding() const _NOEXCEPT
3525
__codecvt_utf16<wchar_t, true>::do_always_noconv() const _NOEXCEPT
3531
__codecvt_utf16<wchar_t, true>::do_length(state_type&,
3532
const extern_type* frm, const extern_type* frm_end, size_t mx) const
3534
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3535
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3536
return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3540
__codecvt_utf16<wchar_t, true>::do_max_length() const _NOEXCEPT
3542
if (_Mode_ & consume_header)
3547
// __codecvt_utf16<char16_t, false>
3549
__codecvt_utf16<char16_t, false>::result
3550
__codecvt_utf16<char16_t, false>::do_out(state_type&,
3551
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3552
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3554
const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3555
const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3556
const uint16_t* _frm_nxt = _frm;
3557
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3558
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3559
uint8_t* _to_nxt = _to;
3560
result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3562
frm_nxt = frm + (_frm_nxt - _frm);
3563
to_nxt = to + (_to_nxt - _to);
3567
__codecvt_utf16<char16_t, false>::result
3568
__codecvt_utf16<char16_t, false>::do_in(state_type&,
3569
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3570
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3572
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3573
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3574
const uint8_t* _frm_nxt = _frm;
3575
uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3576
uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3577
uint16_t* _to_nxt = _to;
3578
result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3580
frm_nxt = frm + (_frm_nxt - _frm);
3581
to_nxt = to + (_to_nxt - _to);
3585
__codecvt_utf16<char16_t, false>::result
3586
__codecvt_utf16<char16_t, false>::do_unshift(state_type&,
3587
extern_type* to, extern_type*, extern_type*& to_nxt) const
3594
__codecvt_utf16<char16_t, false>::do_encoding() const _NOEXCEPT
3600
__codecvt_utf16<char16_t, false>::do_always_noconv() const _NOEXCEPT
3606
__codecvt_utf16<char16_t, false>::do_length(state_type&,
3607
const extern_type* frm, const extern_type* frm_end, size_t mx) const
3609
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3610
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3611
return utf16be_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3615
__codecvt_utf16<char16_t, false>::do_max_length() const _NOEXCEPT
3617
if (_Mode_ & consume_header)
3622
// __codecvt_utf16<char16_t, true>
3624
__codecvt_utf16<char16_t, true>::result
3625
__codecvt_utf16<char16_t, true>::do_out(state_type&,
3626
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3627
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3629
const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3630
const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3631
const uint16_t* _frm_nxt = _frm;
3632
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3633
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3634
uint8_t* _to_nxt = _to;
3635
result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3637
frm_nxt = frm + (_frm_nxt - _frm);
3638
to_nxt = to + (_to_nxt - _to);
3642
__codecvt_utf16<char16_t, true>::result
3643
__codecvt_utf16<char16_t, true>::do_in(state_type&,
3644
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3645
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3647
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3648
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3649
const uint8_t* _frm_nxt = _frm;
3650
uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3651
uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3652
uint16_t* _to_nxt = _to;
3653
result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3655
frm_nxt = frm + (_frm_nxt - _frm);
3656
to_nxt = to + (_to_nxt - _to);
3660
__codecvt_utf16<char16_t, true>::result
3661
__codecvt_utf16<char16_t, true>::do_unshift(state_type&,
3662
extern_type* to, extern_type*, extern_type*& to_nxt) const
3669
__codecvt_utf16<char16_t, true>::do_encoding() const _NOEXCEPT
3675
__codecvt_utf16<char16_t, true>::do_always_noconv() const _NOEXCEPT
3681
__codecvt_utf16<char16_t, true>::do_length(state_type&,
3682
const extern_type* frm, const extern_type* frm_end, size_t mx) const
3684
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3685
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3686
return utf16le_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3690
__codecvt_utf16<char16_t, true>::do_max_length() const _NOEXCEPT
3692
if (_Mode_ & consume_header)
3697
// __codecvt_utf16<char32_t, false>
3699
__codecvt_utf16<char32_t, false>::result
3700
__codecvt_utf16<char32_t, false>::do_out(state_type&,
3701
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3702
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3704
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3705
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3706
const uint32_t* _frm_nxt = _frm;
3707
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3708
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3709
uint8_t* _to_nxt = _to;
3710
result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3712
frm_nxt = frm + (_frm_nxt - _frm);
3713
to_nxt = to + (_to_nxt - _to);
3717
__codecvt_utf16<char32_t, false>::result
3718
__codecvt_utf16<char32_t, false>::do_in(state_type&,
3719
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3720
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3722
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3723
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3724
const uint8_t* _frm_nxt = _frm;
3725
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3726
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3727
uint32_t* _to_nxt = _to;
3728
result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3730
frm_nxt = frm + (_frm_nxt - _frm);
3731
to_nxt = to + (_to_nxt - _to);
3735
__codecvt_utf16<char32_t, false>::result
3736
__codecvt_utf16<char32_t, false>::do_unshift(state_type&,
3737
extern_type* to, extern_type*, extern_type*& to_nxt) const
3744
__codecvt_utf16<char32_t, false>::do_encoding() const _NOEXCEPT
3750
__codecvt_utf16<char32_t, false>::do_always_noconv() const _NOEXCEPT
3756
__codecvt_utf16<char32_t, false>::do_length(state_type&,
3757
const extern_type* frm, const extern_type* frm_end, size_t mx) const
3759
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3760
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3761
return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3765
__codecvt_utf16<char32_t, false>::do_max_length() const _NOEXCEPT
3767
if (_Mode_ & consume_header)
3772
// __codecvt_utf16<char32_t, true>
3774
__codecvt_utf16<char32_t, true>::result
3775
__codecvt_utf16<char32_t, true>::do_out(state_type&,
3776
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3777
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3779
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3780
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3781
const uint32_t* _frm_nxt = _frm;
3782
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3783
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3784
uint8_t* _to_nxt = _to;
3785
result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3787
frm_nxt = frm + (_frm_nxt - _frm);
3788
to_nxt = to + (_to_nxt - _to);
3792
__codecvt_utf16<char32_t, true>::result
3793
__codecvt_utf16<char32_t, true>::do_in(state_type&,
3794
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3795
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3797
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3798
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3799
const uint8_t* _frm_nxt = _frm;
3800
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3801
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3802
uint32_t* _to_nxt = _to;
3803
result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3805
frm_nxt = frm + (_frm_nxt - _frm);
3806
to_nxt = to + (_to_nxt - _to);
3810
__codecvt_utf16<char32_t, true>::result
3811
__codecvt_utf16<char32_t, true>::do_unshift(state_type&,
3812
extern_type* to, extern_type*, extern_type*& to_nxt) const
3819
__codecvt_utf16<char32_t, true>::do_encoding() const _NOEXCEPT
3825
__codecvt_utf16<char32_t, true>::do_always_noconv() const _NOEXCEPT
3831
__codecvt_utf16<char32_t, true>::do_length(state_type&,
3832
const extern_type* frm, const extern_type* frm_end, size_t mx) const
3834
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3835
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3836
return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3840
__codecvt_utf16<char32_t, true>::do_max_length() const _NOEXCEPT
3842
if (_Mode_ & consume_header)
3847
// __codecvt_utf8_utf16<wchar_t>
3849
__codecvt_utf8_utf16<wchar_t>::result
3850
__codecvt_utf8_utf16<wchar_t>::do_out(state_type&,
3851
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3852
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3854
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3855
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3856
const uint32_t* _frm_nxt = _frm;
3857
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3858
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3859
uint8_t* _to_nxt = _to;
3860
result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3862
frm_nxt = frm + (_frm_nxt - _frm);
3863
to_nxt = to + (_to_nxt - _to);
3867
__codecvt_utf8_utf16<wchar_t>::result
3868
__codecvt_utf8_utf16<wchar_t>::do_in(state_type&,
3869
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3870
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3872
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3873
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3874
const uint8_t* _frm_nxt = _frm;
3875
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3876
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3877
uint32_t* _to_nxt = _to;
3878
result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3880
frm_nxt = frm + (_frm_nxt - _frm);
3881
to_nxt = to + (_to_nxt - _to);
3885
__codecvt_utf8_utf16<wchar_t>::result
3886
__codecvt_utf8_utf16<wchar_t>::do_unshift(state_type&,
3887
extern_type* to, extern_type*, extern_type*& to_nxt) const
3894
__codecvt_utf8_utf16<wchar_t>::do_encoding() const _NOEXCEPT
3900
__codecvt_utf8_utf16<wchar_t>::do_always_noconv() const _NOEXCEPT
3906
__codecvt_utf8_utf16<wchar_t>::do_length(state_type&,
3907
const extern_type* frm, const extern_type* frm_end, size_t mx) const
3909
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3910
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3911
return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3915
__codecvt_utf8_utf16<wchar_t>::do_max_length() const _NOEXCEPT
3917
if (_Mode_ & consume_header)
3922
// __codecvt_utf8_utf16<char16_t>
3924
__codecvt_utf8_utf16<char16_t>::result
3925
__codecvt_utf8_utf16<char16_t>::do_out(state_type&,
3926
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3927
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3929
const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3930
const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3931
const uint16_t* _frm_nxt = _frm;
3932
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3933
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3934
uint8_t* _to_nxt = _to;
3935
result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3937
frm_nxt = frm + (_frm_nxt - _frm);
3938
to_nxt = to + (_to_nxt - _to);
3942
__codecvt_utf8_utf16<char16_t>::result
3943
__codecvt_utf8_utf16<char16_t>::do_in(state_type&,
3944
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3945
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3947
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3948
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3949
const uint8_t* _frm_nxt = _frm;
3950
uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3951
uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3952
uint16_t* _to_nxt = _to;
3953
result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3955
frm_nxt = frm + (_frm_nxt - _frm);
3956
to_nxt = to + (_to_nxt - _to);
3960
__codecvt_utf8_utf16<char16_t>::result
3961
__codecvt_utf8_utf16<char16_t>::do_unshift(state_type&,
3962
extern_type* to, extern_type*, extern_type*& to_nxt) const
3969
__codecvt_utf8_utf16<char16_t>::do_encoding() const _NOEXCEPT
3975
__codecvt_utf8_utf16<char16_t>::do_always_noconv() const _NOEXCEPT
3981
__codecvt_utf8_utf16<char16_t>::do_length(state_type&,
3982
const extern_type* frm, const extern_type* frm_end, size_t mx) const
3984
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3985
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3986
return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3990
__codecvt_utf8_utf16<char16_t>::do_max_length() const _NOEXCEPT
3992
if (_Mode_ & consume_header)
3997
// __codecvt_utf8_utf16<char32_t>
3999
__codecvt_utf8_utf16<char32_t>::result
4000
__codecvt_utf8_utf16<char32_t>::do_out(state_type&,
4001
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
4002
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
4004
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
4005
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
4006
const uint32_t* _frm_nxt = _frm;
4007
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
4008
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
4009
uint8_t* _to_nxt = _to;
4010
result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4012
frm_nxt = frm + (_frm_nxt - _frm);
4013
to_nxt = to + (_to_nxt - _to);
4017
__codecvt_utf8_utf16<char32_t>::result
4018
__codecvt_utf8_utf16<char32_t>::do_in(state_type&,
4019
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
4020
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
4022
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4023
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4024
const uint8_t* _frm_nxt = _frm;
4025
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
4026
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
4027
uint32_t* _to_nxt = _to;
4028
result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4030
frm_nxt = frm + (_frm_nxt - _frm);
4031
to_nxt = to + (_to_nxt - _to);
4035
__codecvt_utf8_utf16<char32_t>::result
4036
__codecvt_utf8_utf16<char32_t>::do_unshift(state_type&,
4037
extern_type* to, extern_type*, extern_type*& to_nxt) const
4044
__codecvt_utf8_utf16<char32_t>::do_encoding() const _NOEXCEPT
4050
__codecvt_utf8_utf16<char32_t>::do_always_noconv() const _NOEXCEPT
4056
__codecvt_utf8_utf16<char32_t>::do_length(state_type&,
4057
const extern_type* frm, const extern_type* frm_end, size_t mx) const
4059
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4060
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4061
return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
4065
__codecvt_utf8_utf16<char32_t>::do_max_length() const _NOEXCEPT
4067
if (_Mode_ & consume_header)
4072
// __narrow_to_utf8<16>
4074
__narrow_to_utf8<16>::~__narrow_to_utf8()
4078
// __narrow_to_utf8<32>
4080
__narrow_to_utf8<32>::~__narrow_to_utf8()
4084
// __widen_from_utf8<16>
4086
__widen_from_utf8<16>::~__widen_from_utf8()
4090
// __widen_from_utf8<32>
4092
__widen_from_utf8<32>::~__widen_from_utf8()
4096
// numpunct<char> && numpunct<wchar_t>
4098
locale::id numpunct< char >::id;
4099
locale::id numpunct<wchar_t>::id;
4101
numpunct<char>::numpunct(size_t refs)
4102
: locale::facet(refs),
4103
__decimal_point_('.'),
4104
__thousands_sep_(',')
4108
numpunct<wchar_t>::numpunct(size_t refs)
4109
: locale::facet(refs),
4110
__decimal_point_(L'.'),
4111
__thousands_sep_(L',')
4115
numpunct<char>::~numpunct()
4119
numpunct<wchar_t>::~numpunct()
4123
char numpunct< char >::do_decimal_point() const {return __decimal_point_;}
4124
wchar_t numpunct<wchar_t>::do_decimal_point() const {return __decimal_point_;}
4126
char numpunct< char >::do_thousands_sep() const {return __thousands_sep_;}
4127
wchar_t numpunct<wchar_t>::do_thousands_sep() const {return __thousands_sep_;}
4129
string numpunct< char >::do_grouping() const {return __grouping_;}
4130
string numpunct<wchar_t>::do_grouping() const {return __grouping_;}
4132
string numpunct< char >::do_truename() const {return "true";}
4133
wstring numpunct<wchar_t>::do_truename() const {return L"true";}
4135
string numpunct< char >::do_falsename() const {return "false";}
4136
wstring numpunct<wchar_t>::do_falsename() const {return L"false";}
4138
// numpunct_byname<char>
4140
numpunct_byname<char>::numpunct_byname(const char* nm, size_t refs)
4141
: numpunct<char>(refs)
4146
numpunct_byname<char>::numpunct_byname(const string& nm, size_t refs)
4147
: numpunct<char>(refs)
4152
numpunct_byname<char>::~numpunct_byname()
4157
numpunct_byname<char>::__init(const char* nm)
4159
if (strcmp(nm, "C") != 0)
4161
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
4162
#ifndef _LIBCPP_NO_EXCEPTIONS
4164
throw runtime_error("numpunct_byname<char>::numpunct_byname"
4165
" failed to construct for " + string(nm));
4166
#endif // _LIBCPP_NO_EXCEPTIONS
4167
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4168
lconv* lc = localeconv_l(loc.get());
4170
lconv* lc = __localeconv_l(loc.get());
4172
if (*lc->decimal_point)
4173
__decimal_point_ = *lc->decimal_point;
4174
if (*lc->thousands_sep)
4175
__thousands_sep_ = *lc->thousands_sep;
4176
__grouping_ = lc->grouping;
4177
// localization for truename and falsename is not available
4181
// numpunct_byname<wchar_t>
4183
numpunct_byname<wchar_t>::numpunct_byname(const char* nm, size_t refs)
4184
: numpunct<wchar_t>(refs)
4189
numpunct_byname<wchar_t>::numpunct_byname(const string& nm, size_t refs)
4190
: numpunct<wchar_t>(refs)
4195
numpunct_byname<wchar_t>::~numpunct_byname()
4200
numpunct_byname<wchar_t>::__init(const char* nm)
4202
if (strcmp(nm, "C") != 0)
4204
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
4205
#ifndef _LIBCPP_NO_EXCEPTIONS
4207
throw runtime_error("numpunct_byname<char>::numpunct_byname"
4208
" failed to construct for " + string(nm));
4209
#endif // _LIBCPP_NO_EXCEPTIONS
4210
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4211
lconv* lc = localeconv_l(loc.get());
4213
lconv* lc = __localeconv_l(loc.get());
4215
if (*lc->decimal_point)
4216
__decimal_point_ = *lc->decimal_point;
4217
if (*lc->thousands_sep)
4218
__thousands_sep_ = *lc->thousands_sep;
4219
__grouping_ = lc->grouping;
4220
// locallization for truename and falsename is not available
4227
__num_get_base::__get_base(ios_base& iob)
4229
ios_base::fmtflags __basefield = iob.flags() & ios_base::basefield;
4230
if (__basefield == ios_base::oct)
4232
else if (__basefield == ios_base::hex)
4234
else if (__basefield == 0)
4239
const char __num_get_base::__src[33] = "0123456789abcdefABCDEFxX+-pPiInN";
4242
__check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end,
4243
ios_base::iostate& __err)
4245
if (__grouping.size() != 0)
4247
reverse(__g, __g_end);
4248
const char* __ig = __grouping.data();
4249
const char* __eg = __ig + __grouping.size();
4250
for (unsigned* __r = __g; __r < __g_end-1; ++__r)
4252
if (0 < *__ig && *__ig < numeric_limits<char>::max())
4254
if (static_cast<unsigned>(*__ig) != *__r)
4256
__err = ios_base::failbit;
4260
if (__eg - __ig > 1)
4263
if (0 < *__ig && *__ig < numeric_limits<char>::max())
4265
if (static_cast<unsigned>(*__ig) < __g_end[-1] || __g_end[-1] == 0)
4266
__err = ios_base::failbit;
4272
__num_put_base::__format_int(char* __fmtp, const char* __len, bool __signd,
4273
ios_base::fmtflags __flags)
4275
if (__flags & ios_base::showpos)
4277
if (__flags & ios_base::showbase)
4280
*__fmtp++ = *__len++;
4281
if ((__flags & ios_base::basefield) == ios_base::oct)
4283
else if ((__flags & ios_base::basefield) == ios_base::hex)
4285
if (__flags & ios_base::uppercase)
4297
__num_put_base::__format_float(char* __fmtp, const char* __len,
4298
ios_base::fmtflags __flags)
4300
bool specify_precision = true;
4301
if (__flags & ios_base::showpos)
4303
if (__flags & ios_base::showpoint)
4305
ios_base::fmtflags floatfield = __flags & ios_base::floatfield;
4306
bool uppercase = __flags & ios_base::uppercase;
4307
if (floatfield == (ios_base::fixed | ios_base::scientific))
4308
specify_precision = false;
4315
*__fmtp++ = *__len++;
4316
if (floatfield == ios_base::fixed)
4323
else if (floatfield == ios_base::scientific)
4330
else if (floatfield == (ios_base::fixed | ios_base::scientific))
4344
return specify_precision;
4348
__num_put_base::__identify_padding(char* __nb, char* __ne,
4349
const ios_base& __iob)
4351
switch (__iob.flags() & ios_base::adjustfield)
4353
case ios_base::internal:
4354
if (__nb[0] == '-' || __nb[0] == '+')
4356
if (__ne - __nb >= 2 && __nb[0] == '0'
4357
&& (__nb[1] == 'x' || __nb[1] == 'X'))
4360
case ios_base::left:
4362
case ios_base::right:
4375
static string weeks[14];
4376
weeks[0] = "Sunday";
4377
weeks[1] = "Monday";
4378
weeks[2] = "Tuesday";
4379
weeks[3] = "Wednesday";
4380
weeks[4] = "Thursday";
4381
weeks[5] = "Friday";
4382
weeks[6] = "Saturday";
4397
static wstring weeks[14];
4398
weeks[0] = L"Sunday";
4399
weeks[1] = L"Monday";
4400
weeks[2] = L"Tuesday";
4401
weeks[3] = L"Wednesday";
4402
weeks[4] = L"Thursday";
4403
weeks[5] = L"Friday";
4404
weeks[6] = L"Saturday";
4417
__time_get_c_storage<char>::__weeks() const
4419
static const string* weeks = init_weeks();
4425
__time_get_c_storage<wchar_t>::__weeks() const
4427
static const wstring* weeks = init_wweeks();
4435
static string months[24];
4436
months[0] = "January";
4437
months[1] = "February";
4438
months[2] = "March";
4439
months[3] = "April";
4443
months[7] = "August";
4444
months[8] = "September";
4445
months[9] = "October";
4446
months[10] = "November";
4447
months[11] = "December";
4467
static wstring months[24];
4468
months[0] = L"January";
4469
months[1] = L"February";
4470
months[2] = L"March";
4471
months[3] = L"April";
4473
months[5] = L"June";
4474
months[6] = L"July";
4475
months[7] = L"August";
4476
months[8] = L"September";
4477
months[9] = L"October";
4478
months[10] = L"November";
4479
months[11] = L"December";
4480
months[12] = L"Jan";
4481
months[13] = L"Feb";
4482
months[14] = L"Mar";
4483
months[15] = L"Apr";
4484
months[16] = L"May";
4485
months[17] = L"Jun";
4486
months[18] = L"Jul";
4487
months[19] = L"Aug";
4488
months[20] = L"Sep";
4489
months[21] = L"Oct";
4490
months[22] = L"Nov";
4491
months[23] = L"Dec";
4497
__time_get_c_storage<char>::__months() const
4499
static const string* months = init_months();
4505
__time_get_c_storage<wchar_t>::__months() const
4507
static const wstring* months = init_wmonths();
4515
static string am_pm[24];
4525
static wstring am_pm[24];
4533
__time_get_c_storage<char>::__am_pm() const
4535
static const string* am_pm = init_am_pm();
4541
__time_get_c_storage<wchar_t>::__am_pm() const
4543
static const wstring* am_pm = init_wam_pm();
4549
__time_get_c_storage<char>::__x() const
4551
static string s("%m/%d/%y");
4557
__time_get_c_storage<wchar_t>::__x() const
4559
static wstring s(L"%m/%d/%y");
4565
__time_get_c_storage<char>::__X() const
4567
static string s("%H:%M:%S");
4573
__time_get_c_storage<wchar_t>::__X() const
4575
static wstring s(L"%H:%M:%S");
4581
__time_get_c_storage<char>::__c() const
4583
static string s("%a %b %d %H:%M:%S %Y");
4589
__time_get_c_storage<wchar_t>::__c() const
4591
static wstring s(L"%a %b %d %H:%M:%S %Y");
4597
__time_get_c_storage<char>::__r() const
4599
static string s("%I:%M:%S %p");
4605
__time_get_c_storage<wchar_t>::__r() const
4607
static wstring s(L"%I:%M:%S %p");
4613
__time_get::__time_get(const char* nm)
4614
: __loc_(newlocale(LC_ALL_MASK, nm, 0))
4616
#ifndef _LIBCPP_NO_EXCEPTIONS
4618
throw runtime_error("time_get_byname"
4619
" failed to construct for " + string(nm));
4620
#endif // _LIBCPP_NO_EXCEPTIONS
4623
__time_get::__time_get(const string& nm)
4624
: __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
4626
#ifndef _LIBCPP_NO_EXCEPTIONS
4628
throw runtime_error("time_get_byname"
4629
" failed to construct for " + nm);
4630
#endif // _LIBCPP_NO_EXCEPTIONS
4633
__time_get::~__time_get()
4638
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
4639
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
4643
__time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
4659
size_t n = strftime_l(buf, countof(buf), f, &t, __loc_);
4665
if (ct.is(ctype_base::space, *bb))
4667
result.push_back(' ');
4668
for (++bb; bb != be && ct.is(ctype_base::space, *bb); ++bb)
4673
ios_base::iostate err = ios_base::goodbit;
4674
ptrdiff_t i = __scan_keyword(w, be, this->__weeks_, this->__weeks_+14,
4679
result.push_back('%');
4681
result.push_back('A');
4683
result.push_back('a');
4688
i = __scan_keyword(w, be, this->__months_, this->__months_+24,
4693
result.push_back('%');
4695
result.push_back('B');
4697
result.push_back('b');
4698
if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
4699
result.back() = 'm';
4703
if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0)
4706
i = __scan_keyword(w, be, this->__am_pm_, this->__am_pm_+2,
4707
ct, err, false) - this->__am_pm_;
4710
result.push_back('%');
4711
result.push_back('p');
4717
if (ct.is(ctype_base::digit, *bb))
4719
switch(__get_up_to_n_digits(bb, be, err, ct, 4))
4722
result.push_back('%');
4723
result.push_back('w');
4726
result.push_back('%');
4727
result.push_back('u');
4730
result.push_back('%');
4731
result.push_back('I');
4734
result.push_back('%');
4735
result.push_back('m');
4738
result.push_back('%');
4739
result.push_back('H');
4742
result.push_back('%');
4743
result.push_back('d');
4746
result.push_back('%');
4747
result.push_back('M');
4750
result.push_back('%');
4751
result.push_back('S');
4754
result.push_back('%');
4755
result.push_back('y');
4758
result.push_back('%');
4759
result.push_back('j');
4762
result.push_back('%');
4763
result.push_back('Y');
4766
for (; w != bb; ++w)
4767
result.push_back(*w);
4774
result.push_back('%');
4775
result.push_back('%');
4779
result.push_back(*bb);
4785
#pragma clang diagnostic ignored "-Wmissing-braces"
4789
__time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
4805
strftime_l(buf, countof(buf), f, &t, __loc_);
4807
wchar_t* wbb = wbuf;
4809
const char* bb = buf;
4810
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4811
size_t j = mbsrtowcs_l( wbb, &bb, countof(wbuf), &mb, __loc_);
4813
size_t j = __mbsrtowcs_l( wbb, &bb, countof(wbuf), &mb, __loc_);
4815
if (j == size_t(-1))
4816
__throw_runtime_error("locale not supported");
4817
wchar_t* wbe = wbb + j;
4821
if (ct.is(ctype_base::space, *wbb))
4823
result.push_back(L' ');
4824
for (++wbb; wbb != wbe && ct.is(ctype_base::space, *wbb); ++wbb)
4829
ios_base::iostate err = ios_base::goodbit;
4830
ptrdiff_t i = __scan_keyword(w, wbe, this->__weeks_, this->__weeks_+14,
4835
result.push_back(L'%');
4837
result.push_back(L'A');
4839
result.push_back(L'a');
4844
i = __scan_keyword(w, wbe, this->__months_, this->__months_+24,
4849
result.push_back(L'%');
4851
result.push_back(L'B');
4853
result.push_back(L'b');
4854
if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
4855
result.back() = L'm';
4859
if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0)
4862
i = __scan_keyword(w, wbe, this->__am_pm_, this->__am_pm_+2,
4863
ct, err, false) - this->__am_pm_;
4866
result.push_back(L'%');
4867
result.push_back(L'p');
4873
if (ct.is(ctype_base::digit, *wbb))
4875
switch(__get_up_to_n_digits(wbb, wbe, err, ct, 4))
4878
result.push_back(L'%');
4879
result.push_back(L'w');
4882
result.push_back(L'%');
4883
result.push_back(L'u');
4886
result.push_back(L'%');
4887
result.push_back(L'I');
4890
result.push_back(L'%');
4891
result.push_back(L'm');
4894
result.push_back(L'%');
4895
result.push_back(L'H');
4898
result.push_back(L'%');
4899
result.push_back(L'd');
4902
result.push_back(L'%');
4903
result.push_back(L'M');
4906
result.push_back(L'%');
4907
result.push_back(L'S');
4910
result.push_back(L'%');
4911
result.push_back(L'y');
4914
result.push_back(L'%');
4915
result.push_back(L'j');
4918
result.push_back(L'%');
4919
result.push_back(L'Y');
4922
for (; w != wbb; ++w)
4923
result.push_back(*w);
4928
if (ct.narrow(*wbb, 0) == '%')
4930
result.push_back(L'%');
4931
result.push_back(L'%');
4935
result.push_back(*wbb);
4943
__time_get_storage<char>::init(const ctype<char>& ct)
4948
for (int i = 0; i < 7; ++i)
4951
strftime_l(buf, countof(buf), "%A", &t, __loc_);
4953
strftime_l(buf, countof(buf), "%a", &t, __loc_);
4954
__weeks_[i+7] = buf;
4957
for (int i = 0; i < 12; ++i)
4960
strftime_l(buf, countof(buf), "%B", &t, __loc_);
4962
strftime_l(buf, countof(buf), "%b", &t, __loc_);
4963
__months_[i+12] = buf;
4967
strftime_l(buf, countof(buf), "%p", &t, __loc_);
4970
strftime_l(buf, countof(buf), "%p", &t, __loc_);
4972
__c_ = __analyze('c', ct);
4973
__r_ = __analyze('r', ct);
4974
__x_ = __analyze('x', ct);
4975
__X_ = __analyze('X', ct);
4980
__time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
4988
for (int i = 0; i < 7; ++i)
4991
strftime_l(buf, countof(buf), "%A", &t, __loc_);
4993
const char* bb = buf;
4994
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4995
size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
4997
size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
4999
if (j == size_t(-1))
5000
__throw_runtime_error("locale not supported");
5002
__weeks_[i].assign(wbuf, wbe);
5003
strftime_l(buf, countof(buf), "%a", &t, __loc_);
5006
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5007
j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5009
j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5011
if (j == size_t(-1))
5012
__throw_runtime_error("locale not supported");
5014
__weeks_[i+7].assign(wbuf, wbe);
5017
for (int i = 0; i < 12; ++i)
5020
strftime_l(buf, countof(buf), "%B", &t, __loc_);
5022
const char* bb = buf;
5023
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5024
size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5026
size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5028
if (j == size_t(-1))
5029
__throw_runtime_error("locale not supported");
5031
__months_[i].assign(wbuf, wbe);
5032
strftime_l(buf, countof(buf), "%b", &t, __loc_);
5035
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5036
j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5038
j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5040
if (j == size_t(-1))
5041
__throw_runtime_error("locale not supported");
5043
__months_[i+12].assign(wbuf, wbe);
5047
strftime_l(buf, countof(buf), "%p", &t, __loc_);
5049
const char* bb = buf;
5050
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5051
size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5053
size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5055
if (j == size_t(-1))
5056
__throw_runtime_error("locale not supported");
5058
__am_pm_[0].assign(wbuf, wbe);
5060
strftime_l(buf, countof(buf), "%p", &t, __loc_);
5063
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5064
j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5066
j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5068
if (j == size_t(-1))
5069
__throw_runtime_error("locale not supported");
5071
__am_pm_[1].assign(wbuf, wbe);
5072
__c_ = __analyze('c', ct);
5073
__r_ = __analyze('r', ct);
5074
__x_ = __analyze('x', ct);
5075
__X_ = __analyze('X', ct);
5078
template <class CharT>
5079
struct _LIBCPP_HIDDEN __time_get_temp
5080
: public ctype_byname<CharT>
5082
explicit __time_get_temp(const char* nm)
5083
: ctype_byname<CharT>(nm, 1) {}
5084
explicit __time_get_temp(const string& nm)
5085
: ctype_byname<CharT>(nm, 1) {}
5089
__time_get_storage<char>::__time_get_storage(const char* __nm)
5092
const __time_get_temp<char> ct(__nm);
5097
__time_get_storage<char>::__time_get_storage(const string& __nm)
5100
const __time_get_temp<char> ct(__nm);
5105
__time_get_storage<wchar_t>::__time_get_storage(const char* __nm)
5108
const __time_get_temp<wchar_t> ct(__nm);
5113
__time_get_storage<wchar_t>::__time_get_storage(const string& __nm)
5116
const __time_get_temp<wchar_t> ct(__nm);
5121
time_base::dateorder
5122
__time_get_storage<char>::__do_date_order() const
5125
for (i = 0; i < __x_.size(); ++i)
5133
for (++i; i < __x_.size(); ++i)
5136
if (i == __x_.size())
5142
for (++i; i < __x_.size(); ++i)
5145
if (i == __x_.size())
5149
return time_base::ymd;
5152
for (++i; i < __x_.size(); ++i)
5155
if (i == __x_.size())
5159
return time_base::ydm;
5164
for (++i; i < __x_.size(); ++i)
5167
if (i == __x_.size())
5172
for (++i; i < __x_.size(); ++i)
5175
if (i == __x_.size())
5178
if (__x_[i] == 'y' || __x_[i] == 'Y')
5179
return time_base::mdy;
5184
for (++i; i < __x_.size(); ++i)
5187
if (i == __x_.size())
5192
for (++i; i < __x_.size(); ++i)
5195
if (i == __x_.size())
5198
if (__x_[i] == 'y' || __x_[i] == 'Y')
5199
return time_base::dmy;
5204
return time_base::no_order;
5208
time_base::dateorder
5209
__time_get_storage<wchar_t>::__do_date_order() const
5212
for (i = 0; i < __x_.size(); ++i)
5213
if (__x_[i] == L'%')
5220
for (++i; i < __x_.size(); ++i)
5221
if (__x_[i] == L'%')
5223
if (i == __x_.size())
5229
for (++i; i < __x_.size(); ++i)
5230
if (__x_[i] == L'%')
5232
if (i == __x_.size())
5235
if (__x_[i] == L'd')
5236
return time_base::ymd;
5239
for (++i; i < __x_.size(); ++i)
5240
if (__x_[i] == L'%')
5242
if (i == __x_.size())
5245
if (__x_[i] == L'm')
5246
return time_base::ydm;
5251
for (++i; i < __x_.size(); ++i)
5252
if (__x_[i] == L'%')
5254
if (i == __x_.size())
5257
if (__x_[i] == L'd')
5259
for (++i; i < __x_.size(); ++i)
5260
if (__x_[i] == L'%')
5262
if (i == __x_.size())
5265
if (__x_[i] == L'y' || __x_[i] == L'Y')
5266
return time_base::mdy;
5271
for (++i; i < __x_.size(); ++i)
5272
if (__x_[i] == L'%')
5274
if (i == __x_.size())
5277
if (__x_[i] == L'm')
5279
for (++i; i < __x_.size(); ++i)
5280
if (__x_[i] == L'%')
5282
if (i == __x_.size())
5285
if (__x_[i] == L'y' || __x_[i] == L'Y')
5286
return time_base::dmy;
5291
return time_base::no_order;
5296
__time_put::__time_put(const char* nm)
5297
: __loc_(newlocale(LC_ALL_MASK, nm, 0))
5299
#ifndef _LIBCPP_NO_EXCEPTIONS
5301
throw runtime_error("time_put_byname"
5302
" failed to construct for " + string(nm));
5303
#endif // _LIBCPP_NO_EXCEPTIONS
5306
__time_put::__time_put(const string& nm)
5307
: __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
5309
#ifndef _LIBCPP_NO_EXCEPTIONS
5311
throw runtime_error("time_put_byname"
5312
" failed to construct for " + nm);
5313
#endif // _LIBCPP_NO_EXCEPTIONS
5316
__time_put::~__time_put()
5323
__time_put::__do_put(char* __nb, char*& __ne, const tm* __tm,
5324
char __fmt, char __mod) const
5326
char fmt[] = {'%', __fmt, __mod, 0};
5328
swap(fmt[1], fmt[2]);
5329
size_t n = strftime_l(__nb, countof(__nb, __ne), fmt, __tm, __loc_);
5334
__time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
5335
char __fmt, char __mod) const
5338
char* __ne = __nar + 100;
5339
__do_put(__nar, __ne, __tm, __fmt, __mod);
5341
const char* __nb = __nar;
5342
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5343
size_t j = mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_);
5345
size_t j = __mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_);
5347
if (j == size_t(-1))
5348
__throw_runtime_error("locale not supported");
5352
// moneypunct_byname
5354
template <class charT>
5357
__init_pat(money_base::pattern& pat, basic_string<charT>& __curr_symbol_,
5358
bool intl, char cs_precedes, char sep_by_space, char sign_posn,
5361
const char sign = static_cast<char>(money_base::sign);
5362
const char space = static_cast<char>(money_base::space);
5363
const char none = static_cast<char>(money_base::none);
5364
const char symbol = static_cast<char>(money_base::symbol);
5365
const char value = static_cast<char>(money_base::value);
5366
const bool symbol_contains_sep = intl && __curr_symbol_.size() == 4;
5368
// Comments on case branches reflect 'C11 7.11.2.1 The localeconv
5369
// function'. "Space between sign and symbol or value" means that
5370
// if the sign is adjacent to the symbol, there's a space between
5371
// them, and otherwise there's a space between the sign and value.
5373
// C11's localeconv specifies that the fourth character of an
5374
// international curr_symbol is used to separate the sign and
5375
// value when sep_by_space says to do so. C++ can't represent
5376
// that, so we just use a space. When sep_by_space says to
5377
// separate the symbol and value-or-sign with a space, we rearrange the
5378
// curr_symbol to put its spacing character on the correct side of
5381
// We also need to avoid adding an extra space between the sign
5382
// and value when the currency symbol is suppressed (by not
5383
// setting showbase). We match glibc's strfmon by interpreting
5384
// sep_by_space==1 as "omit the space when the currency symbol is
5387
// Users who want to get this right should use ICU instead.
5389
switch (cs_precedes)
5391
case 0: // value before curr_symbol
5392
if (symbol_contains_sep) {
5393
// Move the separator to before the symbol, to place it
5394
// between the value and symbol.
5395
rotate(__curr_symbol_.begin(), __curr_symbol_.begin() + 3,
5396
__curr_symbol_.end());
5400
case 0: // Parentheses surround the quantity and currency symbol.
5401
pat.field[0] = sign;
5402
pat.field[1] = value;
5403
pat.field[2] = none; // Any space appears in the symbol.
5404
pat.field[3] = symbol;
5405
switch (sep_by_space)
5407
case 0: // No space separates the currency symbol and value.
5408
// This case may have changed between C99 and C11;
5409
// assume the currency symbol matches the intention.
5410
case 2: // Space between sign and currency or value.
5411
// The "sign" is two parentheses, so no space here either.
5413
case 1: // Space between currency-and-sign or currency and value.
5414
if (!symbol_contains_sep) {
5415
// We insert the space into the symbol instead of
5416
// setting pat.field[2]=space so that when
5417
// showbase is not set, the space goes away too.
5418
__curr_symbol_.insert(0, 1, space_char);
5425
case 1: // The sign string precedes the quantity and currency symbol.
5426
pat.field[0] = sign;
5427
pat.field[3] = symbol;
5428
switch (sep_by_space)
5430
case 0: // No space separates the currency symbol and value.
5431
pat.field[1] = value;
5432
pat.field[2] = none;
5434
case 1: // Space between currency-and-sign or currency and value.
5435
pat.field[1] = value;
5436
pat.field[2] = none;
5437
if (!symbol_contains_sep) {
5438
// We insert the space into the symbol instead of
5439
// setting pat.field[2]=space so that when
5440
// showbase is not set, the space goes away too.
5441
__curr_symbol_.insert(0, 1, space_char);
5444
case 2: // Space between sign and currency or value.
5445
pat.field[1] = space;
5446
pat.field[2] = value;
5447
if (symbol_contains_sep) {
5448
// Remove the separator from the symbol, since it
5449
// has already appeared after the sign.
5450
__curr_symbol_.erase(__curr_symbol_.begin());
5457
case 2: // The sign string succeeds the quantity and currency symbol.
5458
pat.field[0] = value;
5459
pat.field[3] = sign;
5460
switch (sep_by_space)
5462
case 0: // No space separates the currency symbol and value.
5463
pat.field[1] = none;
5464
pat.field[2] = symbol;
5466
case 1: // Space between currency-and-sign or currency and value.
5467
if (!symbol_contains_sep) {
5468
// We insert the space into the symbol instead of
5469
// setting pat.field[1]=space so that when
5470
// showbase is not set, the space goes away too.
5471
__curr_symbol_.insert(0, 1, space_char);
5473
pat.field[1] = none;
5474
pat.field[2] = symbol;
5476
case 2: // Space between sign and currency or value.
5477
pat.field[1] = symbol;
5478
pat.field[2] = space;
5479
if (symbol_contains_sep) {
5480
// Remove the separator from the symbol, since it
5481
// should not be removed if showbase is absent.
5482
__curr_symbol_.erase(__curr_symbol_.begin());
5489
case 3: // The sign string immediately precedes the currency symbol.
5490
pat.field[0] = value;
5491
pat.field[3] = symbol;
5492
switch (sep_by_space)
5494
case 0: // No space separates the currency symbol and value.
5495
pat.field[1] = none;
5496
pat.field[2] = sign;
5498
case 1: // Space between currency-and-sign or currency and value.
5499
pat.field[1] = space;
5500
pat.field[2] = sign;
5501
if (symbol_contains_sep) {
5502
// Remove the separator from the symbol, since it
5503
// has already appeared before the sign.
5504
__curr_symbol_.erase(__curr_symbol_.begin());
5507
case 2: // Space between sign and currency or value.
5508
pat.field[1] = sign;
5509
pat.field[2] = none;
5510
if (!symbol_contains_sep) {
5511
// We insert the space into the symbol instead of
5512
// setting pat.field[2]=space so that when
5513
// showbase is not set, the space goes away too.
5514
__curr_symbol_.insert(0, 1, space_char);
5521
case 4: // The sign string immediately succeeds the currency symbol.
5522
pat.field[0] = value;
5523
pat.field[3] = sign;
5524
switch (sep_by_space)
5526
case 0: // No space separates the currency symbol and value.
5527
pat.field[1] = none;
5528
pat.field[2] = symbol;
5530
case 1: // Space between currency-and-sign or currency and value.
5531
pat.field[1] = none;
5532
pat.field[2] = symbol;
5533
if (!symbol_contains_sep) {
5534
// We insert the space into the symbol instead of
5535
// setting pat.field[1]=space so that when
5536
// showbase is not set, the space goes away too.
5537
__curr_symbol_.insert(0, 1, space_char);
5540
case 2: // Space between sign and currency or value.
5541
pat.field[1] = symbol;
5542
pat.field[2] = space;
5543
if (symbol_contains_sep) {
5544
// Remove the separator from the symbol, since it
5545
// should not disappear when showbase is absent.
5546
__curr_symbol_.erase(__curr_symbol_.begin());
5557
case 1: // curr_symbol before value
5560
case 0: // Parentheses surround the quantity and currency symbol.
5561
pat.field[0] = sign;
5562
pat.field[1] = symbol;
5563
pat.field[2] = none; // Any space appears in the symbol.
5564
pat.field[3] = value;
5565
switch (sep_by_space)
5567
case 0: // No space separates the currency symbol and value.
5568
// This case may have changed between C99 and C11;
5569
// assume the currency symbol matches the intention.
5570
case 2: // Space between sign and currency or value.
5571
// The "sign" is two parentheses, so no space here either.
5573
case 1: // Space between currency-and-sign or currency and value.
5574
if (!symbol_contains_sep) {
5575
// We insert the space into the symbol instead of
5576
// setting pat.field[2]=space so that when
5577
// showbase is not set, the space goes away too.
5578
__curr_symbol_.insert(0, 1, space_char);
5585
case 1: // The sign string precedes the quantity and currency symbol.
5586
pat.field[0] = sign;
5587
pat.field[3] = value;
5588
switch (sep_by_space)
5590
case 0: // No space separates the currency symbol and value.
5591
pat.field[1] = symbol;
5592
pat.field[2] = none;
5594
case 1: // Space between currency-and-sign or currency and value.
5595
pat.field[1] = symbol;
5596
pat.field[2] = none;
5597
if (!symbol_contains_sep) {
5598
// We insert the space into the symbol instead of
5599
// setting pat.field[2]=space so that when
5600
// showbase is not set, the space goes away too.
5601
__curr_symbol_.push_back(space_char);
5604
case 2: // Space between sign and currency or value.
5605
pat.field[1] = space;
5606
pat.field[2] = symbol;
5607
if (symbol_contains_sep) {
5608
// Remove the separator from the symbol, since it
5609
// has already appeared after the sign.
5610
__curr_symbol_.pop_back();
5617
case 2: // The sign string succeeds the quantity and currency symbol.
5618
pat.field[0] = symbol;
5619
pat.field[3] = sign;
5620
switch (sep_by_space)
5622
case 0: // No space separates the currency symbol and value.
5623
pat.field[1] = none;
5624
pat.field[2] = value;
5626
case 1: // Space between currency-and-sign or currency and value.
5627
pat.field[1] = none;
5628
pat.field[2] = value;
5629
if (!symbol_contains_sep) {
5630
// We insert the space into the symbol instead of
5631
// setting pat.field[1]=space so that when
5632
// showbase is not set, the space goes away too.
5633
__curr_symbol_.push_back(space_char);
5636
case 2: // Space between sign and currency or value.
5637
pat.field[1] = value;
5638
pat.field[2] = space;
5639
if (symbol_contains_sep) {
5640
// Remove the separator from the symbol, since it
5641
// will appear before the sign.
5642
__curr_symbol_.pop_back();
5649
case 3: // The sign string immediately precedes the currency symbol.
5650
pat.field[0] = sign;
5651
pat.field[3] = value;
5652
switch (sep_by_space)
5654
case 0: // No space separates the currency symbol and value.
5655
pat.field[1] = symbol;
5656
pat.field[2] = none;
5658
case 1: // Space between currency-and-sign or currency and value.
5659
pat.field[1] = symbol;
5660
pat.field[2] = none;
5661
if (!symbol_contains_sep) {
5662
// We insert the space into the symbol instead of
5663
// setting pat.field[2]=space so that when
5664
// showbase is not set, the space goes away too.
5665
__curr_symbol_.push_back(space_char);
5668
case 2: // Space between sign and currency or value.
5669
pat.field[1] = space;
5670
pat.field[2] = symbol;
5671
if (symbol_contains_sep) {
5672
// Remove the separator from the symbol, since it
5673
// has already appeared after the sign.
5674
__curr_symbol_.pop_back();
5681
case 4: // The sign string immediately succeeds the currency symbol.
5682
pat.field[0] = symbol;
5683
pat.field[3] = value;
5684
switch (sep_by_space)
5686
case 0: // No space separates the currency symbol and value.
5687
pat.field[1] = sign;
5688
pat.field[2] = none;
5690
case 1: // Space between currency-and-sign or currency and value.
5691
pat.field[1] = sign;
5692
pat.field[2] = space;
5693
if (symbol_contains_sep) {
5694
// Remove the separator from the symbol, since it
5695
// should not disappear when showbase is absent.
5696
__curr_symbol_.pop_back();
5699
case 2: // Space between sign and currency or value.
5700
pat.field[1] = none;
5701
pat.field[2] = sign;
5702
if (!symbol_contains_sep) {
5703
// We insert the space into the symbol instead of
5704
// setting pat.field[1]=space so that when
5705
// showbase is not set, the space goes away too.
5706
__curr_symbol_.push_back(space_char);
5720
pat.field[0] = symbol;
5721
pat.field[1] = sign;
5722
pat.field[2] = none;
5723
pat.field[3] = value;
5728
moneypunct_byname<char, false>::init(const char* nm)
5730
typedef moneypunct<char, false> base;
5731
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
5732
#ifndef _LIBCPP_NO_EXCEPTIONS
5734
throw runtime_error("moneypunct_byname"
5735
" failed to construct for " + string(nm));
5736
#endif // _LIBCPP_NO_EXCEPTIONS
5737
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5738
lconv* lc = localeconv_l(loc.get());
5740
lconv* lc = __localeconv_l(loc.get());
5742
if (*lc->mon_decimal_point)
5743
__decimal_point_ = *lc->mon_decimal_point;
5745
__decimal_point_ = base::do_decimal_point();
5746
if (*lc->mon_thousands_sep)
5747
__thousands_sep_ = *lc->mon_thousands_sep;
5749
__thousands_sep_ = base::do_thousands_sep();
5750
__grouping_ = lc->mon_grouping;
5751
__curr_symbol_ = lc->currency_symbol;
5752
if (lc->frac_digits != CHAR_MAX)
5753
__frac_digits_ = lc->frac_digits;
5755
__frac_digits_ = base::do_frac_digits();
5756
if (lc->p_sign_posn == 0)
5757
__positive_sign_ = "()";
5759
__positive_sign_ = lc->positive_sign;
5760
if (lc->n_sign_posn == 0)
5761
__negative_sign_ = "()";
5763
__negative_sign_ = lc->negative_sign;
5764
// Assume the positive and negative formats will want spaces in
5765
// the same places in curr_symbol since there's no way to
5766
// represent anything else.
5767
string_type __dummy_curr_symbol = __curr_symbol_;
5768
__init_pat(__pos_format_, __dummy_curr_symbol, false,
5769
lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
5770
__init_pat(__neg_format_, __curr_symbol_, false,
5771
lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
5776
moneypunct_byname<char, true>::init(const char* nm)
5778
typedef moneypunct<char, true> base;
5779
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
5780
#ifndef _LIBCPP_NO_EXCEPTIONS
5782
throw runtime_error("moneypunct_byname"
5783
" failed to construct for " + string(nm));
5784
#endif // _LIBCPP_NO_EXCEPTIONS
5785
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5786
lconv* lc = localeconv_l(loc.get());
5788
lconv* lc = __localeconv_l(loc.get());
5790
if (*lc->mon_decimal_point)
5791
__decimal_point_ = *lc->mon_decimal_point;
5793
__decimal_point_ = base::do_decimal_point();
5794
if (*lc->mon_thousands_sep)
5795
__thousands_sep_ = *lc->mon_thousands_sep;
5797
__thousands_sep_ = base::do_thousands_sep();
5798
__grouping_ = lc->mon_grouping;
5799
__curr_symbol_ = lc->int_curr_symbol;
5800
if (lc->int_frac_digits != CHAR_MAX)
5801
__frac_digits_ = lc->int_frac_digits;
5803
__frac_digits_ = base::do_frac_digits();
5805
if (lc->p_sign_posn == 0)
5807
if (lc->int_p_sign_posn == 0)
5809
__positive_sign_ = "()";
5811
__positive_sign_ = lc->positive_sign;
5813
if(lc->n_sign_posn == 0)
5815
if (lc->int_n_sign_posn == 0)
5817
__negative_sign_ = "()";
5819
__negative_sign_ = lc->negative_sign;
5820
// Assume the positive and negative formats will want spaces in
5821
// the same places in curr_symbol since there's no way to
5822
// represent anything else.
5823
string_type __dummy_curr_symbol = __curr_symbol_;
5825
__init_pat(__pos_format_, __dummy_curr_symbol, true,
5826
lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
5827
__init_pat(__neg_format_, __curr_symbol_, true,
5828
lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
5830
__init_pat(__pos_format_, __dummy_curr_symbol, true,
5831
lc->int_p_cs_precedes, lc->int_p_sep_by_space,
5832
lc->int_p_sign_posn, ' ');
5833
__init_pat(__neg_format_, __curr_symbol_, true,
5834
lc->int_n_cs_precedes, lc->int_n_sep_by_space,
5835
lc->int_n_sign_posn, ' ');
5841
moneypunct_byname<wchar_t, false>::init(const char* nm)
5843
typedef moneypunct<wchar_t, false> base;
5844
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
5845
#ifndef _LIBCPP_NO_EXCEPTIONS
5847
throw runtime_error("moneypunct_byname"
5848
" failed to construct for " + string(nm));
5849
#endif // _LIBCPP_NO_EXCEPTIONS
5850
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5851
lconv* lc = localeconv_l(loc.get());
5853
lconv* lc = __localeconv_l(loc.get());
5855
if (*lc->mon_decimal_point)
5856
__decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
5858
__decimal_point_ = base::do_decimal_point();
5859
if (*lc->mon_thousands_sep)
5860
__thousands_sep_ = static_cast<wchar_t>(*lc->mon_thousands_sep);
5862
__thousands_sep_ = base::do_thousands_sep();
5863
__grouping_ = lc->mon_grouping;
5866
const char* bb = lc->currency_symbol;
5867
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5868
size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5870
size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5872
if (j == size_t(-1))
5873
__throw_runtime_error("locale not supported");
5874
wchar_t* wbe = wbuf + j;
5875
__curr_symbol_.assign(wbuf, wbe);
5876
if (lc->frac_digits != CHAR_MAX)
5877
__frac_digits_ = lc->frac_digits;
5879
__frac_digits_ = base::do_frac_digits();
5880
if (lc->p_sign_posn == 0)
5881
__positive_sign_ = L"()";
5885
bb = lc->positive_sign;
5886
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5887
j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5889
j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5891
if (j == size_t(-1))
5892
__throw_runtime_error("locale not supported");
5894
__positive_sign_.assign(wbuf, wbe);
5896
if (lc->n_sign_posn == 0)
5897
__negative_sign_ = L"()";
5901
bb = lc->negative_sign;
5902
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5903
j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5905
j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5907
if (j == size_t(-1))
5908
__throw_runtime_error("locale not supported");
5910
__negative_sign_.assign(wbuf, wbe);
5912
// Assume the positive and negative formats will want spaces in
5913
// the same places in curr_symbol since there's no way to
5914
// represent anything else.
5915
string_type __dummy_curr_symbol = __curr_symbol_;
5916
__init_pat(__pos_format_, __dummy_curr_symbol, false,
5917
lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
5918
__init_pat(__neg_format_, __curr_symbol_, false,
5919
lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
5924
moneypunct_byname<wchar_t, true>::init(const char* nm)
5926
typedef moneypunct<wchar_t, true> base;
5927
__locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
5928
#ifndef _LIBCPP_NO_EXCEPTIONS
5930
throw runtime_error("moneypunct_byname"
5931
" failed to construct for " + string(nm));
5932
#endif // _LIBCPP_NO_EXCEPTIONS
5933
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5934
lconv* lc = localeconv_l(loc.get());
5936
lconv* lc = __localeconv_l(loc.get());
5938
if (*lc->mon_decimal_point)
5939
__decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
5941
__decimal_point_ = base::do_decimal_point();
5942
if (*lc->mon_thousands_sep)
5943
__thousands_sep_ = static_cast<wchar_t>(*lc->mon_thousands_sep);
5945
__thousands_sep_ = base::do_thousands_sep();
5946
__grouping_ = lc->mon_grouping;
5949
const char* bb = lc->int_curr_symbol;
5950
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5951
size_t j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5953
size_t j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5955
if (j == size_t(-1))
5956
__throw_runtime_error("locale not supported");
5957
wchar_t* wbe = wbuf + j;
5958
__curr_symbol_.assign(wbuf, wbe);
5959
if (lc->int_frac_digits != CHAR_MAX)
5960
__frac_digits_ = lc->int_frac_digits;
5962
__frac_digits_ = base::do_frac_digits();
5964
if (lc->p_sign_posn == 0)
5966
if (lc->int_p_sign_posn == 0)
5968
__positive_sign_ = L"()";
5972
bb = lc->positive_sign;
5973
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5974
j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5976
j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5978
if (j == size_t(-1))
5979
__throw_runtime_error("locale not supported");
5981
__positive_sign_.assign(wbuf, wbe);
5984
if (lc->n_sign_posn == 0)
5986
if (lc->int_n_sign_posn == 0)
5988
__negative_sign_ = L"()";
5992
bb = lc->negative_sign;
5993
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5994
j = mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5996
j = __mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5998
if (j == size_t(-1))
5999
__throw_runtime_error("locale not supported");
6001
__negative_sign_.assign(wbuf, wbe);
6003
// Assume the positive and negative formats will want spaces in
6004
// the same places in curr_symbol since there's no way to
6005
// represent anything else.
6006
string_type __dummy_curr_symbol = __curr_symbol_;
6008
__init_pat(__pos_format_, __dummy_curr_symbol, true,
6009
lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
6010
__init_pat(__neg_format_, __curr_symbol_, true,
6011
lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
6013
__init_pat(__pos_format_, __dummy_curr_symbol, true,
6014
lc->int_p_cs_precedes, lc->int_p_sep_by_space,
6015
lc->int_p_sign_posn, L' ');
6016
__init_pat(__neg_format_, __curr_symbol_, true,
6017
lc->int_n_cs_precedes, lc->int_n_sep_by_space,
6018
lc->int_n_sign_posn, L' ');
6022
void __do_nothing(void*) {}
6024
void __throw_runtime_error(const char* msg)
6026
#ifndef _LIBCPP_NO_EXCEPTIONS
6027
throw runtime_error(msg);
6031
template class collate<char>;
6032
template class collate<wchar_t>;
6034
template class num_get<char>;
6035
template class num_get<wchar_t>;
6037
template struct __num_get<char>;
6038
template struct __num_get<wchar_t>;
6040
template class num_put<char>;
6041
template class num_put<wchar_t>;
6043
template struct __num_put<char>;
6044
template struct __num_put<wchar_t>;
6046
template class time_get<char>;
6047
template class time_get<wchar_t>;
6049
template class time_get_byname<char>;
6050
template class time_get_byname<wchar_t>;
6052
template class time_put<char>;
6053
template class time_put<wchar_t>;
6055
template class time_put_byname<char>;
6056
template class time_put_byname<wchar_t>;
6058
template class moneypunct<char, false>;
6059
template class moneypunct<char, true>;
6060
template class moneypunct<wchar_t, false>;
6061
template class moneypunct<wchar_t, true>;
6063
template class moneypunct_byname<char, false>;
6064
template class moneypunct_byname<char, true>;
6065
template class moneypunct_byname<wchar_t, false>;
6066
template class moneypunct_byname<wchar_t, true>;
6068
template class money_get<char>;
6069
template class money_get<wchar_t>;
6071
template class __money_get<char>;
6072
template class __money_get<wchar_t>;
6074
template class money_put<char>;
6075
template class money_put<wchar_t>;
6077
template class __money_put<char>;
6078
template class __money_put<wchar_t>;
6080
template class messages<char>;
6081
template class messages<wchar_t>;
6083
template class messages_byname<char>;
6084
template class messages_byname<wchar_t>;
6086
template class codecvt_byname<char, char, mbstate_t>;
6087
template class codecvt_byname<wchar_t, char, mbstate_t>;
6088
template class codecvt_byname<char16_t, char, mbstate_t>;
6089
template class codecvt_byname<char32_t, char, mbstate_t>;
6091
template class __vector_base_common<true>;
6093
_LIBCPP_END_NAMESPACE_STD