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));
1056 if (m & space && !iswspace_l(c, __l)) result = false;
1057 if (m & print && !iswprint_l(c, __l)) result = false;
1058 if (m & cntrl && !iswcntrl_l(c, __l)) result = false;
1059 if (m & upper && !iswupper_l(c, __l)) result = false;
1060 if (m & lower && !iswlower_l(c, __l)) result = false;
1061 if (m & alpha && !iswalpha_l(c, __l)) result = false;
1062 if (m & digit && !iswdigit_l(c, __l)) result = false;
1063 if (m & punct && !iswpunct_l(c, __l)) result = false;
1064 if (m & xdigit && !iswxdigit_l(c, __l)) result = false;
1065 if (m & blank && !iswblank_l(c, __l)) result = false;
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)) continue;
1113 if (m & print && !iswprint_l(*low, __l)) continue;
1114 if (m & cntrl && !iswcntrl_l(*low, __l)) continue;
1115 if (m & upper && !iswupper_l(*low, __l)) continue;
1116 if (m & lower && !iswlower_l(*low, __l)) continue;
1117 if (m & alpha && !iswalpha_l(*low, __l)) continue;
1118 if (m & digit && !iswdigit_l(*low, __l)) continue;
1119 if (m & punct && !iswpunct_l(*low, __l)) continue;
1120 if (m & xdigit && !iswxdigit_l(*low, __l)) continue;
1121 if (m & blank && !iswblank_l(*low, __l)) continue;
1129 ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
1131 for (; low != high; ++low)
1133 #ifdef _LIBCPP_WCTYPE_IS_MASK
1134 if (!iswctype_l(*low, m, __l))
1137 if (m & space && iswspace_l(*low, __l)) continue;
1138 if (m & print && iswprint_l(*low, __l)) continue;
1139 if (m & cntrl && iswcntrl_l(*low, __l)) continue;
1140 if (m & upper && iswupper_l(*low, __l)) continue;
1141 if (m & lower && iswlower_l(*low, __l)) continue;
1142 if (m & alpha && iswalpha_l(*low, __l)) continue;
1143 if (m & digit && iswdigit_l(*low, __l)) continue;
1144 if (m & punct && iswpunct_l(*low, __l)) continue;
1145 if (m & xdigit && iswxdigit_l(*low, __l)) continue;
1146 if (m & blank && iswblank_l(*low, __l)) continue;
1154 ctype_byname<wchar_t>::do_toupper(char_type c) const
1156 return towupper_l(c, __l);
1160 ctype_byname<wchar_t>::do_toupper(char_type* low, const char_type* high) const
1162 for (; low != high; ++low)
1163 *low = towupper_l(*low, __l);
1168 ctype_byname<wchar_t>::do_tolower(char_type c) const
1170 return towlower_l(c, __l);
1174 ctype_byname<wchar_t>::do_tolower(char_type* low, const char_type* high) const
1176 for (; low != high; ++low)
1177 *low = towlower_l(*low, __l);
1182 ctype_byname<wchar_t>::do_widen(char c) const
1184 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1185 return btowc_l(c, __l);
1187 return __btowc_l(c, __l);
1192 ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
1194 for (; low != high; ++low, ++dest)
1195 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1196 *dest = btowc_l(*low, __l);
1198 *dest = __btowc_l(*low, __l);
1204 ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const
1206 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1207 int r = wctob_l(c, __l);
1209 int r = __wctob_l(c, __l);
1211 return r != WEOF ? static_cast<char>(r) : dfault;
1215 ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
1217 for (; low != high; ++low, ++dest)
1219 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1220 int r = wctob_l(*low, __l);
1222 int r = __wctob_l(*low, __l);
1224 *dest = r != WEOF ? static_cast<char>(r) : dfault;
1229 // template <> class codecvt<char, char, mbstate_t>
1231 locale::id codecvt<char, char, mbstate_t>::id;
1233 codecvt<char, char, mbstate_t>::~codecvt()
1237 codecvt<char, char, mbstate_t>::result
1238 codecvt<char, char, mbstate_t>::do_out(state_type&,
1239 const intern_type* frm, const intern_type*, const intern_type*& frm_nxt,
1240 extern_type* to, extern_type*, extern_type*& to_nxt) const
1247 codecvt<char, char, mbstate_t>::result
1248 codecvt<char, char, mbstate_t>::do_in(state_type&,
1249 const extern_type* frm, const extern_type*, const extern_type*& frm_nxt,
1250 intern_type* to, intern_type*, intern_type*& to_nxt) const
1257 codecvt<char, char, mbstate_t>::result
1258 codecvt<char, char, mbstate_t>::do_unshift(state_type&,
1259 extern_type* to, extern_type*, extern_type*& to_nxt) const
1266 codecvt<char, char, mbstate_t>::do_encoding() const _NOEXCEPT
1272 codecvt<char, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
1278 codecvt<char, char, mbstate_t>::do_length(state_type&,
1279 const extern_type* frm, const extern_type* end, size_t mx) const
1281 return static_cast<int>(min<size_t>(mx, static_cast<size_t>(end-frm)));
1285 codecvt<char, char, mbstate_t>::do_max_length() const _NOEXCEPT
1290 // template <> class codecvt<wchar_t, char, mbstate_t>
1292 locale::id codecvt<wchar_t, char, mbstate_t>::id;
1294 codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs)
1295 : locale::facet(refs),
1300 codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs)
1301 : locale::facet(refs),
1302 __l(newlocale(LC_ALL_MASK, nm, 0))
1304 #ifndef _LIBCPP_NO_EXCEPTIONS
1306 throw runtime_error("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname"
1307 " failed to construct for " + string(nm));
1308 #endif // _LIBCPP_NO_EXCEPTIONS
1311 codecvt<wchar_t, char, mbstate_t>::~codecvt()
1317 codecvt<wchar_t, char, mbstate_t>::result
1318 codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
1319 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
1320 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
1322 // look for first internal null in frm
1323 const intern_type* fend = frm;
1324 for (; fend != frm_end; ++fend)
1327 // loop over all null-terminated sequences in frm
1329 for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
1331 // save state in case needed to reover to_nxt on error
1332 mbstate_t save_state = st;
1333 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1334 size_t n = wcsnrtombs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
1335 static_cast<size_t>(to_end-to), &st, __l);
1337 size_t n = __wcsnrtombs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
1339 if (n == size_t(-1))
1341 // need to recover to_nxt
1342 for (to_nxt = to; frm != frm_nxt; ++frm)
1344 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1345 n = wcrtomb_l(to_nxt, *frm, &save_state, __l);
1347 n = __wcrtomb_l(to_nxt, *frm, &save_state, __l);
1349 if (n == size_t(-1))
1359 if (to_nxt == to_end)
1361 if (fend != frm_end) // set up next null terminated sequence
1363 // Try to write the terminating null
1364 extern_type tmp[MB_LEN_MAX];
1365 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1366 n = wcrtomb_l(tmp, intern_type(), &st, __l);
1368 n = __wcrtomb_l(tmp, intern_type(), &st, __l);
1370 if (n == size_t(-1)) // on error
1372 if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
1374 for (extern_type* p = tmp; n; --n) // write it
1377 // look for next null in frm
1378 for (fend = frm_nxt; fend != frm_end; ++fend)
1383 return frm_nxt == frm_end ? ok : partial;
1386 codecvt<wchar_t, char, mbstate_t>::result
1387 codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
1388 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
1389 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
1391 // look for first internal null in frm
1392 const extern_type* fend = frm;
1393 for (; fend != frm_end; ++fend)
1396 // loop over all null-terminated sequences in frm
1398 for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
1400 // save state in case needed to reover to_nxt on error
1401 mbstate_t save_state = st;
1402 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1403 size_t n = mbsnrtowcs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
1404 static_cast<size_t>(to_end-to), &st, __l);
1406 size_t n = __mbsnrtowcs_l(to, &frm_nxt, fend-frm, to_end-to, &st, __l);
1408 if (n == size_t(-1))
1410 // need to recover to_nxt
1411 for (to_nxt = to; frm != frm_nxt; ++to_nxt)
1413 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1414 n = mbrtowc_l(to_nxt, frm, static_cast<size_t>(fend-frm),
1417 n = __mbrtowc_l(to_nxt, frm, fend-frm, &save_state, __l);
1436 return frm_nxt == frm_end ? ok : partial;
1441 if (to_nxt == to_end)
1443 if (fend != frm_end) // set up next null terminated sequence
1445 // Try to write the terminating null
1446 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1447 n = mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l);
1449 n = __mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l);
1451 if (n != 0) // on error
1455 // look for next null in frm
1456 for (fend = frm_nxt; fend != frm_end; ++fend)
1461 return frm_nxt == frm_end ? ok : partial;
1464 codecvt<wchar_t, char, mbstate_t>::result
1465 codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st,
1466 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
1469 extern_type tmp[MB_LEN_MAX];
1470 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1471 size_t n = wcrtomb_l(tmp, intern_type(), &st, __l);
1473 size_t n = __wcrtomb_l(tmp, intern_type(), &st, __l);
1475 if (n == size_t(-1) || n == 0) // on error
1478 if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
1480 for (extern_type* p = tmp; n; --n) // write it
1486 codecvt<wchar_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
1488 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1489 if (mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
1491 if (__mbtowc_l((wchar_t*) 0, (const char*) 0, MB_LEN_MAX, __l) == 0)
1494 // stateless encoding
1495 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1496 if (__l == 0 || MB_CUR_MAX_L(__l) == 1) // there are no known constant length encodings
1498 if (__l == 0 || __mb_cur_max_l(__l) == 1) // there are no known constant length encodings
1500 return 1; // which take more than 1 char to form a wchar_t
1507 codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
1513 codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st,
1514 const extern_type* frm, const extern_type* frm_end, size_t mx) const
1517 for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t)
1519 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1520 size_t n = mbrlen_l(frm, static_cast<size_t>(frm_end-frm), &st, __l);
1522 size_t n = __mbrlen_l(frm, frm_end-frm, &st, __l);
1543 codecvt<wchar_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
1545 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
1546 return __l == 0 ? 1 : MB_CUR_MAX_L(__l);
1548 return __l == 0 ? 1 : __mb_cur_max_l(__l);
1553 // UTF-32 UTF-16 UTF-8 # of code points
1554 // first second first second third fourth
1555 // 000000 - 00007F 0000 - 007F 00 - 7F 127
1556 // 000080 - 0007FF 0080 - 07FF C2 - DF, 80 - BF 1920
1557 // 000800 - 000FFF 0800 - 0FFF E0 - E0, A0 - BF, 80 - BF 2048
1558 // 001000 - 00CFFF 1000 - CFFF E1 - EC, 80 - BF, 80 - BF 49152
1559 // 00D000 - 00D7FF D000 - D7FF ED - ED, 80 - 9F, 80 - BF 2048
1560 // 00D800 - 00DFFF invalid
1561 // 00E000 - 00FFFF E000 - FFFF EE - EF, 80 - BF, 80 - BF 8192
1562 // 010000 - 03FFFF D800 - D8BF, DC00 - DFFF F0 - F0, 90 - BF, 80 - BF, 80 - BF 196608
1563 // 040000 - 0FFFFF D8C0 - DBBF, DC00 - DFFF F1 - F3, 80 - BF, 80 - BF, 80 - BF 786432
1564 // 100000 - 10FFFF DBC0 - DBFF, DC00 - DFFF F4 - F4, 80 - 8F, 80 - BF, 80 - BF 65536
1567 codecvt_base::result
1568 utf16_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
1569 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
1570 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1574 if (mode & generate_header)
1576 if (to_end-to_nxt < 3)
1577 return codecvt_base::partial;
1578 *to_nxt++ = static_cast<uint8_t>(0xEF);
1579 *to_nxt++ = static_cast<uint8_t>(0xBB);
1580 *to_nxt++ = static_cast<uint8_t>(0xBF);
1582 for (; frm_nxt < frm_end; ++frm_nxt)
1584 uint16_t wc1 = *frm_nxt;
1586 return codecvt_base::error;
1589 if (to_end-to_nxt < 1)
1590 return codecvt_base::partial;
1591 *to_nxt++ = static_cast<uint8_t>(wc1);
1593 else if (wc1 < 0x0800)
1595 if (to_end-to_nxt < 2)
1596 return codecvt_base::partial;
1597 *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
1598 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
1600 else if (wc1 < 0xD800)
1602 if (to_end-to_nxt < 3)
1603 return codecvt_base::partial;
1604 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1605 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1606 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1608 else if (wc1 < 0xDC00)
1610 if (frm_end-frm_nxt < 2)
1611 return codecvt_base::partial;
1612 uint16_t wc2 = frm_nxt[1];
1613 if ((wc2 & 0xFC00) != 0xDC00)
1614 return codecvt_base::error;
1615 if (to_end-to_nxt < 4)
1616 return codecvt_base::partial;
1617 if ((((((unsigned long)wc1 & 0x03C0) >> 6) + 1) << 16) +
1618 (((unsigned long)wc1 & 0x003F) << 10) + (wc2 & 0x03FF) > Maxcode)
1619 return codecvt_base::error;
1621 uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
1622 *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
1623 *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
1624 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
1625 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
1627 else if (wc1 < 0xE000)
1629 return codecvt_base::error;
1633 if (to_end-to_nxt < 3)
1634 return codecvt_base::partial;
1635 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1636 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1637 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1640 return codecvt_base::ok;
1644 codecvt_base::result
1645 utf16_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
1646 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
1647 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1651 if (mode & generate_header)
1653 if (to_end-to_nxt < 3)
1654 return codecvt_base::partial;
1655 *to_nxt++ = static_cast<uint8_t>(0xEF);
1656 *to_nxt++ = static_cast<uint8_t>(0xBB);
1657 *to_nxt++ = static_cast<uint8_t>(0xBF);
1659 for (; frm_nxt < frm_end; ++frm_nxt)
1661 uint16_t wc1 = static_cast<uint16_t>(*frm_nxt);
1663 return codecvt_base::error;
1666 if (to_end-to_nxt < 1)
1667 return codecvt_base::partial;
1668 *to_nxt++ = static_cast<uint8_t>(wc1);
1670 else if (wc1 < 0x0800)
1672 if (to_end-to_nxt < 2)
1673 return codecvt_base::partial;
1674 *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
1675 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
1677 else if (wc1 < 0xD800)
1679 if (to_end-to_nxt < 3)
1680 return codecvt_base::partial;
1681 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1682 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1683 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1685 else if (wc1 < 0xDC00)
1687 if (frm_end-frm_nxt < 2)
1688 return codecvt_base::partial;
1689 uint16_t wc2 = static_cast<uint16_t>(frm_nxt[1]);
1690 if ((wc2 & 0xFC00) != 0xDC00)
1691 return codecvt_base::error;
1692 if (to_end-to_nxt < 4)
1693 return codecvt_base::partial;
1694 if ((((((unsigned long)wc1 & 0x03C0) >> 6) + 1) << 16) +
1695 (((unsigned long)wc1 & 0x003F) << 10) + (wc2 & 0x03FF) > Maxcode)
1696 return codecvt_base::error;
1698 uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
1699 *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
1700 *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
1701 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
1702 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
1704 else if (wc1 < 0xE000)
1706 return codecvt_base::error;
1710 if (to_end-to_nxt < 3)
1711 return codecvt_base::partial;
1712 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1713 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1714 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1717 return codecvt_base::ok;
1721 codecvt_base::result
1722 utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
1723 uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
1724 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1728 if (mode & consume_header)
1730 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
1734 for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
1736 uint8_t c1 = *frm_nxt;
1738 return codecvt_base::error;
1741 *to_nxt = static_cast<uint16_t>(c1);
1746 return codecvt_base::error;
1750 if (frm_end-frm_nxt < 2)
1751 return codecvt_base::partial;
1752 uint8_t c2 = frm_nxt[1];
1753 if ((c2 & 0xC0) != 0x80)
1754 return codecvt_base::error;
1755 uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
1757 return codecvt_base::error;
1763 if (frm_end-frm_nxt < 3)
1764 return codecvt_base::partial;
1765 uint8_t c2 = frm_nxt[1];
1766 uint8_t c3 = frm_nxt[2];
1770 if ((c2 & 0xE0) != 0xA0)
1771 return codecvt_base::error;
1774 if ((c2 & 0xE0) != 0x80)
1775 return codecvt_base::error;
1778 if ((c2 & 0xC0) != 0x80)
1779 return codecvt_base::error;
1782 if ((c3 & 0xC0) != 0x80)
1783 return codecvt_base::error;
1784 uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
1785 | ((c2 & 0x3F) << 6)
1788 return codecvt_base::error;
1794 if (frm_end-frm_nxt < 4)
1795 return codecvt_base::partial;
1796 uint8_t c2 = frm_nxt[1];
1797 uint8_t c3 = frm_nxt[2];
1798 uint8_t c4 = frm_nxt[3];
1802 if (!(0x90 <= c2 && c2 <= 0xBF))
1803 return codecvt_base::error;
1806 if ((c2 & 0xF0) != 0x80)
1807 return codecvt_base::error;
1810 if ((c2 & 0xC0) != 0x80)
1811 return codecvt_base::error;
1814 if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
1815 return codecvt_base::error;
1816 if (to_end-to_nxt < 2)
1817 return codecvt_base::partial;
1818 if (((((unsigned long)c1 & 7) << 18) +
1819 (((unsigned long)c2 & 0x3F) << 12) +
1820 (((unsigned long)c3 & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode)
1821 return codecvt_base::error;
1822 *to_nxt = static_cast<uint16_t>(
1824 | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
1825 | ((c2 & 0x0F) << 2)
1826 | ((c3 & 0x30) >> 4));
1827 *++to_nxt = static_cast<uint16_t>(
1829 | ((c3 & 0x0F) << 6)
1835 return codecvt_base::error;
1838 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
1842 codecvt_base::result
1843 utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
1844 uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
1845 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1849 if (mode & consume_header)
1851 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
1855 for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
1857 uint8_t c1 = *frm_nxt;
1859 return codecvt_base::error;
1862 *to_nxt = static_cast<uint32_t>(c1);
1867 return codecvt_base::error;
1871 if (frm_end-frm_nxt < 2)
1872 return codecvt_base::partial;
1873 uint8_t c2 = frm_nxt[1];
1874 if ((c2 & 0xC0) != 0x80)
1875 return codecvt_base::error;
1876 uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
1878 return codecvt_base::error;
1879 *to_nxt = static_cast<uint32_t>(t);
1884 if (frm_end-frm_nxt < 3)
1885 return codecvt_base::partial;
1886 uint8_t c2 = frm_nxt[1];
1887 uint8_t c3 = frm_nxt[2];
1891 if ((c2 & 0xE0) != 0xA0)
1892 return codecvt_base::error;
1895 if ((c2 & 0xE0) != 0x80)
1896 return codecvt_base::error;
1899 if ((c2 & 0xC0) != 0x80)
1900 return codecvt_base::error;
1903 if ((c3 & 0xC0) != 0x80)
1904 return codecvt_base::error;
1905 uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
1906 | ((c2 & 0x3F) << 6)
1909 return codecvt_base::error;
1910 *to_nxt = static_cast<uint32_t>(t);
1915 if (frm_end-frm_nxt < 4)
1916 return codecvt_base::partial;
1917 uint8_t c2 = frm_nxt[1];
1918 uint8_t c3 = frm_nxt[2];
1919 uint8_t c4 = frm_nxt[3];
1923 if (!(0x90 <= c2 && c2 <= 0xBF))
1924 return codecvt_base::error;
1927 if ((c2 & 0xF0) != 0x80)
1928 return codecvt_base::error;
1931 if ((c2 & 0xC0) != 0x80)
1932 return codecvt_base::error;
1935 if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
1936 return codecvt_base::error;
1937 if (to_end-to_nxt < 2)
1938 return codecvt_base::partial;
1939 if (((((unsigned long)c1 & 7) << 18) +
1940 (((unsigned long)c2 & 0x3F) << 12) +
1941 (((unsigned long)c3 & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode)
1942 return codecvt_base::error;
1943 *to_nxt = static_cast<uint32_t>(
1945 | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
1946 | ((c2 & 0x0F) << 2)
1947 | ((c3 & 0x30) >> 4));
1948 *++to_nxt = static_cast<uint32_t>(
1950 | ((c3 & 0x0F) << 6)
1956 return codecvt_base::error;
1959 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
1964 utf8_to_utf16_length(const uint8_t* frm, const uint8_t* frm_end,
1965 size_t mx, unsigned long Maxcode = 0x10FFFF,
1966 codecvt_mode mode = codecvt_mode(0))
1968 const uint8_t* frm_nxt = frm;
1969 if (mode & consume_header)
1971 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
1975 for (size_t nchar16_t = 0; frm_nxt < frm_end && nchar16_t < mx; ++nchar16_t)
1977 uint8_t c1 = *frm_nxt;
1990 if ((frm_end-frm_nxt < 2) || (frm_nxt[1] & 0xC0) != 0x80)
1992 uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F));
1999 if (frm_end-frm_nxt < 3)
2001 uint8_t c2 = frm_nxt[1];
2002 uint8_t c3 = frm_nxt[2];
2006 if ((c2 & 0xE0) != 0xA0)
2007 return static_cast<int>(frm_nxt - frm);
2010 if ((c2 & 0xE0) != 0x80)
2011 return static_cast<int>(frm_nxt - frm);
2014 if ((c2 & 0xC0) != 0x80)
2015 return static_cast<int>(frm_nxt - frm);
2018 if ((c3 & 0xC0) != 0x80)
2020 if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
2026 if (frm_end-frm_nxt < 4 || mx-nchar16_t < 2)
2028 uint8_t c2 = frm_nxt[1];
2029 uint8_t c3 = frm_nxt[2];
2030 uint8_t c4 = frm_nxt[3];
2034 if (!(0x90 <= c2 && c2 <= 0xBF))
2035 return static_cast<int>(frm_nxt - frm);
2038 if ((c2 & 0xF0) != 0x80)
2039 return static_cast<int>(frm_nxt - frm);
2042 if ((c2 & 0xC0) != 0x80)
2043 return static_cast<int>(frm_nxt - frm);
2046 if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2048 if (((((unsigned long)c1 & 7) << 18) +
2049 (((unsigned long)c2 & 0x3F) << 12) +
2050 (((unsigned long)c3 & 0x3F) << 6) + (c4 & 0x3F)) > Maxcode)
2060 return static_cast<int>(frm_nxt - frm);
2064 codecvt_base::result
2065 ucs4_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
2066 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2067 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2071 if (mode & generate_header)
2073 if (to_end-to_nxt < 3)
2074 return codecvt_base::partial;
2075 *to_nxt++ = static_cast<uint8_t>(0xEF);
2076 *to_nxt++ = static_cast<uint8_t>(0xBB);
2077 *to_nxt++ = static_cast<uint8_t>(0xBF);
2079 for (; frm_nxt < frm_end; ++frm_nxt)
2081 uint32_t wc = *frm_nxt;
2082 if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
2083 return codecvt_base::error;
2086 if (to_end-to_nxt < 1)
2087 return codecvt_base::partial;
2088 *to_nxt++ = static_cast<uint8_t>(wc);
2090 else if (wc < 0x000800)
2092 if (to_end-to_nxt < 2)
2093 return codecvt_base::partial;
2094 *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
2095 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
2097 else if (wc < 0x010000)
2099 if (to_end-to_nxt < 3)
2100 return codecvt_base::partial;
2101 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
2102 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
2103 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
2105 else // if (wc < 0x110000)
2107 if (to_end-to_nxt < 4)
2108 return codecvt_base::partial;
2109 *to_nxt++ = static_cast<uint8_t>(0xF0 | (wc >> 18));
2110 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x03F000) >> 12));
2111 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x000FC0) >> 6));
2112 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x00003F));
2115 return codecvt_base::ok;
2119 codecvt_base::result
2120 utf8_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2121 uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2122 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2126 if (mode & consume_header)
2128 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2132 for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
2134 uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2138 return codecvt_base::error;
2139 *to_nxt = static_cast<uint32_t>(c1);
2144 return codecvt_base::error;
2148 if (frm_end-frm_nxt < 2)
2149 return codecvt_base::partial;
2150 uint8_t c2 = frm_nxt[1];
2151 if ((c2 & 0xC0) != 0x80)
2152 return codecvt_base::error;
2153 uint32_t t = static_cast<uint32_t>(((c1 & 0x1F) << 6)
2156 return codecvt_base::error;
2162 if (frm_end-frm_nxt < 3)
2163 return codecvt_base::partial;
2164 uint8_t c2 = frm_nxt[1];
2165 uint8_t c3 = frm_nxt[2];
2169 if ((c2 & 0xE0) != 0xA0)
2170 return codecvt_base::error;
2173 if ((c2 & 0xE0) != 0x80)
2174 return codecvt_base::error;
2177 if ((c2 & 0xC0) != 0x80)
2178 return codecvt_base::error;
2181 if ((c3 & 0xC0) != 0x80)
2182 return codecvt_base::error;
2183 uint32_t t = static_cast<uint32_t>(((c1 & 0x0F) << 12)
2184 | ((c2 & 0x3F) << 6)
2187 return codecvt_base::error;
2193 if (frm_end-frm_nxt < 4)
2194 return codecvt_base::partial;
2195 uint8_t c2 = frm_nxt[1];
2196 uint8_t c3 = frm_nxt[2];
2197 uint8_t c4 = frm_nxt[3];
2201 if (!(0x90 <= c2 && c2 <= 0xBF))
2202 return codecvt_base::error;
2205 if ((c2 & 0xF0) != 0x80)
2206 return codecvt_base::error;
2209 if ((c2 & 0xC0) != 0x80)
2210 return codecvt_base::error;
2213 if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2214 return codecvt_base::error;
2215 uint32_t t = static_cast<uint32_t>(((c1 & 0x07) << 18)
2216 | ((c2 & 0x3F) << 12)
2217 | ((c3 & 0x3F) << 6)
2220 return codecvt_base::error;
2226 return codecvt_base::error;
2229 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2234 utf8_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
2235 size_t mx, unsigned long Maxcode = 0x10FFFF,
2236 codecvt_mode mode = codecvt_mode(0))
2238 const uint8_t* frm_nxt = frm;
2239 if (mode & consume_header)
2241 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2245 for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
2247 uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2260 if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
2262 if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
2268 if (frm_end-frm_nxt < 3)
2270 uint8_t c2 = frm_nxt[1];
2271 uint8_t c3 = frm_nxt[2];
2275 if ((c2 & 0xE0) != 0xA0)
2276 return static_cast<int>(frm_nxt - frm);
2279 if ((c2 & 0xE0) != 0x80)
2280 return static_cast<int>(frm_nxt - frm);
2283 if ((c2 & 0xC0) != 0x80)
2284 return static_cast<int>(frm_nxt - frm);
2287 if ((c3 & 0xC0) != 0x80)
2289 if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
2295 if (frm_end-frm_nxt < 4)
2297 uint8_t c2 = frm_nxt[1];
2298 uint8_t c3 = frm_nxt[2];
2299 uint8_t c4 = frm_nxt[3];
2303 if (!(0x90 <= c2 && c2 <= 0xBF))
2304 return static_cast<int>(frm_nxt - frm);
2307 if ((c2 & 0xF0) != 0x80)
2308 return static_cast<int>(frm_nxt - frm);
2311 if ((c2 & 0xC0) != 0x80)
2312 return static_cast<int>(frm_nxt - frm);
2315 if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2317 if ((((c1 & 0x07u) << 18) | ((c2 & 0x3Fu) << 12) |
2318 ((c3 & 0x3Fu) << 6) | (c4 & 0x3Fu)) > Maxcode)
2327 return static_cast<int>(frm_nxt - frm);
2331 codecvt_base::result
2332 ucs2_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
2333 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2334 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2338 if (mode & generate_header)
2340 if (to_end-to_nxt < 3)
2341 return codecvt_base::partial;
2342 *to_nxt++ = static_cast<uint8_t>(0xEF);
2343 *to_nxt++ = static_cast<uint8_t>(0xBB);
2344 *to_nxt++ = static_cast<uint8_t>(0xBF);
2346 for (; frm_nxt < frm_end; ++frm_nxt)
2348 uint16_t wc = *frm_nxt;
2349 if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
2350 return codecvt_base::error;
2353 if (to_end-to_nxt < 1)
2354 return codecvt_base::partial;
2355 *to_nxt++ = static_cast<uint8_t>(wc);
2357 else if (wc < 0x0800)
2359 if (to_end-to_nxt < 2)
2360 return codecvt_base::partial;
2361 *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
2362 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
2364 else // if (wc <= 0xFFFF)
2366 if (to_end-to_nxt < 3)
2367 return codecvt_base::partial;
2368 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
2369 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
2370 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
2373 return codecvt_base::ok;
2377 codecvt_base::result
2378 utf8_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2379 uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
2380 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2384 if (mode & consume_header)
2386 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2390 for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
2392 uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2396 return codecvt_base::error;
2397 *to_nxt = static_cast<uint16_t>(c1);
2402 return codecvt_base::error;
2406 if (frm_end-frm_nxt < 2)
2407 return codecvt_base::partial;
2408 uint8_t c2 = frm_nxt[1];
2409 if ((c2 & 0xC0) != 0x80)
2410 return codecvt_base::error;
2411 uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6)
2414 return codecvt_base::error;
2420 if (frm_end-frm_nxt < 3)
2421 return codecvt_base::partial;
2422 uint8_t c2 = frm_nxt[1];
2423 uint8_t c3 = frm_nxt[2];
2427 if ((c2 & 0xE0) != 0xA0)
2428 return codecvt_base::error;
2431 if ((c2 & 0xE0) != 0x80)
2432 return codecvt_base::error;
2435 if ((c2 & 0xC0) != 0x80)
2436 return codecvt_base::error;
2439 if ((c3 & 0xC0) != 0x80)
2440 return codecvt_base::error;
2441 uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
2442 | ((c2 & 0x3F) << 6)
2445 return codecvt_base::error;
2451 return codecvt_base::error;
2454 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2459 utf8_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
2460 size_t mx, unsigned long Maxcode = 0x10FFFF,
2461 codecvt_mode mode = codecvt_mode(0))
2463 const uint8_t* frm_nxt = frm;
2464 if (mode & consume_header)
2466 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2470 for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
2472 uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2485 if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
2487 if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
2493 if (frm_end-frm_nxt < 3)
2495 uint8_t c2 = frm_nxt[1];
2496 uint8_t c3 = frm_nxt[2];
2500 if ((c2 & 0xE0) != 0xA0)
2501 return static_cast<int>(frm_nxt - frm);
2504 if ((c2 & 0xE0) != 0x80)
2505 return static_cast<int>(frm_nxt - frm);
2508 if ((c2 & 0xC0) != 0x80)
2509 return static_cast<int>(frm_nxt - frm);
2512 if ((c3 & 0xC0) != 0x80)
2514 if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
2523 return static_cast<int>(frm_nxt - frm);
2527 codecvt_base::result
2528 ucs4_to_utf16be(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
2529 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2530 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2534 if (mode & generate_header)
2536 if (to_end-to_nxt < 2)
2537 return codecvt_base::partial;
2538 *to_nxt++ = static_cast<uint8_t>(0xFE);
2539 *to_nxt++ = static_cast<uint8_t>(0xFF);
2541 for (; frm_nxt < frm_end; ++frm_nxt)
2543 uint32_t wc = *frm_nxt;
2544 if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
2545 return codecvt_base::error;
2548 if (to_end-to_nxt < 2)
2549 return codecvt_base::partial;
2550 *to_nxt++ = static_cast<uint8_t>(wc >> 8);
2551 *to_nxt++ = static_cast<uint8_t>(wc);
2555 if (to_end-to_nxt < 4)
2556 return codecvt_base::partial;
2557 uint16_t t = static_cast<uint16_t>(
2559 | ((((wc & 0x1F0000) >> 16) - 1) << 6)
2560 | ((wc & 0x00FC00) >> 10));
2561 *to_nxt++ = static_cast<uint8_t>(t >> 8);
2562 *to_nxt++ = static_cast<uint8_t>(t);
2563 t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
2564 *to_nxt++ = static_cast<uint8_t>(t >> 8);
2565 *to_nxt++ = static_cast<uint8_t>(t);
2568 return codecvt_base::ok;
2572 codecvt_base::result
2573 utf16be_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2574 uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2575 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2579 if (mode & consume_header)
2581 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2584 for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2586 uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2587 if ((c1 & 0xFC00) == 0xDC00)
2588 return codecvt_base::error;
2589 if ((c1 & 0xFC00) != 0xD800)
2592 return codecvt_base::error;
2593 *to_nxt = static_cast<uint32_t>(c1);
2598 if (frm_end-frm_nxt < 4)
2599 return codecvt_base::partial;
2600 uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
2601 if ((c2 & 0xFC00) != 0xDC00)
2602 return codecvt_base::error;
2603 uint32_t t = static_cast<uint32_t>(
2604 ((((c1 & 0x03C0) >> 6) + 1) << 16)
2605 | ((c1 & 0x003F) << 10)
2608 return codecvt_base::error;
2613 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2618 utf16be_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
2619 size_t mx, unsigned long Maxcode = 0x10FFFF,
2620 codecvt_mode mode = codecvt_mode(0))
2622 const uint8_t* frm_nxt = frm;
2624 if (mode & consume_header)
2626 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2629 for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
2631 uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2632 if ((c1 & 0xFC00) == 0xDC00)
2634 if ((c1 & 0xFC00) != 0xD800)
2642 if (frm_end-frm_nxt < 4)
2644 uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
2645 if ((c2 & 0xFC00) != 0xDC00)
2647 uint32_t t = static_cast<uint32_t>(
2648 ((((c1 & 0x03C0) >> 6) + 1) << 16)
2649 | ((c1 & 0x003F) << 10)
2656 return static_cast<int>(frm_nxt - frm);
2660 codecvt_base::result
2661 ucs4_to_utf16le(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
2662 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2663 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2667 if (mode & generate_header)
2669 if (to_end-to_nxt < 2)
2670 return codecvt_base::partial;
2671 *to_nxt++ = static_cast<uint8_t>(0xFF);
2672 *to_nxt++ = static_cast<uint8_t>(0xFE);
2674 for (; frm_nxt < frm_end; ++frm_nxt)
2676 uint32_t wc = *frm_nxt;
2677 if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
2678 return codecvt_base::error;
2681 if (to_end-to_nxt < 2)
2682 return codecvt_base::partial;
2683 *to_nxt++ = static_cast<uint8_t>(wc);
2684 *to_nxt++ = static_cast<uint8_t>(wc >> 8);
2688 if (to_end-to_nxt < 4)
2689 return codecvt_base::partial;
2690 uint16_t t = static_cast<uint16_t>(
2692 | ((((wc & 0x1F0000) >> 16) - 1) << 6)
2693 | ((wc & 0x00FC00) >> 10));
2694 *to_nxt++ = static_cast<uint8_t>(t);
2695 *to_nxt++ = static_cast<uint8_t>(t >> 8);
2696 t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
2697 *to_nxt++ = static_cast<uint8_t>(t);
2698 *to_nxt++ = static_cast<uint8_t>(t >> 8);
2701 return codecvt_base::ok;
2705 codecvt_base::result
2706 utf16le_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2707 uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2708 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2712 if (mode & consume_header)
2714 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
2717 for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2719 uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
2720 if ((c1 & 0xFC00) == 0xDC00)
2721 return codecvt_base::error;
2722 if ((c1 & 0xFC00) != 0xD800)
2725 return codecvt_base::error;
2726 *to_nxt = static_cast<uint32_t>(c1);
2731 if (frm_end-frm_nxt < 4)
2732 return codecvt_base::partial;
2733 uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
2734 if ((c2 & 0xFC00) != 0xDC00)
2735 return codecvt_base::error;
2736 uint32_t t = static_cast<uint32_t>(
2737 ((((c1 & 0x03C0) >> 6) + 1) << 16)
2738 | ((c1 & 0x003F) << 10)
2741 return codecvt_base::error;
2746 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2751 utf16le_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
2752 size_t mx, unsigned long Maxcode = 0x10FFFF,
2753 codecvt_mode mode = codecvt_mode(0))
2755 const uint8_t* frm_nxt = frm;
2757 if (mode & consume_header)
2759 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
2762 for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
2764 uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
2765 if ((c1 & 0xFC00) == 0xDC00)
2767 if ((c1 & 0xFC00) != 0xD800)
2775 if (frm_end-frm_nxt < 4)
2777 uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
2778 if ((c2 & 0xFC00) != 0xDC00)
2780 uint32_t t = static_cast<uint32_t>(
2781 ((((c1 & 0x03C0) >> 6) + 1) << 16)
2782 | ((c1 & 0x003F) << 10)
2789 return static_cast<int>(frm_nxt - frm);
2793 codecvt_base::result
2794 ucs2_to_utf16be(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
2795 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2796 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2800 if (mode & generate_header)
2802 if (to_end-to_nxt < 2)
2803 return codecvt_base::partial;
2804 *to_nxt++ = static_cast<uint8_t>(0xFE);
2805 *to_nxt++ = static_cast<uint8_t>(0xFF);
2807 for (; frm_nxt < frm_end; ++frm_nxt)
2809 uint16_t wc = *frm_nxt;
2810 if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
2811 return codecvt_base::error;
2812 if (to_end-to_nxt < 2)
2813 return codecvt_base::partial;
2814 *to_nxt++ = static_cast<uint8_t>(wc >> 8);
2815 *to_nxt++ = static_cast<uint8_t>(wc);
2817 return codecvt_base::ok;
2821 codecvt_base::result
2822 utf16be_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2823 uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
2824 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2828 if (mode & consume_header)
2830 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2833 for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2835 uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2836 if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
2837 return codecvt_base::error;
2841 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2846 utf16be_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
2847 size_t mx, unsigned long Maxcode = 0x10FFFF,
2848 codecvt_mode mode = codecvt_mode(0))
2850 const uint8_t* frm_nxt = frm;
2852 if (mode & consume_header)
2854 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2857 for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
2859 uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2860 if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
2864 return static_cast<int>(frm_nxt - frm);
2868 codecvt_base::result
2869 ucs2_to_utf16le(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
2870 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2871 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2875 if (mode & generate_header)
2877 if (to_end-to_nxt < 2)
2878 return codecvt_base::partial;
2879 *to_nxt++ = static_cast<uint8_t>(0xFF);
2880 *to_nxt++ = static_cast<uint8_t>(0xFE);
2882 for (; frm_nxt < frm_end; ++frm_nxt)
2884 uint16_t wc = *frm_nxt;
2885 if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
2886 return codecvt_base::error;
2887 if (to_end-to_nxt < 2)
2888 return codecvt_base::partial;
2889 *to_nxt++ = static_cast<uint8_t>(wc);
2890 *to_nxt++ = static_cast<uint8_t>(wc >> 8);
2892 return codecvt_base::ok;
2896 codecvt_base::result
2897 utf16le_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2898 uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
2899 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2903 if (mode & consume_header)
2905 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
2908 for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2910 uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
2911 if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
2912 return codecvt_base::error;
2916 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2921 utf16le_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
2922 size_t mx, unsigned long Maxcode = 0x10FFFF,
2923 codecvt_mode mode = codecvt_mode(0))
2925 const uint8_t* frm_nxt = frm;
2927 if (mode & consume_header)
2929 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
2932 for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
2934 uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
2935 if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
2939 return static_cast<int>(frm_nxt - frm);
2942 // template <> class codecvt<char16_t, char, mbstate_t>
2944 locale::id codecvt<char16_t, char, mbstate_t>::id;
2946 codecvt<char16_t, char, mbstate_t>::~codecvt()
2950 codecvt<char16_t, char, mbstate_t>::result
2951 codecvt<char16_t, char, mbstate_t>::do_out(state_type&,
2952 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
2953 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
2955 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
2956 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
2957 const uint16_t* _frm_nxt = _frm;
2958 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
2959 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
2960 uint8_t* _to_nxt = _to;
2961 result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
2962 frm_nxt = frm + (_frm_nxt - _frm);
2963 to_nxt = to + (_to_nxt - _to);
2967 codecvt<char16_t, char, mbstate_t>::result
2968 codecvt<char16_t, char, mbstate_t>::do_in(state_type&,
2969 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
2970 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
2972 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
2973 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
2974 const uint8_t* _frm_nxt = _frm;
2975 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
2976 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
2977 uint16_t* _to_nxt = _to;
2978 result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
2979 frm_nxt = frm + (_frm_nxt - _frm);
2980 to_nxt = to + (_to_nxt - _to);
2984 codecvt<char16_t, char, mbstate_t>::result
2985 codecvt<char16_t, char, mbstate_t>::do_unshift(state_type&,
2986 extern_type* to, extern_type*, extern_type*& to_nxt) const
2993 codecvt<char16_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
2999 codecvt<char16_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
3005 codecvt<char16_t, char, mbstate_t>::do_length(state_type&,
3006 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3008 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3009 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3010 return utf8_to_utf16_length(_frm, _frm_end, mx);
3014 codecvt<char16_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
3019 // template <> class codecvt<char32_t, char, mbstate_t>
3021 locale::id codecvt<char32_t, char, mbstate_t>::id;
3023 codecvt<char32_t, char, mbstate_t>::~codecvt()
3027 codecvt<char32_t, char, mbstate_t>::result
3028 codecvt<char32_t, char, mbstate_t>::do_out(state_type&,
3029 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3030 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3032 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3033 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3034 const uint32_t* _frm_nxt = _frm;
3035 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3036 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3037 uint8_t* _to_nxt = _to;
3038 result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3039 frm_nxt = frm + (_frm_nxt - _frm);
3040 to_nxt = to + (_to_nxt - _to);
3044 codecvt<char32_t, char, mbstate_t>::result
3045 codecvt<char32_t, char, mbstate_t>::do_in(state_type&,
3046 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3047 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3049 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3050 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3051 const uint8_t* _frm_nxt = _frm;
3052 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3053 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3054 uint32_t* _to_nxt = _to;
3055 result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3056 frm_nxt = frm + (_frm_nxt - _frm);
3057 to_nxt = to + (_to_nxt - _to);
3061 codecvt<char32_t, char, mbstate_t>::result
3062 codecvt<char32_t, char, mbstate_t>::do_unshift(state_type&,
3063 extern_type* to, extern_type*, extern_type*& to_nxt) const
3070 codecvt<char32_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
3076 codecvt<char32_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
3082 codecvt<char32_t, char, mbstate_t>::do_length(state_type&,
3083 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3085 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3086 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3087 return utf8_to_ucs4_length(_frm, _frm_end, mx);
3091 codecvt<char32_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
3096 // __codecvt_utf8<wchar_t>
3098 __codecvt_utf8<wchar_t>::result
3099 __codecvt_utf8<wchar_t>::do_out(state_type&,
3100 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3101 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3103 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3104 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3105 const uint32_t* _frm_nxt = _frm;
3106 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3107 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3108 uint8_t* _to_nxt = _to;
3109 result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3111 frm_nxt = frm + (_frm_nxt - _frm);
3112 to_nxt = to + (_to_nxt - _to);
3116 __codecvt_utf8<wchar_t>::result
3117 __codecvt_utf8<wchar_t>::do_in(state_type&,
3118 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3119 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3121 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3122 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3123 const uint8_t* _frm_nxt = _frm;
3124 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3125 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3126 uint32_t* _to_nxt = _to;
3127 result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3129 frm_nxt = frm + (_frm_nxt - _frm);
3130 to_nxt = to + (_to_nxt - _to);
3134 __codecvt_utf8<wchar_t>::result
3135 __codecvt_utf8<wchar_t>::do_unshift(state_type&,
3136 extern_type* to, extern_type*, extern_type*& to_nxt) const
3143 __codecvt_utf8<wchar_t>::do_encoding() const _NOEXCEPT
3149 __codecvt_utf8<wchar_t>::do_always_noconv() const _NOEXCEPT
3155 __codecvt_utf8<wchar_t>::do_length(state_type&,
3156 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3158 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3159 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3160 return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3164 __codecvt_utf8<wchar_t>::do_max_length() const _NOEXCEPT
3166 if (_Mode_ & consume_header)
3171 // __codecvt_utf8<char16_t>
3173 __codecvt_utf8<char16_t>::result
3174 __codecvt_utf8<char16_t>::do_out(state_type&,
3175 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3176 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3178 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3179 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3180 const uint16_t* _frm_nxt = _frm;
3181 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3182 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3183 uint8_t* _to_nxt = _to;
3184 result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3186 frm_nxt = frm + (_frm_nxt - _frm);
3187 to_nxt = to + (_to_nxt - _to);
3191 __codecvt_utf8<char16_t>::result
3192 __codecvt_utf8<char16_t>::do_in(state_type&,
3193 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3194 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3196 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3197 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3198 const uint8_t* _frm_nxt = _frm;
3199 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3200 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3201 uint16_t* _to_nxt = _to;
3202 result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3204 frm_nxt = frm + (_frm_nxt - _frm);
3205 to_nxt = to + (_to_nxt - _to);
3209 __codecvt_utf8<char16_t>::result
3210 __codecvt_utf8<char16_t>::do_unshift(state_type&,
3211 extern_type* to, extern_type*, extern_type*& to_nxt) const
3218 __codecvt_utf8<char16_t>::do_encoding() const _NOEXCEPT
3224 __codecvt_utf8<char16_t>::do_always_noconv() const _NOEXCEPT
3230 __codecvt_utf8<char16_t>::do_length(state_type&,
3231 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3233 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3234 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3235 return utf8_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3239 __codecvt_utf8<char16_t>::do_max_length() const _NOEXCEPT
3241 if (_Mode_ & consume_header)
3246 // __codecvt_utf8<char32_t>
3248 __codecvt_utf8<char32_t>::result
3249 __codecvt_utf8<char32_t>::do_out(state_type&,
3250 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3251 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3253 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3254 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3255 const uint32_t* _frm_nxt = _frm;
3256 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3257 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3258 uint8_t* _to_nxt = _to;
3259 result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3261 frm_nxt = frm + (_frm_nxt - _frm);
3262 to_nxt = to + (_to_nxt - _to);
3266 __codecvt_utf8<char32_t>::result
3267 __codecvt_utf8<char32_t>::do_in(state_type&,
3268 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3269 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3271 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3272 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3273 const uint8_t* _frm_nxt = _frm;
3274 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3275 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3276 uint32_t* _to_nxt = _to;
3277 result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3279 frm_nxt = frm + (_frm_nxt - _frm);
3280 to_nxt = to + (_to_nxt - _to);
3284 __codecvt_utf8<char32_t>::result
3285 __codecvt_utf8<char32_t>::do_unshift(state_type&,
3286 extern_type* to, extern_type*, extern_type*& to_nxt) const
3293 __codecvt_utf8<char32_t>::do_encoding() const _NOEXCEPT
3299 __codecvt_utf8<char32_t>::do_always_noconv() const _NOEXCEPT
3305 __codecvt_utf8<char32_t>::do_length(state_type&,
3306 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3308 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3309 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3310 return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3314 __codecvt_utf8<char32_t>::do_max_length() const _NOEXCEPT
3316 if (_Mode_ & consume_header)
3321 // __codecvt_utf16<wchar_t, false>
3323 __codecvt_utf16<wchar_t, false>::result
3324 __codecvt_utf16<wchar_t, false>::do_out(state_type&,
3325 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3326 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3328 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3329 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3330 const uint32_t* _frm_nxt = _frm;
3331 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3332 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3333 uint8_t* _to_nxt = _to;
3334 result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3336 frm_nxt = frm + (_frm_nxt - _frm);
3337 to_nxt = to + (_to_nxt - _to);
3341 __codecvt_utf16<wchar_t, false>::result
3342 __codecvt_utf16<wchar_t, false>::do_in(state_type&,
3343 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3344 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3346 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3347 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3348 const uint8_t* _frm_nxt = _frm;
3349 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3350 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3351 uint32_t* _to_nxt = _to;
3352 result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3354 frm_nxt = frm + (_frm_nxt - _frm);
3355 to_nxt = to + (_to_nxt - _to);
3359 __codecvt_utf16<wchar_t, false>::result
3360 __codecvt_utf16<wchar_t, false>::do_unshift(state_type&,
3361 extern_type* to, extern_type*, extern_type*& to_nxt) const
3368 __codecvt_utf16<wchar_t, false>::do_encoding() const _NOEXCEPT
3374 __codecvt_utf16<wchar_t, false>::do_always_noconv() const _NOEXCEPT
3380 __codecvt_utf16<wchar_t, false>::do_length(state_type&,
3381 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3383 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3384 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3385 return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3389 __codecvt_utf16<wchar_t, false>::do_max_length() const _NOEXCEPT
3391 if (_Mode_ & consume_header)
3396 // __codecvt_utf16<wchar_t, true>
3398 __codecvt_utf16<wchar_t, true>::result
3399 __codecvt_utf16<wchar_t, true>::do_out(state_type&,
3400 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3401 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3403 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3404 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3405 const uint32_t* _frm_nxt = _frm;
3406 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3407 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3408 uint8_t* _to_nxt = _to;
3409 result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3411 frm_nxt = frm + (_frm_nxt - _frm);
3412 to_nxt = to + (_to_nxt - _to);
3416 __codecvt_utf16<wchar_t, true>::result
3417 __codecvt_utf16<wchar_t, true>::do_in(state_type&,
3418 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3419 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3421 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3422 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3423 const uint8_t* _frm_nxt = _frm;
3424 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3425 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3426 uint32_t* _to_nxt = _to;
3427 result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3429 frm_nxt = frm + (_frm_nxt - _frm);
3430 to_nxt = to + (_to_nxt - _to);
3434 __codecvt_utf16<wchar_t, true>::result
3435 __codecvt_utf16<wchar_t, true>::do_unshift(state_type&,
3436 extern_type* to, extern_type*, extern_type*& to_nxt) const
3443 __codecvt_utf16<wchar_t, true>::do_encoding() const _NOEXCEPT
3449 __codecvt_utf16<wchar_t, true>::do_always_noconv() const _NOEXCEPT
3455 __codecvt_utf16<wchar_t, true>::do_length(state_type&,
3456 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3458 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3459 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3460 return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3464 __codecvt_utf16<wchar_t, true>::do_max_length() const _NOEXCEPT
3466 if (_Mode_ & consume_header)
3471 // __codecvt_utf16<char16_t, false>
3473 __codecvt_utf16<char16_t, false>::result
3474 __codecvt_utf16<char16_t, false>::do_out(state_type&,
3475 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3476 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3478 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3479 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3480 const uint16_t* _frm_nxt = _frm;
3481 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3482 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3483 uint8_t* _to_nxt = _to;
3484 result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3486 frm_nxt = frm + (_frm_nxt - _frm);
3487 to_nxt = to + (_to_nxt - _to);
3491 __codecvt_utf16<char16_t, false>::result
3492 __codecvt_utf16<char16_t, false>::do_in(state_type&,
3493 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3494 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3496 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3497 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3498 const uint8_t* _frm_nxt = _frm;
3499 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3500 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3501 uint16_t* _to_nxt = _to;
3502 result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3504 frm_nxt = frm + (_frm_nxt - _frm);
3505 to_nxt = to + (_to_nxt - _to);
3509 __codecvt_utf16<char16_t, false>::result
3510 __codecvt_utf16<char16_t, false>::do_unshift(state_type&,
3511 extern_type* to, extern_type*, extern_type*& to_nxt) const
3518 __codecvt_utf16<char16_t, false>::do_encoding() const _NOEXCEPT
3524 __codecvt_utf16<char16_t, false>::do_always_noconv() const _NOEXCEPT
3530 __codecvt_utf16<char16_t, false>::do_length(state_type&,
3531 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3533 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3534 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3535 return utf16be_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3539 __codecvt_utf16<char16_t, false>::do_max_length() const _NOEXCEPT
3541 if (_Mode_ & consume_header)
3546 // __codecvt_utf16<char16_t, true>
3548 __codecvt_utf16<char16_t, true>::result
3549 __codecvt_utf16<char16_t, true>::do_out(state_type&,
3550 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3551 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3553 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3554 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3555 const uint16_t* _frm_nxt = _frm;
3556 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3557 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3558 uint8_t* _to_nxt = _to;
3559 result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3561 frm_nxt = frm + (_frm_nxt - _frm);
3562 to_nxt = to + (_to_nxt - _to);
3566 __codecvt_utf16<char16_t, true>::result
3567 __codecvt_utf16<char16_t, true>::do_in(state_type&,
3568 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3569 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3571 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3572 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3573 const uint8_t* _frm_nxt = _frm;
3574 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3575 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3576 uint16_t* _to_nxt = _to;
3577 result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3579 frm_nxt = frm + (_frm_nxt - _frm);
3580 to_nxt = to + (_to_nxt - _to);
3584 __codecvt_utf16<char16_t, true>::result
3585 __codecvt_utf16<char16_t, true>::do_unshift(state_type&,
3586 extern_type* to, extern_type*, extern_type*& to_nxt) const
3593 __codecvt_utf16<char16_t, true>::do_encoding() const _NOEXCEPT
3599 __codecvt_utf16<char16_t, true>::do_always_noconv() const _NOEXCEPT
3605 __codecvt_utf16<char16_t, true>::do_length(state_type&,
3606 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3608 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3609 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3610 return utf16le_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3614 __codecvt_utf16<char16_t, true>::do_max_length() const _NOEXCEPT
3616 if (_Mode_ & consume_header)
3621 // __codecvt_utf16<char32_t, false>
3623 __codecvt_utf16<char32_t, false>::result
3624 __codecvt_utf16<char32_t, false>::do_out(state_type&,
3625 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3626 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3628 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3629 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3630 const uint32_t* _frm_nxt = _frm;
3631 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3632 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3633 uint8_t* _to_nxt = _to;
3634 result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3636 frm_nxt = frm + (_frm_nxt - _frm);
3637 to_nxt = to + (_to_nxt - _to);
3641 __codecvt_utf16<char32_t, false>::result
3642 __codecvt_utf16<char32_t, false>::do_in(state_type&,
3643 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3644 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3646 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3647 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3648 const uint8_t* _frm_nxt = _frm;
3649 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3650 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3651 uint32_t* _to_nxt = _to;
3652 result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3654 frm_nxt = frm + (_frm_nxt - _frm);
3655 to_nxt = to + (_to_nxt - _to);
3659 __codecvt_utf16<char32_t, false>::result
3660 __codecvt_utf16<char32_t, false>::do_unshift(state_type&,
3661 extern_type* to, extern_type*, extern_type*& to_nxt) const
3668 __codecvt_utf16<char32_t, false>::do_encoding() const _NOEXCEPT
3674 __codecvt_utf16<char32_t, false>::do_always_noconv() const _NOEXCEPT
3680 __codecvt_utf16<char32_t, false>::do_length(state_type&,
3681 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3683 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3684 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3685 return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3689 __codecvt_utf16<char32_t, false>::do_max_length() const _NOEXCEPT
3691 if (_Mode_ & consume_header)
3696 // __codecvt_utf16<char32_t, true>
3698 __codecvt_utf16<char32_t, true>::result
3699 __codecvt_utf16<char32_t, true>::do_out(state_type&,
3700 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3701 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3703 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3704 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3705 const uint32_t* _frm_nxt = _frm;
3706 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3707 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3708 uint8_t* _to_nxt = _to;
3709 result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3711 frm_nxt = frm + (_frm_nxt - _frm);
3712 to_nxt = to + (_to_nxt - _to);
3716 __codecvt_utf16<char32_t, true>::result
3717 __codecvt_utf16<char32_t, true>::do_in(state_type&,
3718 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3719 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3721 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3722 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3723 const uint8_t* _frm_nxt = _frm;
3724 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3725 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3726 uint32_t* _to_nxt = _to;
3727 result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3729 frm_nxt = frm + (_frm_nxt - _frm);
3730 to_nxt = to + (_to_nxt - _to);
3734 __codecvt_utf16<char32_t, true>::result
3735 __codecvt_utf16<char32_t, true>::do_unshift(state_type&,
3736 extern_type* to, extern_type*, extern_type*& to_nxt) const
3743 __codecvt_utf16<char32_t, true>::do_encoding() const _NOEXCEPT
3749 __codecvt_utf16<char32_t, true>::do_always_noconv() const _NOEXCEPT
3755 __codecvt_utf16<char32_t, true>::do_length(state_type&,
3756 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3758 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3759 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3760 return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3764 __codecvt_utf16<char32_t, true>::do_max_length() const _NOEXCEPT
3766 if (_Mode_ & consume_header)
3771 // __codecvt_utf8_utf16<wchar_t>
3773 __codecvt_utf8_utf16<wchar_t>::result
3774 __codecvt_utf8_utf16<wchar_t>::do_out(state_type&,
3775 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3776 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3778 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3779 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3780 const uint32_t* _frm_nxt = _frm;
3781 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3782 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3783 uint8_t* _to_nxt = _to;
3784 result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3786 frm_nxt = frm + (_frm_nxt - _frm);
3787 to_nxt = to + (_to_nxt - _to);
3791 __codecvt_utf8_utf16<wchar_t>::result
3792 __codecvt_utf8_utf16<wchar_t>::do_in(state_type&,
3793 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3794 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3796 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3797 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3798 const uint8_t* _frm_nxt = _frm;
3799 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3800 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3801 uint32_t* _to_nxt = _to;
3802 result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3804 frm_nxt = frm + (_frm_nxt - _frm);
3805 to_nxt = to + (_to_nxt - _to);
3809 __codecvt_utf8_utf16<wchar_t>::result
3810 __codecvt_utf8_utf16<wchar_t>::do_unshift(state_type&,
3811 extern_type* to, extern_type*, extern_type*& to_nxt) const
3818 __codecvt_utf8_utf16<wchar_t>::do_encoding() const _NOEXCEPT
3824 __codecvt_utf8_utf16<wchar_t>::do_always_noconv() const _NOEXCEPT
3830 __codecvt_utf8_utf16<wchar_t>::do_length(state_type&,
3831 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3833 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3834 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3835 return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3839 __codecvt_utf8_utf16<wchar_t>::do_max_length() const _NOEXCEPT
3841 if (_Mode_ & consume_header)
3846 // __codecvt_utf8_utf16<char16_t>
3848 __codecvt_utf8_utf16<char16_t>::result
3849 __codecvt_utf8_utf16<char16_t>::do_out(state_type&,
3850 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3851 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3853 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3854 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3855 const uint16_t* _frm_nxt = _frm;
3856 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3857 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3858 uint8_t* _to_nxt = _to;
3859 result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3861 frm_nxt = frm + (_frm_nxt - _frm);
3862 to_nxt = to + (_to_nxt - _to);
3866 __codecvt_utf8_utf16<char16_t>::result
3867 __codecvt_utf8_utf16<char16_t>::do_in(state_type&,
3868 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3869 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3871 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3872 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3873 const uint8_t* _frm_nxt = _frm;
3874 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3875 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3876 uint16_t* _to_nxt = _to;
3877 result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3879 frm_nxt = frm + (_frm_nxt - _frm);
3880 to_nxt = to + (_to_nxt - _to);
3884 __codecvt_utf8_utf16<char16_t>::result
3885 __codecvt_utf8_utf16<char16_t>::do_unshift(state_type&,
3886 extern_type* to, extern_type*, extern_type*& to_nxt) const
3893 __codecvt_utf8_utf16<char16_t>::do_encoding() const _NOEXCEPT
3899 __codecvt_utf8_utf16<char16_t>::do_always_noconv() const _NOEXCEPT
3905 __codecvt_utf8_utf16<char16_t>::do_length(state_type&,
3906 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3908 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3909 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3910 return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3914 __codecvt_utf8_utf16<char16_t>::do_max_length() const _NOEXCEPT
3916 if (_Mode_ & consume_header)
3921 // __codecvt_utf8_utf16<char32_t>
3923 __codecvt_utf8_utf16<char32_t>::result
3924 __codecvt_utf8_utf16<char32_t>::do_out(state_type&,
3925 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3926 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3928 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3929 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3930 const uint32_t* _frm_nxt = _frm;
3931 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3932 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3933 uint8_t* _to_nxt = _to;
3934 result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3936 frm_nxt = frm + (_frm_nxt - _frm);
3937 to_nxt = to + (_to_nxt - _to);
3941 __codecvt_utf8_utf16<char32_t>::result
3942 __codecvt_utf8_utf16<char32_t>::do_in(state_type&,
3943 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3944 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3946 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3947 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3948 const uint8_t* _frm_nxt = _frm;
3949 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3950 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3951 uint32_t* _to_nxt = _to;
3952 result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3954 frm_nxt = frm + (_frm_nxt - _frm);
3955 to_nxt = to + (_to_nxt - _to);
3959 __codecvt_utf8_utf16<char32_t>::result
3960 __codecvt_utf8_utf16<char32_t>::do_unshift(state_type&,
3961 extern_type* to, extern_type*, extern_type*& to_nxt) const
3968 __codecvt_utf8_utf16<char32_t>::do_encoding() const _NOEXCEPT
3974 __codecvt_utf8_utf16<char32_t>::do_always_noconv() const _NOEXCEPT
3980 __codecvt_utf8_utf16<char32_t>::do_length(state_type&,
3981 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3983 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3984 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3985 return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3989 __codecvt_utf8_utf16<char32_t>::do_max_length() const _NOEXCEPT
3991 if (_Mode_ & consume_header)
3996 // __narrow_to_utf8<16>
3998 __narrow_to_utf8<16>::~__narrow_to_utf8()
4002 // __narrow_to_utf8<32>
4004 __narrow_to_utf8<32>::~__narrow_to_utf8()
4008 // __widen_from_utf8<16>
4010 __widen_from_utf8<16>::~__widen_from_utf8()
4014 // __widen_from_utf8<32>
4016 __widen_from_utf8<32>::~__widen_from_utf8()
4020 // numpunct<char> && numpunct<wchar_t>
4022 locale::id numpunct< char >::id;
4023 locale::id numpunct<wchar_t>::id;
4025 numpunct<char>::numpunct(size_t refs)
4026 : locale::facet(refs),
4027 __decimal_point_('.'),
4028 __thousands_sep_(',')
4032 numpunct<wchar_t>::numpunct(size_t refs)
4033 : locale::facet(refs),
4034 __decimal_point_(L'.'),
4035 __thousands_sep_(L',')
4039 numpunct<char>::~numpunct()
4043 numpunct<wchar_t>::~numpunct()
4047 char numpunct< char >::do_decimal_point() const {return __decimal_point_;}
4048 wchar_t numpunct<wchar_t>::do_decimal_point() const {return __decimal_point_;}
4050 char numpunct< char >::do_thousands_sep() const {return __thousands_sep_;}
4051 wchar_t numpunct<wchar_t>::do_thousands_sep() const {return __thousands_sep_;}
4053 string numpunct< char >::do_grouping() const {return __grouping_;}
4054 string numpunct<wchar_t>::do_grouping() const {return __grouping_;}
4056 string numpunct< char >::do_truename() const {return "true";}
4057 wstring numpunct<wchar_t>::do_truename() const {return L"true";}
4059 string numpunct< char >::do_falsename() const {return "false";}
4060 wstring numpunct<wchar_t>::do_falsename() const {return L"false";}
4062 // numpunct_byname<char>
4064 numpunct_byname<char>::numpunct_byname(const char* nm, size_t refs)
4065 : numpunct<char>(refs)
4070 numpunct_byname<char>::numpunct_byname(const string& nm, size_t refs)
4071 : numpunct<char>(refs)
4076 numpunct_byname<char>::~numpunct_byname()
4081 numpunct_byname<char>::__init(const char* nm)
4083 if (strcmp(nm, "C") != 0)
4085 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
4086 #ifndef _LIBCPP_NO_EXCEPTIONS
4088 throw runtime_error("numpunct_byname<char>::numpunct_byname"
4089 " failed to construct for " + string(nm));
4090 #endif // _LIBCPP_NO_EXCEPTIONS
4091 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4092 lconv* lc = localeconv_l(loc.get());
4094 lconv* lc = __localeconv_l(loc.get());
4096 if (*lc->decimal_point)
4097 __decimal_point_ = *lc->decimal_point;
4098 if (*lc->thousands_sep)
4099 __thousands_sep_ = *lc->thousands_sep;
4100 __grouping_ = lc->grouping;
4101 // localization for truename and falsename is not available
4105 // numpunct_byname<wchar_t>
4107 numpunct_byname<wchar_t>::numpunct_byname(const char* nm, size_t refs)
4108 : numpunct<wchar_t>(refs)
4113 numpunct_byname<wchar_t>::numpunct_byname(const string& nm, size_t refs)
4114 : numpunct<wchar_t>(refs)
4119 numpunct_byname<wchar_t>::~numpunct_byname()
4124 numpunct_byname<wchar_t>::__init(const char* nm)
4126 if (strcmp(nm, "C") != 0)
4128 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
4129 #ifndef _LIBCPP_NO_EXCEPTIONS
4131 throw runtime_error("numpunct_byname<char>::numpunct_byname"
4132 " failed to construct for " + string(nm));
4133 #endif // _LIBCPP_NO_EXCEPTIONS
4134 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4135 lconv* lc = localeconv_l(loc.get());
4137 lconv* lc = __localeconv_l(loc.get());
4139 if (*lc->decimal_point)
4140 __decimal_point_ = *lc->decimal_point;
4141 if (*lc->thousands_sep)
4142 __thousands_sep_ = *lc->thousands_sep;
4143 __grouping_ = lc->grouping;
4144 // locallization for truename and falsename is not available
4151 __num_get_base::__get_base(ios_base& iob)
4153 ios_base::fmtflags __basefield = iob.flags() & ios_base::basefield;
4154 if (__basefield == ios_base::oct)
4156 else if (__basefield == ios_base::hex)
4158 else if (__basefield == 0)
4163 const char __num_get_base::__src[33] = "0123456789abcdefABCDEFxX+-pPiInN";
4166 __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end,
4167 ios_base::iostate& __err)
4169 if (__grouping.size() != 0)
4171 reverse(__g, __g_end);
4172 const char* __ig = __grouping.data();
4173 const char* __eg = __ig + __grouping.size();
4174 for (unsigned* __r = __g; __r < __g_end-1; ++__r)
4176 if (0 < *__ig && *__ig < numeric_limits<char>::max())
4178 if (static_cast<unsigned>(*__ig) != *__r)
4180 __err = ios_base::failbit;
4184 if (__eg - __ig > 1)
4187 if (0 < *__ig && *__ig < numeric_limits<char>::max())
4189 if (static_cast<unsigned>(*__ig) < __g_end[-1] || __g_end[-1] == 0)
4190 __err = ios_base::failbit;
4196 __num_put_base::__format_int(char* __fmtp, const char* __len, bool __signd,
4197 ios_base::fmtflags __flags)
4199 if (__flags & ios_base::showpos)
4201 if (__flags & ios_base::showbase)
4204 *__fmtp++ = *__len++;
4205 if ((__flags & ios_base::basefield) == ios_base::oct)
4207 else if ((__flags & ios_base::basefield) == ios_base::hex)
4209 if (__flags & ios_base::uppercase)
4221 __num_put_base::__format_float(char* __fmtp, const char* __len,
4222 ios_base::fmtflags __flags)
4224 bool specify_precision = true;
4225 if (__flags & ios_base::showpos)
4227 if (__flags & ios_base::showpoint)
4229 ios_base::fmtflags floatfield = __flags & ios_base::floatfield;
4230 bool uppercase = __flags & ios_base::uppercase;
4231 if (floatfield == (ios_base::fixed | ios_base::scientific))
4232 specify_precision = false;
4239 *__fmtp++ = *__len++;
4240 if (floatfield == ios_base::fixed)
4247 else if (floatfield == ios_base::scientific)
4254 else if (floatfield == (ios_base::fixed | ios_base::scientific))
4268 return specify_precision;
4272 __num_put_base::__identify_padding(char* __nb, char* __ne,
4273 const ios_base& __iob)
4275 switch (__iob.flags() & ios_base::adjustfield)
4277 case ios_base::internal:
4278 if (__nb[0] == '-' || __nb[0] == '+')
4280 if (__ne - __nb >= 2 && __nb[0] == '0'
4281 && (__nb[1] == 'x' || __nb[1] == 'X'))
4284 case ios_base::left:
4286 case ios_base::right:
4299 static string weeks[14];
4300 weeks[0] = "Sunday";
4301 weeks[1] = "Monday";
4302 weeks[2] = "Tuesday";
4303 weeks[3] = "Wednesday";
4304 weeks[4] = "Thursday";
4305 weeks[5] = "Friday";
4306 weeks[6] = "Saturday";
4321 static wstring weeks[14];
4322 weeks[0] = L"Sunday";
4323 weeks[1] = L"Monday";
4324 weeks[2] = L"Tuesday";
4325 weeks[3] = L"Wednesday";
4326 weeks[4] = L"Thursday";
4327 weeks[5] = L"Friday";
4328 weeks[6] = L"Saturday";
4341 __time_get_c_storage<char>::__weeks() const
4343 static const string* weeks = init_weeks();
4349 __time_get_c_storage<wchar_t>::__weeks() const
4351 static const wstring* weeks = init_wweeks();
4359 static string months[24];
4360 months[0] = "January";
4361 months[1] = "February";
4362 months[2] = "March";
4363 months[3] = "April";
4367 months[7] = "August";
4368 months[8] = "September";
4369 months[9] = "October";
4370 months[10] = "November";
4371 months[11] = "December";
4391 static wstring months[24];
4392 months[0] = L"January";
4393 months[1] = L"February";
4394 months[2] = L"March";
4395 months[3] = L"April";
4397 months[5] = L"June";
4398 months[6] = L"July";
4399 months[7] = L"August";
4400 months[8] = L"September";
4401 months[9] = L"October";
4402 months[10] = L"November";
4403 months[11] = L"December";
4404 months[12] = L"Jan";
4405 months[13] = L"Feb";
4406 months[14] = L"Mar";
4407 months[15] = L"Apr";
4408 months[16] = L"May";
4409 months[17] = L"Jun";
4410 months[18] = L"Jul";
4411 months[19] = L"Aug";
4412 months[20] = L"Sep";
4413 months[21] = L"Oct";
4414 months[22] = L"Nov";
4415 months[23] = L"Dec";
4421 __time_get_c_storage<char>::__months() const
4423 static const string* months = init_months();
4429 __time_get_c_storage<wchar_t>::__months() const
4431 static const wstring* months = init_wmonths();
4439 static string am_pm[24];
4449 static wstring am_pm[24];
4457 __time_get_c_storage<char>::__am_pm() const
4459 static const string* am_pm = init_am_pm();
4465 __time_get_c_storage<wchar_t>::__am_pm() const
4467 static const wstring* am_pm = init_wam_pm();
4473 __time_get_c_storage<char>::__x() const
4475 static string s("%m/%d/%y");
4481 __time_get_c_storage<wchar_t>::__x() const
4483 static wstring s(L"%m/%d/%y");
4489 __time_get_c_storage<char>::__X() const
4491 static string s("%H:%M:%S");
4497 __time_get_c_storage<wchar_t>::__X() const
4499 static wstring s(L"%H:%M:%S");
4505 __time_get_c_storage<char>::__c() const
4507 static string s("%a %b %d %H:%M:%S %Y");
4513 __time_get_c_storage<wchar_t>::__c() const
4515 static wstring s(L"%a %b %d %H:%M:%S %Y");
4521 __time_get_c_storage<char>::__r() const
4523 static string s("%I:%M:%S %p");
4529 __time_get_c_storage<wchar_t>::__r() const
4531 static wstring s(L"%I:%M:%S %p");
4537 __time_get::__time_get(const char* nm)
4538 : __loc_(newlocale(LC_ALL_MASK, nm, 0))
4540 #ifndef _LIBCPP_NO_EXCEPTIONS
4542 throw runtime_error("time_get_byname"
4543 " failed to construct for " + string(nm));
4544 #endif // _LIBCPP_NO_EXCEPTIONS
4547 __time_get::__time_get(const string& nm)
4548 : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
4550 #ifndef _LIBCPP_NO_EXCEPTIONS
4552 throw runtime_error("time_get_byname"
4553 " failed to construct for " + nm);
4554 #endif // _LIBCPP_NO_EXCEPTIONS
4557 __time_get::~__time_get()
4562 #pragma clang diagnostic ignored "-Wmissing-field-initializers"
4566 __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
4582 size_t n = strftime_l(buf, 100, f, &t, __loc_);
4588 if (ct.is(ctype_base::space, *bb))
4590 result.push_back(' ');
4591 for (++bb; bb != be && ct.is(ctype_base::space, *bb); ++bb)
4596 ios_base::iostate err = ios_base::goodbit;
4597 ptrdiff_t i = __scan_keyword(w, be, this->__weeks_, this->__weeks_+14,
4602 result.push_back('%');
4604 result.push_back('A');
4606 result.push_back('a');
4611 i = __scan_keyword(w, be, this->__months_, this->__months_+24,
4616 result.push_back('%');
4618 result.push_back('B');
4620 result.push_back('b');
4621 if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
4622 result.back() = 'm';
4626 if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0)
4629 i = __scan_keyword(w, be, this->__am_pm_, this->__am_pm_+2,
4630 ct, err, false) - this->__am_pm_;
4633 result.push_back('%');
4634 result.push_back('p');
4640 if (ct.is(ctype_base::digit, *bb))
4642 switch(__get_up_to_n_digits(bb, be, err, ct, 4))
4645 result.push_back('%');
4646 result.push_back('w');
4649 result.push_back('%');
4650 result.push_back('u');
4653 result.push_back('%');
4654 result.push_back('I');
4657 result.push_back('%');
4658 result.push_back('m');
4661 result.push_back('%');
4662 result.push_back('H');
4665 result.push_back('%');
4666 result.push_back('d');
4669 result.push_back('%');
4670 result.push_back('M');
4673 result.push_back('%');
4674 result.push_back('S');
4677 result.push_back('%');
4678 result.push_back('y');
4681 result.push_back('%');
4682 result.push_back('j');
4685 result.push_back('%');
4686 result.push_back('Y');
4689 for (; w != bb; ++w)
4690 result.push_back(*w);
4697 result.push_back('%');
4698 result.push_back('%');
4702 result.push_back(*bb);
4708 #pragma clang diagnostic ignored "-Wmissing-braces"
4712 __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
4728 strftime_l(buf, 100, f, &t, __loc_);
4730 wchar_t* wbb = wbuf;
4732 const char* bb = buf;
4733 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4734 size_t j = mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4736 size_t j = __mbsrtowcs_l( wbb, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4738 if (j == size_t(-1))
4739 __throw_runtime_error("locale not supported");
4740 wchar_t* wbe = wbb + j;
4744 if (ct.is(ctype_base::space, *wbb))
4746 result.push_back(L' ');
4747 for (++wbb; wbb != wbe && ct.is(ctype_base::space, *wbb); ++wbb)
4752 ios_base::iostate err = ios_base::goodbit;
4753 ptrdiff_t i = __scan_keyword(w, wbe, this->__weeks_, this->__weeks_+14,
4758 result.push_back(L'%');
4760 result.push_back(L'A');
4762 result.push_back(L'a');
4767 i = __scan_keyword(w, wbe, this->__months_, this->__months_+24,
4772 result.push_back(L'%');
4774 result.push_back(L'B');
4776 result.push_back(L'b');
4777 if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
4778 result.back() = L'm';
4782 if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0)
4785 i = __scan_keyword(w, wbe, this->__am_pm_, this->__am_pm_+2,
4786 ct, err, false) - this->__am_pm_;
4789 result.push_back(L'%');
4790 result.push_back(L'p');
4796 if (ct.is(ctype_base::digit, *wbb))
4798 switch(__get_up_to_n_digits(wbb, wbe, err, ct, 4))
4801 result.push_back(L'%');
4802 result.push_back(L'w');
4805 result.push_back(L'%');
4806 result.push_back(L'u');
4809 result.push_back(L'%');
4810 result.push_back(L'I');
4813 result.push_back(L'%');
4814 result.push_back(L'm');
4817 result.push_back(L'%');
4818 result.push_back(L'H');
4821 result.push_back(L'%');
4822 result.push_back(L'd');
4825 result.push_back(L'%');
4826 result.push_back(L'M');
4829 result.push_back(L'%');
4830 result.push_back(L'S');
4833 result.push_back(L'%');
4834 result.push_back(L'y');
4837 result.push_back(L'%');
4838 result.push_back(L'j');
4841 result.push_back(L'%');
4842 result.push_back(L'Y');
4845 for (; w != wbb; ++w)
4846 result.push_back(*w);
4851 if (ct.narrow(*wbb, 0) == '%')
4853 result.push_back(L'%');
4854 result.push_back(L'%');
4858 result.push_back(*wbb);
4866 __time_get_storage<char>::init(const ctype<char>& ct)
4871 for (int i = 0; i < 7; ++i)
4874 strftime_l(buf, 100, "%A", &t, __loc_);
4876 strftime_l(buf, 100, "%a", &t, __loc_);
4877 __weeks_[i+7] = buf;
4880 for (int i = 0; i < 12; ++i)
4883 strftime_l(buf, 100, "%B", &t, __loc_);
4885 strftime_l(buf, 100, "%b", &t, __loc_);
4886 __months_[i+12] = buf;
4890 strftime_l(buf, 100, "%p", &t, __loc_);
4893 strftime_l(buf, 100, "%p", &t, __loc_);
4895 __c_ = __analyze('c', ct);
4896 __r_ = __analyze('r', ct);
4897 __x_ = __analyze('x', ct);
4898 __X_ = __analyze('X', ct);
4903 __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
4912 for (int i = 0; i < 7; ++i)
4915 be = strftime_l(buf, 100, "%A", &t, __loc_);
4917 const char* bb = buf;
4918 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4919 size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4921 size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4923 if (j == size_t(-1))
4924 __throw_runtime_error("locale not supported");
4926 __weeks_[i].assign(wbuf, wbe);
4927 be = strftime_l(buf, 100, "%a", &t, __loc_);
4930 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4931 j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4933 j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4935 if (j == size_t(-1))
4936 __throw_runtime_error("locale not supported");
4938 __weeks_[i+7].assign(wbuf, wbe);
4941 for (int i = 0; i < 12; ++i)
4944 be = strftime_l(buf, 100, "%B", &t, __loc_);
4946 const char* bb = buf;
4947 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4948 size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4950 size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4952 if (j == size_t(-1))
4953 __throw_runtime_error("locale not supported");
4955 __months_[i].assign(wbuf, wbe);
4956 be = strftime_l(buf, 100, "%b", &t, __loc_);
4959 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4960 j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4962 j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4964 if (j == size_t(-1))
4965 __throw_runtime_error("locale not supported");
4967 __months_[i+12].assign(wbuf, wbe);
4971 be = strftime_l(buf, 100, "%p", &t, __loc_);
4973 const char* bb = buf;
4974 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4975 size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4977 size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4979 if (j == size_t(-1))
4980 __throw_runtime_error("locale not supported");
4982 __am_pm_[0].assign(wbuf, wbe);
4984 be = strftime_l(buf, 100, "%p", &t, __loc_);
4987 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
4988 j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4990 j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, __loc_);
4992 if (j == size_t(-1))
4993 __throw_runtime_error("locale not supported");
4995 __am_pm_[1].assign(wbuf, wbe);
4996 __c_ = __analyze('c', ct);
4997 __r_ = __analyze('r', ct);
4998 __x_ = __analyze('x', ct);
4999 __X_ = __analyze('X', ct);
5002 template <class CharT>
5003 struct _LIBCPP_HIDDEN __time_get_temp
5004 : public ctype_byname<CharT>
5006 explicit __time_get_temp(const char* nm)
5007 : ctype_byname<CharT>(nm, 1) {}
5008 explicit __time_get_temp(const string& nm)
5009 : ctype_byname<CharT>(nm, 1) {}
5013 __time_get_storage<char>::__time_get_storage(const char* __nm)
5016 const __time_get_temp<char> ct(__nm);
5021 __time_get_storage<char>::__time_get_storage(const string& __nm)
5024 const __time_get_temp<char> ct(__nm);
5029 __time_get_storage<wchar_t>::__time_get_storage(const char* __nm)
5032 const __time_get_temp<wchar_t> ct(__nm);
5037 __time_get_storage<wchar_t>::__time_get_storage(const string& __nm)
5040 const __time_get_temp<wchar_t> ct(__nm);
5045 time_base::dateorder
5046 __time_get_storage<char>::__do_date_order() const
5049 for (i = 0; i < __x_.size(); ++i)
5057 for (++i; i < __x_.size(); ++i)
5060 if (i == __x_.size())
5066 for (++i; i < __x_.size(); ++i)
5069 if (i == __x_.size())
5073 return time_base::ymd;
5076 for (++i; i < __x_.size(); ++i)
5079 if (i == __x_.size())
5083 return time_base::ydm;
5088 for (++i; i < __x_.size(); ++i)
5091 if (i == __x_.size())
5096 for (++i; i < __x_.size(); ++i)
5099 if (i == __x_.size())
5102 if (__x_[i] == 'y' || __x_[i] == 'Y')
5103 return time_base::mdy;
5108 for (++i; i < __x_.size(); ++i)
5111 if (i == __x_.size())
5116 for (++i; i < __x_.size(); ++i)
5119 if (i == __x_.size())
5122 if (__x_[i] == 'y' || __x_[i] == 'Y')
5123 return time_base::dmy;
5128 return time_base::no_order;
5132 time_base::dateorder
5133 __time_get_storage<wchar_t>::__do_date_order() const
5136 for (i = 0; i < __x_.size(); ++i)
5137 if (__x_[i] == L'%')
5144 for (++i; i < __x_.size(); ++i)
5145 if (__x_[i] == L'%')
5147 if (i == __x_.size())
5153 for (++i; i < __x_.size(); ++i)
5154 if (__x_[i] == L'%')
5156 if (i == __x_.size())
5159 if (__x_[i] == L'd')
5160 return time_base::ymd;
5163 for (++i; i < __x_.size(); ++i)
5164 if (__x_[i] == L'%')
5166 if (i == __x_.size())
5169 if (__x_[i] == L'm')
5170 return time_base::ydm;
5175 for (++i; i < __x_.size(); ++i)
5176 if (__x_[i] == L'%')
5178 if (i == __x_.size())
5181 if (__x_[i] == L'd')
5183 for (++i; i < __x_.size(); ++i)
5184 if (__x_[i] == L'%')
5186 if (i == __x_.size())
5189 if (__x_[i] == L'y' || __x_[i] == L'Y')
5190 return time_base::mdy;
5195 for (++i; i < __x_.size(); ++i)
5196 if (__x_[i] == L'%')
5198 if (i == __x_.size())
5201 if (__x_[i] == L'm')
5203 for (++i; i < __x_.size(); ++i)
5204 if (__x_[i] == L'%')
5206 if (i == __x_.size())
5209 if (__x_[i] == L'y' || __x_[i] == L'Y')
5210 return time_base::dmy;
5215 return time_base::no_order;
5220 __time_put::__time_put(const char* nm)
5221 : __loc_(newlocale(LC_ALL_MASK, nm, 0))
5223 #ifndef _LIBCPP_NO_EXCEPTIONS
5225 throw runtime_error("time_put_byname"
5226 " failed to construct for " + string(nm));
5227 #endif // _LIBCPP_NO_EXCEPTIONS
5230 __time_put::__time_put(const string& nm)
5231 : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
5233 #ifndef _LIBCPP_NO_EXCEPTIONS
5235 throw runtime_error("time_put_byname"
5236 " failed to construct for " + nm);
5237 #endif // _LIBCPP_NO_EXCEPTIONS
5240 __time_put::~__time_put()
5247 __time_put::__do_put(char* __nb, char*& __ne, const tm* __tm,
5248 char __fmt, char __mod) const
5250 char fmt[] = {'%', __fmt, __mod, 0};
5252 swap(fmt[1], fmt[2]);
5253 size_t n = strftime_l(__nb, static_cast<size_t>(__ne-__nb), fmt, __tm, __loc_);
5258 __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
5259 char __fmt, char __mod) const
5262 char* __ne = __nar + 100;
5263 __do_put(__nar, __ne, __tm, __fmt, __mod);
5265 const char* __nb = __nar;
5266 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5267 size_t j = mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_);
5269 size_t j = __mbsrtowcs_l(__wb, &__nb, 100, &mb, __loc_);
5271 if (j == size_t(-1))
5272 __throw_runtime_error("locale not supported");
5276 // moneypunct_byname
5278 template <class charT>
5281 __init_pat(money_base::pattern& pat, basic_string<charT>& __curr_symbol_,
5282 bool intl, char cs_precedes, char sep_by_space, char sign_posn,
5285 const char sign = static_cast<char>(money_base::sign);
5286 const char space = static_cast<char>(money_base::space);
5287 const char none = static_cast<char>(money_base::none);
5288 const char symbol = static_cast<char>(money_base::symbol);
5289 const char value = static_cast<char>(money_base::value);
5290 const bool symbol_contains_sep = intl && __curr_symbol_.size() == 4;
5292 // Comments on case branches reflect 'C11 7.11.2.1 The localeconv
5293 // function'. "Space between sign and symbol or value" means that
5294 // if the sign is adjacent to the symbol, there's a space between
5295 // them, and otherwise there's a space between the sign and value.
5297 // C11's localeconv specifies that the fourth character of an
5298 // international curr_symbol is used to separate the sign and
5299 // value when sep_by_space says to do so. C++ can't represent
5300 // that, so we just use a space. When sep_by_space says to
5301 // separate the symbol and value-or-sign with a space, we rearrange the
5302 // curr_symbol to put its spacing character on the correct side of
5305 // We also need to avoid adding an extra space between the sign
5306 // and value when the currency symbol is suppressed (by not
5307 // setting showbase). We match glibc's strfmon by interpreting
5308 // sep_by_space==1 as "omit the space when the currency symbol is
5311 // Users who want to get this right should use ICU instead.
5313 switch (cs_precedes)
5315 case 0: // value before curr_symbol
5316 if (symbol_contains_sep) {
5317 // Move the separator to before the symbol, to place it
5318 // between the value and symbol.
5319 rotate(__curr_symbol_.begin(), __curr_symbol_.begin() + 3,
5320 __curr_symbol_.end());
5324 case 0: // Parentheses surround the quantity and currency symbol.
5325 pat.field[0] = sign;
5326 pat.field[1] = value;
5327 pat.field[2] = none; // Any space appears in the symbol.
5328 pat.field[3] = symbol;
5329 switch (sep_by_space)
5331 case 0: // No space separates the currency symbol and value.
5332 // This case may have changed between C99 and C11;
5333 // assume the currency symbol matches the intention.
5334 case 2: // Space between sign and currency or value.
5335 // The "sign" is two parentheses, so no space here either.
5337 case 1: // Space between currency-and-sign or currency and value.
5338 if (!symbol_contains_sep) {
5339 // We insert the space into the symbol instead of
5340 // setting pat.field[2]=space so that when
5341 // showbase is not set, the space goes away too.
5342 __curr_symbol_.insert(0, 1, space_char);
5349 case 1: // The sign string precedes the quantity and currency symbol.
5350 pat.field[0] = sign;
5351 pat.field[3] = symbol;
5352 switch (sep_by_space)
5354 case 0: // No space separates the currency symbol and value.
5355 pat.field[1] = value;
5356 pat.field[2] = none;
5358 case 1: // Space between currency-and-sign or currency and value.
5359 pat.field[1] = value;
5360 pat.field[2] = none;
5361 if (!symbol_contains_sep) {
5362 // We insert the space into the symbol instead of
5363 // setting pat.field[2]=space so that when
5364 // showbase is not set, the space goes away too.
5365 __curr_symbol_.insert(0, 1, space_char);
5368 case 2: // Space between sign and currency or value.
5369 pat.field[1] = space;
5370 pat.field[2] = value;
5371 if (symbol_contains_sep) {
5372 // Remove the separator from the symbol, since it
5373 // has already appeared after the sign.
5374 __curr_symbol_.erase(__curr_symbol_.begin());
5381 case 2: // The sign string succeeds the quantity and currency symbol.
5382 pat.field[0] = value;
5383 pat.field[3] = sign;
5384 switch (sep_by_space)
5386 case 0: // No space separates the currency symbol and value.
5387 pat.field[1] = none;
5388 pat.field[2] = symbol;
5390 case 1: // Space between currency-and-sign or currency and value.
5391 if (!symbol_contains_sep) {
5392 // We insert the space into the symbol instead of
5393 // setting pat.field[1]=space so that when
5394 // showbase is not set, the space goes away too.
5395 __curr_symbol_.insert(0, 1, space_char);
5397 pat.field[1] = none;
5398 pat.field[2] = symbol;
5400 case 2: // Space between sign and currency or value.
5401 pat.field[1] = symbol;
5402 pat.field[2] = space;
5403 if (symbol_contains_sep) {
5404 // Remove the separator from the symbol, since it
5405 // should not be removed if showbase is absent.
5406 __curr_symbol_.erase(__curr_symbol_.begin());
5413 case 3: // The sign string immediately precedes the currency symbol.
5414 pat.field[0] = value;
5415 pat.field[3] = symbol;
5416 switch (sep_by_space)
5418 case 0: // No space separates the currency symbol and value.
5419 pat.field[1] = none;
5420 pat.field[2] = sign;
5422 case 1: // Space between currency-and-sign or currency and value.
5423 pat.field[1] = space;
5424 pat.field[2] = sign;
5425 if (symbol_contains_sep) {
5426 // Remove the separator from the symbol, since it
5427 // has already appeared before the sign.
5428 __curr_symbol_.erase(__curr_symbol_.begin());
5431 case 2: // Space between sign and currency or value.
5432 pat.field[1] = sign;
5433 pat.field[2] = none;
5434 if (!symbol_contains_sep) {
5435 // We insert the space into the symbol instead of
5436 // setting pat.field[2]=space so that when
5437 // showbase is not set, the space goes away too.
5438 __curr_symbol_.insert(0, 1, space_char);
5445 case 4: // The sign string immediately succeeds the currency symbol.
5446 pat.field[0] = value;
5447 pat.field[3] = sign;
5448 switch (sep_by_space)
5450 case 0: // No space separates the currency symbol and value.
5451 pat.field[1] = none;
5452 pat.field[2] = symbol;
5454 case 1: // Space between currency-and-sign or currency and value.
5455 pat.field[1] = none;
5456 pat.field[2] = symbol;
5457 if (!symbol_contains_sep) {
5458 // We insert the space into the symbol instead of
5459 // setting pat.field[1]=space so that when
5460 // showbase is not set, the space goes away too.
5461 __curr_symbol_.insert(0, 1, space_char);
5464 case 2: // Space between sign and currency or value.
5465 pat.field[1] = symbol;
5466 pat.field[2] = space;
5467 if (symbol_contains_sep) {
5468 // Remove the separator from the symbol, since it
5469 // should not disappear when showbase is absent.
5470 __curr_symbol_.erase(__curr_symbol_.begin());
5481 case 1: // curr_symbol before value
5484 case 0: // Parentheses surround the quantity and currency symbol.
5485 pat.field[0] = sign;
5486 pat.field[1] = symbol;
5487 pat.field[2] = none; // Any space appears in the symbol.
5488 pat.field[3] = value;
5489 switch (sep_by_space)
5491 case 0: // No space separates the currency symbol and value.
5492 // This case may have changed between C99 and C11;
5493 // assume the currency symbol matches the intention.
5494 case 2: // Space between sign and currency or value.
5495 // The "sign" is two parentheses, so no space here either.
5497 case 1: // Space between currency-and-sign or currency and value.
5498 if (!symbol_contains_sep) {
5499 // We insert the space into the symbol instead of
5500 // setting pat.field[2]=space so that when
5501 // showbase is not set, the space goes away too.
5502 __curr_symbol_.insert(0, 1, space_char);
5509 case 1: // The sign string precedes the quantity and currency symbol.
5510 pat.field[0] = sign;
5511 pat.field[3] = value;
5512 switch (sep_by_space)
5514 case 0: // No space separates the currency symbol and value.
5515 pat.field[1] = symbol;
5516 pat.field[2] = none;
5518 case 1: // Space between currency-and-sign or currency and value.
5519 pat.field[1] = symbol;
5520 pat.field[2] = none;
5521 if (!symbol_contains_sep) {
5522 // We insert the space into the symbol instead of
5523 // setting pat.field[2]=space so that when
5524 // showbase is not set, the space goes away too.
5525 __curr_symbol_.push_back(space_char);
5528 case 2: // Space between sign and currency or value.
5529 pat.field[1] = space;
5530 pat.field[2] = symbol;
5531 if (symbol_contains_sep) {
5532 // Remove the separator from the symbol, since it
5533 // has already appeared after the sign.
5534 __curr_symbol_.pop_back();
5541 case 2: // The sign string succeeds the quantity and currency symbol.
5542 pat.field[0] = symbol;
5543 pat.field[3] = sign;
5544 switch (sep_by_space)
5546 case 0: // No space separates the currency symbol and value.
5547 pat.field[1] = none;
5548 pat.field[2] = value;
5550 case 1: // Space between currency-and-sign or currency and value.
5551 pat.field[1] = none;
5552 pat.field[2] = value;
5553 if (!symbol_contains_sep) {
5554 // We insert the space into the symbol instead of
5555 // setting pat.field[1]=space so that when
5556 // showbase is not set, the space goes away too.
5557 __curr_symbol_.push_back(space_char);
5560 case 2: // Space between sign and currency or value.
5561 pat.field[1] = value;
5562 pat.field[2] = space;
5563 if (symbol_contains_sep) {
5564 // Remove the separator from the symbol, since it
5565 // will appear before the sign.
5566 __curr_symbol_.pop_back();
5573 case 3: // The sign string immediately precedes the currency symbol.
5574 pat.field[0] = sign;
5575 pat.field[3] = value;
5576 switch (sep_by_space)
5578 case 0: // No space separates the currency symbol and value.
5579 pat.field[1] = symbol;
5580 pat.field[2] = none;
5582 case 1: // Space between currency-and-sign or currency and value.
5583 pat.field[1] = symbol;
5584 pat.field[2] = none;
5585 if (!symbol_contains_sep) {
5586 // We insert the space into the symbol instead of
5587 // setting pat.field[2]=space so that when
5588 // showbase is not set, the space goes away too.
5589 __curr_symbol_.push_back(space_char);
5592 case 2: // Space between sign and currency or value.
5593 pat.field[1] = space;
5594 pat.field[2] = symbol;
5595 if (symbol_contains_sep) {
5596 // Remove the separator from the symbol, since it
5597 // has already appeared after the sign.
5598 __curr_symbol_.pop_back();
5605 case 4: // The sign string immediately succeeds the currency symbol.
5606 pat.field[0] = symbol;
5607 pat.field[3] = value;
5608 switch (sep_by_space)
5610 case 0: // No space separates the currency symbol and value.
5611 pat.field[1] = sign;
5612 pat.field[2] = none;
5614 case 1: // Space between currency-and-sign or currency and value.
5615 pat.field[1] = sign;
5616 pat.field[2] = space;
5617 if (symbol_contains_sep) {
5618 // Remove the separator from the symbol, since it
5619 // should not disappear when showbase is absent.
5620 __curr_symbol_.pop_back();
5623 case 2: // Space between sign and currency or value.
5624 pat.field[1] = none;
5625 pat.field[2] = sign;
5626 if (!symbol_contains_sep) {
5627 // We insert the space into the symbol instead of
5628 // setting pat.field[1]=space so that when
5629 // showbase is not set, the space goes away too.
5630 __curr_symbol_.push_back(space_char);
5644 pat.field[0] = symbol;
5645 pat.field[1] = sign;
5646 pat.field[2] = none;
5647 pat.field[3] = value;
5652 moneypunct_byname<char, false>::init(const char* nm)
5654 typedef moneypunct<char, false> base;
5655 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
5656 #ifndef _LIBCPP_NO_EXCEPTIONS
5658 throw runtime_error("moneypunct_byname"
5659 " failed to construct for " + string(nm));
5660 #endif // _LIBCPP_NO_EXCEPTIONS
5661 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5662 lconv* lc = localeconv_l(loc.get());
5664 lconv* lc = __localeconv_l(loc.get());
5666 if (*lc->mon_decimal_point)
5667 __decimal_point_ = *lc->mon_decimal_point;
5669 __decimal_point_ = base::do_decimal_point();
5670 if (*lc->mon_thousands_sep)
5671 __thousands_sep_ = *lc->mon_thousands_sep;
5673 __thousands_sep_ = base::do_thousands_sep();
5674 __grouping_ = lc->mon_grouping;
5675 __curr_symbol_ = lc->currency_symbol;
5676 if (lc->frac_digits != CHAR_MAX)
5677 __frac_digits_ = lc->frac_digits;
5679 __frac_digits_ = base::do_frac_digits();
5680 if (lc->p_sign_posn == 0)
5681 __positive_sign_ = "()";
5683 __positive_sign_ = lc->positive_sign;
5684 if (lc->n_sign_posn == 0)
5685 __negative_sign_ = "()";
5687 __negative_sign_ = lc->negative_sign;
5688 // Assume the positive and negative formats will want spaces in
5689 // the same places in curr_symbol since there's no way to
5690 // represent anything else.
5691 string_type __dummy_curr_symbol = __curr_symbol_;
5692 __init_pat(__pos_format_, __dummy_curr_symbol, false,
5693 lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
5694 __init_pat(__neg_format_, __curr_symbol_, false,
5695 lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
5700 moneypunct_byname<char, true>::init(const char* nm)
5702 typedef moneypunct<char, true> base;
5703 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
5704 #ifndef _LIBCPP_NO_EXCEPTIONS
5706 throw runtime_error("moneypunct_byname"
5707 " failed to construct for " + string(nm));
5708 #endif // _LIBCPP_NO_EXCEPTIONS
5709 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5710 lconv* lc = localeconv_l(loc.get());
5712 lconv* lc = __localeconv_l(loc.get());
5714 if (*lc->mon_decimal_point)
5715 __decimal_point_ = *lc->mon_decimal_point;
5717 __decimal_point_ = base::do_decimal_point();
5718 if (*lc->mon_thousands_sep)
5719 __thousands_sep_ = *lc->mon_thousands_sep;
5721 __thousands_sep_ = base::do_thousands_sep();
5722 __grouping_ = lc->mon_grouping;
5723 __curr_symbol_ = lc->int_curr_symbol;
5724 if (lc->int_frac_digits != CHAR_MAX)
5725 __frac_digits_ = lc->int_frac_digits;
5727 __frac_digits_ = base::do_frac_digits();
5729 if (lc->p_sign_posn == 0)
5731 if (lc->int_p_sign_posn == 0)
5733 __positive_sign_ = "()";
5735 __positive_sign_ = lc->positive_sign;
5737 if(lc->n_sign_posn == 0)
5739 if (lc->int_n_sign_posn == 0)
5741 __negative_sign_ = "()";
5743 __negative_sign_ = lc->negative_sign;
5744 // Assume the positive and negative formats will want spaces in
5745 // the same places in curr_symbol since there's no way to
5746 // represent anything else.
5747 string_type __dummy_curr_symbol = __curr_symbol_;
5749 __init_pat(__pos_format_, __dummy_curr_symbol, true,
5750 lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
5751 __init_pat(__neg_format_, __curr_symbol_, true,
5752 lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
5754 __init_pat(__pos_format_, __dummy_curr_symbol, true,
5755 lc->int_p_cs_precedes, lc->int_p_sep_by_space,
5756 lc->int_p_sign_posn, ' ');
5757 __init_pat(__neg_format_, __curr_symbol_, true,
5758 lc->int_n_cs_precedes, lc->int_n_sep_by_space,
5759 lc->int_n_sign_posn, ' ');
5765 moneypunct_byname<wchar_t, false>::init(const char* nm)
5767 typedef moneypunct<wchar_t, false> base;
5768 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
5769 #ifndef _LIBCPP_NO_EXCEPTIONS
5771 throw runtime_error("moneypunct_byname"
5772 " failed to construct for " + string(nm));
5773 #endif // _LIBCPP_NO_EXCEPTIONS
5774 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5775 lconv* lc = localeconv_l(loc.get());
5777 lconv* lc = __localeconv_l(loc.get());
5779 if (*lc->mon_decimal_point)
5780 __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
5782 __decimal_point_ = base::do_decimal_point();
5783 if (*lc->mon_thousands_sep)
5784 __thousands_sep_ = static_cast<wchar_t>(*lc->mon_thousands_sep);
5786 __thousands_sep_ = base::do_thousands_sep();
5787 __grouping_ = lc->mon_grouping;
5790 const char* bb = lc->currency_symbol;
5791 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5792 size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5794 size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5796 if (j == size_t(-1))
5797 __throw_runtime_error("locale not supported");
5798 wchar_t* wbe = wbuf + j;
5799 __curr_symbol_.assign(wbuf, wbe);
5800 if (lc->frac_digits != CHAR_MAX)
5801 __frac_digits_ = lc->frac_digits;
5803 __frac_digits_ = base::do_frac_digits();
5804 if (lc->p_sign_posn == 0)
5805 __positive_sign_ = L"()";
5809 bb = lc->positive_sign;
5810 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5811 j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5813 j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5815 if (j == size_t(-1))
5816 __throw_runtime_error("locale not supported");
5818 __positive_sign_.assign(wbuf, wbe);
5820 if (lc->n_sign_posn == 0)
5821 __negative_sign_ = L"()";
5825 bb = lc->negative_sign;
5826 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5827 j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5829 j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5831 if (j == size_t(-1))
5832 __throw_runtime_error("locale not supported");
5834 __negative_sign_.assign(wbuf, wbe);
5836 // Assume the positive and negative formats will want spaces in
5837 // the same places in curr_symbol since there's no way to
5838 // represent anything else.
5839 string_type __dummy_curr_symbol = __curr_symbol_;
5840 __init_pat(__pos_format_, __dummy_curr_symbol, false,
5841 lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
5842 __init_pat(__neg_format_, __curr_symbol_, false,
5843 lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
5848 moneypunct_byname<wchar_t, true>::init(const char* nm)
5850 typedef moneypunct<wchar_t, true> base;
5851 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
5852 #ifndef _LIBCPP_NO_EXCEPTIONS
5854 throw runtime_error("moneypunct_byname"
5855 " failed to construct for " + string(nm));
5856 #endif // _LIBCPP_NO_EXCEPTIONS
5857 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5858 lconv* lc = localeconv_l(loc.get());
5860 lconv* lc = __localeconv_l(loc.get());
5862 if (*lc->mon_decimal_point)
5863 __decimal_point_ = static_cast<wchar_t>(*lc->mon_decimal_point);
5865 __decimal_point_ = base::do_decimal_point();
5866 if (*lc->mon_thousands_sep)
5867 __thousands_sep_ = static_cast<wchar_t>(*lc->mon_thousands_sep);
5869 __thousands_sep_ = base::do_thousands_sep();
5870 __grouping_ = lc->mon_grouping;
5873 const char* bb = lc->int_curr_symbol;
5874 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5875 size_t j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5877 size_t j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5879 if (j == size_t(-1))
5880 __throw_runtime_error("locale not supported");
5881 wchar_t* wbe = wbuf + j;
5882 __curr_symbol_.assign(wbuf, wbe);
5883 if (lc->int_frac_digits != CHAR_MAX)
5884 __frac_digits_ = lc->int_frac_digits;
5886 __frac_digits_ = base::do_frac_digits();
5888 if (lc->p_sign_posn == 0)
5890 if (lc->int_p_sign_posn == 0)
5892 __positive_sign_ = L"()";
5896 bb = lc->positive_sign;
5897 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5898 j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5900 j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5902 if (j == size_t(-1))
5903 __throw_runtime_error("locale not supported");
5905 __positive_sign_.assign(wbuf, wbe);
5908 if (lc->n_sign_posn == 0)
5910 if (lc->int_n_sign_posn == 0)
5912 __negative_sign_ = L"()";
5916 bb = lc->negative_sign;
5917 #ifdef _LIBCPP_LOCALE__L_EXTENSIONS
5918 j = mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5920 j = __mbsrtowcs_l(wbuf, &bb, sizeof(wbuf)/sizeof(wbuf[0]), &mb, loc.get());
5922 if (j == size_t(-1))
5923 __throw_runtime_error("locale not supported");
5925 __negative_sign_.assign(wbuf, wbe);
5927 // Assume the positive and negative formats will want spaces in
5928 // the same places in curr_symbol since there's no way to
5929 // represent anything else.
5930 string_type __dummy_curr_symbol = __curr_symbol_;
5932 __init_pat(__pos_format_, __dummy_curr_symbol, true,
5933 lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
5934 __init_pat(__neg_format_, __curr_symbol_, true,
5935 lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
5937 __init_pat(__pos_format_, __dummy_curr_symbol, true,
5938 lc->int_p_cs_precedes, lc->int_p_sep_by_space,
5939 lc->int_p_sign_posn, L' ');
5940 __init_pat(__neg_format_, __curr_symbol_, true,
5941 lc->int_n_cs_precedes, lc->int_n_sep_by_space,
5942 lc->int_n_sign_posn, L' ');
5946 void __do_nothing(void*) {}
5948 void __throw_runtime_error(const char* msg)
5950 #ifndef _LIBCPP_NO_EXCEPTIONS
5951 throw runtime_error(msg);
5955 template class collate<char>;
5956 template class collate<wchar_t>;
5958 template class num_get<char>;
5959 template class num_get<wchar_t>;
5961 template struct __num_get<char>;
5962 template struct __num_get<wchar_t>;
5964 template class num_put<char>;
5965 template class num_put<wchar_t>;
5967 template struct __num_put<char>;
5968 template struct __num_put<wchar_t>;
5970 template class time_get<char>;
5971 template class time_get<wchar_t>;
5973 template class time_get_byname<char>;
5974 template class time_get_byname<wchar_t>;
5976 template class time_put<char>;
5977 template class time_put<wchar_t>;
5979 template class time_put_byname<char>;
5980 template class time_put_byname<wchar_t>;
5982 template class moneypunct<char, false>;
5983 template class moneypunct<char, true>;
5984 template class moneypunct<wchar_t, false>;
5985 template class moneypunct<wchar_t, true>;
5987 template class moneypunct_byname<char, false>;
5988 template class moneypunct_byname<char, true>;
5989 template class moneypunct_byname<wchar_t, false>;
5990 template class moneypunct_byname<wchar_t, true>;
5992 template class money_get<char>;
5993 template class money_get<wchar_t>;
5995 template class __money_get<char>;
5996 template class __money_get<wchar_t>;
5998 template class money_put<char>;
5999 template class money_put<wchar_t>;
6001 template class __money_put<char>;
6002 template class __money_put<wchar_t>;
6004 template class messages<char>;
6005 template class messages<wchar_t>;
6007 template class messages_byname<char>;
6008 template class messages_byname<wchar_t>;
6010 template class codecvt_byname<char, char, mbstate_t>;
6011 template class codecvt_byname<wchar_t, char, mbstate_t>;
6012 template class codecvt_byname<char16_t, char, mbstate_t>;
6013 template class codecvt_byname<char32_t, char, mbstate_t>;
6015 template class __vector_base_common<true>;
6017 _LIBCPP_END_NAMESPACE_STD