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 _LIBCPP_BEGIN_NAMESPACE_STD
39 // In theory this could create a race condition. In practice
40 // the race condition is non-fatal since it will just create
41 // a little resource leak. Better approach would be appreciated.
42 static locale_t result = newlocale(LC_ALL_MASK, "C", 0);
45 #endif // __cloc_defined
51 void operator()(locale::facet* p) {p->__release_shared();}
54 template <class T, class A0>
59 static typename aligned_storage<sizeof(T)>::type buf;
64 template <class T, class A0, class A1>
69 static typename aligned_storage<sizeof(T)>::type buf;
70 ::new (&buf) T(a0, a1);
74 template <class T, class A0, class A1, class A2>
77 make(A0 a0, A1 a1, A2 a2)
79 static typename aligned_storage<sizeof(T)>::type buf;
80 ::new (&buf) T(a0, a1, a2);
86 #pragma clang diagnostic push
87 #pragma clang diagnostic ignored "-Wpadded"
89 class _LIBCPP_HIDDEN locale::__imp
93 vector<facet*, __sso_allocator<facet*, N> > facets_;
96 explicit __imp(size_t refs = 0);
97 explicit __imp(const string& name, size_t refs = 0);
99 __imp(const __imp&, const string&, locale::category c);
100 __imp(const __imp& other, const __imp& one, locale::category c);
101 __imp(const __imp&, facet* f, long id);
104 const string& name() const {return name_;}
105 bool has_facet(long id) const
106 {return static_cast<size_t>(id) < facets_.size() && facets_[static_cast<size_t>(id)];}
107 const locale::facet* use_facet(long id) const;
109 static const locale& make_classic();
110 static locale& make_global();
112 void install(facet* f, long id);
113 template <class F> void install(F* f) {install(f, f->id.__get());}
114 template <class F> void install_from(const __imp& other);
117 #pragma clang diagnostic pop
119 locale::__imp::__imp(size_t refs)
125 install(&make<_VSTD::collate<char> >(1u));
126 install(&make<_VSTD::collate<wchar_t> >(1u));
127 install(&make<_VSTD::ctype<char> >((ctype_base::mask*)0, false, 1u));
128 install(&make<_VSTD::ctype<wchar_t> >(1u));
129 install(&make<codecvt<char, char, mbstate_t> >(1u));
130 install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));
131 install(&make<codecvt<char16_t, char, mbstate_t> >(1u));
132 install(&make<codecvt<char32_t, char, mbstate_t> >(1u));
133 install(&make<numpunct<char> >(1u));
134 install(&make<numpunct<wchar_t> >(1u));
135 install(&make<num_get<char> >(1u));
136 install(&make<num_get<wchar_t> >(1u));
137 install(&make<num_put<char> >(1u));
138 install(&make<num_put<wchar_t> >(1u));
139 install(&make<moneypunct<char, false> >(1u));
140 install(&make<moneypunct<char, true> >(1u));
141 install(&make<moneypunct<wchar_t, false> >(1u));
142 install(&make<moneypunct<wchar_t, true> >(1u));
143 install(&make<money_get<char> >(1u));
144 install(&make<money_get<wchar_t> >(1u));
145 install(&make<money_put<char> >(1u));
146 install(&make<money_put<wchar_t> >(1u));
147 install(&make<time_get<char> >(1u));
148 install(&make<time_get<wchar_t> >(1u));
149 install(&make<time_put<char> >(1u));
150 install(&make<time_put<wchar_t> >(1u));
151 install(&make<_VSTD::messages<char> >(1u));
152 install(&make<_VSTD::messages<wchar_t> >(1u));
155 locale::__imp::__imp(const string& name, size_t refs)
160 #ifndef _LIBCPP_NO_EXCEPTIONS
163 #endif // _LIBCPP_NO_EXCEPTIONS
164 facets_ = locale::classic().__locale_->facets_;
165 for (unsigned i = 0; i < facets_.size(); ++i)
167 facets_[i]->__add_shared();
168 install(new collate_byname<char>(name_));
169 install(new collate_byname<wchar_t>(name_));
170 install(new ctype_byname<char>(name_));
171 install(new ctype_byname<wchar_t>(name_));
172 install(new codecvt_byname<char, char, mbstate_t>(name_));
173 install(new codecvt_byname<wchar_t, char, mbstate_t>(name_));
174 install(new codecvt_byname<char16_t, char, mbstate_t>(name_));
175 install(new codecvt_byname<char32_t, char, mbstate_t>(name_));
176 install(new numpunct_byname<char>(name_));
177 install(new numpunct_byname<wchar_t>(name_));
178 install(new moneypunct_byname<char, false>(name_));
179 install(new moneypunct_byname<char, true>(name_));
180 install(new moneypunct_byname<wchar_t, false>(name_));
181 install(new moneypunct_byname<wchar_t, true>(name_));
182 install(new time_get_byname<char>(name_));
183 install(new time_get_byname<wchar_t>(name_));
184 install(new time_put_byname<char>(name_));
185 install(new time_put_byname<wchar_t>(name_));
186 install(new messages_byname<char>(name_));
187 install(new messages_byname<wchar_t>(name_));
188 #ifndef _LIBCPP_NO_EXCEPTIONS
192 for (unsigned i = 0; i < facets_.size(); ++i)
194 facets_[i]->__release_shared();
197 #endif // _LIBCPP_NO_EXCEPTIONS
200 locale::__imp::__imp(const __imp& other)
201 : facets_(max<size_t>(N, other.facets_.size())),
204 facets_ = other.facets_;
205 for (unsigned i = 0; i < facets_.size(); ++i)
207 facets_[i]->__add_shared();
210 locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
214 facets_ = other.facets_;
215 for (unsigned i = 0; i < facets_.size(); ++i)
217 facets_[i]->__add_shared();
218 #ifndef _LIBCPP_NO_EXCEPTIONS
221 #endif // _LIBCPP_NO_EXCEPTIONS
222 if (c & locale::collate)
224 install(new collate_byname<char>(name));
225 install(new collate_byname<wchar_t>(name));
227 if (c & locale::ctype)
229 install(new ctype_byname<char>(name));
230 install(new ctype_byname<wchar_t>(name));
231 install(new codecvt_byname<char, char, mbstate_t>(name));
232 install(new codecvt_byname<wchar_t, char, mbstate_t>(name));
233 install(new codecvt_byname<char16_t, char, mbstate_t>(name));
234 install(new codecvt_byname<char32_t, char, mbstate_t>(name));
236 if (c & locale::monetary)
238 install(new moneypunct_byname<char, false>(name));
239 install(new moneypunct_byname<char, true>(name));
240 install(new moneypunct_byname<wchar_t, false>(name));
241 install(new moneypunct_byname<wchar_t, true>(name));
243 if (c & locale::numeric)
245 install(new numpunct_byname<char>(name));
246 install(new numpunct_byname<wchar_t>(name));
248 if (c & locale::time)
250 install(new time_get_byname<char>(name));
251 install(new time_get_byname<wchar_t>(name));
252 install(new time_put_byname<char>(name));
253 install(new time_put_byname<wchar_t>(name));
255 if (c & locale::messages)
257 install(new messages_byname<char>(name));
258 install(new messages_byname<wchar_t>(name));
260 #ifndef _LIBCPP_NO_EXCEPTIONS
264 for (unsigned i = 0; i < facets_.size(); ++i)
266 facets_[i]->__release_shared();
269 #endif // _LIBCPP_NO_EXCEPTIONS
275 locale::__imp::install_from(const locale::__imp& one)
277 long id = F::id.__get();
278 install(const_cast<F*>(static_cast<const F*>(one.use_facet(id))), id);
281 locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)
285 facets_ = other.facets_;
286 for (unsigned i = 0; i < facets_.size(); ++i)
288 facets_[i]->__add_shared();
289 #ifndef _LIBCPP_NO_EXCEPTIONS
292 #endif // _LIBCPP_NO_EXCEPTIONS
293 if (c & locale::collate)
295 install_from<_VSTD::collate<char> >(one);
296 install_from<_VSTD::collate<wchar_t> >(one);
298 if (c & locale::ctype)
300 install_from<_VSTD::ctype<char> >(one);
301 install_from<_VSTD::ctype<wchar_t> >(one);
302 install_from<_VSTD::codecvt<char, char, mbstate_t> >(one);
303 install_from<_VSTD::codecvt<char16_t, char, mbstate_t> >(one);
304 install_from<_VSTD::codecvt<char32_t, char, mbstate_t> >(one);
305 install_from<_VSTD::codecvt<wchar_t, char, mbstate_t> >(one);
307 if (c & locale::monetary)
309 install_from<moneypunct<char, false> >(one);
310 install_from<moneypunct<char, true> >(one);
311 install_from<moneypunct<wchar_t, false> >(one);
312 install_from<moneypunct<wchar_t, true> >(one);
313 install_from<money_get<char> >(one);
314 install_from<money_get<wchar_t> >(one);
315 install_from<money_put<char> >(one);
316 install_from<money_put<wchar_t> >(one);
318 if (c & locale::numeric)
320 install_from<numpunct<char> >(one);
321 install_from<numpunct<wchar_t> >(one);
322 install_from<num_get<char> >(one);
323 install_from<num_get<wchar_t> >(one);
324 install_from<num_put<char> >(one);
325 install_from<num_put<wchar_t> >(one);
327 if (c & locale::time)
329 install_from<time_get<char> >(one);
330 install_from<time_get<wchar_t> >(one);
331 install_from<time_put<char> >(one);
332 install_from<time_put<wchar_t> >(one);
334 if (c & locale::messages)
336 install_from<_VSTD::messages<char> >(one);
337 install_from<_VSTD::messages<wchar_t> >(one);
339 #ifndef _LIBCPP_NO_EXCEPTIONS
343 for (unsigned i = 0; i < facets_.size(); ++i)
345 facets_[i]->__release_shared();
348 #endif // _LIBCPP_NO_EXCEPTIONS
351 locale::__imp::__imp(const __imp& other, facet* f, long id)
352 : facets_(max<size_t>(N, other.facets_.size()+1)),
356 unique_ptr<facet, release> hold(f);
357 facets_ = other.facets_;
358 for (unsigned i = 0; i < other.facets_.size(); ++i)
360 facets_[i]->__add_shared();
361 install(hold.get(), id);
364 locale::__imp::~__imp()
366 for (unsigned i = 0; i < facets_.size(); ++i)
368 facets_[i]->__release_shared();
372 locale::__imp::install(facet* f, long id)
375 unique_ptr<facet, release> hold(f);
376 if (static_cast<size_t>(id) >= facets_.size())
377 facets_.resize(static_cast<size_t>(id+1));
378 if (facets_[static_cast<size_t>(id)])
379 facets_[static_cast<size_t>(id)]->__release_shared();
380 facets_[static_cast<size_t>(id)] = hold.release();
384 locale::__imp::use_facet(long id) const
386 #ifndef _LIBCPP_NO_EXCEPTIONS
389 #endif // _LIBCPP_NO_EXCEPTIONS
390 return facets_[static_cast<size_t>(id)];
396 locale::__imp::make_classic()
398 // only one thread can get in here and it only gets in once
399 static aligned_storage<sizeof(locale)>::type buf;
400 locale* c = (locale*)&buf;
401 c->__locale_ = &make<__imp>(1u);
408 static const locale& c = __imp::make_classic();
413 locale::__imp::make_global()
415 // only one thread can get in here and it only gets in once
416 static aligned_storage<sizeof(locale)>::type buf;
417 ::new (&buf) locale(locale::classic());
418 return *(locale*)&buf;
424 static locale& g = __imp::make_global();
428 locale::locale() _NOEXCEPT
429 : __locale_(__global().__locale_)
431 __locale_->__add_shared();
434 locale::locale(const locale& l) _NOEXCEPT
435 : __locale_(l.__locale_)
437 __locale_->__add_shared();
442 __locale_->__release_shared();
446 locale::operator=(const locale& other) _NOEXCEPT
448 other.__locale_->__add_shared();
449 __locale_->__release_shared();
450 __locale_ = other.__locale_;
454 locale::locale(const char* name)
455 #ifndef _LIBCPP_NO_EXCEPTIONS
456 : __locale_(name ? new __imp(name)
457 : throw runtime_error("locale constructed with null"))
458 #else // _LIBCPP_NO_EXCEPTIONS
459 : __locale_(new __imp(name))
462 __locale_->__add_shared();
465 locale::locale(const string& name)
466 : __locale_(new __imp(name))
468 __locale_->__add_shared();
471 locale::locale(const locale& other, const char* name, category c)
472 #ifndef _LIBCPP_NO_EXCEPTIONS
473 : __locale_(name ? new __imp(*other.__locale_, name, c)
474 : throw runtime_error("locale constructed with null"))
475 #else // _LIBCPP_NO_EXCEPTIONS
476 : __locale_(new __imp(*other.__locale_, name, c))
479 __locale_->__add_shared();
482 locale::locale(const locale& other, const string& name, category c)
483 : __locale_(new __imp(*other.__locale_, name, c))
485 __locale_->__add_shared();
488 locale::locale(const locale& other, const locale& one, category c)
489 : __locale_(new __imp(*other.__locale_, *one.__locale_, c))
491 __locale_->__add_shared();
497 return __locale_->name();
501 locale::__install_ctor(const locale& other, facet* f, long id)
504 __locale_ = new __imp(*other.__locale_, f, id);
506 __locale_ = other.__locale_;
507 __locale_->__add_shared();
511 locale::global(const locale& loc)
513 locale& g = __global();
517 setlocale(LC_ALL, g.name().c_str());
522 locale::has_facet(id& x) const
524 return __locale_->has_facet(x.__get());
528 locale::use_facet(id& x) const
530 return __locale_->use_facet(x.__get());
534 locale::operator==(const locale& y) const
536 return (__locale_ == y.__locale_)
537 || (__locale_->name() != "*" && __locale_->name() == y.__locale_->name());
542 locale::facet::~facet()
547 locale::facet::__on_zero_shared() _NOEXCEPT
554 int32_t locale::id::__next_id = 0;
562 void (locale::id::* pmf_)();
564 __fake_bind(void (locale::id::* pmf)(), locale::id* id)
565 : id_(id), pmf_(pmf) {}
567 void operator()() const
578 call_once(__flag_, __fake_bind(&locale::id::__init, this));
585 __id_ = __sync_add_and_fetch(&__next_id, 1);
588 // template <> class collate_byname<char>
590 collate_byname<char>::collate_byname(const char* n, size_t refs)
591 : collate<char>(refs),
592 __l(newlocale(LC_ALL_MASK, n, 0))
594 #ifndef _LIBCPP_NO_EXCEPTIONS
596 throw runtime_error("collate_byname<char>::collate_byname"
597 " failed to construct for " + string(n));
598 #endif // _LIBCPP_NO_EXCEPTIONS
601 collate_byname<char>::collate_byname(const string& name, size_t refs)
602 : collate<char>(refs),
603 __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
605 #ifndef _LIBCPP_NO_EXCEPTIONS
607 throw runtime_error("collate_byname<char>::collate_byname"
608 " failed to construct for " + name);
609 #endif // _LIBCPP_NO_EXCEPTIONS
612 collate_byname<char>::~collate_byname()
618 collate_byname<char>::do_compare(const char_type* __lo1, const char_type* __hi1,
619 const char_type* __lo2, const char_type* __hi2) const
621 string_type lhs(__lo1, __hi1);
622 string_type rhs(__lo2, __hi2);
623 int r = strcoll_l(lhs.c_str(), rhs.c_str(), __l);
631 collate_byname<char>::string_type
632 collate_byname<char>::do_transform(const char_type* lo, const char_type* hi) const
634 const string_type in(lo, hi);
635 string_type out(strxfrm_l(0, in.c_str(), 0, __l), char());
636 strxfrm_l(const_cast<char*>(out.c_str()), in.c_str(), out.size()+1, __l);
640 // template <> class collate_byname<wchar_t>
642 collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)
643 : collate<wchar_t>(refs),
644 __l(newlocale(LC_ALL_MASK, n, 0))
646 #ifndef _LIBCPP_NO_EXCEPTIONS
648 throw runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
649 " failed to construct for " + string(n));
650 #endif // _LIBCPP_NO_EXCEPTIONS
653 collate_byname<wchar_t>::collate_byname(const string& name, size_t refs)
654 : collate<wchar_t>(refs),
655 __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
657 #ifndef _LIBCPP_NO_EXCEPTIONS
659 throw runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
660 " failed to construct for " + name);
661 #endif // _LIBCPP_NO_EXCEPTIONS
664 collate_byname<wchar_t>::~collate_byname()
670 collate_byname<wchar_t>::do_compare(const char_type* __lo1, const char_type* __hi1,
671 const char_type* __lo2, const char_type* __hi2) const
673 string_type lhs(__lo1, __hi1);
674 string_type rhs(__lo2, __hi2);
675 int r = wcscoll_l(lhs.c_str(), rhs.c_str(), __l);
683 collate_byname<wchar_t>::string_type
684 collate_byname<wchar_t>::do_transform(const char_type* lo, const char_type* hi) const
686 const string_type in(lo, hi);
687 string_type out(wcsxfrm_l(0, in.c_str(), 0, __l), wchar_t());
688 wcsxfrm_l(const_cast<wchar_t*>(out.c_str()), in.c_str(), out.size()+1, __l);
692 // template <> class ctype<wchar_t>;
694 locale::id ctype<wchar_t>::id;
696 ctype<wchar_t>::~ctype()
701 ctype<wchar_t>::do_is(mask m, char_type c) const
703 return isascii(c) ? ctype<char>::classic_table()[c] & m : false;
707 ctype<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const
709 for (; low != high; ++low, ++vec)
710 *vec = static_cast<mask>(isascii(*low) ?
711 ctype<char>::classic_table()[*low] : 0);
716 ctype<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const
718 for (; low != high; ++low)
719 if (isascii(*low) && (ctype<char>::classic_table()[*low] & m))
725 ctype<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
727 for (; low != high; ++low)
728 if (!(isascii(*low) && (ctype<char>::classic_table()[*low] & m)))
734 ctype<wchar_t>::do_toupper(char_type c) const
736 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
737 return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
738 #elif defined(__GLIBC__)
739 return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
741 return (isascii(c) && iswlower_l(c, __cloc())) ? c-L'a'+L'A' : c;
746 ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
748 for (; low != high; ++low)
749 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
750 *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
751 #elif defined(__GLIBC__)
752 *low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
755 *low = (isascii(*low) && islower_l(*low, __cloc())) ? (*low-L'a'+L'A') : *low;
761 ctype<wchar_t>::do_tolower(char_type c) const
763 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
764 return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
765 #elif defined(__GLIBC__)
766 return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
768 return (isascii(c) && isupper_l(c, __cloc())) ? c-L'A'+'a' : c;
773 ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const
775 for (; low != high; ++low)
776 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
777 *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
778 #elif defined(__GLIBC__)
779 *low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
782 *low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-L'A'+L'a' : *low;
788 ctype<wchar_t>::do_widen(char c) const
794 ctype<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
796 for (; low != high; ++low, ++dest)
802 ctype<wchar_t>::do_narrow(char_type c, char dfault) const
805 return static_cast<char>(c);
810 ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
812 for (; low != high; ++low, ++dest)
814 *dest = static_cast<char>(*low);
820 // template <> class ctype<char>;
822 locale::id ctype<char>::id;
824 ctype<char>::ctype(const mask* tab, bool del, size_t refs)
825 : locale::facet(refs),
830 __tab_ = classic_table();
833 ctype<char>::~ctype()
835 if (__tab_ && __del_)
840 ctype<char>::do_toupper(char_type c) const
842 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
844 static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
845 #elif defined(__GLIBC__)
846 return isascii(c) ? __classic_upper_table()[c] : c;
848 return (isascii(c) && islower_l(c, __cloc())) ? c-'a'+'A' : c;
853 ctype<char>::do_toupper(char_type* low, const char_type* high) const
855 for (; low != high; ++low)
856 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
857 *low = isascii(*low) ?
858 static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
859 #elif defined(__GLIBC__)
860 *low = isascii(*low) ? __classic_upper_table()[*low] : *low;
862 *low = (isascii(*low) && islower_l(*low, __cloc())) ? *low-'a'+'A' : *low;
868 ctype<char>::do_tolower(char_type c) const
870 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
872 static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
873 #elif defined(__GLIBC__)
874 return isascii(c) ? __classic_lower_table()[c] : c;
876 return (isascii(c) && isupper_l(c, __cloc())) ? c-'A'+'a' : c;
881 ctype<char>::do_tolower(char_type* low, const char_type* high) const
883 for (; low != high; ++low)
884 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
885 *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;
886 #elif defined(__GLIBC__)
887 *low = isascii(*low) ? __classic_lower_table()[*low] : *low;
889 *low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-'A'+'a' : *low;
895 ctype<char>::do_widen(char c) const
901 ctype<char>::do_widen(const char* low, const char* high, char_type* dest) const
903 for (; low != high; ++low, ++dest)
909 ctype<char>::do_narrow(char_type c, char dfault) const
912 return static_cast<char>(c);
917 ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
919 for (; low != high; ++low, ++dest)
927 const ctype<char>::mask*
928 ctype<char>::classic_table() _NOEXCEPT
930 #if defined(__APPLE__) || defined(__FreeBSD__)
931 return _DefaultRuneLocale.__runetype;
932 #elif defined(__GLIBC__)
933 return __cloc()->__ctype_b;
937 return _ctype+1; // internal ctype mask table defined in msvcrt.dll
938 // This is assumed to be safe, which is a nonsense assumption because we're
939 // going to end up dereferencing it later...
941 // Platform not supported: abort so the person doing the port knows what to
943 # warning ctype<char>::classic_table() is not implemented
949 #if defined(__GLIBC__)
951 ctype<char>::__classic_lower_table() _NOEXCEPT
953 return __cloc()->__ctype_tolower;
957 ctype<char>::__classic_upper_table() _NOEXCEPT
959 return __cloc()->__ctype_toupper;
963 // template <> class ctype_byname<char>
965 ctype_byname<char>::ctype_byname(const char* name, size_t refs)
966 : ctype<char>(0, false, refs),
967 __l(newlocale(LC_ALL_MASK, name, 0))
969 #ifndef _LIBCPP_NO_EXCEPTIONS
971 throw runtime_error("ctype_byname<char>::ctype_byname"
972 " failed to construct for " + string(name));
973 #endif // _LIBCPP_NO_EXCEPTIONS
976 ctype_byname<char>::ctype_byname(const string& name, size_t refs)
977 : ctype<char>(0, false, refs),
978 __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
980 #ifndef _LIBCPP_NO_EXCEPTIONS
982 throw runtime_error("ctype_byname<char>::ctype_byname"
983 " failed to construct for " + name);
984 #endif // _LIBCPP_NO_EXCEPTIONS
987 ctype_byname<char>::~ctype_byname()
993 ctype_byname<char>::do_toupper(char_type c) const
995 return static_cast<char>(toupper_l(c, __l));
999 ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const
1001 for (; low != high; ++low)
1002 *low = static_cast<char>(toupper_l(*low, __l));
1007 ctype_byname<char>::do_tolower(char_type c) const
1009 return static_cast<char>(tolower_l(c, __l));
1013 ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
1015 for (; low != high; ++low)
1016 *low = static_cast<char>(tolower_l(*low, __l));
1020 // template <> class ctype_byname<wchar_t>
1022 ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
1023 : ctype<wchar_t>(refs),
1024 __l(newlocale(LC_ALL_MASK, name, 0))
1026 #ifndef _LIBCPP_NO_EXCEPTIONS
1028 throw runtime_error("ctype_byname<wchar_t>::ctype_byname"
1029 " failed to construct for " + string(name));
1030 #endif // _LIBCPP_NO_EXCEPTIONS
1033 ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)
1034 : ctype<wchar_t>(refs),
1035 __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
1037 #ifndef _LIBCPP_NO_EXCEPTIONS
1039 throw runtime_error("ctype_byname<wchar_t>::ctype_byname"
1040 " failed to construct for " + name);
1041 #endif // _LIBCPP_NO_EXCEPTIONS
1044 ctype_byname<wchar_t>::~ctype_byname()
1050 ctype_byname<wchar_t>::do_is(mask m, char_type c) const
1052 #ifdef _LIBCPP_WCTYPE_IS_MASK
1053 return static_cast<bool>(iswctype_l(c, m, __l));
1055 bool result = false;
1056 if (m & space) result |= (iswspace_l(c, __l) != 0);
1057 if (m & print) result |= (iswprint_l(c, __l) != 0);
1058 if (m & cntrl) result |= (iswcntrl_l(c, __l) != 0);
1059 if (m & upper) result |= (iswupper_l(c, __l) != 0);
1060 if (m & lower) result |= (iswlower_l(c, __l) != 0);
1061 if (m & alpha) result |= (iswalpha_l(c, __l) != 0);
1062 if (m & digit) result |= (iswdigit_l(c, __l) != 0);
1063 if (m & punct) result |= (iswpunct_l(c, __l) != 0);
1064 if (m & xdigit) result |= (iswxdigit_l(c, __l) != 0);
1065 if (m & blank) result |= (iswblank_l(c, __l) != 0);
1071 ctype_byname<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const
1073 for (; low != high; ++low, ++vec)
1076 *vec = static_cast<mask>(ctype<char>::classic_table()[*low]);
1080 if (iswspace_l(*low, __l))
1082 if (iswprint_l(*low, __l))
1084 if (iswcntrl_l(*low, __l))
1086 if (iswupper_l(*low, __l))
1088 if (iswlower_l(*low, __l))
1090 if (iswalpha_l(*low, __l))
1092 if (iswdigit_l(*low, __l))
1094 if (iswpunct_l(*low, __l))
1096 if (iswxdigit_l(*low, __l))
1104 ctype_byname<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const
1106 for (; low != high; ++low)
1108 #ifdef _LIBCPP_WCTYPE_IS_MASK
1109 if (iswctype_l(*low, m, __l))
1112 if (m & space && iswspace_l(*low, __l)) break;
1113 if (m & print && iswprint_l(*low, __l)) break;
1114 if (m & cntrl && iswcntrl_l(*low, __l)) break;
1115 if (m & upper && iswupper_l(*low, __l)) break;
1116 if (m & lower && iswlower_l(*low, __l)) break;
1117 if (m & alpha && iswalpha_l(*low, __l)) break;
1118 if (m & digit && iswdigit_l(*low, __l)) break;
1119 if (m & punct && iswpunct_l(*low, __l)) break;
1120 if (m & xdigit && iswxdigit_l(*low, __l)) break;
1121 if (m & blank && iswblank_l(*low, __l)) break;
1128 ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
1130 for (; low != high; ++low)
1132 #ifdef _LIBCPP_WCTYPE_IS_MASK
1133 if (!iswctype_l(*low, m, __l))
1136 if (m & space && iswspace_l(*low, __l)) continue;
1137 if (m & print && iswprint_l(*low, __l)) continue;
1138 if (m & cntrl && iswcntrl_l(*low, __l)) continue;
1139 if (m & upper && iswupper_l(*low, __l)) continue;
1140 if (m & lower && iswlower_l(*low, __l)) continue;
1141 if (m & alpha && iswalpha_l(*low, __l)) continue;
1142 if (m & digit && iswdigit_l(*low, __l)) continue;
1143 if (m & punct && iswpunct_l(*low, __l)) continue;
1144 if (m & xdigit && iswxdigit_l(*low, __l)) continue;
1145 if (m & blank && iswblank_l(*low, __l)) continue;
1153 ctype_byname<wchar_t>::do_toupper(char_type c) const
1155 return towupper_l(c, __l);
1159 ctype_byname<wchar_t>::do_toupper(char_type* low, const char_type* high) const
1161 for (; low != high; ++low)
1162 *low = towupper_l(*low, __l);
1167 ctype_byname<wchar_t>::do_tolower(char_type c) const
1169 return towlower_l(c, __l);
1173 ctype_byname<wchar_t>::do_tolower(char_type* low, const char_type* high) const
1175 for (; low != high; ++low)
1176 *low = towlower_l(*low, __l);
1181 ctype_byname<wchar_t>::do_widen(char c) const
1183 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1184 return btowc_l(c, __l);
1186 return __btowc_l(c, __l);
1191 ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
1193 for (; low != high; ++low, ++dest)
1194 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1195 *dest = btowc_l(*low, __l);
1197 *dest = __btowc_l(*low, __l);
1203 ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const
1205 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1206 int r = wctob_l(c, __l);
1208 int r = __wctob_l(c, __l);
1210 return r != WEOF ? static_cast<char>(r) : dfault;
1214 ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
1216 for (; low != high; ++low, ++dest)
1218 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1219 int r = wctob_l(*low, __l);
1221 int r = __wctob_l(*low, __l);
1223 *dest = r != WEOF ? static_cast<char>(r) : dfault;
1228 // template <> class codecvt<char, char, mbstate_t>
1230 locale::id codecvt<char, char, mbstate_t>::id;
1232 codecvt<char, char, mbstate_t>::~codecvt()
1236 codecvt<char, char, mbstate_t>::result
1237 codecvt<char, char, mbstate_t>::do_out(state_type&,
1238 const intern_type* frm, const intern_type*, const intern_type*& frm_nxt,
1239 extern_type* to, extern_type*, extern_type*& to_nxt) const
1246 codecvt<char, char, mbstate_t>::result
1247 codecvt<char, char, mbstate_t>::do_in(state_type&,
1248 const extern_type* frm, const extern_type*, const extern_type*& frm_nxt,
1249 intern_type* to, intern_type*, intern_type*& to_nxt) const
1256 codecvt<char, char, mbstate_t>::result
1257 codecvt<char, char, mbstate_t>::do_unshift(state_type&,
1258 extern_type* to, extern_type*, extern_type*& to_nxt) const
1265 codecvt<char, char, mbstate_t>::do_encoding() const _NOEXCEPT
1271 codecvt<char, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
1277 codecvt<char, char, mbstate_t>::do_length(state_type&,
1278 const extern_type* frm, const extern_type* end, size_t mx) const
1280 return static_cast<int>(min<size_t>(mx, static_cast<size_t>(end-frm)));
1284 codecvt<char, char, mbstate_t>::do_max_length() const _NOEXCEPT
1289 // template <> class codecvt<wchar_t, char, mbstate_t>
1291 locale::id codecvt<wchar_t, char, mbstate_t>::id;
1293 codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs)
1294 : locale::facet(refs),
1299 codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs)
1300 : locale::facet(refs),
1301 __l(newlocale(LC_ALL_MASK, nm, 0))
1303 #ifndef _LIBCPP_NO_EXCEPTIONS
1305 throw runtime_error("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname"
1306 " failed to construct for " + string(nm));
1307 #endif // _LIBCPP_NO_EXCEPTIONS
1310 codecvt<wchar_t, char, mbstate_t>::~codecvt()
1316 codecvt<wchar_t, char, mbstate_t>::result
1317 codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
1318 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
1319 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
1321 // look for first internal null in frm
1322 const intern_type* fend = frm;
1323 for (; fend != frm_end; ++fend)
1326 // loop over all null-terminated sequences in frm
1328 for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
1330 // save state in case needed to reover to_nxt on error
1331 mbstate_t save_state = st;
1332 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1333 size_t n = wcsnrtombs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
1334 static_cast<size_t>(to_end-to), &st, __l);
1336 size_t n = __wcsnrtombs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
1338 if (n == size_t(-1))
1340 // need to recover to_nxt
1341 for (to_nxt = to; frm != frm_nxt; ++frm)
1343 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1344 n = wcrtomb_l(to_nxt, *frm, &save_state, __l);
1346 n = __wcrtomb_l(to_nxt, *frm, &save_state, __l);
1348 if (n == size_t(-1))
1358 if (to_nxt == to_end)
1360 if (fend != frm_end) // set up next null terminated sequence
1362 // Try to write the terminating null
1363 extern_type tmp[MB_LEN_MAX];
1364 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1365 n = wcrtomb_l(tmp, intern_type(), &st, __l);
1367 n = __wcrtomb_l(tmp, intern_type(), &st, __l);
1369 if (n == size_t(-1)) // on error
1371 if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
1373 for (extern_type* p = tmp; n; --n) // write it
1376 // look for next null in frm
1377 for (fend = frm_nxt; fend != frm_end; ++fend)
1382 return frm_nxt == frm_end ? ok : partial;
1385 codecvt<wchar_t, char, mbstate_t>::result
1386 codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
1387 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
1388 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
1390 // look for first internal null in frm
1391 const extern_type* fend = frm;
1392 for (; fend != frm_end; ++fend)
1395 // loop over all null-terminated sequences in frm
1397 for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
1399 // save state in case needed to reover to_nxt on error
1400 mbstate_t save_state = st;
1401 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1402 size_t n = mbsnrtowcs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
1403 static_cast<size_t>(to_end-to), &st, __l);
1405 size_t n = __mbsnrtowcs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
1407 if (n == size_t(-1))
1409 // need to recover to_nxt
1410 for (to_nxt = to; frm != frm_nxt; ++to_nxt)
1412 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1413 n = mbrtowc_l(to_nxt, frm, static_cast<size_t>(fend-frm),
1416 n = __mbrtowc_l(to_nxt, frm, fend-frm, &save_state, __l);
1435 return frm_nxt == frm_end ? ok : partial;
1440 if (to_nxt == to_end)
1442 if (fend != frm_end) // set up next null terminated sequence
1444 // Try to write the terminating null
1445 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1446 n = mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l);
1448 n = __mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l);
1450 if (n != 0) // on error
1454 // look for next null in frm
1455 for (fend = frm_nxt; fend != frm_end; ++fend)
1460 return frm_nxt == frm_end ? ok : partial;
1463 codecvt<wchar_t, char, mbstate_t>::result
1464 codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st,
1465 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
1468 extern_type tmp[MB_LEN_MAX];
1469 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1470 size_t n = wcrtomb_l(tmp, intern_type(), &st, __l);
1472 size_t n = __wcrtomb_l(tmp, intern_type(), &st, __l);
1474 if (n == size_t(-1) || n == 0) // on error
1477 if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
1479 for (extern_type* p = tmp; n; --n) // write it
1485 codecvt<wchar_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
1487 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1488 if (mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
1490 if (__mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
1493 // stateless encoding
1494 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1495 if (__l == 0 || MB_CUR_MAX_L(__l) == 1) // there are no known constant length encodings
1497 if (__l == 0 || __mb_cur_max_l(__l) == 1) // there are no known constant length encodings
1499 return 1; // which take more than 1 char to form a wchar_t
1506 codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
1512 codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st,
1513 const extern_type* frm, const extern_type* frm_end, size_t mx) const
1516 for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t)
1518 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1519 size_t n = mbrlen_l(frm, static_cast<size_t>(frm_end-frm), &st, __l);
1521 size_t n = __mbrlen_l(frm, frm_end-frm, &st, __l);
1542 codecvt<wchar_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
1544 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1545 return __l == 0 ? 1 : MB_CUR_MAX_L(__l);
1547 return __l == 0 ? 1 : __mb_cur_max_l(__l);
1552 // UTF-32 UTF-16 UTF-8 # of code points
1553 // first second first second third fourth
1554 // 000000 - 00007F 0000 - 007F 00 - 7F 127
1555 // 000080 - 0007FF 0080 - 07FF C2 - DF, 80 - BF 1920
1556 // 000800 - 000FFF 0800 - 0FFF E0 - E0, A0 - BF, 80 - BF 2048
1557 // 001000 - 00CFFF 1000 - CFFF E1 - EC, 80 - BF, 80 - BF 49152
1558 // 00D000 - 00D7FF D000 - D7FF ED - ED, 80 - 9F, 80 - BF 2048
1559 // 00D800 - 00DFFF invalid
1560 // 00E000 - 00FFFF E000 - FFFF EE - EF, 80 - BF, 80 - BF 8192
1561 // 010000 - 03FFFF D800 - D8BF, DC00 - DFFF F0 - F0, 90 - BF, 80 - BF, 80 - BF 196608
1562 // 040000 - 0FFFFF D8C0 - DBBF, DC00 - DFFF F1 - F3, 80 - BF, 80 - BF, 80 - BF 786432
1563 // 100000 - 10FFFF DBC0 - DBFF, DC00 - DFFF F4 - F4, 80 - 8F, 80 - BF, 80 - BF 65536
1566 codecvt_base::result
1567 utf16_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
1568 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
1569 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1573 if (mode & generate_header)
1575 if (to_end-to_nxt < 3)
1576 return codecvt_base::partial;
1577 *to_nxt++ = static_cast<uint8_t>(0xEF);
1578 *to_nxt++ = static_cast<uint8_t>(0xBB);
1579 *to_nxt++ = static_cast<uint8_t>(0xBF);
1581 for (; frm_nxt < frm_end; ++frm_nxt)
1583 uint16_t wc1 = *frm_nxt;
1585 return codecvt_base::error;
1588 if (to_end-to_nxt < 1)
1589 return codecvt_base::partial;
1590 *to_nxt++ = static_cast<uint8_t>(wc1);
1592 else if (wc1 < 0x0800)
1594 if (to_end-to_nxt < 2)
1595 return codecvt_base::partial;
1596 *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
1597 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
1599 else if (wc1 < 0xD800)
1601 if (to_end-to_nxt < 3)
1602 return codecvt_base::partial;
1603 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1604 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1605 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1607 else if (wc1 < 0xDC00)
1609 if (frm_end-frm_nxt < 2)
1610 return codecvt_base::partial;
1611 uint16_t wc2 = frm_nxt[1];
1612 if ((wc2 & 0xFC00) != 0xDC00)
1613 return codecvt_base::error;
1614 if (to_end-to_nxt < 4)
1615 return codecvt_base::partial;
1616 if ((((((unsigned long)wc1 & 0x03C0) >> 6) + 1) << 16) +
1617 (((unsigned long)wc1 & 0x003F) << 10) + (wc2 & 0x03FF) > Maxcode)
1618 return codecvt_base::error;
1620 uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
1621 *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
1622 *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
1623 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
1624 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
1626 else if (wc1 < 0xE000)
1628 return codecvt_base::error;
1632 if (to_end-to_nxt < 3)
1633 return codecvt_base::partial;
1634 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1635 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1636 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1639 return codecvt_base::ok;
1643 codecvt_base::result
1644 utf16_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
1645 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
1646 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1650 if (mode & generate_header)
1652 if (to_end-to_nxt < 3)
1653 return codecvt_base::partial;
1654 *to_nxt++ = static_cast<uint8_t>(0xEF);
1655 *to_nxt++ = static_cast<uint8_t>(0xBB);
1656 *to_nxt++ = static_cast<uint8_t>(0xBF);
1658 for (; frm_nxt < frm_end; ++frm_nxt)
1660 uint16_t wc1 = static_cast<uint16_t>(*frm_nxt);
1662 return codecvt_base::error;
1665 if (to_end-to_nxt < 1)
1666 return codecvt_base::partial;
1667 *to_nxt++ = static_cast<uint8_t>(wc1);
1669 else if (wc1 < 0x0800)
1671 if (to_end-to_nxt < 2)
1672 return codecvt_base::partial;
1673 *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
1674 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
1676 else if (wc1 < 0xD800)
1678 if (to_end-to_nxt < 3)
1679 return codecvt_base::partial;
1680 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1681 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1682 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1684 else if (wc1 < 0xDC00)
1686 if (frm_end-frm_nxt < 2)
1687 return codecvt_base::partial;
1688 uint16_t wc2 = static_cast<uint16_t>(frm_nxt[1]);
1689 if ((wc2 & 0xFC00) != 0xDC00)
1690 return codecvt_base::error;
1691 if (to_end-to_nxt < 4)
1692 return codecvt_base::partial;
1693 if ((((((unsigned long)wc1 & 0x03C0) >> 6) + 1) << 16) +
1694 (((unsigned long)wc1 & 0x003F) << 10) + (wc2 & 0x03FF) > Maxcode)
1695 return codecvt_base::error;
1697 uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
1698 *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
1699 *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
1700 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
1701 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
1703 else if (wc1 < 0xE000)
1705 return codecvt_base::error;
1709 if (to_end-to_nxt < 3)
1710 return codecvt_base::partial;
1711 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1712 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1713 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1716 return codecvt_base::ok;
1720 codecvt_base::result
1721 utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
1722 uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
1723 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1727 if (mode & consume_header)
1729 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
1733 for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
1735 uint8_t c1 = *frm_nxt;
1737 return codecvt_base::error;
1740 *to_nxt = static_cast<uint16_t>(c1);
1745 return codecvt_base::error;
1749 if (frm_end-frm_nxt < 2)
1750 return codecvt_base::partial;
1751 uint8_t c2 = frm_nxt[1];
1752 if ((c2 & 0xC0) != 0x80)
1753 return codecvt_base::error;
1754 uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
1756 return codecvt_base::error;
1762 if (frm_end-frm_nxt < 3)
1763 return codecvt_base::partial;
1764 uint8_t c2 = frm_nxt[1];
1765 uint8_t c3 = frm_nxt[2];
1769 if ((c2 & 0xE0) != 0xA0)
1770 return codecvt_base::error;
1773 if ((c2 & 0xE0) != 0x80)
1774 return codecvt_base::error;
1777 if ((c2 & 0xC0) != 0x80)
1778 return codecvt_base::error;
1781 if ((c3 & 0xC0) != 0x80)
1782 return codecvt_base::error;
1783 uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
1784 | ((c2 & 0x3F) << 6)
1787 return codecvt_base::error;
1793 if (frm_end-frm_nxt < 4)
1794 return codecvt_base::partial;
1795 uint8_t c2 = frm_nxt[1];
1796 uint8_t c3 = frm_nxt[2];
1797 uint8_t c4 = frm_nxt[3];
1801 if (!(0x90 <= c2 && c2 <= 0xBF))
1802 return codecvt_base::error;
1805 if ((c2 & 0xF0) != 0x80)
1806 return codecvt_base::error;
1809 if ((c2 & 0xC0) != 0x80)
1810 return codecvt_base::error;
1813 if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
1814 return codecvt_base::error;
1815 if (to_end-to_nxt < 2)
1816 return codecvt_base::partial;
1817 if (((((unsigned long)c1 & 7) << 18) +
1818 (((unsigned long)c2 & 0x3F) << 12) +
1819 (((unsigned long)c3 & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode)
1820 return codecvt_base::error;
1821 *to_nxt = static_cast<uint16_t>(
1823 | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
1824 | ((c2 & 0x0F) << 2)
1825 | ((c3 & 0x30) >> 4));
1826 *++to_nxt = static_cast<uint16_t>(
1828 | ((c3 & 0x0F) << 6)
1834 return codecvt_base::error;
1837 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
1841 codecvt_base::result
1842 utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
1843 uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
1844 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1848 if (mode & consume_header)
1850 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
1854 for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
1856 uint8_t c1 = *frm_nxt;
1858 return codecvt_base::error;
1861 *to_nxt = static_cast<uint32_t>(c1);
1866 return codecvt_base::error;
1870 if (frm_end-frm_nxt < 2)
1871 return codecvt_base::partial;
1872 uint8_t c2 = frm_nxt[1];
1873 if ((c2 & 0xC0) != 0x80)
1874 return codecvt_base::error;
1875 uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
1877 return codecvt_base::error;
1878 *to_nxt = static_cast<uint32_t>(t);
1883 if (frm_end-frm_nxt < 3)
1884 return codecvt_base::partial;
1885 uint8_t c2 = frm_nxt[1];
1886 uint8_t c3 = frm_nxt[2];
1890 if ((c2 & 0xE0) != 0xA0)
1891 return codecvt_base::error;
1894 if ((c2 & 0xE0) != 0x80)
1895 return codecvt_base::error;
1898 if ((c2 & 0xC0) != 0x80)
1899 return codecvt_base::error;
1902 if ((c3 & 0xC0) != 0x80)
1903 return codecvt_base::error;
1904 uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
1905 | ((c2 & 0x3F) << 6)
1908 return codecvt_base::error;
1909 *to_nxt = static_cast<uint32_t>(t);
1914 if (frm_end-frm_nxt < 4)
1915 return codecvt_base::partial;
1916 uint8_t c2 = frm_nxt[1];
1917 uint8_t c3 = frm_nxt[2];
1918 uint8_t c4 = frm_nxt[3];
1922 if (!(0x90 <= c2 && c2 <= 0xBF))
1923 return codecvt_base::error;
1926 if ((c2 & 0xF0) != 0x80)
1927 return codecvt_base::error;
1930 if ((c2 & 0xC0) != 0x80)
1931 return codecvt_base::error;
1934 if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
1935 return codecvt_base::error;
1936 if (to_end-to_nxt < 2)
1937 return codecvt_base::partial;
1938 if (((((unsigned long)c1 & 7) << 18) +
1939 (((unsigned long)c2 & 0x3F) << 12) +
1940 (((unsigned long)c3 & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode)
1941 return codecvt_base::error;
1942 *to_nxt = static_cast<uint32_t>(
1944 | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
1945 | ((c2 & 0x0F) << 2)
1946 | ((c3 & 0x30) >> 4));
1947 *++to_nxt = static_cast<uint32_t>(
1949 | ((c3 & 0x0F) << 6)
1955 return codecvt_base::error;
1958 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
1963 utf8_to_utf16_length(const uint8_t* frm, const uint8_t* frm_end,
1964 size_t mx, unsigned long Maxcode = 0x10FFFF,
1965 codecvt_mode mode = codecvt_mode(0))
1967 const uint8_t* frm_nxt = frm;
1968 if (mode & consume_header)
1970 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
1974 for (size_t nchar16_t = 0; frm_nxt < frm_end && nchar16_t < mx; ++nchar16_t)
1976 uint8_t c1 = *frm_nxt;
1989 if ((frm_end-frm_nxt < 2) || (frm_nxt[1] & 0xC0) != 0x80)
1991 uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F));
1998 if (frm_end-frm_nxt < 3)
2000 uint8_t c2 = frm_nxt[1];
2001 uint8_t c3 = frm_nxt[2];
2005 if ((c2 & 0xE0) != 0xA0)
2006 return static_cast<int>(frm_nxt - frm);
2009 if ((c2 & 0xE0) != 0x80)
2010 return static_cast<int>(frm_nxt - frm);
2013 if ((c2 & 0xC0) != 0x80)
2014 return static_cast<int>(frm_nxt - frm);
2017 if ((c3 & 0xC0) != 0x80)
2019 if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
2025 if (frm_end-frm_nxt < 4 || mx-nchar16_t < 2)
2027 uint8_t c2 = frm_nxt[1];
2028 uint8_t c3 = frm_nxt[2];
2029 uint8_t c4 = frm_nxt[3];
2033 if (!(0x90 <= c2 && c2 <= 0xBF))
2034 return static_cast<int>(frm_nxt - frm);
2037 if ((c2 & 0xF0) != 0x80)
2038 return static_cast<int>(frm_nxt - frm);
2041 if ((c2 & 0xC0) != 0x80)
2042 return static_cast<int>(frm_nxt - frm);
2045 if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2047 if (((((unsigned long)c1 & 7) << 18) +
2048 (((unsigned long)c2 & 0x3F) << 12) +
2049 (((unsigned long)c3 & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode)
2059 return static_cast<int>(frm_nxt - frm);
2063 codecvt_base::result
2064 ucs4_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
2065 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2066 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2070 if (mode & generate_header)
2072 if (to_end-to_nxt < 3)
2073 return codecvt_base::partial;
2074 *to_nxt++ = static_cast<uint8_t>(0xEF);
2075 *to_nxt++ = static_cast<uint8_t>(0xBB);
2076 *to_nxt++ = static_cast<uint8_t>(0xBF);
2078 for (; frm_nxt < frm_end; ++frm_nxt)
2080 uint32_t wc = *frm_nxt;
2081 if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
2082 return codecvt_base::error;
2085 if (to_end-to_nxt < 1)
2086 return codecvt_base::partial;
2087 *to_nxt++ = static_cast<uint8_t>(wc);
2089 else if (wc < 0x000800)
2091 if (to_end-to_nxt < 2)
2092 return codecvt_base::partial;
2093 *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
2094 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
2096 else if (wc < 0x010000)
2098 if (to_end-to_nxt < 3)
2099 return codecvt_base::partial;
2100 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
2101 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
2102 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
2104 else // if (wc < 0x110000)
2106 if (to_end-to_nxt < 4)
2107 return codecvt_base::partial;
2108 *to_nxt++ = static_cast<uint8_t>(0xF0 | (wc >> 18));
2109 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x03F000) >> 12));
2110 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x000FC0) >> 6));
2111 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x00003F));
2114 return codecvt_base::ok;
2118 codecvt_base::result
2119 utf8_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2120 uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2121 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2125 if (mode & consume_header)
2127 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2131 for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
2133 uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2137 return codecvt_base::error;
2138 *to_nxt = static_cast<uint32_t>(c1);
2143 return codecvt_base::error;
2147 if (frm_end-frm_nxt < 2)
2148 return codecvt_base::partial;
2149 uint8_t c2 = frm_nxt[1];
2150 if ((c2 & 0xC0) != 0x80)
2151 return codecvt_base::error;
2152 uint32_t t = static_cast<uint32_t>(((c1 & 0x1F) << 6)
2155 return codecvt_base::error;
2161 if (frm_end-frm_nxt < 3)
2162 return codecvt_base::partial;
2163 uint8_t c2 = frm_nxt[1];
2164 uint8_t c3 = frm_nxt[2];
2168 if ((c2 & 0xE0) != 0xA0)
2169 return codecvt_base::error;
2172 if ((c2 & 0xE0) != 0x80)
2173 return codecvt_base::error;
2176 if ((c2 & 0xC0) != 0x80)
2177 return codecvt_base::error;
2180 if ((c3 & 0xC0) != 0x80)
2181 return codecvt_base::error;
2182 uint32_t t = static_cast<uint32_t>(((c1 & 0x0F) << 12)
2183 | ((c2 & 0x3F) << 6)
2186 return codecvt_base::error;
2192 if (frm_end-frm_nxt < 4)
2193 return codecvt_base::partial;
2194 uint8_t c2 = frm_nxt[1];
2195 uint8_t c3 = frm_nxt[2];
2196 uint8_t c4 = frm_nxt[3];
2200 if (!(0x90 <= c2 && c2 <= 0xBF))
2201 return codecvt_base::error;
2204 if ((c2 & 0xF0) != 0x80)
2205 return codecvt_base::error;
2208 if ((c2 & 0xC0) != 0x80)
2209 return codecvt_base::error;
2212 if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2213 return codecvt_base::error;
2214 uint32_t t = static_cast<uint32_t>(((c1 & 0x07) << 18)
2215 | ((c2 & 0x3F) << 12)
2216 | ((c3 & 0x3F) << 6)
2219 return codecvt_base::error;
2225 return codecvt_base::error;
2228 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2233 utf8_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
2234 size_t mx, unsigned long Maxcode = 0x10FFFF,
2235 codecvt_mode mode = codecvt_mode(0))
2237 const uint8_t* frm_nxt = frm;
2238 if (mode & consume_header)
2240 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2244 for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
2246 uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2259 if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
2261 if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
2267 if (frm_end-frm_nxt < 3)
2269 uint8_t c2 = frm_nxt[1];
2270 uint8_t c3 = frm_nxt[2];
2274 if ((c2 & 0xE0) != 0xA0)
2275 return static_cast<int>(frm_nxt - frm);
2278 if ((c2 & 0xE0) != 0x80)
2279 return static_cast<int>(frm_nxt - frm);
2282 if ((c2 & 0xC0) != 0x80)
2283 return static_cast<int>(frm_nxt - frm);
2286 if ((c3 & 0xC0) != 0x80)
2288 if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
2294 if (frm_end-frm_nxt < 4)
2296 uint8_t c2 = frm_nxt[1];
2297 uint8_t c3 = frm_nxt[2];
2298 uint8_t c4 = frm_nxt[3];
2302 if (!(0x90 <= c2 && c2 <= 0xBF))
2303 return static_cast<int>(frm_nxt - frm);
2306 if ((c2 & 0xF0) != 0x80)
2307 return static_cast<int>(frm_nxt - frm);
2310 if ((c2 & 0xC0) != 0x80)
2311 return static_cast<int>(frm_nxt - frm);
2314 if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2316 if ((((c1 & 0x07u) << 18) | ((c2 & 0x3Fu) << 12) |
2317 ((c3 & 0x3Fu) << 6) | (c4 & 0x3Fu)) > Maxcode)
2326 return static_cast<int>(frm_nxt - frm);
2330 codecvt_base::result
2331 ucs2_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
2332 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2333 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2337 if (mode & generate_header)
2339 if (to_end-to_nxt < 3)
2340 return codecvt_base::partial;
2341 *to_nxt++ = static_cast<uint8_t>(0xEF);
2342 *to_nxt++ = static_cast<uint8_t>(0xBB);
2343 *to_nxt++ = static_cast<uint8_t>(0xBF);
2345 for (; frm_nxt < frm_end; ++frm_nxt)
2347 uint16_t wc = *frm_nxt;
2348 if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
2349 return codecvt_base::error;
2352 if (to_end-to_nxt < 1)
2353 return codecvt_base::partial;
2354 *to_nxt++ = static_cast<uint8_t>(wc);
2356 else if (wc < 0x0800)
2358 if (to_end-to_nxt < 2)
2359 return codecvt_base::partial;
2360 *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
2361 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
2363 else // if (wc <= 0xFFFF)
2365 if (to_end-to_nxt < 3)
2366 return codecvt_base::partial;
2367 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
2368 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
2369 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
2372 return codecvt_base::ok;
2376 codecvt_base::result
2377 utf8_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2378 uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
2379 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2383 if (mode & consume_header)
2385 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2389 for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
2391 uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2395 return codecvt_base::error;
2396 *to_nxt = static_cast<uint16_t>(c1);
2401 return codecvt_base::error;
2405 if (frm_end-frm_nxt < 2)
2406 return codecvt_base::partial;
2407 uint8_t c2 = frm_nxt[1];
2408 if ((c2 & 0xC0) != 0x80)
2409 return codecvt_base::error;
2410 uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6)
2413 return codecvt_base::error;
2419 if (frm_end-frm_nxt < 3)
2420 return codecvt_base::partial;
2421 uint8_t c2 = frm_nxt[1];
2422 uint8_t c3 = frm_nxt[2];
2426 if ((c2 & 0xE0) != 0xA0)
2427 return codecvt_base::error;
2430 if ((c2 & 0xE0) != 0x80)
2431 return codecvt_base::error;
2434 if ((c2 & 0xC0) != 0x80)
2435 return codecvt_base::error;
2438 if ((c3 & 0xC0) != 0x80)
2439 return codecvt_base::error;
2440 uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
2441 | ((c2 & 0x3F) << 6)
2444 return codecvt_base::error;
2450 return codecvt_base::error;
2453 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2458 utf8_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
2459 size_t mx, unsigned long Maxcode = 0x10FFFF,
2460 codecvt_mode mode = codecvt_mode(0))
2462 const uint8_t* frm_nxt = frm;
2463 if (mode & consume_header)
2465 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2469 for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
2471 uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2484 if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
2486 if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
2492 if (frm_end-frm_nxt < 3)
2494 uint8_t c2 = frm_nxt[1];
2495 uint8_t c3 = frm_nxt[2];
2499 if ((c2 & 0xE0) != 0xA0)
2500 return static_cast<int>(frm_nxt - frm);
2503 if ((c2 & 0xE0) != 0x80)
2504 return static_cast<int>(frm_nxt - frm);
2507 if ((c2 & 0xC0) != 0x80)
2508 return static_cast<int>(frm_nxt - frm);
2511 if ((c3 & 0xC0) != 0x80)
2513 if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
2522 return static_cast<int>(frm_nxt - frm);
2526 codecvt_base::result
2527 ucs4_to_utf16be(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
2528 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2529 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2533 if (mode & generate_header)
2535 if (to_end-to_nxt < 2)
2536 return codecvt_base::partial;
2537 *to_nxt++ = static_cast<uint8_t>(0xFE);
2538 *to_nxt++ = static_cast<uint8_t>(0xFF);
2540 for (; frm_nxt < frm_end; ++frm_nxt)
2542 uint32_t wc = *frm_nxt;
2543 if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
2544 return codecvt_base::error;
2547 if (to_end-to_nxt < 2)
2548 return codecvt_base::partial;
2549 *to_nxt++ = static_cast<uint8_t>(wc >> 8);
2550 *to_nxt++ = static_cast<uint8_t>(wc);
2554 if (to_end-to_nxt < 4)
2555 return codecvt_base::partial;
2556 uint16_t t = static_cast<uint16_t>(
2558 | ((((wc & 0x1F0000) >> 16) - 1) << 6)
2559 | ((wc & 0x00FC00) >> 10));
2560 *to_nxt++ = static_cast<uint8_t>(t >> 8);
2561 *to_nxt++ = static_cast<uint8_t>(t);
2562 t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
2563 *to_nxt++ = static_cast<uint8_t>(t >> 8);
2564 *to_nxt++ = static_cast<uint8_t>(t);
2567 return codecvt_base::ok;
2571 codecvt_base::result
2572 utf16be_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2573 uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2574 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2578 if (mode & consume_header)
2580 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2583 for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2585 uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2586 if ((c1 & 0xFC00) == 0xDC00)
2587 return codecvt_base::error;
2588 if ((c1 & 0xFC00) != 0xD800)
2591 return codecvt_base::error;
2592 *to_nxt = static_cast<uint32_t>(c1);
2597 if (frm_end-frm_nxt < 4)
2598 return codecvt_base::partial;
2599 uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
2600 if ((c2 & 0xFC00) != 0xDC00)
2601 return codecvt_base::error;
2602 uint32_t t = static_cast<uint32_t>(
2603 ((((c1 & 0x03C0) >> 6) + 1) << 16)
2604 | ((c1 & 0x003F) << 10)
2607 return codecvt_base::error;
2612 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2617 utf16be_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
2618 size_t mx, unsigned long Maxcode = 0x10FFFF,
2619 codecvt_mode mode = codecvt_mode(0))
2621 const uint8_t* frm_nxt = frm;
2623 if (mode & consume_header)
2625 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2628 for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
2630 uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2631 if ((c1 & 0xFC00) == 0xDC00)
2633 if ((c1 & 0xFC00) != 0xD800)
2641 if (frm_end-frm_nxt < 4)
2643 uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
2644 if ((c2 & 0xFC00) != 0xDC00)
2646 uint32_t t = static_cast<uint32_t>(
2647 ((((c1 & 0x03C0) >> 6) + 1) << 16)
2648 | ((c1 & 0x003F) << 10)
2655 return static_cast<int>(frm_nxt - frm);
2659 codecvt_base::result
2660 ucs4_to_utf16le(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
2661 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2662 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2666 if (mode & generate_header)
2668 if (to_end-to_nxt < 2)
2669 return codecvt_base::partial;
2670 *to_nxt++ = static_cast<uint8_t>(0xFF);
2671 *to_nxt++ = static_cast<uint8_t>(0xFE);
2673 for (; frm_nxt < frm_end; ++frm_nxt)
2675 uint32_t wc = *frm_nxt;
2676 if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
2677 return codecvt_base::error;
2680 if (to_end-to_nxt < 2)
2681 return codecvt_base::partial;
2682 *to_nxt++ = static_cast<uint8_t>(wc);
2683 *to_nxt++ = static_cast<uint8_t>(wc >> 8);
2687 if (to_end-to_nxt < 4)
2688 return codecvt_base::partial;
2689 uint16_t t = static_cast<uint16_t>(
2691 | ((((wc & 0x1F0000) >> 16) - 1) << 6)
2692 | ((wc & 0x00FC00) >> 10));
2693 *to_nxt++ = static_cast<uint8_t>(t);
2694 *to_nxt++ = static_cast<uint8_t>(t >> 8);
2695 t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
2696 *to_nxt++ = static_cast<uint8_t>(t);
2697 *to_nxt++ = static_cast<uint8_t>(t >> 8);
2700 return codecvt_base::ok;
2704 codecvt_base::result
2705 utf16le_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2706 uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2707 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2711 if (mode & consume_header)
2713 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
2716 for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2718 uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
2719 if ((c1 & 0xFC00) == 0xDC00)
2720 return codecvt_base::error;
2721 if ((c1 & 0xFC00) != 0xD800)
2724 return codecvt_base::error;
2725 *to_nxt = static_cast<uint32_t>(c1);
2730 if (frm_end-frm_nxt < 4)
2731 return codecvt_base::partial;
2732 uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
2733 if ((c2 & 0xFC00) != 0xDC00)
2734 return codecvt_base::error;
2735 uint32_t t = static_cast<uint32_t>(
2736 ((((c1 & 0x03C0) >> 6) + 1) << 16)
2737 | ((c1 & 0x003F) << 10)
2740 return codecvt_base::error;
2745 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2750 utf16le_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
2751 size_t mx, unsigned long Maxcode = 0x10FFFF,
2752 codecvt_mode mode = codecvt_mode(0))
2754 const uint8_t* frm_nxt = frm;
2756 if (mode & consume_header)
2758 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
2761 for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
2763 uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
2764 if ((c1 & 0xFC00) == 0xDC00)
2766 if ((c1 & 0xFC00) != 0xD800)
2774 if (frm_end-frm_nxt < 4)
2776 uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
2777 if ((c2 & 0xFC00) != 0xDC00)
2779 uint32_t t = static_cast<uint32_t>(
2780 ((((c1 & 0x03C0) >> 6) + 1) << 16)
2781 | ((c1 & 0x003F) << 10)
2788 return static_cast<int>(frm_nxt - frm);
2792 codecvt_base::result
2793 ucs2_to_utf16be(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
2794 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2795 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2799 if (mode & generate_header)
2801 if (to_end-to_nxt < 2)
2802 return codecvt_base::partial;
2803 *to_nxt++ = static_cast<uint8_t>(0xFE);
2804 *to_nxt++ = static_cast<uint8_t>(0xFF);
2806 for (; frm_nxt < frm_end; ++frm_nxt)
2808 uint16_t wc = *frm_nxt;
2809 if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
2810 return codecvt_base::error;
2811 if (to_end-to_nxt < 2)
2812 return codecvt_base::partial;
2813 *to_nxt++ = static_cast<uint8_t>(wc >> 8);
2814 *to_nxt++ = static_cast<uint8_t>(wc);
2816 return codecvt_base::ok;
2820 codecvt_base::result
2821 utf16be_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2822 uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
2823 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2827 if (mode & consume_header)
2829 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2832 for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2834 uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2835 if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
2836 return codecvt_base::error;
2840 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2845 utf16be_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
2846 size_t mx, unsigned long Maxcode = 0x10FFFF,
2847 codecvt_mode mode = codecvt_mode(0))
2849 const uint8_t* frm_nxt = frm;
2851 if (mode & consume_header)
2853 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2856 for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
2858 uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2859 if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
2863 return static_cast<int>(frm_nxt - frm);
2867 codecvt_base::result
2868 ucs2_to_utf16le(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
2869 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2870 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2874 if (mode & generate_header)
2876 if (to_end-to_nxt < 2)
2877 return codecvt_base::partial;
2878 *to_nxt++ = static_cast<uint8_t>(0xFF);
2879 *to_nxt++ = static_cast<uint8_t>(0xFE);
2881 for (; frm_nxt < frm_end; ++frm_nxt)
2883 uint16_t wc = *frm_nxt;
2884 if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
2885 return codecvt_base::error;
2886 if (to_end-to_nxt < 2)
2887 return codecvt_base::partial;
2888 *to_nxt++ = static_cast<uint8_t>(wc);
2889 *to_nxt++ = static_cast<uint8_t>(wc >> 8);
2891 return codecvt_base::ok;
2895 codecvt_base::result
2896 utf16le_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2897 uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
2898 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2902 if (mode & consume_header)
2904 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
2907 for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2909 uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
2910 if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
2911 return codecvt_base::error;
2915 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2920 utf16le_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
2921 size_t mx, unsigned long Maxcode = 0x10FFFF,
2922 codecvt_mode mode = codecvt_mode(0))
2924 const uint8_t* frm_nxt = frm;
2926 if (mode & consume_header)
2928 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
2931 for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
2933 uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
2934 if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
2938 return static_cast<int>(frm_nxt - frm);
2941 // template <> class codecvt<char16_t, char, mbstate_t>
2943 locale::id codecvt<char16_t, char, mbstate_t>::id;
2945 codecvt<char16_t, char, mbstate_t>::~codecvt()
2949 codecvt<char16_t, char, mbstate_t>::result
2950 codecvt<char16_t, char, mbstate_t>::do_out(state_type&,
2951 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
2952 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
2954 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
2955 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
2956 const uint16_t* _frm_nxt = _frm;
2957 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
2958 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
2959 uint8_t* _to_nxt = _to;
2960 result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
2961 frm_nxt = frm + (_frm_nxt - _frm);
2962 to_nxt = to + (_to_nxt - _to);
2966 codecvt<char16_t, char, mbstate_t>::result
2967 codecvt<char16_t, char, mbstate_t>::do_in(state_type&,
2968 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
2969 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
2971 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
2972 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
2973 const uint8_t* _frm_nxt = _frm;
2974 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
2975 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
2976 uint16_t* _to_nxt = _to;
2977 result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
2978 frm_nxt = frm + (_frm_nxt - _frm);
2979 to_nxt = to + (_to_nxt - _to);
2983 codecvt<char16_t, char, mbstate_t>::result
2984 codecvt<char16_t, char, mbstate_t>::do_unshift(state_type&,
2985 extern_type* to, extern_type*, extern_type*& to_nxt) const
2992 codecvt<char16_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
2998 codecvt<char16_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
3004 codecvt<char16_t, char, mbstate_t>::do_length(state_type&,
3005 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3007 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3008 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3009 return utf8_to_utf16_length(_frm, _frm_end, mx);
3013 codecvt<char16_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
3018 // template <> class codecvt<char32_t, char, mbstate_t>
3020 locale::id codecvt<char32_t, char, mbstate_t>::id;
3022 codecvt<char32_t, char, mbstate_t>::~codecvt()
3026 codecvt<char32_t, char, mbstate_t>::result
3027 codecvt<char32_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 uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3032 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3033 const uint32_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 = ucs4_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<char32_t, char, mbstate_t>::result
3044 codecvt<char32_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 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3052 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3053 uint32_t* _to_nxt = _to;
3054 result r = utf8_to_ucs4(_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<char32_t, char, mbstate_t>::result
3061 codecvt<char32_t, char, mbstate_t>::do_unshift(state_type&,
3062 extern_type* to, extern_type*, extern_type*& to_nxt) const
3069 codecvt<char32_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
3075 codecvt<char32_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
3081 codecvt<char32_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_ucs4_length(_frm, _frm_end, mx);
3090 codecvt<char32_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
3095 // __codecvt_utf8<wchar_t>
3097 __codecvt_utf8<wchar_t>::result
3098 __codecvt_utf8<wchar_t>::do_out(state_type&,
3099 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3100 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3102 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3103 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3104 const uint32_t* _frm_nxt = _frm;
3105 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3106 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3107 uint8_t* _to_nxt = _to;
3108 result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3110 frm_nxt = frm + (_frm_nxt - _frm);
3111 to_nxt = to + (_to_nxt - _to);
3115 __codecvt_utf8<wchar_t>::result
3116 __codecvt_utf8<wchar_t>::do_in(state_type&,
3117 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3118 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3120 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3121 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3122 const uint8_t* _frm_nxt = _frm;
3123 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3124 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3125 uint32_t* _to_nxt = _to;
3126 result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3128 frm_nxt = frm + (_frm_nxt - _frm);
3129 to_nxt = to + (_to_nxt - _to);
3133 __codecvt_utf8<wchar_t>::result
3134 __codecvt_utf8<wchar_t>::do_unshift(state_type&,
3135 extern_type* to, extern_type*, extern_type*& to_nxt) const
3142 __codecvt_utf8<wchar_t>::do_encoding() const _NOEXCEPT
3148 __codecvt_utf8<wchar_t>::do_always_noconv() const _NOEXCEPT
3154 __codecvt_utf8<wchar_t>::do_length(state_type&,
3155 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3157 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3158 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3159 return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3163 __codecvt_utf8<wchar_t>::do_max_length() const _NOEXCEPT
3165 if (_Mode_ & consume_header)
3170 // __codecvt_utf8<char16_t>
3172 __codecvt_utf8<char16_t>::result
3173 __codecvt_utf8<char16_t>::do_out(state_type&,
3174 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3175 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3177 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3178 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3179 const uint16_t* _frm_nxt = _frm;
3180 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3181 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3182 uint8_t* _to_nxt = _to;
3183 result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3185 frm_nxt = frm + (_frm_nxt - _frm);
3186 to_nxt = to + (_to_nxt - _to);
3190 __codecvt_utf8<char16_t>::result
3191 __codecvt_utf8<char16_t>::do_in(state_type&,
3192 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3193 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3195 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3196 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3197 const uint8_t* _frm_nxt = _frm;
3198 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3199 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3200 uint16_t* _to_nxt = _to;
3201 result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3203 frm_nxt = frm + (_frm_nxt - _frm);
3204 to_nxt = to + (_to_nxt - _to);
3208 __codecvt_utf8<char16_t>::result
3209 __codecvt_utf8<char16_t>::do_unshift(state_type&,
3210 extern_type* to, extern_type*, extern_type*& to_nxt) const
3217 __codecvt_utf8<char16_t>::do_encoding() const _NOEXCEPT
3223 __codecvt_utf8<char16_t>::do_always_noconv() const _NOEXCEPT
3229 __codecvt_utf8<char16_t>::do_length(state_type&,
3230 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3232 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3233 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3234 return utf8_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3238 __codecvt_utf8<char16_t>::do_max_length() const _NOEXCEPT
3240 if (_Mode_ & consume_header)
3245 // __codecvt_utf8<char32_t>
3247 __codecvt_utf8<char32_t>::result
3248 __codecvt_utf8<char32_t>::do_out(state_type&,
3249 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3250 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3252 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3253 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3254 const uint32_t* _frm_nxt = _frm;
3255 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3256 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3257 uint8_t* _to_nxt = _to;
3258 result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3260 frm_nxt = frm + (_frm_nxt - _frm);
3261 to_nxt = to + (_to_nxt - _to);
3265 __codecvt_utf8<char32_t>::result
3266 __codecvt_utf8<char32_t>::do_in(state_type&,
3267 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3268 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3270 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3271 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3272 const uint8_t* _frm_nxt = _frm;
3273 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3274 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3275 uint32_t* _to_nxt = _to;
3276 result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3278 frm_nxt = frm + (_frm_nxt - _frm);
3279 to_nxt = to + (_to_nxt - _to);
3283 __codecvt_utf8<char32_t>::result
3284 __codecvt_utf8<char32_t>::do_unshift(state_type&,
3285 extern_type* to, extern_type*, extern_type*& to_nxt) const
3292 __codecvt_utf8<char32_t>::do_encoding() const _NOEXCEPT
3298 __codecvt_utf8<char32_t>::do_always_noconv() const _NOEXCEPT
3304 __codecvt_utf8<char32_t>::do_length(state_type&,
3305 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3307 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3308 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3309 return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3313 __codecvt_utf8<char32_t>::do_max_length() const _NOEXCEPT
3315 if (_Mode_ & consume_header)
3320 // __codecvt_utf16<wchar_t, false>
3322 __codecvt_utf16<wchar_t, false>::result
3323 __codecvt_utf16<wchar_t, false>::do_out(state_type&,
3324 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3325 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3327 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3328 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3329 const uint32_t* _frm_nxt = _frm;
3330 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3331 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3332 uint8_t* _to_nxt = _to;
3333 result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3335 frm_nxt = frm + (_frm_nxt - _frm);
3336 to_nxt = to + (_to_nxt - _to);
3340 __codecvt_utf16<wchar_t, false>::result
3341 __codecvt_utf16<wchar_t, false>::do_in(state_type&,
3342 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3343 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3345 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3346 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3347 const uint8_t* _frm_nxt = _frm;
3348 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3349 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3350 uint32_t* _to_nxt = _to;
3351 result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3353 frm_nxt = frm + (_frm_nxt - _frm);
3354 to_nxt = to + (_to_nxt - _to);
3358 __codecvt_utf16<wchar_t, false>::result
3359 __codecvt_utf16<wchar_t, false>::do_unshift(state_type&,
3360 extern_type* to, extern_type*, extern_type*& to_nxt) const
3367 __codecvt_utf16<wchar_t, false>::do_encoding() const _NOEXCEPT
3373 __codecvt_utf16<wchar_t, false>::do_always_noconv() const _NOEXCEPT
3379 __codecvt_utf16<wchar_t, false>::do_length(state_type&,
3380 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3382 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3383 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3384 return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3388 __codecvt_utf16<wchar_t, false>::do_max_length() const _NOEXCEPT
3390 if (_Mode_ & consume_header)
3395 // __codecvt_utf16<wchar_t, true>
3397 __codecvt_utf16<wchar_t, true>::result
3398 __codecvt_utf16<wchar_t, true>::do_out(state_type&,
3399 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3400 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3402 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3403 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3404 const uint32_t* _frm_nxt = _frm;
3405 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3406 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3407 uint8_t* _to_nxt = _to;
3408 result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3410 frm_nxt = frm + (_frm_nxt - _frm);
3411 to_nxt = to + (_to_nxt - _to);
3415 __codecvt_utf16<wchar_t, true>::result
3416 __codecvt_utf16<wchar_t, true>::do_in(state_type&,
3417 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3418 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3420 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3421 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3422 const uint8_t* _frm_nxt = _frm;
3423 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3424 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3425 uint32_t* _to_nxt = _to;
3426 result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3428 frm_nxt = frm + (_frm_nxt - _frm);
3429 to_nxt = to + (_to_nxt - _to);
3433 __codecvt_utf16<wchar_t, true>::result
3434 __codecvt_utf16<wchar_t, true>::do_unshift(state_type&,
3435 extern_type* to, extern_type*, extern_type*& to_nxt) const
3442 __codecvt_utf16<wchar_t, true>::do_encoding() const _NOEXCEPT
3448 __codecvt_utf16<wchar_t, true>::do_always_noconv() const _NOEXCEPT
3454 __codecvt_utf16<wchar_t, true>::do_length(state_type&,
3455 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3457 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3458 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3459 return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3463 __codecvt_utf16<wchar_t, true>::do_max_length() const _NOEXCEPT
3465 if (_Mode_ & consume_header)
3470 // __codecvt_utf16<char16_t, false>
3472 __codecvt_utf16<char16_t, false>::result
3473 __codecvt_utf16<char16_t, false>::do_out(state_type&,
3474 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3475 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3477 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3478 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3479 const uint16_t* _frm_nxt = _frm;
3480 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3481 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3482 uint8_t* _to_nxt = _to;
3483 result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3485 frm_nxt = frm + (_frm_nxt - _frm);
3486 to_nxt = to + (_to_nxt - _to);
3490 __codecvt_utf16<char16_t, false>::result
3491 __codecvt_utf16<char16_t, false>::do_in(state_type&,
3492 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3493 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3495 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3496 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3497 const uint8_t* _frm_nxt = _frm;
3498 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3499 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3500 uint16_t* _to_nxt = _to;
3501 result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3503 frm_nxt = frm + (_frm_nxt - _frm);
3504 to_nxt = to + (_to_nxt - _to);
3508 __codecvt_utf16<char16_t, false>::result
3509 __codecvt_utf16<char16_t, false>::do_unshift(state_type&,
3510 extern_type* to, extern_type*, extern_type*& to_nxt) const
3517 __codecvt_utf16<char16_t, false>::do_encoding() const _NOEXCEPT
3523 __codecvt_utf16<char16_t, false>::do_always_noconv() const _NOEXCEPT
3529 __codecvt_utf16<char16_t, false>::do_length(state_type&,
3530 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3532 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3533 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3534 return utf16be_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3538 __codecvt_utf16<char16_t, false>::do_max_length() const _NOEXCEPT
3540 if (_Mode_ & consume_header)
3545 // __codecvt_utf16<char16_t, true>
3547 __codecvt_utf16<char16_t, true>::result
3548 __codecvt_utf16<char16_t, true>::do_out(state_type&,
3549 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3550 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3552 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3553 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3554 const uint16_t* _frm_nxt = _frm;
3555 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3556 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3557 uint8_t* _to_nxt = _to;
3558 result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3560 frm_nxt = frm + (_frm_nxt - _frm);
3561 to_nxt = to + (_to_nxt - _to);
3565 __codecvt_utf16<char16_t, true>::result
3566 __codecvt_utf16<char16_t, true>::do_in(state_type&,
3567 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3568 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3570 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3571 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3572 const uint8_t* _frm_nxt = _frm;
3573 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3574 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3575 uint16_t* _to_nxt = _to;
3576 result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3578 frm_nxt = frm + (_frm_nxt - _frm);
3579 to_nxt = to + (_to_nxt - _to);
3583 __codecvt_utf16<char16_t, true>::result
3584 __codecvt_utf16<char16_t, true>::do_unshift(state_type&,
3585 extern_type* to, extern_type*, extern_type*& to_nxt) const
3592 __codecvt_utf16<char16_t, true>::do_encoding() const _NOEXCEPT
3598 __codecvt_utf16<char16_t, true>::do_always_noconv() const _NOEXCEPT
3604 __codecvt_utf16<char16_t, true>::do_length(state_type&,
3605 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3607 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3608 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3609 return utf16le_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3613 __codecvt_utf16<char16_t, true>::do_max_length() const _NOEXCEPT
3615 if (_Mode_ & consume_header)
3620 // __codecvt_utf16<char32_t, false>
3622 __codecvt_utf16<char32_t, false>::result
3623 __codecvt_utf16<char32_t, false>::do_out(state_type&,
3624 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3625 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3627 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3628 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3629 const uint32_t* _frm_nxt = _frm;
3630 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3631 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3632 uint8_t* _to_nxt = _to;
3633 result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3635 frm_nxt = frm + (_frm_nxt - _frm);
3636 to_nxt = to + (_to_nxt - _to);
3640 __codecvt_utf16<char32_t, false>::result
3641 __codecvt_utf16<char32_t, false>::do_in(state_type&,
3642 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3643 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3645 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3646 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3647 const uint8_t* _frm_nxt = _frm;
3648 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3649 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3650 uint32_t* _to_nxt = _to;
3651 result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3653 frm_nxt = frm + (_frm_nxt - _frm);
3654 to_nxt = to + (_to_nxt - _to);
3658 __codecvt_utf16<char32_t, false>::result
3659 __codecvt_utf16<char32_t, false>::do_unshift(state_type&,
3660 extern_type* to, extern_type*, extern_type*& to_nxt) const
3667 __codecvt_utf16<char32_t, false>::do_encoding() const _NOEXCEPT
3673 __codecvt_utf16<char32_t, false>::do_always_noconv() const _NOEXCEPT
3679 __codecvt_utf16<char32_t, false>::do_length(state_type&,
3680 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3682 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3683 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3684 return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3688 __codecvt_utf16<char32_t, false>::do_max_length() const _NOEXCEPT
3690 if (_Mode_ & consume_header)
3695 // __codecvt_utf16<char32_t, true>
3697 __codecvt_utf16<char32_t, true>::result
3698 __codecvt_utf16<char32_t, true>::do_out(state_type&,
3699 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3700 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3702 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3703 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3704 const uint32_t* _frm_nxt = _frm;
3705 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3706 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3707 uint8_t* _to_nxt = _to;
3708 result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3710 frm_nxt = frm + (_frm_nxt - _frm);
3711 to_nxt = to + (_to_nxt - _to);
3715 __codecvt_utf16<char32_t, true>::result
3716 __codecvt_utf16<char32_t, true>::do_in(state_type&,
3717 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3718 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3720 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3721 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3722 const uint8_t* _frm_nxt = _frm;
3723 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3724 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3725 uint32_t* _to_nxt = _to;
3726 result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3728 frm_nxt = frm + (_frm_nxt - _frm);
3729 to_nxt = to + (_to_nxt - _to);
3733 __codecvt_utf16<char32_t, true>::result
3734 __codecvt_utf16<char32_t, true>::do_unshift(state_type&,
3735 extern_type* to, extern_type*, extern_type*& to_nxt) const
3742 __codecvt_utf16<char32_t, true>::do_encoding() const _NOEXCEPT
3748 __codecvt_utf16<char32_t, true>::do_always_noconv() const _NOEXCEPT
3754 __codecvt_utf16<char32_t, true>::do_length(state_type&,
3755 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3757 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3758 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3759 return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3763 __codecvt_utf16<char32_t, true>::do_max_length() const _NOEXCEPT
3765 if (_Mode_ & consume_header)
3770 // __codecvt_utf8_utf16<wchar_t>
3772 __codecvt_utf8_utf16<wchar_t>::result
3773 __codecvt_utf8_utf16<wchar_t>::do_out(state_type&,
3774 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3775 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3777 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3778 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3779 const uint32_t* _frm_nxt = _frm;
3780 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3781 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3782 uint8_t* _to_nxt = _to;
3783 result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3785 frm_nxt = frm + (_frm_nxt - _frm);
3786 to_nxt = to + (_to_nxt - _to);
3790 __codecvt_utf8_utf16<wchar_t>::result
3791 __codecvt_utf8_utf16<wchar_t>::do_in(state_type&,
3792 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3793 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3795 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3796 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3797 const uint8_t* _frm_nxt = _frm;
3798 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3799 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3800 uint32_t* _to_nxt = _to;
3801 result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3803 frm_nxt = frm + (_frm_nxt - _frm);
3804 to_nxt = to + (_to_nxt - _to);
3808 __codecvt_utf8_utf16<wchar_t>::result
3809 __codecvt_utf8_utf16<wchar_t>::do_unshift(state_type&,
3810 extern_type* to, extern_type*, extern_type*& to_nxt) const
3817 __codecvt_utf8_utf16<wchar_t>::do_encoding() const _NOEXCEPT
3823 __codecvt_utf8_utf16<wchar_t>::do_always_noconv() const _NOEXCEPT
3829 __codecvt_utf8_utf16<wchar_t>::do_length(state_type&,
3830 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3832 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3833 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3834 return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3838 __codecvt_utf8_utf16<wchar_t>::do_max_length() const _NOEXCEPT
3840 if (_Mode_ & consume_header)
3845 // __codecvt_utf8_utf16<char16_t>
3847 __codecvt_utf8_utf16<char16_t>::result
3848 __codecvt_utf8_utf16<char16_t>::do_out(state_type&,
3849 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3850 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3852 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3853 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3854 const uint16_t* _frm_nxt = _frm;
3855 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3856 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3857 uint8_t* _to_nxt = _to;
3858 result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3860 frm_nxt = frm + (_frm_nxt - _frm);
3861 to_nxt = to + (_to_nxt - _to);
3865 __codecvt_utf8_utf16<char16_t>::result
3866 __codecvt_utf8_utf16<char16_t>::do_in(state_type&,
3867 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3868 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3870 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3871 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3872 const uint8_t* _frm_nxt = _frm;
3873 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3874 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3875 uint16_t* _to_nxt = _to;
3876 result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3878 frm_nxt = frm + (_frm_nxt - _frm);
3879 to_nxt = to + (_to_nxt - _to);
3883 __codecvt_utf8_utf16<char16_t>::result
3884 __codecvt_utf8_utf16<char16_t>::do_unshift(state_type&,
3885 extern_type* to, extern_type*, extern_type*& to_nxt) const
3892 __codecvt_utf8_utf16<char16_t>::do_encoding() const _NOEXCEPT
3898 __codecvt_utf8_utf16<char16_t>::do_always_noconv() const _NOEXCEPT
3904 __codecvt_utf8_utf16<char16_t>::do_length(state_type&,
3905 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3907 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3908 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3909 return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3913 __codecvt_utf8_utf16<char16_t>::do_max_length() const _NOEXCEPT
3915 if (_Mode_ & consume_header)
3920 // __codecvt_utf8_utf16<char32_t>
3922 __codecvt_utf8_utf16<char32_t>::result
3923 __codecvt_utf8_utf16<char32_t>::do_out(state_type&,
3924 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3925 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3927 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3928 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3929 const uint32_t* _frm_nxt = _frm;
3930 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3931 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3932 uint8_t* _to_nxt = _to;
3933 result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3935 frm_nxt = frm + (_frm_nxt - _frm);
3936 to_nxt = to + (_to_nxt - _to);
3940 __codecvt_utf8_utf16<char32_t>::result
3941 __codecvt_utf8_utf16<char32_t>::do_in(state_type&,
3942 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3943 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3945 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3946 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3947 const uint8_t* _frm_nxt = _frm;
3948 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3949 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3950 uint32_t* _to_nxt = _to;
3951 result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3953 frm_nxt = frm + (_frm_nxt - _frm);
3954 to_nxt = to + (_to_nxt - _to);
3958 __codecvt_utf8_utf16<char32_t>::result
3959 __codecvt_utf8_utf16<char32_t>::do_unshift(state_type&,
3960 extern_type* to, extern_type*, extern_type*& to_nxt) const
3967 __codecvt_utf8_utf16<char32_t>::do_encoding() const _NOEXCEPT
3973 __codecvt_utf8_utf16<char32_t>::do_always_noconv() const _NOEXCEPT
3979 __codecvt_utf8_utf16<char32_t>::do_length(state_type&,
3980 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3982 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3983 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3984 return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3988 __codecvt_utf8_utf16<char32_t>::do_max_length() const _NOEXCEPT
3990 if (_Mode_ & consume_header)
3995 // __narrow_to_utf8<16>
3997 __narrow_to_utf8<16>::~__narrow_to_utf8()
4001 // __narrow_to_utf8<32>
4003 __narrow_to_utf8<32>::~__narrow_to_utf8()
4007 // __widen_from_utf8<16>
4009 __widen_from_utf8<16>::~__widen_from_utf8()
4013 // __widen_from_utf8<32>
4015 __widen_from_utf8<32>::~__widen_from_utf8()
4019 // numpunct<char> && numpunct<wchar_t>
4021 locale::id numpunct< char >::id;
4022 locale::id numpunct<wchar_t>::id;
4024 numpunct<char>::numpunct(size_t refs)
4025 : locale::facet(refs),
4026 __decimal_point_('.'),
4027 __thousands_sep_(',')
4031 numpunct<wchar_t>::numpunct(size_t refs)
4032 : locale::facet(refs),
4033 __decimal_point_(L'.'),
4034 __thousands_sep_(L',')
4038 numpunct<char>::~numpunct()
4042 numpunct<wchar_t>::~numpunct()
4046 char numpunct< char >::do_decimal_point() const {return __decimal_point_;}
4047 wchar_t numpunct<wchar_t>::do_decimal_point() const {return __decimal_point_;}
4049 char numpunct< char >::do_thousands_sep() const {return __thousands_sep_;}
4050 wchar_t numpunct<wchar_t>::do_thousands_sep() const {return __thousands_sep_;}
4052 string numpunct< char >::do_grouping() const {return __grouping_;}
4053 string numpunct<wchar_t>::do_grouping() const {return __grouping_;}
4055 string numpunct< char >::do_truename() const {return "true";}
4056 wstring numpunct<wchar_t>::do_truename() const {return L"true";}
4058 string numpunct< char >::do_falsename() const {return "false";}
4059 wstring numpunct<wchar_t>::do_falsename() const {return L"false";}
4061 // numpunct_byname<char>
4063 numpunct_byname<char>::numpunct_byname(const char* nm, size_t refs)
4064 : numpunct<char>(refs)
4069 numpunct_byname<char>::numpunct_byname(const string& nm, size_t refs)
4070 : numpunct<char>(refs)
4075 numpunct_byname<char>::~numpunct_byname()
4080 numpunct_byname<char>::__init(const char* nm)
4082 if (strcmp(nm, "C") != 0)
4084 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
4085 #ifndef _LIBCPP_NO_EXCEPTIONS
4087 throw runtime_error("numpunct_byname<char>::numpunct_byname"
4088 " failed to construct for " + string(nm));
4089 #endif // _LIBCPP_NO_EXCEPTIONS
4090 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4091 lconv* lc = localeconv_l(loc.get());
4093 lconv* lc = __localeconv_l(loc.get());
4095 if (*lc->decimal_point)
4096 __decimal_point_ = *lc->decimal_point;
4097 if (*lc->thousands_sep)
4098 __thousands_sep_ = *lc->thousands_sep;
4099 __grouping_ = lc->grouping;
4100 // localization for truename and falsename is not available
4104 // numpunct_byname<wchar_t>
4106 numpunct_byname<wchar_t>::numpunct_byname(const char* nm, size_t refs)
4107 : numpunct<wchar_t>(refs)
4112 numpunct_byname<wchar_t>::numpunct_byname(const string& nm, size_t refs)
4113 : numpunct<wchar_t>(refs)
4118 numpunct_byname<wchar_t>::~numpunct_byname()
4123 numpunct_byname<wchar_t>::__init(const char* nm)
4125 if (strcmp(nm, "C") != 0)
4127 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
4128 #ifndef _LIBCPP_NO_EXCEPTIONS
4130 throw runtime_error("numpunct_byname<char>::numpunct_byname"
4131 " failed to construct for " + string(nm));
4132 #endif // _LIBCPP_NO_EXCEPTIONS
4133 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4134 lconv* lc = localeconv_l(loc.get());
4136 lconv* lc = __localeconv_l(loc.get());
4138 if (*lc->decimal_point)
4139 __decimal_point_ = *lc->decimal_point;
4140 if (*lc->thousands_sep)
4141 __thousands_sep_ = *lc->thousands_sep;
4142 __grouping_ = lc->grouping;
4143 // locallization for truename and falsename is not available
4150 __num_get_base::__get_base(ios_base& iob)
4152 ios_base::fmtflags __basefield = iob.flags() & ios_base::basefield;
4153 if (__basefield == ios_base::oct)
4155 else if (__basefield == ios_base::hex)
4157 else if (__basefield == 0)
4162 const char __num_get_base::__src[33] = "0123456789abcdefABCDEFxX+-pPiInN";
4165 __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end,
4166 ios_base::iostate& __err)
4168 if (__grouping.size() != 0)
4170 reverse(__g, __g_end);
4171 const char* __ig = __grouping.data();
4172 const char* __eg = __ig + __grouping.size();
4173 for (unsigned* __r = __g; __r < __g_end-1; ++__r)
4175 if (0 < *__ig && *__ig < numeric_limits<char>::max())
4177 if (static_cast<unsigned>(*__ig) != *__r)
4179 __err = ios_base::failbit;
4183 if (__eg - __ig > 1)
4186 if (0 < *__ig && *__ig < numeric_limits<char>::max())
4188 if (static_cast<unsigned>(*__ig) < __g_end[-1] || __g_end[-1] == 0)
4189 __err = ios_base::failbit;
4195 __num_put_base::__format_int(char* __fmtp, const char* __len, bool __signd,
4196 ios_base::fmtflags __flags)
4198 if (__flags & ios_base::showpos)
4200 if (__flags & ios_base::showbase)
4203 *__fmtp++ = *__len++;
4204 if ((__flags & ios_base::basefield) == ios_base::oct)
4206 else if ((__flags & ios_base::basefield) == ios_base::hex)
4208 if (__flags & ios_base::uppercase)
4220 __num_put_base::__format_float(char* __fmtp, const char* __len,
4221 ios_base::fmtflags __flags)
4223 bool specify_precision = true;
4224 if (__flags & ios_base::showpos)
4226 if (__flags & ios_base::showpoint)
4228 ios_base::fmtflags floatfield = __flags & ios_base::floatfield;
4229 bool uppercase = __flags & ios_base::uppercase;
4230 if (floatfield == (ios_base::fixed | ios_base::scientific))
4231 specify_precision = false;
4238 *__fmtp++ = *__len++;
4239 if (floatfield == ios_base::fixed)
4246 else if (floatfield == ios_base::scientific)
4253 else if (floatfield == (ios_base::fixed | ios_base::scientific))
4267 return specify_precision;
4271 __num_put_base::__identify_padding(char* __nb, char* __ne,
4272 const ios_base& __iob)
4274 switch (__iob.flags() & ios_base::adjustfield)
4276 case ios_base::internal:
4277 if (__nb[0] == '-' || __nb[0] == '+')
4279 if (__ne - __nb >= 2 && __nb[0] == '0'
4280 && (__nb[1] == 'x' || __nb[1] == 'X'))
4283 case ios_base::left:
4285 case ios_base::right:
4298 static string weeks[14];
4299 weeks[0] = "Sunday";
4300 weeks[1] = "Monday";
4301 weeks[2] = "Tuesday";
4302 weeks[3] = "Wednesday";
4303 weeks[4] = "Thursday";
4304 weeks[5] = "Friday";
4305 weeks[6] = "Saturday";
4320 static wstring weeks[14];
4321 weeks[0] = L"Sunday";
4322 weeks[1] = L"Monday";
4323 weeks[2] = L"Tuesday";
4324 weeks[3] = L"Wednesday";
4325 weeks[4] = L"Thursday";
4326 weeks[5] = L"Friday";
4327 weeks[6] = L"Saturday";
4340 __time_get_c_storage<char>::__weeks() const
4342 static const string* weeks = init_weeks();
4348 __time_get_c_storage<wchar_t>::__weeks() const
4350 static const wstring* weeks = init_wweeks();
4358 static string months[24];
4359 months[0] = "January";
4360 months[1] = "February";
4361 months[2] = "March";
4362 months[3] = "April";
4366 months[7] = "August";
4367 months[8] = "September";
4368 months[9] = "October";
4369 months[10] = "November";
4370 months[11] = "December";
4390 static wstring months[24];
4391 months[0] = L"January";
4392 months[1] = L"February";
4393 months[2] = L"March";
4394 months[3] = L"April";
4396 months[5] = L"June";
4397 months[6] = L"July";
4398 months[7] = L"August";
4399 months[8] = L"September";
4400 months[9] = L"October";
4401 months[10] = L"November";
4402 months[11] = L"December";
4403 months[12] = L"Jan";
4404 months[13] = L"Feb";
4405 months[14] = L"Mar";
4406 months[15] = L"Apr";
4407 months[16] = L"May";
4408 months[17] = L"Jun";
4409 months[18] = L"Jul";
4410 months[19] = L"Aug";
4411 months[20] = L"Sep";
4412 months[21] = L"Oct";
4413 months[22] = L"Nov";
4414 months[23] = L"Dec";
4420 __time_get_c_storage<char>::__months() const
4422 static const string* months = init_months();
4428 __time_get_c_storage<wchar_t>::__months() const
4430 static const wstring* months = init_wmonths();
4438 static string am_pm[24];
4448 static wstring am_pm[24];
4456 __time_get_c_storage<char>::__am_pm() const
4458 static const string* am_pm = init_am_pm();
4464 __time_get_c_storage<wchar_t>::__am_pm() const
4466 static const wstring* am_pm = init_wam_pm();
4472 __time_get_c_storage<char>::__x() const
4474 static string s("%m/%d/%y");
4480 __time_get_c_storage<wchar_t>::__x() const
4482 static wstring s(L"%m/%d/%y");
4488 __time_get_c_storage<char>::__X() const
4490 static string s("%H:%M:%S");
4496 __time_get_c_storage<wchar_t>::__X() const
4498 static wstring s(L"%H:%M:%S");
4504 __time_get_c_storage<char>::__c() const
4506 static string s("%a %b %d %H:%M:%S %Y");
4512 __time_get_c_storage<wchar_t>::__c() const
4514 static wstring s(L"%a %b %d %H:%M:%S %Y");
4520 __time_get_c_storage<char>::__r() const
4522 static string s("%I:%M:%S %p");
4528 __time_get_c_storage<wchar_t>::__r() const
4530 static wstring s(L"%I:%M:%S %p");
4536 __time_get::__time_get(const char* nm)
4537 : __loc_(newlocale(LC_ALL_MASK, nm, 0))
4539 #ifndef _LIBCPP_NO_EXCEPTIONS
4541 throw runtime_error("time_get_byname"
4542 " failed to construct for " + string(nm));
4543 #endif // _LIBCPP_NO_EXCEPTIONS
4546 __time_get::__time_get(const string& nm)
4547 : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
4549 #ifndef _LIBCPP_NO_EXCEPTIONS
4551 throw runtime_error("time_get_byname"
4552 " failed to construct for " + nm);
4553 #endif // _LIBCPP_NO_EXCEPTIONS
4556 __time_get::~__time_get()
4561 #pragma clang diagnostic ignored "-Wmissing-field-initializers"
4565 __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
4581 size_t n = strftime_l(buf, 100, f, &t, __loc_);
4587 if (ct.is(ctype_base::space, *bb))
4589 result.push_back(' ');
4590 for (++bb; bb != be && ct.is(ctype_base::space, *bb); ++bb)
4595 ios_base::iostate err = ios_base::goodbit;
4596 ptrdiff_t i = __scan_keyword(w, be, this->__weeks_, this->__weeks_+14,
4601 result.push_back('%');
4603 result.push_back('A');
4605 result.push_back('a');
4610 i = __scan_keyword(w, be, this->__months_, this->__months_+24,
4615 result.push_back('%');
4617 result.push_back('B');
4619 result.push_back('b');
4620 if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
4621 result.back() = 'm';
4625 if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0)
4628 i = __scan_keyword(w, be, this->__am_pm_, this->__am_pm_+2,
4629 ct, err, false) - this->__am_pm_;
4632 result.push_back('%');
4633 result.push_back('p');
4639 if (ct.is(ctype_base::digit, *bb))
4641 switch(__get_up_to_n_digits(bb, be, err, ct, 4))
4644 result.push_back('%');
4645 result.push_back('w');
4648 result.push_back('%');
4649 result.push_back('u');
4652 result.push_back('%');
4653 result.push_back('I');
4656 result.push_back('%');
4657 result.push_back('m');
4660 result.push_back('%');
4661 result.push_back('H');
4664 result.push_back('%');
4665 result.push_back('d');
4668 result.push_back('%');
4669 result.push_back('M');
4672 result.push_back('%');
4673 result.push_back('S');
4676 result.push_back('%');
4677 result.push_back('y');
4680 result.push_back('%');
4681 result.push_back('j');
4684 result.push_back('%');
4685 result.push_back('Y');
4688 for (; w != bb; ++w)
4689 result.push_back(*w);
4696 result.push_back('%');
4697 result.push_back('%');
4701 result.push_back(*bb);
4707 #pragma clang diagnostic ignored "-Wmissing-braces"
4711 __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
4727 strftime_l(buf, 100, f, &t, __loc_);
4729 wchar_t* wbb = wbuf;
4731 const char* bb = buf;
4732 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4733 size_t j = mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4735 size_t j = __mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4737 if (j == size_t(-1))
4738 __throw_runtime_error("locale not supported");
4739 wchar_t* wbe = wbb + j;
4743 if (ct.is(ctype_base::space, *wbb))
4745 result.push_back(L' ');
4746 for (++wbb; wbb != wbe && ct.is(ctype_base::space, *wbb); ++wbb)
4751 ios_base::iostate err = ios_base::goodbit;
4752 ptrdiff_t i = __scan_keyword(w, wbe, this->__weeks_, this->__weeks_+14,
4757 result.push_back(L'%');
4759 result.push_back(L'A');
4761 result.push_back(L'a');
4766 i = __scan_keyword(w, wbe, this->__months_, this->__months_+24,
4771 result.push_back(L'%');
4773 result.push_back(L'B');
4775 result.push_back(L'b');
4776 if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
4777 result.back() = L'm';
4781 if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0)
4784 i = __scan_keyword(w, wbe, this->__am_pm_, this->__am_pm_+2,
4785 ct, err, false) - this->__am_pm_;
4788 result.push_back(L'%');
4789 result.push_back(L'p');
4795 if (ct.is(ctype_base::digit, *wbb))
4797 switch(__get_up_to_n_digits(wbb, wbe, err, ct, 4))
4800 result.push_back(L'%');
4801 result.push_back(L'w');
4804 result.push_back(L'%');
4805 result.push_back(L'u');
4808 result.push_back(L'%');
4809 result.push_back(L'I');
4812 result.push_back(L'%');
4813 result.push_back(L'm');
4816 result.push_back(L'%');
4817 result.push_back(L'H');
4820 result.push_back(L'%');
4821 result.push_back(L'd');
4824 result.push_back(L'%');
4825 result.push_back(L'M');
4828 result.push_back(L'%');
4829 result.push_back(L'S');
4832 result.push_back(L'%');
4833 result.push_back(L'y');
4836 result.push_back(L'%');
4837 result.push_back(L'j');
4840 result.push_back(L'%');
4841 result.push_back(L'Y');
4844 for (; w != wbb; ++w)
4845 result.push_back(*w);
4850 if (ct.narrow(*wbb, 0) == '%')
4852 result.push_back(L'%');
4853 result.push_back(L'%');
4857 result.push_back(*wbb);
4865 __time_get_storage<char>::init(const ctype<char>& ct)
4870 for (int i = 0; i < 7; ++i)
4873 strftime_l(buf, 100, "%A", &t, __loc_);
4875 strftime_l(buf, 100, "%a", &t, __loc_);
4876 __weeks_[i+7] = buf;
4879 for (int i = 0; i < 12; ++i)
4882 strftime_l(buf, 100, "%B", &t, __loc_);
4884 strftime_l(buf, 100, "%b", &t, __loc_);
4885 __months_[i+12] = buf;
4889 strftime_l(buf, 100, "%p", &t, __loc_);
4892 strftime_l(buf, 100, "%p", &t, __loc_);
4894 __c_ = __analyze('c', ct);
4895 __r_ = __analyze('r', ct);
4896 __x_ = __analyze('x', ct);
4897 __X_ = __analyze('X', ct);
4902 __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
4911 for (int i = 0; i < 7; ++i)
4914 be = strftime_l(buf, 100, "%A", &t, __loc_);
4916 const char* bb = buf;
4917 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4918 size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4920 size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4922 if (j == size_t(-1))
4923 __throw_runtime_error("locale not supported");
4925 __weeks_[i].assign(wbuf, wbe);
4926 be = strftime_l(buf, 100, "%a", &t, __loc_);
4929 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4930 j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4932 j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4934 if (j == size_t(-1))
4935 __throw_runtime_error("locale not supported");
4937 __weeks_[i+7].assign(wbuf, wbe);
4940 for (int i = 0; i < 12; ++i)
4943 be = strftime_l(buf, 100, "%B", &t, __loc_);
4945 const char* bb = buf;
4946 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4947 size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4949 size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4951 if (j == size_t(-1))
4952 __throw_runtime_error("locale not supported");
4954 __months_[i].assign(wbuf, wbe);
4955 be = strftime_l(buf, 100, "%b", &t, __loc_);
4958 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4959 j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4961 j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4963 if (j == size_t(-1))
4964 __throw_runtime_error("locale not supported");
4966 __months_[i+12].assign(wbuf, wbe);
4970 be = strftime_l(buf, 100, "%p", &t, __loc_);
4972 const char* bb = buf;
4973 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4974 size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4976 size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4978 if (j == size_t(-1))
4979 __throw_runtime_error("locale not supported");
4981 __am_pm_[0].assign(wbuf, wbe);
4983 be = strftime_l(buf, 100, "%p", &t, __loc_);
4986 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4987 j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4989 j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4991 if (j == size_t(-1))
4992 __throw_runtime_error("locale not supported");
4994 __am_pm_[1].assign(wbuf, wbe);
4995 __c_ = __analyze('c', ct);
4996 __r_ = __analyze('r', ct);
4997 __x_ = __analyze('x', ct);
4998 __X_ = __analyze('X', ct);
5001 template <class CharT>
5002 struct _LIBCPP_HIDDEN __time_get_temp
5003 : public ctype_byname<CharT>
5005 explicit __time_get_temp(const char* nm)
5006 : ctype_byname<CharT>(nm, 1) {}
5007 explicit __time_get_temp(const string& nm)
5008 : ctype_byname<CharT>(nm, 1) {}
5012 __time_get_storage<char>::__time_get_storage(const char* __nm)
5015 const __time_get_temp<char> ct(__nm);
5020 __time_get_storage<char>::__time_get_storage(const string& __nm)
5023 const __time_get_temp<char> ct(__nm);
5028 __time_get_storage<wchar_t>::__time_get_storage(const char* __nm)
5031 const __time_get_temp<wchar_t> ct(__nm);
5036 __time_get_storage<wchar_t>::__time_get_storage(const string& __nm)
5039 const __time_get_temp<wchar_t> ct(__nm);
5044 time_base::dateorder
5045 __time_get_storage<char>::__do_date_order() const
5048 for (i = 0; i < __x_.size(); ++i)
5056 for (++i; i < __x_.size(); ++i)
5059 if (i == __x_.size())
5065 for (++i; i < __x_.size(); ++i)
5068 if (i == __x_.size())
5072 return time_base::ymd;
5075 for (++i; i < __x_.size(); ++i)
5078 if (i == __x_.size())
5082 return time_base::ydm;
5087 for (++i; i < __x_.size(); ++i)
5090 if (i == __x_.size())
5095 for (++i; i < __x_.size(); ++i)
5098 if (i == __x_.size())
5101 if (__x_[i] == 'y' || __x_[i] == 'Y')
5102 return time_base::mdy;
5107 for (++i; i < __x_.size(); ++i)
5110 if (i == __x_.size())
5115 for (++i; i < __x_.size(); ++i)
5118 if (i == __x_.size())
5121 if (__x_[i] == 'y' || __x_[i] == 'Y')
5122 return time_base::dmy;
5127 return time_base::no_order;
5131 time_base::dateorder
5132 __time_get_storage<wchar_t>::__do_date_order() const
5135 for (i = 0; i < __x_.size(); ++i)
5136 if (__x_[i] == L'%')
5143 for (++i; i < __x_.size(); ++i)
5144 if (__x_[i] == L'%')
5146 if (i == __x_.size())
5152 for (++i; i < __x_.size(); ++i)
5153 if (__x_[i] == L'%')
5155 if (i == __x_.size())
5158 if (__x_[i] == L'd')
5159 return time_base::ymd;
5162 for (++i; i < __x_.size(); ++i)
5163 if (__x_[i] == L'%')
5165 if (i == __x_.size())
5168 if (__x_[i] == L'm')
5169 return time_base::ydm;
5174 for (++i; i < __x_.size(); ++i)
5175 if (__x_[i] == L'%')
5177 if (i == __x_.size())
5180 if (__x_[i] == L'd')
5182 for (++i; i < __x_.size(); ++i)
5183 if (__x_[i] == L'%')
5185 if (i == __x_.size())
5188 if (__x_[i] == L'y' || __x_[i] == L'Y')
5189 return time_base::mdy;
5194 for (++i; i < __x_.size(); ++i)
5195 if (__x_[i] == L'%')
5197 if (i == __x_.size())
5200 if (__x_[i] == L'm')
5202 for (++i; i < __x_.size(); ++i)
5203 if (__x_[i] == L'%')
5205 if (i == __x_.size())
5208 if (__x_[i] == L'y' || __x_[i] == L'Y')
5209 return time_base::dmy;
5214 return time_base::no_order;
5219 __time_put::__time_put(const char* nm)
5220 : __loc_(newlocale(LC_ALL_MASK, nm, 0))
5222 #ifndef _LIBCPP_NO_EXCEPTIONS
5224 throw runtime_error("time_put_byname"
5225 " failed to construct for " + string(nm));
5226 #endif // _LIBCPP_NO_EXCEPTIONS
5229 __time_put::__time_put(const string& nm)
5230 : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
5232 #ifndef _LIBCPP_NO_EXCEPTIONS
5234 throw runtime_error("time_put_byname"
5235 " failed to construct for " + nm);
5236 #endif // _LIBCPP_NO_EXCEPTIONS
5239 __time_put::~__time_put()
5246 __time_put::__do_put(char* __nb, char*& __ne, const tm* __tm,
5247 char __fmt, char __mod) const
5249 char fmt[] = {'%', __fmt, __mod, 0};
5251 swap(fmt[1], fmt[2]);
5252 size_t n = strftime_l(__nb, static_cast<size_t>(__ne-__nb), fmt, __tm, __loc_);
5257 __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
5258 char __fmt, char __mod) const
5261 char* __ne = __nar + 100;
5262 __do_put(__nar, __ne, __tm, __fmt, __mod);
5264 const char* __nb = __nar;
5265 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5266 size_t j = mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_);
5268 size_t j = __mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_);
5270 if (j == size_t(-1))
5271 __throw_runtime_error("locale not supported");
5275 // moneypunct_byname
5277 template <class charT>
5280 __init_pat(money_base::pattern& pat, basic_string<charT>& __curr_symbol_,
5281 bool intl, char cs_precedes, char sep_by_space, char sign_posn,
5284 const char sign = static_cast<char>(money_base::sign);
5285 const char space = static_cast<char>(money_base::space);
5286 const char none = static_cast<char>(money_base::none);
5287 const char symbol = static_cast<char>(money_base::symbol);
5288 const char value = static_cast<char>(money_base::value);
5289 const bool symbol_contains_sep = intl && __curr_symbol_.size() == 4;
5291 // Comments on case branches reflect 'C11 7.11.2.1 The localeconv
5292 // function'. "Space between sign and symbol or value" means that
5293 // if the sign is adjacent to the symbol, there's a space between
5294 // them, and otherwise there's a space between the sign and value.
5296 // C11's localeconv specifies that the fourth character of an
5297 // international curr_symbol is used to separate the sign and
5298 // value when sep_by_space says to do so. C++ can't represent
5299 // that, so we just use a space. When sep_by_space says to
5300 // separate the symbol and value-or-sign with a space, we rearrange the
5301 // curr_symbol to put its spacing character on the correct side of
5304 // We also need to avoid adding an extra space between the sign
5305 // and value when the currency symbol is suppressed (by not
5306 // setting showbase). We match glibc's strfmon by interpreting
5307 // sep_by_space==1 as "omit the space when the currency symbol is
5310 // Users who want to get this right should use ICU instead.
5312 switch (cs_precedes)
5314 case 0: // value before curr_symbol
5315 if (symbol_contains_sep) {
5316 // Move the separator to before the symbol, to place it
5317 // between the value and symbol.
5318 rotate(__curr_symbol_.begin(), __curr_symbol_.begin() + 3,
5319 __curr_symbol_.end());
5323 case 0: // Parentheses surround the quantity and currency symbol.
5324 pat.field[0] = sign;
5325 pat.field[1] = value;
5326 pat.field[2] = none; // Any space appears in the symbol.
5327 pat.field[3] = symbol;
5328 switch (sep_by_space)
5330 case 0: // No space separates the currency symbol and value.
5331 // This case may have changed between C99 and C11;
5332 // assume the currency symbol matches the intention.
5333 case 2: // Space between sign and currency or value.
5334 // The "sign" is two parentheses, so no space here either.
5336 case 1: // Space between currency-and-sign or currency and value.
5337 if (!symbol_contains_sep) {
5338 // We insert the space into the symbol instead of
5339 // setting pat.field[2]=space so that when
5340 // showbase is not set, the space goes away too.
5341 __curr_symbol_.insert(0, 1, space_char);
5348 case 1: // The sign string precedes the quantity and currency symbol.
5349 pat.field[0] = sign;
5350 pat.field[3] = symbol;
5351 switch (sep_by_space)
5353 case 0: // No space separates the currency symbol and value.
5354 pat.field[1] = value;
5355 pat.field[2] = none;
5357 case 1: // Space between currency-and-sign or currency and value.
5358 pat.field[1] = value;
5359 pat.field[2] = none;
5360 if (!symbol_contains_sep) {
5361 // We insert the space into the symbol instead of
5362 // setting pat.field[2]=space so that when
5363 // showbase is not set, the space goes away too.
5364 __curr_symbol_.insert(0, 1, space_char);
5367 case 2: // Space between sign and currency or value.
5368 pat.field[1] = space;
5369 pat.field[2] = value;
5370 if (symbol_contains_sep) {
5371 // Remove the separator from the symbol, since it
5372 // has already appeared after the sign.
5373 __curr_symbol_.erase(__curr_symbol_.begin());
5380 case 2: // The sign string succeeds the quantity and currency symbol.
5381 pat.field[0] = value;
5382 pat.field[3] = sign;
5383 switch (sep_by_space)
5385 case 0: // No space separates the currency symbol and value.
5386 pat.field[1] = none;
5387 pat.field[2] = symbol;
5389 case 1: // Space between currency-and-sign or currency and value.
5390 if (!symbol_contains_sep) {
5391 // We insert the space into the symbol instead of
5392 // setting pat.field[1]=space so that when
5393 // showbase is not set, the space goes away too.
5394 __curr_symbol_.insert(0, 1, space_char);
5396 pat.field[1] = none;
5397 pat.field[2] = symbol;
5399 case 2: // Space between sign and currency or value.
5400 pat.field[1] = symbol;
5401 pat.field[2] = space;
5402 if (symbol_contains_sep) {
5403 // Remove the separator from the symbol, since it
5404 // should not be removed if showbase is absent.
5405 __curr_symbol_.erase(__curr_symbol_.begin());
5412 case 3: // The sign string immediately precedes the currency symbol.
5413 pat.field[0] = value;
5414 pat.field[3] = symbol;
5415 switch (sep_by_space)
5417 case 0: // No space separates the currency symbol and value.
5418 pat.field[1] = none;
5419 pat.field[2] = sign;
5421 case 1: // Space between currency-and-sign or currency and value.
5422 pat.field[1] = space;
5423 pat.field[2] = sign;
5424 if (symbol_contains_sep) {
5425 // Remove the separator from the symbol, since it
5426 // has already appeared before the sign.
5427 __curr_symbol_.erase(__curr_symbol_.begin());
5430 case 2: // Space between sign and currency or value.
5431 pat.field[1] = sign;
5432 pat.field[2] = none;
5433 if (!symbol_contains_sep) {
5434 // We insert the space into the symbol instead of
5435 // setting pat.field[2]=space so that when
5436 // showbase is not set, the space goes away too.
5437 __curr_symbol_.insert(0, 1, space_char);
5444 case 4: // The sign string immediately succeeds the currency symbol.
5445 pat.field[0] = value;
5446 pat.field[3] = sign;
5447 switch (sep_by_space)
5449 case 0: // No space separates the currency symbol and value.
5450 pat.field[1] = none;
5451 pat.field[2] = symbol;
5453 case 1: // Space between currency-and-sign or currency and value.
5454 pat.field[1] = none;
5455 pat.field[2] = symbol;
5456 if (!symbol_contains_sep) {
5457 // We insert the space into the symbol instead of
5458 // setting pat.field[1]=space so that when
5459 // showbase is not set, the space goes away too.
5460 __curr_symbol_.insert(0, 1, space_char);
5463 case 2: // Space between sign and currency or value.
5464 pat.field[1] = symbol;
5465 pat.field[2] = space;
5466 if (symbol_contains_sep) {
5467 // Remove the separator from the symbol, since it
5468 // should not disappear when showbase is absent.
5469 __curr_symbol_.erase(__curr_symbol_.begin());
5480 case 1: // curr_symbol before value
5483 case 0: // Parentheses surround the quantity and currency symbol.
5484 pat.field[0] = sign;
5485 pat.field[1] = symbol;
5486 pat.field[2] = none; // Any space appears in the symbol.
5487 pat.field[3] = value;
5488 switch (sep_by_space)
5490 case 0: // No space separates the currency symbol and value.
5491 // This case may have changed between C99 and C11;
5492 // assume the currency symbol matches the intention.
5493 case 2: // Space between sign and currency or value.
5494 // The "sign" is two parentheses, so no space here either.
5496 case 1: // Space between currency-and-sign or currency and value.
5497 if (!symbol_contains_sep) {
5498 // We insert the space into the symbol instead of
5499 // setting pat.field[2]=space so that when
5500 // showbase is not set, the space goes away too.
5501 __curr_symbol_.insert(0, 1, space_char);
5508 case 1: // The sign string precedes the quantity and currency symbol.
5509 pat.field[0] = sign;
5510 pat.field[3] = value;
5511 switch (sep_by_space)
5513 case 0: // No space separates the currency symbol and value.
5514 pat.field[1] = symbol;
5515 pat.field[2] = none;
5517 case 1: // Space between currency-and-sign or currency and value.
5518 pat.field[1] = symbol;
5519 pat.field[2] = none;
5520 if (!symbol_contains_sep) {
5521 // We insert the space into the symbol instead of
5522 // setting pat.field[2]=space so that when
5523 // showbase is not set, the space goes away too.
5524 __curr_symbol_.push_back(space_char);
5527 case 2: // Space between sign and currency or value.
5528 pat.field[1] = space;
5529 pat.field[2] = symbol;
5530 if (symbol_contains_sep) {
5531 // Remove the separator from the symbol, since it
5532 // has already appeared after the sign.
5533 __curr_symbol_.pop_back();
5540 case 2: // The sign string succeeds the quantity and currency symbol.
5541 pat.field[0] = symbol;
5542 pat.field[3] = sign;
5543 switch (sep_by_space)
5545 case 0: // No space separates the currency symbol and value.
5546 pat.field[1] = none;
5547 pat.field[2] = value;
5549 case 1: // Space between currency-and-sign or currency and value.
5550 pat.field[1] = none;
5551 pat.field[2] = value;
5552 if (!symbol_contains_sep) {
5553 // We insert the space into the symbol instead of
5554 // setting pat.field[1]=space so that when
5555 // showbase is not set, the space goes away too.
5556 __curr_symbol_.push_back(space_char);
5559 case 2: // Space between sign and currency or value.
5560 pat.field[1] = value;
5561 pat.field[2] = space;
5562 if (symbol_contains_sep) {
5563 // Remove the separator from the symbol, since it
5564 // will appear before the sign.
5565 __curr_symbol_.pop_back();
5572 case 3: // The sign string immediately precedes the currency symbol.
5573 pat.field[0] = sign;
5574 pat.field[3] = value;
5575 switch (sep_by_space)
5577 case 0: // No space separates the currency symbol and value.
5578 pat.field[1] = symbol;
5579 pat.field[2] = none;
5581 case 1: // Space between currency-and-sign or currency and value.
5582 pat.field[1] = symbol;
5583 pat.field[2] = none;
5584 if (!symbol_contains_sep) {
5585 // We insert the space into the symbol instead of
5586 // setting pat.field[2]=space so that when
5587 // showbase is not set, the space goes away too.
5588 __curr_symbol_.push_back(space_char);
5591 case 2: // Space between sign and currency or value.
5592 pat.field[1] = space;
5593 pat.field[2] = symbol;
5594 if (symbol_contains_sep) {
5595 // Remove the separator from the symbol, since it
5596 // has already appeared after the sign.
5597 __curr_symbol_.pop_back();
5604 case 4: // The sign string immediately succeeds the currency symbol.
5605 pat.field[0] = symbol;
5606 pat.field[3] = value;
5607 switch (sep_by_space)
5609 case 0: // No space separates the currency symbol and value.
5610 pat.field[1] = sign;
5611 pat.field[2] = none;
5613 case 1: // Space between currency-and-sign or currency and value.
5614 pat.field[1] = sign;
5615 pat.field[2] = space;
5616 if (symbol_contains_sep) {
5617 // Remove the separator from the symbol, since it
5618 // should not disappear when showbase is absent.
5619 __curr_symbol_.pop_back();
5622 case 2: // Space between sign and currency or value.
5623 pat.field[1] = none;
5624 pat.field[2] = sign;
5625 if (!symbol_contains_sep) {
5626 // We insert the space into the symbol instead of
5627 // setting pat.field[1]=space so that when
5628 // showbase is not set, the space goes away too.
5629 __curr_symbol_.push_back(space_char);
5643 pat.field[0] = symbol;
5644 pat.field[1] = sign;
5645 pat.field[2] = none;
5646 pat.field[3] = value;
5651 moneypunct_byname<char, false>::init(const char* nm)
5653 typedef moneypunct<char, false> base;
5654 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
5655 #ifndef _LIBCPP_NO_EXCEPTIONS
5657 throw runtime_error("moneypunct_byname"
5658 " failed to construct for " + string(nm));
5659 #endif // _LIBCPP_NO_EXCEPTIONS
5660 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5661 lconv* lc = localeconv_l(loc.get());
5663 lconv* lc = __localeconv_l(loc.get());
5665 if (*lc->mon_decimal_point)
5666 __decimal_point_ = *lc->mon_decimal_point;
5668 __decimal_point_ = base::do_decimal_point();
5669 if (*lc->mon_thousands_sep)
5670 __thousands_sep_ = *lc->mon_thousands_sep;
5672 __thousands_sep_ = base::do_thousands_sep();
5673 __grouping_ = lc->mon_grouping;
5674 __curr_symbol_ = lc->currency_symbol;
5675 if (lc->frac_digits != CHAR_MAX)
5676 __frac_digits_ = lc->frac_digits;
5678 __frac_digits_ = base::do_frac_digits();
5679 if (lc->p_sign_posn == 0)
5680 __positive_sign_ = "()";
5682 __positive_sign_ = lc->positive_sign;
5683 if (lc->n_sign_posn == 0)
5684 __negative_sign_ = "()";
5686 __negative_sign_ = lc->negative_sign;
5687 // Assume the positive and negative formats will want spaces in
5688 // the same places in curr_symbol since there's no way to
5689 // represent anything else.
5690 string_type __dummy_curr_symbol = __curr_symbol_;
5691 __init_pat(__pos_format_, __dummy_curr_symbol, false,
5692 lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
5693 __init_pat(__neg_format_, __curr_symbol_, false,
5694 lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
5699 moneypunct_byname<char, true>::init(const char* nm)
5701 typedef moneypunct<char, true> base;
5702 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
5703 #ifndef _LIBCPP_NO_EXCEPTIONS
5705 throw runtime_error("moneypunct_byname"
5706 " failed to construct for " + string(nm));
5707 #endif // _LIBCPP_NO_EXCEPTIONS
5708 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5709 lconv* lc = localeconv_l(loc.get());
5711 lconv* lc = __localeconv_l(loc.get());
5713 if (*lc->mon_decimal_point)
5714 __decimal_point_ = *lc->mon_decimal_point;
5716 __decimal_point_ = base::do_decimal_point();
5717 if (*lc->mon_thousands_sep)
5718 __thousands_sep_ = *lc->mon_thousands_sep;
5720 __thousands_sep_ = base::do_thousands_sep();
5721 __grouping_ = lc->mon_grouping;
5722 __curr_symbol_ = lc->int_curr_symbol;
5723 if (lc->int_frac_digits != CHAR_MAX)
5724 __frac_digits_ = lc->int_frac_digits;
5726 __frac_digits_ = base::do_frac_digits();
5728 if (lc->p_sign_posn == 0)
5730 if (lc->int_p_sign_posn == 0)
5732 __positive_sign_ = "()";
5734 __positive_sign_ = lc->positive_sign;
5736 if(lc->n_sign_posn == 0)
5738 if (lc->int_n_sign_posn == 0)
5740 __negative_sign_ = "()";
5742 __negative_sign_ = lc->negative_sign;
5743 // Assume the positive and negative formats will want spaces in
5744 // the same places in curr_symbol since there's no way to
5745 // represent anything else.
5746 string_type __dummy_curr_symbol = __curr_symbol_;
5748 __init_pat(__pos_format_, __dummy_curr_symbol, true,
5749 lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
5750 __init_pat(__neg_format_, __curr_symbol_, true,
5751 lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
5753 __init_pat(__pos_format_, __dummy_curr_symbol, true,
5754 lc->int_p_cs_precedes, lc->int_p_sep_by_space,
5755 lc->int_p_sign_posn, ' ');
5756 __init_pat(__neg_format_, __curr_symbol_, true,
5757 lc->int_n_cs_precedes, lc->int_n_sep_by_space,
5758 lc->int_n_sign_posn, ' ');
5764 moneypunct_byname<wchar_t, false>::init(const char* nm)
5766 typedef moneypunct<wchar_t, false> base;
5767 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
5768 #ifndef _LIBCPP_NO_EXCEPTIONS
5770 throw runtime_error("moneypunct_byname"
5771 " failed to construct for " + string(nm));
5772 #endif // _LIBCPP_NO_EXCEPTIONS
5773 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5774 lconv* lc = localeconv_l(loc.get());
5776 lconv* lc = __localeconv_l(loc.get());
5778 if (*lc->mon_decimal_point)
5779 __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
5781 __decimal_point_ = base::do_decimal_point();
5782 if (*lc->mon_thousands_sep)
5783 __thousands_sep_ = static_cast<wchar_t>(*lc->mon_thousands_sep);
5785 __thousands_sep_ = base::do_thousands_sep();
5786 __grouping_ = lc->mon_grouping;
5789 const char* bb = lc->currency_symbol;
5790 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5791 size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5793 size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5795 if (j == size_t(-1))
5796 __throw_runtime_error("locale not supported");
5797 wchar_t* wbe = wbuf + j;
5798 __curr_symbol_.assign(wbuf, wbe);
5799 if (lc->frac_digits != CHAR_MAX)
5800 __frac_digits_ = lc->frac_digits;
5802 __frac_digits_ = base::do_frac_digits();
5803 if (lc->p_sign_posn == 0)
5804 __positive_sign_ = L"()";
5808 bb = lc->positive_sign;
5809 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5810 j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5812 j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5814 if (j == size_t(-1))
5815 __throw_runtime_error("locale not supported");
5817 __positive_sign_.assign(wbuf, wbe);
5819 if (lc->n_sign_posn == 0)
5820 __negative_sign_ = L"()";
5824 bb = lc->negative_sign;
5825 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5826 j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5828 j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5830 if (j == size_t(-1))
5831 __throw_runtime_error("locale not supported");
5833 __negative_sign_.assign(wbuf, wbe);
5835 // Assume the positive and negative formats will want spaces in
5836 // the same places in curr_symbol since there's no way to
5837 // represent anything else.
5838 string_type __dummy_curr_symbol = __curr_symbol_;
5839 __init_pat(__pos_format_, __dummy_curr_symbol, false,
5840 lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
5841 __init_pat(__neg_format_, __curr_symbol_, false,
5842 lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
5847 moneypunct_byname<wchar_t, true>::init(const char* nm)
5849 typedef moneypunct<wchar_t, true> base;
5850 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
5851 #ifndef _LIBCPP_NO_EXCEPTIONS
5853 throw runtime_error("moneypunct_byname"
5854 " failed to construct for " + string(nm));
5855 #endif // _LIBCPP_NO_EXCEPTIONS
5856 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5857 lconv* lc = localeconv_l(loc.get());
5859 lconv* lc = __localeconv_l(loc.get());
5861 if (*lc->mon_decimal_point)
5862 __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
5864 __decimal_point_ = base::do_decimal_point();
5865 if (*lc->mon_thousands_sep)
5866 __thousands_sep_ = static_cast<wchar_t>(*lc->mon_thousands_sep);
5868 __thousands_sep_ = base::do_thousands_sep();
5869 __grouping_ = lc->mon_grouping;
5872 const char* bb = lc->int_curr_symbol;
5873 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5874 size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5876 size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5878 if (j == size_t(-1))
5879 __throw_runtime_error("locale not supported");
5880 wchar_t* wbe = wbuf + j;
5881 __curr_symbol_.assign(wbuf, wbe);
5882 if (lc->int_frac_digits != CHAR_MAX)
5883 __frac_digits_ = lc->int_frac_digits;
5885 __frac_digits_ = base::do_frac_digits();
5887 if (lc->p_sign_posn == 0)
5889 if (lc->int_p_sign_posn == 0)
5891 __positive_sign_ = L"()";
5895 bb = lc->positive_sign;
5896 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5897 j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5899 j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5901 if (j == size_t(-1))
5902 __throw_runtime_error("locale not supported");
5904 __positive_sign_.assign(wbuf, wbe);
5907 if (lc->n_sign_posn == 0)
5909 if (lc->int_n_sign_posn == 0)
5911 __negative_sign_ = L"()";
5915 bb = lc->negative_sign;
5916 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5917 j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5919 j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5921 if (j == size_t(-1))
5922 __throw_runtime_error("locale not supported");
5924 __negative_sign_.assign(wbuf, wbe);
5926 // Assume the positive and negative formats will want spaces in
5927 // the same places in curr_symbol since there's no way to
5928 // represent anything else.
5929 string_type __dummy_curr_symbol = __curr_symbol_;
5931 __init_pat(__pos_format_, __dummy_curr_symbol, true,
5932 lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
5933 __init_pat(__neg_format_, __curr_symbol_, true,
5934 lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
5936 __init_pat(__pos_format_, __dummy_curr_symbol, true,
5937 lc->int_p_cs_precedes, lc->int_p_sep_by_space,
5938 lc->int_p_sign_posn, L' ');
5939 __init_pat(__neg_format_, __curr_symbol_, true,
5940 lc->int_n_cs_precedes, lc->int_n_sep_by_space,
5941 lc->int_n_sign_posn, L' ');
5945 void __do_nothing(void*) {}
5947 void __throw_runtime_error(const char* msg)
5949 #ifndef _LIBCPP_NO_EXCEPTIONS
5950 throw runtime_error(msg);
5954 template class collate<char>;
5955 template class collate<wchar_t>;
5957 template class num_get<char>;
5958 template class num_get<wchar_t>;
5960 template struct __num_get<char>;
5961 template struct __num_get<wchar_t>;
5963 template class num_put<char>;
5964 template class num_put<wchar_t>;
5966 template struct __num_put<char>;
5967 template struct __num_put<wchar_t>;
5969 template class time_get<char>;
5970 template class time_get<wchar_t>;
5972 template class time_get_byname<char>;
5973 template class time_get_byname<wchar_t>;
5975 template class time_put<char>;
5976 template class time_put<wchar_t>;
5978 template class time_put_byname<char>;
5979 template class time_put_byname<wchar_t>;
5981 template class moneypunct<char, false>;
5982 template class moneypunct<char, true>;
5983 template class moneypunct<wchar_t, false>;
5984 template class moneypunct<wchar_t, true>;
5986 template class moneypunct_byname<char, false>;
5987 template class moneypunct_byname<char, true>;
5988 template class moneypunct_byname<wchar_t, false>;
5989 template class moneypunct_byname<wchar_t, true>;
5991 template class money_get<char>;
5992 template class money_get<wchar_t>;
5994 template class __money_get<char>;
5995 template class __money_get<wchar_t>;
5997 template class money_put<char>;
5998 template class money_put<wchar_t>;
6000 template class __money_put<char>;
6001 template class __money_put<wchar_t>;
6003 template class messages<char>;
6004 template class messages<wchar_t>;
6006 template class messages_byname<char>;
6007 template class messages_byname<wchar_t>;
6009 template class codecvt_byname<char, char, mbstate_t>;
6010 template class codecvt_byname<wchar_t, char, mbstate_t>;
6011 template class codecvt_byname<char16_t, char, mbstate_t>;
6012 template class codecvt_byname<char32_t, char, mbstate_t>;
6014 template class __vector_base_common<true>;
6016 _LIBCPP_END_NAMESPACE_STD