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
22 #ifndef _LIBCPP_NO_EXCEPTIONS
23 # include "type_traits"
27 #if defined(_LIBCPP_MSVCRT)
28 #define _CTYPE_DISABLE_MACROS
31 #include "__sso_allocator"
32 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
33 #include "support/win32/locale_win32.h"
34 #elif !defined(__BIONIC__)
40 // On Linux, wint_t and wchar_t have different signed-ness, and this causes
41 // lots of noise in the build log, but no bugs that I know of.
42 #if defined(__clang__)
43 #pragma clang diagnostic ignored "-Wsign-conversion"
46 _LIBCPP_BEGIN_NAMESPACE_STD
50 // In theory this could create a race condition. In practice
51 // the race condition is non-fatal since it will just create
52 // a little resource leak. Better approach would be appreciated.
53 static locale_t result = newlocale(LC_ALL_MASK, "C", 0);
56 #endif // __cloc_defined
62 void operator()(locale::facet* p) {p->__release_shared();}
65 template <class T, class A0>
70 static typename aligned_storage<sizeof(T)>::type buf;
72 return *reinterpret_cast<T*>(&buf);
75 template <class T, class A0, class A1>
80 static typename aligned_storage<sizeof(T)>::type buf;
81 ::new (&buf) T(a0, a1);
82 return *reinterpret_cast<T*>(&buf);
85 template <class T, class A0, class A1, class A2>
88 make(A0 a0, A1 a1, A2 a2)
90 static typename aligned_storage<sizeof(T)>::type buf;
91 ::new (&buf) T(a0, a1, a2);
92 return *reinterpret_cast<T*>(&buf);
95 template <typename T, size_t N>
99 countof(const T (&)[N])
104 template <typename T>
108 countof(const T * const begin, const T * const end)
110 return static_cast<size_t>(end - begin);
113 _LIBCPP_NORETURN static void __throw_runtime_error(const string &msg)
115 #ifndef _LIBCPP_NO_EXCEPTIONS
116 throw runtime_error(msg);
126 // Set priority to INT_MIN + 256 + 150
127 # pragma priority ( -2147483242 )
130 const locale::category locale::none;
131 const locale::category locale::collate;
132 const locale::category locale::ctype;
133 const locale::category locale::monetary;
134 const locale::category locale::numeric;
135 const locale::category locale::time;
136 const locale::category locale::messages;
137 const locale::category locale::all;
139 class _LIBCPP_HIDDEN locale::__imp
143 #if defined(_LIBCPP_COMPILER_MSVC)
144 // FIXME: MSVC doesn't support aligned parameters by value.
145 // I can't get the __sso_allocator to work here
146 // for MSVC I think for this reason.
147 vector<facet*> facets_;
149 vector<facet*, __sso_allocator<facet*, N> > facets_;
153 explicit __imp(size_t refs = 0);
154 explicit __imp(const string& name, size_t refs = 0);
156 __imp(const __imp&, const string&, locale::category c);
157 __imp(const __imp& other, const __imp& one, locale::category c);
158 __imp(const __imp&, facet* f, long id);
161 const string& name() const {return name_;}
162 bool has_facet(long id) const
163 {return static_cast<size_t>(id) < facets_.size() && facets_[static_cast<size_t>(id)];}
164 const locale::facet* use_facet(long id) const;
166 static const locale& make_classic();
167 static locale& make_global();
169 void install(facet* f, long id);
170 template <class F> void install(F* f) {install(f, f->id.__get());}
171 template <class F> void install_from(const __imp& other);
174 locale::__imp::__imp(size_t refs)
180 install(&make<_VSTD::collate<char> >(1u));
181 install(&make<_VSTD::collate<wchar_t> >(1u));
182 install(&make<_VSTD::ctype<char> >(nullptr, false, 1u));
183 install(&make<_VSTD::ctype<wchar_t> >(1u));
184 install(&make<codecvt<char, char, mbstate_t> >(1u));
185 install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));
186 install(&make<codecvt<char16_t, char, mbstate_t> >(1u));
187 install(&make<codecvt<char32_t, char, mbstate_t> >(1u));
188 install(&make<numpunct<char> >(1u));
189 install(&make<numpunct<wchar_t> >(1u));
190 install(&make<num_get<char> >(1u));
191 install(&make<num_get<wchar_t> >(1u));
192 install(&make<num_put<char> >(1u));
193 install(&make<num_put<wchar_t> >(1u));
194 install(&make<moneypunct<char, false> >(1u));
195 install(&make<moneypunct<char, true> >(1u));
196 install(&make<moneypunct<wchar_t, false> >(1u));
197 install(&make<moneypunct<wchar_t, true> >(1u));
198 install(&make<money_get<char> >(1u));
199 install(&make<money_get<wchar_t> >(1u));
200 install(&make<money_put<char> >(1u));
201 install(&make<money_put<wchar_t> >(1u));
202 install(&make<time_get<char> >(1u));
203 install(&make<time_get<wchar_t> >(1u));
204 install(&make<time_put<char> >(1u));
205 install(&make<time_put<wchar_t> >(1u));
206 install(&make<_VSTD::messages<char> >(1u));
207 install(&make<_VSTD::messages<wchar_t> >(1u));
210 locale::__imp::__imp(const string& name, size_t refs)
215 #ifndef _LIBCPP_NO_EXCEPTIONS
218 #endif // _LIBCPP_NO_EXCEPTIONS
219 facets_ = locale::classic().__locale_->facets_;
220 for (unsigned i = 0; i < facets_.size(); ++i)
222 facets_[i]->__add_shared();
223 install(new collate_byname<char>(name_));
224 install(new collate_byname<wchar_t>(name_));
225 install(new ctype_byname<char>(name_));
226 install(new ctype_byname<wchar_t>(name_));
227 install(new codecvt_byname<char, char, mbstate_t>(name_));
228 install(new codecvt_byname<wchar_t, char, mbstate_t>(name_));
229 install(new codecvt_byname<char16_t, char, mbstate_t>(name_));
230 install(new codecvt_byname<char32_t, char, mbstate_t>(name_));
231 install(new numpunct_byname<char>(name_));
232 install(new numpunct_byname<wchar_t>(name_));
233 install(new moneypunct_byname<char, false>(name_));
234 install(new moneypunct_byname<char, true>(name_));
235 install(new moneypunct_byname<wchar_t, false>(name_));
236 install(new moneypunct_byname<wchar_t, true>(name_));
237 install(new time_get_byname<char>(name_));
238 install(new time_get_byname<wchar_t>(name_));
239 install(new time_put_byname<char>(name_));
240 install(new time_put_byname<wchar_t>(name_));
241 install(new messages_byname<char>(name_));
242 install(new messages_byname<wchar_t>(name_));
243 #ifndef _LIBCPP_NO_EXCEPTIONS
247 for (unsigned i = 0; i < facets_.size(); ++i)
249 facets_[i]->__release_shared();
252 #endif // _LIBCPP_NO_EXCEPTIONS
255 // NOTE avoid the `base class should be explicitly initialized in the
256 // copy constructor` warning emitted by GCC
257 #if defined(__clang__) || _GNUC_VER >= 406
258 #pragma GCC diagnostic push
259 #pragma GCC diagnostic ignored "-Wextra"
262 locale::__imp::__imp(const __imp& other)
263 : facets_(max<size_t>(N, other.facets_.size())),
266 facets_ = other.facets_;
267 for (unsigned i = 0; i < facets_.size(); ++i)
269 facets_[i]->__add_shared();
272 #if defined(__clang__) || _GNUC_VER >= 406
273 #pragma GCC diagnostic pop
276 locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
280 facets_ = other.facets_;
281 for (unsigned i = 0; i < facets_.size(); ++i)
283 facets_[i]->__add_shared();
284 #ifndef _LIBCPP_NO_EXCEPTIONS
287 #endif // _LIBCPP_NO_EXCEPTIONS
288 if (c & locale::collate)
290 install(new collate_byname<char>(name));
291 install(new collate_byname<wchar_t>(name));
293 if (c & locale::ctype)
295 install(new ctype_byname<char>(name));
296 install(new ctype_byname<wchar_t>(name));
297 install(new codecvt_byname<char, char, mbstate_t>(name));
298 install(new codecvt_byname<wchar_t, char, mbstate_t>(name));
299 install(new codecvt_byname<char16_t, char, mbstate_t>(name));
300 install(new codecvt_byname<char32_t, char, mbstate_t>(name));
302 if (c & locale::monetary)
304 install(new moneypunct_byname<char, false>(name));
305 install(new moneypunct_byname<char, true>(name));
306 install(new moneypunct_byname<wchar_t, false>(name));
307 install(new moneypunct_byname<wchar_t, true>(name));
309 if (c & locale::numeric)
311 install(new numpunct_byname<char>(name));
312 install(new numpunct_byname<wchar_t>(name));
314 if (c & locale::time)
316 install(new time_get_byname<char>(name));
317 install(new time_get_byname<wchar_t>(name));
318 install(new time_put_byname<char>(name));
319 install(new time_put_byname<wchar_t>(name));
321 if (c & locale::messages)
323 install(new messages_byname<char>(name));
324 install(new messages_byname<wchar_t>(name));
326 #ifndef _LIBCPP_NO_EXCEPTIONS
330 for (unsigned i = 0; i < facets_.size(); ++i)
332 facets_[i]->__release_shared();
335 #endif // _LIBCPP_NO_EXCEPTIONS
341 locale::__imp::install_from(const locale::__imp& one)
343 long id = F::id.__get();
344 install(const_cast<F*>(static_cast<const F*>(one.use_facet(id))), id);
347 locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)
351 facets_ = other.facets_;
352 for (unsigned i = 0; i < facets_.size(); ++i)
354 facets_[i]->__add_shared();
355 #ifndef _LIBCPP_NO_EXCEPTIONS
358 #endif // _LIBCPP_NO_EXCEPTIONS
359 if (c & locale::collate)
361 install_from<_VSTD::collate<char> >(one);
362 install_from<_VSTD::collate<wchar_t> >(one);
364 if (c & locale::ctype)
366 install_from<_VSTD::ctype<char> >(one);
367 install_from<_VSTD::ctype<wchar_t> >(one);
368 install_from<_VSTD::codecvt<char, char, mbstate_t> >(one);
369 install_from<_VSTD::codecvt<char16_t, char, mbstate_t> >(one);
370 install_from<_VSTD::codecvt<char32_t, char, mbstate_t> >(one);
371 install_from<_VSTD::codecvt<wchar_t, char, mbstate_t> >(one);
373 if (c & locale::monetary)
375 install_from<moneypunct<char, false> >(one);
376 install_from<moneypunct<char, true> >(one);
377 install_from<moneypunct<wchar_t, false> >(one);
378 install_from<moneypunct<wchar_t, true> >(one);
379 install_from<money_get<char> >(one);
380 install_from<money_get<wchar_t> >(one);
381 install_from<money_put<char> >(one);
382 install_from<money_put<wchar_t> >(one);
384 if (c & locale::numeric)
386 install_from<numpunct<char> >(one);
387 install_from<numpunct<wchar_t> >(one);
388 install_from<num_get<char> >(one);
389 install_from<num_get<wchar_t> >(one);
390 install_from<num_put<char> >(one);
391 install_from<num_put<wchar_t> >(one);
393 if (c & locale::time)
395 install_from<time_get<char> >(one);
396 install_from<time_get<wchar_t> >(one);
397 install_from<time_put<char> >(one);
398 install_from<time_put<wchar_t> >(one);
400 if (c & locale::messages)
402 install_from<_VSTD::messages<char> >(one);
403 install_from<_VSTD::messages<wchar_t> >(one);
405 #ifndef _LIBCPP_NO_EXCEPTIONS
409 for (unsigned i = 0; i < facets_.size(); ++i)
411 facets_[i]->__release_shared();
414 #endif // _LIBCPP_NO_EXCEPTIONS
417 locale::__imp::__imp(const __imp& other, facet* f, long id)
418 : facets_(max<size_t>(N, other.facets_.size()+1)),
422 unique_ptr<facet, release> hold(f);
423 facets_ = other.facets_;
424 for (unsigned i = 0; i < other.facets_.size(); ++i)
426 facets_[i]->__add_shared();
427 install(hold.get(), id);
430 locale::__imp::~__imp()
432 for (unsigned i = 0; i < facets_.size(); ++i)
434 facets_[i]->__release_shared();
438 locale::__imp::install(facet* f, long id)
441 unique_ptr<facet, release> hold(f);
442 if (static_cast<size_t>(id) >= facets_.size())
443 facets_.resize(static_cast<size_t>(id+1));
444 if (facets_[static_cast<size_t>(id)])
445 facets_[static_cast<size_t>(id)]->__release_shared();
446 facets_[static_cast<size_t>(id)] = hold.release();
450 locale::__imp::use_facet(long id) const
452 #ifndef _LIBCPP_NO_EXCEPTIONS
455 #endif // _LIBCPP_NO_EXCEPTIONS
456 return facets_[static_cast<size_t>(id)];
462 locale::__imp::make_classic()
464 // only one thread can get in here and it only gets in once
465 static aligned_storage<sizeof(locale)>::type buf;
466 locale* c = reinterpret_cast<locale*>(&buf);
467 c->__locale_ = &make<__imp>(1u);
474 static const locale& c = __imp::make_classic();
479 locale::__imp::make_global()
481 // only one thread can get in here and it only gets in once
482 static aligned_storage<sizeof(locale)>::type buf;
483 ::new (&buf) locale(locale::classic());
484 return *reinterpret_cast<locale*>(&buf);
490 static locale& g = __imp::make_global();
494 locale::locale() _NOEXCEPT
495 : __locale_(__global().__locale_)
497 __locale_->__add_shared();
500 locale::locale(const locale& l) _NOEXCEPT
501 : __locale_(l.__locale_)
503 __locale_->__add_shared();
508 __locale_->__release_shared();
512 locale::operator=(const locale& other) _NOEXCEPT
514 other.__locale_->__add_shared();
515 __locale_->__release_shared();
516 __locale_ = other.__locale_;
520 locale::locale(const char* name)
521 #ifndef _LIBCPP_NO_EXCEPTIONS
522 : __locale_(name ? new __imp(name)
523 : throw runtime_error("locale constructed with null"))
524 #else // _LIBCPP_NO_EXCEPTIONS
525 : __locale_(new __imp(name))
528 __locale_->__add_shared();
531 locale::locale(const string& name)
532 : __locale_(new __imp(name))
534 __locale_->__add_shared();
537 locale::locale(const locale& other, const char* name, category c)
538 #ifndef _LIBCPP_NO_EXCEPTIONS
539 : __locale_(name ? new __imp(*other.__locale_, name, c)
540 : throw runtime_error("locale constructed with null"))
541 #else // _LIBCPP_NO_EXCEPTIONS
542 : __locale_(new __imp(*other.__locale_, name, c))
545 __locale_->__add_shared();
548 locale::locale(const locale& other, const string& name, category c)
549 : __locale_(new __imp(*other.__locale_, name, c))
551 __locale_->__add_shared();
554 locale::locale(const locale& other, const locale& one, category c)
555 : __locale_(new __imp(*other.__locale_, *one.__locale_, c))
557 __locale_->__add_shared();
563 return __locale_->name();
567 locale::__install_ctor(const locale& other, facet* f, long id)
570 __locale_ = new __imp(*other.__locale_, f, id);
572 __locale_ = other.__locale_;
573 __locale_->__add_shared();
577 locale::global(const locale& loc)
579 locale& g = __global();
584 setlocale(LC_ALL, g.name().c_str());
590 locale::has_facet(id& x) const
592 return __locale_->has_facet(x.__get());
596 locale::use_facet(id& x) const
598 return __locale_->use_facet(x.__get());
602 locale::operator==(const locale& y) const
604 return (__locale_ == y.__locale_)
605 || (__locale_->name() != "*" && __locale_->name() == y.__locale_->name());
610 locale::facet::~facet()
615 locale::facet::__on_zero_shared() _NOEXCEPT
622 int32_t locale::id::__next_id = 0;
630 void (locale::id::* pmf_)();
632 __fake_bind(void (locale::id::* pmf)(), locale::id* id)
633 : id_(id), pmf_(pmf) {}
635 void operator()() const
646 call_once(__flag_, __fake_bind(&locale::id::__init, this));
653 __id_ = __sync_add_and_fetch(&__next_id, 1);
656 // template <> class collate_byname<char>
658 collate_byname<char>::collate_byname(const char* n, size_t refs)
659 : collate<char>(refs),
660 __l(newlocale(LC_ALL_MASK, n, 0))
663 __throw_runtime_error("collate_byname<char>::collate_byname"
664 " failed to construct for " + string(n));
667 collate_byname<char>::collate_byname(const string& name, size_t refs)
668 : collate<char>(refs),
669 __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
672 __throw_runtime_error("collate_byname<char>::collate_byname"
673 " failed to construct for " + name);
676 collate_byname<char>::~collate_byname()
682 collate_byname<char>::do_compare(const char_type* __lo1, const char_type* __hi1,
683 const char_type* __lo2, const char_type* __hi2) const
685 string_type lhs(__lo1, __hi1);
686 string_type rhs(__lo2, __hi2);
687 int r = strcoll_l(lhs.c_str(), rhs.c_str(), __l);
695 collate_byname<char>::string_type
696 collate_byname<char>::do_transform(const char_type* lo, const char_type* hi) const
698 const string_type in(lo, hi);
699 string_type out(strxfrm_l(0, in.c_str(), 0, __l), char());
700 strxfrm_l(const_cast<char*>(out.c_str()), in.c_str(), out.size()+1, __l);
704 // template <> class collate_byname<wchar_t>
706 collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)
707 : collate<wchar_t>(refs),
708 __l(newlocale(LC_ALL_MASK, n, 0))
711 __throw_runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
712 " failed to construct for " + string(n));
715 collate_byname<wchar_t>::collate_byname(const string& name, size_t refs)
716 : collate<wchar_t>(refs),
717 __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
720 __throw_runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
721 " failed to construct for " + name);
724 collate_byname<wchar_t>::~collate_byname()
730 collate_byname<wchar_t>::do_compare(const char_type* __lo1, const char_type* __hi1,
731 const char_type* __lo2, const char_type* __hi2) const
733 string_type lhs(__lo1, __hi1);
734 string_type rhs(__lo2, __hi2);
735 int r = wcscoll_l(lhs.c_str(), rhs.c_str(), __l);
743 collate_byname<wchar_t>::string_type
744 collate_byname<wchar_t>::do_transform(const char_type* lo, const char_type* hi) const
746 const string_type in(lo, hi);
747 string_type out(wcsxfrm_l(0, in.c_str(), 0, __l), wchar_t());
748 wcsxfrm_l(const_cast<wchar_t*>(out.c_str()), in.c_str(), out.size()+1, __l);
752 // template <> class ctype<wchar_t>;
754 const ctype_base::mask ctype_base::space;
755 const ctype_base::mask ctype_base::print;
756 const ctype_base::mask ctype_base::cntrl;
757 const ctype_base::mask ctype_base::upper;
758 const ctype_base::mask ctype_base::lower;
759 const ctype_base::mask ctype_base::alpha;
760 const ctype_base::mask ctype_base::digit;
761 const ctype_base::mask ctype_base::punct;
762 const ctype_base::mask ctype_base::xdigit;
763 const ctype_base::mask ctype_base::blank;
764 const ctype_base::mask ctype_base::alnum;
765 const ctype_base::mask ctype_base::graph;
767 locale::id ctype<wchar_t>::id;
769 ctype<wchar_t>::~ctype()
774 ctype<wchar_t>::do_is(mask m, char_type c) const
776 return isascii(c) ? (ctype<char>::classic_table()[c] & m) != 0 : false;
780 ctype<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const
782 for (; low != high; ++low, ++vec)
783 *vec = static_cast<mask>(isascii(*low) ?
784 ctype<char>::classic_table()[*low] : 0);
789 ctype<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const
791 for (; low != high; ++low)
792 if (isascii(*low) && (ctype<char>::classic_table()[*low] & m))
798 ctype<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
800 for (; low != high; ++low)
801 if (!(isascii(*low) && (ctype<char>::classic_table()[*low] & m)))
807 ctype<wchar_t>::do_toupper(char_type c) const
809 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
810 return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
811 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
813 return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
815 return (isascii(c) && iswlower_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'a'+L'A' : c;
820 ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
822 for (; low != high; ++low)
823 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
824 *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
825 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
827 *low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
830 *low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? (*low-L'a'+L'A') : *low;
836 ctype<wchar_t>::do_tolower(char_type c) const
838 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
839 return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
840 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
842 return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
844 return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'A'+'a' : c;
849 ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const
851 for (; low != high; ++low)
852 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
853 *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
854 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
856 *low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
859 *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-L'A'+L'a' : *low;
865 ctype<wchar_t>::do_widen(char c) const
871 ctype<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
873 for (; low != high; ++low, ++dest)
879 ctype<wchar_t>::do_narrow(char_type c, char dfault) const
882 return static_cast<char>(c);
887 ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
889 for (; low != high; ++low, ++dest)
891 *dest = static_cast<char>(*low);
897 // template <> class ctype<char>;
899 locale::id ctype<char>::id;
901 ctype<char>::ctype(const mask* tab, bool del, size_t refs)
902 : locale::facet(refs),
907 __tab_ = classic_table();
910 ctype<char>::~ctype()
912 if (__tab_ && __del_)
917 ctype<char>::do_toupper(char_type c) const
919 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
921 static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
922 #elif defined(__NetBSD__)
923 return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]);
924 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
926 static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c;
928 return (isascii(c) && islower_l(c, _LIBCPP_GET_C_LOCALE)) ? c-'a'+'A' : c;
933 ctype<char>::do_toupper(char_type* low, const char_type* high) const
935 for (; low != high; ++low)
936 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
937 *low = isascii(*low) ?
938 static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
939 #elif defined(__NetBSD__)
940 *low = static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(*low)]);
941 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
942 *low = isascii(*low) ?
943 static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
945 *low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-'a'+'A' : *low;
951 ctype<char>::do_tolower(char_type c) const
953 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
955 static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
956 #elif defined(__NetBSD__)
957 return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(c)]);
958 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
960 static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
962 return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c-'A'+'a' : c;
967 ctype<char>::do_tolower(char_type* low, const char_type* high) const
969 for (; low != high; ++low)
970 #ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
971 *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;
972 #elif defined(__NetBSD__)
973 *low = static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(*low)]);
974 #elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
975 *low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
977 *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-'A'+'a' : *low;
983 ctype<char>::do_widen(char c) const
989 ctype<char>::do_widen(const char* low, const char* high, char_type* dest) const
991 for (; low != high; ++low, ++dest)
997 ctype<char>::do_narrow(char_type c, char dfault) const
1000 return static_cast<char>(c);
1005 ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
1007 for (; low != high; ++low, ++dest)
1015 #if defined(__EMSCRIPTEN__)
1016 extern "C" const unsigned short ** __ctype_b_loc();
1017 extern "C" const int ** __ctype_tolower_loc();
1018 extern "C" const int ** __ctype_toupper_loc();
1021 #ifdef _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
1022 const ctype<char>::mask*
1023 ctype<char>::classic_table() _NOEXCEPT
1025 static _LIBCPP_CONSTEXPR const ctype<char>::mask builtin_table[table_size] = {
1030 cntrl, cntrl | space | blank,
1031 cntrl | space, cntrl | space,
1032 cntrl | space, cntrl | space,
1042 space | blank | print, punct | print,
1043 punct | print, punct | print,
1044 punct | print, punct | print,
1045 punct | print, punct | print,
1046 punct | print, punct | print,
1047 punct | print, punct | print,
1048 punct | print, punct | print,
1049 punct | print, punct | print,
1050 digit | print | xdigit, digit | print | xdigit,
1051 digit | print | xdigit, digit | print | xdigit,
1052 digit | print | xdigit, digit | print | xdigit,
1053 digit | print | xdigit, digit | print | xdigit,
1054 digit | print | xdigit, digit | print | xdigit,
1055 punct | print, punct | print,
1056 punct | print, punct | print,
1057 punct | print, punct | print,
1058 punct | print, upper | xdigit | print | alpha,
1059 upper | xdigit | print | alpha, upper | xdigit | print | alpha,
1060 upper | xdigit | print | alpha, upper | xdigit | print | alpha,
1061 upper | xdigit | print | alpha, upper | print | alpha,
1062 upper | print | alpha, upper | print | alpha,
1063 upper | print | alpha, upper | print | alpha,
1064 upper | print | alpha, upper | print | alpha,
1065 upper | print | alpha, upper | print | alpha,
1066 upper | print | alpha, upper | print | alpha,
1067 upper | print | alpha, upper | print | alpha,
1068 upper | print | alpha, upper | print | alpha,
1069 upper | print | alpha, upper | print | alpha,
1070 upper | print | alpha, upper | print | alpha,
1071 upper | print | alpha, punct | print,
1072 punct | print, punct | print,
1073 punct | print, punct | print,
1074 punct | print, lower | xdigit | print | alpha,
1075 lower | xdigit | print | alpha, lower | xdigit | print | alpha,
1076 lower | xdigit | print | alpha, lower | xdigit | print | alpha,
1077 lower | xdigit | print | alpha, lower | print | alpha,
1078 lower | print | alpha, lower | print | alpha,
1079 lower | print | alpha, lower | print | alpha,
1080 lower | print | alpha, lower | print | alpha,
1081 lower | print | alpha, lower | print | alpha,
1082 lower | print | alpha, lower | print | alpha,
1083 lower | print | alpha, lower | print | alpha,
1084 lower | print | alpha, lower | print | alpha,
1085 lower | print | alpha, lower | print | alpha,
1086 lower | print | alpha, lower | print | alpha,
1087 lower | print | alpha, punct | print,
1088 punct | print, punct | print,
1089 punct | print, cntrl,
1090 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1091 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1092 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1093 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1094 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1095 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1096 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1097 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1099 return builtin_table;
1102 const ctype<char>::mask*
1103 ctype<char>::classic_table() _NOEXCEPT
1105 #if defined(__APPLE__) || defined(__FreeBSD__)
1106 return _DefaultRuneLocale.__runetype;
1107 #elif defined(__NetBSD__)
1108 return _C_ctype_tab_ + 1;
1109 #elif defined(__GLIBC__)
1110 return _LIBCPP_GET_C_LOCALE->__ctype_b;
1112 return __ctype_mask;
1113 #elif defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
1114 #if _VC_CRT_MAJOR_VERSION < 14
1115 // This is assumed to be safe, which is a nonsense assumption because we're
1116 // going to end up dereferencing it later...
1117 return _ctype+1; // internal ctype mask table defined in msvcrt.dll
1119 return __pctype_func();
1121 #elif defined(__EMSCRIPTEN__)
1122 return *__ctype_b_loc();
1123 #elif defined(_NEWLIB_VERSION)
1124 // Newlib has a 257-entry table in ctype_.c, where (char)0 starts at [1].
1127 return (const unsigned int *)__lc_ctype_ptr->obj->mask;
1129 // Platform not supported: abort so the person doing the port knows what to
1131 # warning ctype<char>::classic_table() is not implemented
1132 printf("ctype<char>::classic_table() is not implemented\n");
1139 #if defined(__GLIBC__)
1141 ctype<char>::__classic_lower_table() _NOEXCEPT
1143 return _LIBCPP_GET_C_LOCALE->__ctype_tolower;
1147 ctype<char>::__classic_upper_table() _NOEXCEPT
1149 return _LIBCPP_GET_C_LOCALE->__ctype_toupper;
1153 ctype<char>::__classic_lower_table() _NOEXCEPT
1155 return _C_tolower_tab_ + 1;
1159 ctype<char>::__classic_upper_table() _NOEXCEPT
1161 return _C_toupper_tab_ + 1;
1164 #elif defined(__EMSCRIPTEN__)
1166 ctype<char>::__classic_lower_table() _NOEXCEPT
1168 return *__ctype_tolower_loc();
1172 ctype<char>::__classic_upper_table() _NOEXCEPT
1174 return *__ctype_toupper_loc();
1176 #endif // __GLIBC__ || __NETBSD__ || __EMSCRIPTEN__
1178 // template <> class ctype_byname<char>
1180 ctype_byname<char>::ctype_byname(const char* name, size_t refs)
1181 : ctype<char>(0, false, refs),
1182 __l(newlocale(LC_ALL_MASK, name, 0))
1185 __throw_runtime_error("ctype_byname<char>::ctype_byname"
1186 " failed to construct for " + string(name));
1189 ctype_byname<char>::ctype_byname(const string& name, size_t refs)
1190 : ctype<char>(0, false, refs),
1191 __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
1194 __throw_runtime_error("ctype_byname<char>::ctype_byname"
1195 " failed to construct for " + name);
1198 ctype_byname<char>::~ctype_byname()
1204 ctype_byname<char>::do_toupper(char_type c) const
1206 return static_cast<char>(toupper_l(static_cast<unsigned char>(c), __l));
1210 ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const
1212 for (; low != high; ++low)
1213 *low = static_cast<char>(toupper_l(static_cast<unsigned char>(*low), __l));
1218 ctype_byname<char>::do_tolower(char_type c) const
1220 return static_cast<char>(tolower_l(static_cast<unsigned char>(c), __l));
1224 ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
1226 for (; low != high; ++low)
1227 *low = static_cast<char>(tolower_l(static_cast<unsigned char>(*low), __l));
1231 // template <> class ctype_byname<wchar_t>
1233 ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
1234 : ctype<wchar_t>(refs),
1235 __l(newlocale(LC_ALL_MASK, name, 0))
1238 __throw_runtime_error("ctype_byname<wchar_t>::ctype_byname"
1239 " failed to construct for " + string(name));
1242 ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)
1243 : ctype<wchar_t>(refs),
1244 __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
1247 __throw_runtime_error("ctype_byname<wchar_t>::ctype_byname"
1248 " failed to construct for " + name);
1251 ctype_byname<wchar_t>::~ctype_byname()
1257 ctype_byname<wchar_t>::do_is(mask m, char_type c) const
1259 #ifdef _LIBCPP_WCTYPE_IS_MASK
1260 return static_cast<bool>(iswctype_l(c, m, __l));
1262 bool result = false;
1263 wint_t ch = static_cast<wint_t>(c);
1264 if ((m & space) == space) result |= (iswspace_l(ch, __l) != 0);
1265 if ((m & print) == print) result |= (iswprint_l(ch, __l) != 0);
1266 if ((m & cntrl) == cntrl) result |= (iswcntrl_l(ch, __l) != 0);
1267 if ((m & upper) == upper) result |= (iswupper_l(ch, __l) != 0);
1268 if ((m & lower) == lower) result |= (iswlower_l(ch, __l) != 0);
1269 if ((m & alpha) == alpha) result |= (iswalpha_l(ch, __l) != 0);
1270 if ((m & digit) == digit) result |= (iswdigit_l(ch, __l) != 0);
1271 if ((m & punct) == punct) result |= (iswpunct_l(ch, __l) != 0);
1272 if ((m & xdigit) == xdigit) result |= (iswxdigit_l(ch, __l) != 0);
1273 if ((m & blank) == blank) result |= (iswblank_l(ch, __l) != 0);
1279 ctype_byname<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const
1281 for (; low != high; ++low, ++vec)
1284 *vec = static_cast<mask>(ctype<char>::classic_table()[*low]);
1288 wint_t ch = static_cast<wint_t>(*low);
1289 if (iswspace_l(ch, __l))
1291 #ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
1292 if (iswprint_l(ch, __l))
1295 if (iswcntrl_l(ch, __l))
1297 if (iswupper_l(ch, __l))
1299 if (iswlower_l(ch, __l))
1301 #ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
1302 if (iswalpha_l(ch, __l))
1305 if (iswdigit_l(ch, __l))
1307 if (iswpunct_l(ch, __l))
1309 #ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
1310 if (iswxdigit_l(ch, __l))
1313 #if !defined(__sun__)
1314 if (iswblank_l(ch, __l))
1323 ctype_byname<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const
1325 for (; low != high; ++low)
1327 #ifdef _LIBCPP_WCTYPE_IS_MASK
1328 if (iswctype_l(*low, m, __l))
1331 wint_t ch = static_cast<wint_t>(*low);
1332 if ((m & space) == space && iswspace_l(ch, __l)) break;
1333 if ((m & print) == print && iswprint_l(ch, __l)) break;
1334 if ((m & cntrl) == cntrl && iswcntrl_l(ch, __l)) break;
1335 if ((m & upper) == upper && iswupper_l(ch, __l)) break;
1336 if ((m & lower) == lower && iswlower_l(ch, __l)) break;
1337 if ((m & alpha) == alpha && iswalpha_l(ch, __l)) break;
1338 if ((m & digit) == digit && iswdigit_l(ch, __l)) break;
1339 if ((m & punct) == punct && iswpunct_l(ch, __l)) break;
1340 if ((m & xdigit) == xdigit && iswxdigit_l(ch, __l)) break;
1341 if ((m & blank) == blank && iswblank_l(ch, __l)) break;
1348 ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
1350 for (; low != high; ++low)
1352 #ifdef _LIBCPP_WCTYPE_IS_MASK
1353 if (!iswctype_l(*low, m, __l))
1356 wint_t ch = static_cast<wint_t>(*low);
1357 if ((m & space) == space && iswspace_l(ch, __l)) continue;
1358 if ((m & print) == print && iswprint_l(ch, __l)) continue;
1359 if ((m & cntrl) == cntrl && iswcntrl_l(ch, __l)) continue;
1360 if ((m & upper) == upper && iswupper_l(ch, __l)) continue;
1361 if ((m & lower) == lower && iswlower_l(ch, __l)) continue;
1362 if ((m & alpha) == alpha && iswalpha_l(ch, __l)) continue;
1363 if ((m & digit) == digit && iswdigit_l(ch, __l)) continue;
1364 if ((m & punct) == punct && iswpunct_l(ch, __l)) continue;
1365 if ((m & xdigit) == xdigit && iswxdigit_l(ch, __l)) continue;
1366 if ((m & blank) == blank && iswblank_l(ch, __l)) continue;
1374 ctype_byname<wchar_t>::do_toupper(char_type c) const
1376 return towupper_l(c, __l);
1380 ctype_byname<wchar_t>::do_toupper(char_type* low, const char_type* high) const
1382 for (; low != high; ++low)
1383 *low = towupper_l(*low, __l);
1388 ctype_byname<wchar_t>::do_tolower(char_type c) const
1390 return towlower_l(c, __l);
1394 ctype_byname<wchar_t>::do_tolower(char_type* low, const char_type* high) const
1396 for (; low != high; ++low)
1397 *low = towlower_l(*low, __l);
1402 ctype_byname<wchar_t>::do_widen(char c) const
1404 return __libcpp_btowc_l(c, __l);
1408 ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
1410 for (; low != high; ++low, ++dest)
1411 *dest = __libcpp_btowc_l(*low, __l);
1416 ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const
1418 int r = __libcpp_wctob_l(c, __l);
1419 return r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
1423 ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
1425 for (; low != high; ++low, ++dest)
1427 int r = __libcpp_wctob_l(*low, __l);
1428 *dest = r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
1433 // template <> class codecvt<char, char, mbstate_t>
1435 locale::id codecvt<char, char, mbstate_t>::id;
1437 codecvt<char, char, mbstate_t>::~codecvt()
1441 codecvt<char, char, mbstate_t>::result
1442 codecvt<char, char, mbstate_t>::do_out(state_type&,
1443 const intern_type* frm, const intern_type*, const intern_type*& frm_nxt,
1444 extern_type* to, extern_type*, extern_type*& to_nxt) const
1451 codecvt<char, char, mbstate_t>::result
1452 codecvt<char, char, mbstate_t>::do_in(state_type&,
1453 const extern_type* frm, const extern_type*, const extern_type*& frm_nxt,
1454 intern_type* to, intern_type*, intern_type*& to_nxt) const
1461 codecvt<char, char, mbstate_t>::result
1462 codecvt<char, char, mbstate_t>::do_unshift(state_type&,
1463 extern_type* to, extern_type*, extern_type*& to_nxt) const
1470 codecvt<char, char, mbstate_t>::do_encoding() const _NOEXCEPT
1476 codecvt<char, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
1482 codecvt<char, char, mbstate_t>::do_length(state_type&,
1483 const extern_type* frm, const extern_type* end, size_t mx) const
1485 return static_cast<int>(min<size_t>(mx, static_cast<size_t>(end-frm)));
1489 codecvt<char, char, mbstate_t>::do_max_length() const _NOEXCEPT
1494 // template <> class codecvt<wchar_t, char, mbstate_t>
1496 locale::id codecvt<wchar_t, char, mbstate_t>::id;
1498 codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs)
1499 : locale::facet(refs),
1500 __l(_LIBCPP_GET_C_LOCALE)
1504 codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs)
1505 : locale::facet(refs),
1506 __l(newlocale(LC_ALL_MASK, nm, 0))
1509 __throw_runtime_error("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname"
1510 " failed to construct for " + string(nm));
1513 codecvt<wchar_t, char, mbstate_t>::~codecvt()
1515 if (__l != _LIBCPP_GET_C_LOCALE)
1519 codecvt<wchar_t, char, mbstate_t>::result
1520 codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
1521 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
1522 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
1524 // look for first internal null in frm
1525 const intern_type* fend = frm;
1526 for (; fend != frm_end; ++fend)
1529 // loop over all null-terminated sequences in frm
1531 for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
1533 // save state in case it is needed to recover to_nxt on error
1534 mbstate_t save_state = st;
1535 size_t n = __libcpp_wcsnrtombs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
1536 static_cast<size_t>(to_end-to), &st, __l);
1537 if (n == size_t(-1))
1539 // need to recover to_nxt
1540 for (to_nxt = to; frm != frm_nxt; ++frm)
1542 n = __libcpp_wcrtomb_l(to_nxt, *frm, &save_state, __l);
1543 if (n == size_t(-1))
1553 if (to_nxt == to_end)
1555 if (fend != frm_end) // set up next null terminated sequence
1557 // Try to write the terminating null
1558 extern_type tmp[MB_LEN_MAX];
1559 n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l);
1560 if (n == size_t(-1)) // on error
1562 if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
1564 for (extern_type* p = tmp; n; --n) // write it
1567 // look for next null in frm
1568 for (fend = frm_nxt; fend != frm_end; ++fend)
1573 return frm_nxt == frm_end ? ok : partial;
1576 codecvt<wchar_t, char, mbstate_t>::result
1577 codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
1578 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
1579 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
1581 // look for first internal null in frm
1582 const extern_type* fend = frm;
1583 for (; fend != frm_end; ++fend)
1586 // loop over all null-terminated sequences in frm
1588 for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
1590 // save state in case it is needed to recover to_nxt on error
1591 mbstate_t save_state = st;
1592 size_t n = __libcpp_mbsnrtowcs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
1593 static_cast<size_t>(to_end-to), &st, __l);
1594 if (n == size_t(-1))
1596 // need to recover to_nxt
1597 for (to_nxt = to; frm != frm_nxt; ++to_nxt)
1599 n = __libcpp_mbrtowc_l(to_nxt, frm, static_cast<size_t>(fend-frm),
1618 return frm_nxt == frm_end ? ok : partial;
1620 if (n == size_t(-1))
1623 if (to_nxt == to_end)
1625 if (fend != frm_end) // set up next null terminated sequence
1627 // Try to write the terminating null
1628 n = __libcpp_mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l);
1629 if (n != 0) // on error
1633 // look for next null in frm
1634 for (fend = frm_nxt; fend != frm_end; ++fend)
1639 return frm_nxt == frm_end ? ok : partial;
1642 codecvt<wchar_t, char, mbstate_t>::result
1643 codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st,
1644 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
1647 extern_type tmp[MB_LEN_MAX];
1648 size_t n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l);
1649 if (n == size_t(-1) || n == 0) // on error
1652 if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
1654 for (extern_type* p = tmp; n; --n) // write it
1660 codecvt<wchar_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
1662 if (__libcpp_mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) != 0)
1665 // stateless encoding
1666 if (__l == 0 || __libcpp_mb_cur_max_l(__l) == 1) // there are no known constant length encodings
1667 return 1; // which take more than 1 char to form a wchar_t
1672 codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
1678 codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st,
1679 const extern_type* frm, const extern_type* frm_end, size_t mx) const
1682 for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t)
1684 size_t n = __libcpp_mbrlen_l(frm, static_cast<size_t>(frm_end-frm), &st, __l);
1704 codecvt<wchar_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
1706 return __l == 0 ? 1 : static_cast<int>(__libcpp_mb_cur_max_l(__l));
1710 // UTF-32 UTF-16 UTF-8 # of code points
1711 // first second first second third fourth
1712 // 000000 - 00007F 0000 - 007F 00 - 7F 127
1713 // 000080 - 0007FF 0080 - 07FF C2 - DF, 80 - BF 1920
1714 // 000800 - 000FFF 0800 - 0FFF E0 - E0, A0 - BF, 80 - BF 2048
1715 // 001000 - 00CFFF 1000 - CFFF E1 - EC, 80 - BF, 80 - BF 49152
1716 // 00D000 - 00D7FF D000 - D7FF ED - ED, 80 - 9F, 80 - BF 2048
1717 // 00D800 - 00DFFF invalid
1718 // 00E000 - 00FFFF E000 - FFFF EE - EF, 80 - BF, 80 - BF 8192
1719 // 010000 - 03FFFF D800 - D8BF, DC00 - DFFF F0 - F0, 90 - BF, 80 - BF, 80 - BF 196608
1720 // 040000 - 0FFFFF D8C0 - DBBF, DC00 - DFFF F1 - F3, 80 - BF, 80 - BF, 80 - BF 786432
1721 // 100000 - 10FFFF DBC0 - DBFF, DC00 - DFFF F4 - F4, 80 - 8F, 80 - BF, 80 - BF 65536
1724 codecvt_base::result
1725 utf16_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
1726 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
1727 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1731 if (mode & generate_header)
1733 if (to_end-to_nxt < 3)
1734 return codecvt_base::partial;
1735 *to_nxt++ = static_cast<uint8_t>(0xEF);
1736 *to_nxt++ = static_cast<uint8_t>(0xBB);
1737 *to_nxt++ = static_cast<uint8_t>(0xBF);
1739 for (; frm_nxt < frm_end; ++frm_nxt)
1741 uint16_t wc1 = *frm_nxt;
1743 return codecvt_base::error;
1746 if (to_end-to_nxt < 1)
1747 return codecvt_base::partial;
1748 *to_nxt++ = static_cast<uint8_t>(wc1);
1750 else if (wc1 < 0x0800)
1752 if (to_end-to_nxt < 2)
1753 return codecvt_base::partial;
1754 *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
1755 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
1757 else if (wc1 < 0xD800)
1759 if (to_end-to_nxt < 3)
1760 return codecvt_base::partial;
1761 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1762 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1763 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1765 else if (wc1 < 0xDC00)
1767 if (frm_end-frm_nxt < 2)
1768 return codecvt_base::partial;
1769 uint16_t wc2 = frm_nxt[1];
1770 if ((wc2 & 0xFC00) != 0xDC00)
1771 return codecvt_base::error;
1772 if (to_end-to_nxt < 4)
1773 return codecvt_base::partial;
1774 if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) +
1775 ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
1776 return codecvt_base::error;
1778 uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
1779 *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
1780 *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
1781 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
1782 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
1784 else if (wc1 < 0xE000)
1786 return codecvt_base::error;
1790 if (to_end-to_nxt < 3)
1791 return codecvt_base::partial;
1792 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1793 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1794 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1797 return codecvt_base::ok;
1801 codecvt_base::result
1802 utf16_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
1803 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
1804 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1808 if (mode & generate_header)
1810 if (to_end-to_nxt < 3)
1811 return codecvt_base::partial;
1812 *to_nxt++ = static_cast<uint8_t>(0xEF);
1813 *to_nxt++ = static_cast<uint8_t>(0xBB);
1814 *to_nxt++ = static_cast<uint8_t>(0xBF);
1816 for (; frm_nxt < frm_end; ++frm_nxt)
1818 uint16_t wc1 = static_cast<uint16_t>(*frm_nxt);
1820 return codecvt_base::error;
1823 if (to_end-to_nxt < 1)
1824 return codecvt_base::partial;
1825 *to_nxt++ = static_cast<uint8_t>(wc1);
1827 else if (wc1 < 0x0800)
1829 if (to_end-to_nxt < 2)
1830 return codecvt_base::partial;
1831 *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
1832 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
1834 else if (wc1 < 0xD800)
1836 if (to_end-to_nxt < 3)
1837 return codecvt_base::partial;
1838 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1839 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1840 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1842 else if (wc1 < 0xDC00)
1844 if (frm_end-frm_nxt < 2)
1845 return codecvt_base::partial;
1846 uint16_t wc2 = static_cast<uint16_t>(frm_nxt[1]);
1847 if ((wc2 & 0xFC00) != 0xDC00)
1848 return codecvt_base::error;
1849 if (to_end-to_nxt < 4)
1850 return codecvt_base::partial;
1851 if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) +
1852 ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
1853 return codecvt_base::error;
1855 uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
1856 *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
1857 *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
1858 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
1859 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
1861 else if (wc1 < 0xE000)
1863 return codecvt_base::error;
1867 if (to_end-to_nxt < 3)
1868 return codecvt_base::partial;
1869 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
1870 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1871 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
1874 return codecvt_base::ok;
1878 codecvt_base::result
1879 utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
1880 uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
1881 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1885 if (mode & consume_header)
1887 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
1891 for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
1893 uint8_t c1 = *frm_nxt;
1895 return codecvt_base::error;
1898 *to_nxt = static_cast<uint16_t>(c1);
1903 return codecvt_base::error;
1907 if (frm_end-frm_nxt < 2)
1908 return codecvt_base::partial;
1909 uint8_t c2 = frm_nxt[1];
1910 if ((c2 & 0xC0) != 0x80)
1911 return codecvt_base::error;
1912 uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
1914 return codecvt_base::error;
1920 if (frm_end-frm_nxt < 3)
1921 return codecvt_base::partial;
1922 uint8_t c2 = frm_nxt[1];
1923 uint8_t c3 = frm_nxt[2];
1927 if ((c2 & 0xE0) != 0xA0)
1928 return codecvt_base::error;
1931 if ((c2 & 0xE0) != 0x80)
1932 return codecvt_base::error;
1935 if ((c2 & 0xC0) != 0x80)
1936 return codecvt_base::error;
1939 if ((c3 & 0xC0) != 0x80)
1940 return codecvt_base::error;
1941 uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
1942 | ((c2 & 0x3F) << 6)
1945 return codecvt_base::error;
1951 if (frm_end-frm_nxt < 4)
1952 return codecvt_base::partial;
1953 uint8_t c2 = frm_nxt[1];
1954 uint8_t c3 = frm_nxt[2];
1955 uint8_t c4 = frm_nxt[3];
1959 if (!(0x90 <= c2 && c2 <= 0xBF))
1960 return codecvt_base::error;
1963 if ((c2 & 0xF0) != 0x80)
1964 return codecvt_base::error;
1967 if ((c2 & 0xC0) != 0x80)
1968 return codecvt_base::error;
1971 if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
1972 return codecvt_base::error;
1973 if (to_end-to_nxt < 2)
1974 return codecvt_base::partial;
1975 if ((((c1 & 7UL) << 18) +
1976 ((c2 & 0x3FUL) << 12) +
1977 ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
1978 return codecvt_base::error;
1979 *to_nxt = static_cast<uint16_t>(
1981 | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
1982 | ((c2 & 0x0F) << 2)
1983 | ((c3 & 0x30) >> 4));
1984 *++to_nxt = static_cast<uint16_t>(
1986 | ((c3 & 0x0F) << 6)
1992 return codecvt_base::error;
1995 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
1999 codecvt_base::result
2000 utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2001 uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2002 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2006 if (mode & consume_header)
2008 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2012 for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
2014 uint8_t c1 = *frm_nxt;
2016 return codecvt_base::error;
2019 *to_nxt = static_cast<uint32_t>(c1);
2024 return codecvt_base::error;
2028 if (frm_end-frm_nxt < 2)
2029 return codecvt_base::partial;
2030 uint8_t c2 = frm_nxt[1];
2031 if ((c2 & 0xC0) != 0x80)
2032 return codecvt_base::error;
2033 uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
2035 return codecvt_base::error;
2036 *to_nxt = static_cast<uint32_t>(t);
2041 if (frm_end-frm_nxt < 3)
2042 return codecvt_base::partial;
2043 uint8_t c2 = frm_nxt[1];
2044 uint8_t c3 = frm_nxt[2];
2048 if ((c2 & 0xE0) != 0xA0)
2049 return codecvt_base::error;
2052 if ((c2 & 0xE0) != 0x80)
2053 return codecvt_base::error;
2056 if ((c2 & 0xC0) != 0x80)
2057 return codecvt_base::error;
2060 if ((c3 & 0xC0) != 0x80)
2061 return codecvt_base::error;
2062 uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
2063 | ((c2 & 0x3F) << 6)
2066 return codecvt_base::error;
2067 *to_nxt = static_cast<uint32_t>(t);
2072 if (frm_end-frm_nxt < 4)
2073 return codecvt_base::partial;
2074 uint8_t c2 = frm_nxt[1];
2075 uint8_t c3 = frm_nxt[2];
2076 uint8_t c4 = frm_nxt[3];
2080 if (!(0x90 <= c2 && c2 <= 0xBF))
2081 return codecvt_base::error;
2084 if ((c2 & 0xF0) != 0x80)
2085 return codecvt_base::error;
2088 if ((c2 & 0xC0) != 0x80)
2089 return codecvt_base::error;
2092 if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2093 return codecvt_base::error;
2094 if (to_end-to_nxt < 2)
2095 return codecvt_base::partial;
2096 if ((((c1 & 7UL) << 18) +
2097 ((c2 & 0x3FUL) << 12) +
2098 ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
2099 return codecvt_base::error;
2100 *to_nxt = static_cast<uint32_t>(
2102 | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
2103 | ((c2 & 0x0F) << 2)
2104 | ((c3 & 0x30) >> 4));
2105 *++to_nxt = static_cast<uint32_t>(
2107 | ((c3 & 0x0F) << 6)
2113 return codecvt_base::error;
2116 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2121 utf8_to_utf16_length(const uint8_t* frm, const uint8_t* frm_end,
2122 size_t mx, unsigned long Maxcode = 0x10FFFF,
2123 codecvt_mode mode = codecvt_mode(0))
2125 const uint8_t* frm_nxt = frm;
2126 if (mode & consume_header)
2128 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2132 for (size_t nchar16_t = 0; frm_nxt < frm_end && nchar16_t < mx; ++nchar16_t)
2134 uint8_t c1 = *frm_nxt;
2147 if ((frm_end-frm_nxt < 2) || (frm_nxt[1] & 0xC0) != 0x80)
2149 uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F));
2156 if (frm_end-frm_nxt < 3)
2158 uint8_t c2 = frm_nxt[1];
2159 uint8_t c3 = frm_nxt[2];
2163 if ((c2 & 0xE0) != 0xA0)
2164 return static_cast<int>(frm_nxt - frm);
2167 if ((c2 & 0xE0) != 0x80)
2168 return static_cast<int>(frm_nxt - frm);
2171 if ((c2 & 0xC0) != 0x80)
2172 return static_cast<int>(frm_nxt - frm);
2175 if ((c3 & 0xC0) != 0x80)
2177 if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
2183 if (frm_end-frm_nxt < 4 || mx-nchar16_t < 2)
2185 uint8_t c2 = frm_nxt[1];
2186 uint8_t c3 = frm_nxt[2];
2187 uint8_t c4 = frm_nxt[3];
2191 if (!(0x90 <= c2 && c2 <= 0xBF))
2192 return static_cast<int>(frm_nxt - frm);
2195 if ((c2 & 0xF0) != 0x80)
2196 return static_cast<int>(frm_nxt - frm);
2199 if ((c2 & 0xC0) != 0x80)
2200 return static_cast<int>(frm_nxt - frm);
2203 if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2205 if ((((c1 & 7UL) << 18) +
2206 ((c2 & 0x3FUL) << 12) +
2207 ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
2217 return static_cast<int>(frm_nxt - frm);
2221 codecvt_base::result
2222 ucs4_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
2223 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2224 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2228 if (mode & generate_header)
2230 if (to_end-to_nxt < 3)
2231 return codecvt_base::partial;
2232 *to_nxt++ = static_cast<uint8_t>(0xEF);
2233 *to_nxt++ = static_cast<uint8_t>(0xBB);
2234 *to_nxt++ = static_cast<uint8_t>(0xBF);
2236 for (; frm_nxt < frm_end; ++frm_nxt)
2238 uint32_t wc = *frm_nxt;
2239 if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
2240 return codecvt_base::error;
2243 if (to_end-to_nxt < 1)
2244 return codecvt_base::partial;
2245 *to_nxt++ = static_cast<uint8_t>(wc);
2247 else if (wc < 0x000800)
2249 if (to_end-to_nxt < 2)
2250 return codecvt_base::partial;
2251 *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
2252 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
2254 else if (wc < 0x010000)
2256 if (to_end-to_nxt < 3)
2257 return codecvt_base::partial;
2258 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
2259 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
2260 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
2262 else // if (wc < 0x110000)
2264 if (to_end-to_nxt < 4)
2265 return codecvt_base::partial;
2266 *to_nxt++ = static_cast<uint8_t>(0xF0 | (wc >> 18));
2267 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x03F000) >> 12));
2268 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x000FC0) >> 6));
2269 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x00003F));
2272 return codecvt_base::ok;
2276 codecvt_base::result
2277 utf8_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2278 uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2279 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2283 if (mode & consume_header)
2285 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2289 for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
2291 uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2295 return codecvt_base::error;
2296 *to_nxt = static_cast<uint32_t>(c1);
2301 return codecvt_base::error;
2305 if (frm_end-frm_nxt < 2)
2306 return codecvt_base::partial;
2307 uint8_t c2 = frm_nxt[1];
2308 if ((c2 & 0xC0) != 0x80)
2309 return codecvt_base::error;
2310 uint32_t t = static_cast<uint32_t>(((c1 & 0x1F) << 6)
2313 return codecvt_base::error;
2319 if (frm_end-frm_nxt < 3)
2320 return codecvt_base::partial;
2321 uint8_t c2 = frm_nxt[1];
2322 uint8_t c3 = frm_nxt[2];
2326 if ((c2 & 0xE0) != 0xA0)
2327 return codecvt_base::error;
2330 if ((c2 & 0xE0) != 0x80)
2331 return codecvt_base::error;
2334 if ((c2 & 0xC0) != 0x80)
2335 return codecvt_base::error;
2338 if ((c3 & 0xC0) != 0x80)
2339 return codecvt_base::error;
2340 uint32_t t = static_cast<uint32_t>(((c1 & 0x0F) << 12)
2341 | ((c2 & 0x3F) << 6)
2344 return codecvt_base::error;
2350 if (frm_end-frm_nxt < 4)
2351 return codecvt_base::partial;
2352 uint8_t c2 = frm_nxt[1];
2353 uint8_t c3 = frm_nxt[2];
2354 uint8_t c4 = frm_nxt[3];
2358 if (!(0x90 <= c2 && c2 <= 0xBF))
2359 return codecvt_base::error;
2362 if ((c2 & 0xF0) != 0x80)
2363 return codecvt_base::error;
2366 if ((c2 & 0xC0) != 0x80)
2367 return codecvt_base::error;
2370 if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2371 return codecvt_base::error;
2372 uint32_t t = static_cast<uint32_t>(((c1 & 0x07) << 18)
2373 | ((c2 & 0x3F) << 12)
2374 | ((c3 & 0x3F) << 6)
2377 return codecvt_base::error;
2383 return codecvt_base::error;
2386 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2391 utf8_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
2392 size_t mx, unsigned long Maxcode = 0x10FFFF,
2393 codecvt_mode mode = codecvt_mode(0))
2395 const uint8_t* frm_nxt = frm;
2396 if (mode & consume_header)
2398 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2402 for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
2404 uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2417 if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
2419 if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
2425 if (frm_end-frm_nxt < 3)
2427 uint8_t c2 = frm_nxt[1];
2428 uint8_t c3 = frm_nxt[2];
2432 if ((c2 & 0xE0) != 0xA0)
2433 return static_cast<int>(frm_nxt - frm);
2436 if ((c2 & 0xE0) != 0x80)
2437 return static_cast<int>(frm_nxt - frm);
2440 if ((c2 & 0xC0) != 0x80)
2441 return static_cast<int>(frm_nxt - frm);
2444 if ((c3 & 0xC0) != 0x80)
2446 if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
2452 if (frm_end-frm_nxt < 4)
2454 uint8_t c2 = frm_nxt[1];
2455 uint8_t c3 = frm_nxt[2];
2456 uint8_t c4 = frm_nxt[3];
2460 if (!(0x90 <= c2 && c2 <= 0xBF))
2461 return static_cast<int>(frm_nxt - frm);
2464 if ((c2 & 0xF0) != 0x80)
2465 return static_cast<int>(frm_nxt - frm);
2468 if ((c2 & 0xC0) != 0x80)
2469 return static_cast<int>(frm_nxt - frm);
2472 if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2474 if ((((c1 & 0x07u) << 18) | ((c2 & 0x3Fu) << 12) |
2475 ((c3 & 0x3Fu) << 6) | (c4 & 0x3Fu)) > Maxcode)
2484 return static_cast<int>(frm_nxt - frm);
2488 codecvt_base::result
2489 ucs2_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
2490 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2491 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2495 if (mode & generate_header)
2497 if (to_end-to_nxt < 3)
2498 return codecvt_base::partial;
2499 *to_nxt++ = static_cast<uint8_t>(0xEF);
2500 *to_nxt++ = static_cast<uint8_t>(0xBB);
2501 *to_nxt++ = static_cast<uint8_t>(0xBF);
2503 for (; frm_nxt < frm_end; ++frm_nxt)
2505 uint16_t wc = *frm_nxt;
2506 if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
2507 return codecvt_base::error;
2510 if (to_end-to_nxt < 1)
2511 return codecvt_base::partial;
2512 *to_nxt++ = static_cast<uint8_t>(wc);
2514 else if (wc < 0x0800)
2516 if (to_end-to_nxt < 2)
2517 return codecvt_base::partial;
2518 *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
2519 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
2521 else // if (wc <= 0xFFFF)
2523 if (to_end-to_nxt < 3)
2524 return codecvt_base::partial;
2525 *to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
2526 *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
2527 *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
2530 return codecvt_base::ok;
2534 codecvt_base::result
2535 utf8_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2536 uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
2537 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2541 if (mode & consume_header)
2543 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2547 for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
2549 uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2553 return codecvt_base::error;
2554 *to_nxt = static_cast<uint16_t>(c1);
2559 return codecvt_base::error;
2563 if (frm_end-frm_nxt < 2)
2564 return codecvt_base::partial;
2565 uint8_t c2 = frm_nxt[1];
2566 if ((c2 & 0xC0) != 0x80)
2567 return codecvt_base::error;
2568 uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6)
2571 return codecvt_base::error;
2577 if (frm_end-frm_nxt < 3)
2578 return codecvt_base::partial;
2579 uint8_t c2 = frm_nxt[1];
2580 uint8_t c3 = frm_nxt[2];
2584 if ((c2 & 0xE0) != 0xA0)
2585 return codecvt_base::error;
2588 if ((c2 & 0xE0) != 0x80)
2589 return codecvt_base::error;
2592 if ((c2 & 0xC0) != 0x80)
2593 return codecvt_base::error;
2596 if ((c3 & 0xC0) != 0x80)
2597 return codecvt_base::error;
2598 uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
2599 | ((c2 & 0x3F) << 6)
2602 return codecvt_base::error;
2608 return codecvt_base::error;
2611 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2616 utf8_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
2617 size_t mx, unsigned long Maxcode = 0x10FFFF,
2618 codecvt_mode mode = codecvt_mode(0))
2620 const uint8_t* frm_nxt = frm;
2621 if (mode & consume_header)
2623 if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2627 for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
2629 uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2642 if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
2644 if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
2650 if (frm_end-frm_nxt < 3)
2652 uint8_t c2 = frm_nxt[1];
2653 uint8_t c3 = frm_nxt[2];
2657 if ((c2 & 0xE0) != 0xA0)
2658 return static_cast<int>(frm_nxt - frm);
2661 if ((c2 & 0xE0) != 0x80)
2662 return static_cast<int>(frm_nxt - frm);
2665 if ((c2 & 0xC0) != 0x80)
2666 return static_cast<int>(frm_nxt - frm);
2669 if ((c3 & 0xC0) != 0x80)
2671 if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
2680 return static_cast<int>(frm_nxt - frm);
2684 codecvt_base::result
2685 ucs4_to_utf16be(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
2686 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2687 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2691 if (mode & generate_header)
2693 if (to_end-to_nxt < 2)
2694 return codecvt_base::partial;
2695 *to_nxt++ = static_cast<uint8_t>(0xFE);
2696 *to_nxt++ = static_cast<uint8_t>(0xFF);
2698 for (; frm_nxt < frm_end; ++frm_nxt)
2700 uint32_t wc = *frm_nxt;
2701 if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
2702 return codecvt_base::error;
2705 if (to_end-to_nxt < 2)
2706 return codecvt_base::partial;
2707 *to_nxt++ = static_cast<uint8_t>(wc >> 8);
2708 *to_nxt++ = static_cast<uint8_t>(wc);
2712 if (to_end-to_nxt < 4)
2713 return codecvt_base::partial;
2714 uint16_t t = static_cast<uint16_t>(
2716 | ((((wc & 0x1F0000) >> 16) - 1) << 6)
2717 | ((wc & 0x00FC00) >> 10));
2718 *to_nxt++ = static_cast<uint8_t>(t >> 8);
2719 *to_nxt++ = static_cast<uint8_t>(t);
2720 t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
2721 *to_nxt++ = static_cast<uint8_t>(t >> 8);
2722 *to_nxt++ = static_cast<uint8_t>(t);
2725 return codecvt_base::ok;
2729 codecvt_base::result
2730 utf16be_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2731 uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2732 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2736 if (mode & consume_header)
2738 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2741 for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2743 uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2744 if ((c1 & 0xFC00) == 0xDC00)
2745 return codecvt_base::error;
2746 if ((c1 & 0xFC00) != 0xD800)
2749 return codecvt_base::error;
2750 *to_nxt = static_cast<uint32_t>(c1);
2755 if (frm_end-frm_nxt < 4)
2756 return codecvt_base::partial;
2757 uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
2758 if ((c2 & 0xFC00) != 0xDC00)
2759 return codecvt_base::error;
2760 uint32_t t = static_cast<uint32_t>(
2761 ((((c1 & 0x03C0) >> 6) + 1) << 16)
2762 | ((c1 & 0x003F) << 10)
2765 return codecvt_base::error;
2770 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2775 utf16be_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
2776 size_t mx, unsigned long Maxcode = 0x10FFFF,
2777 codecvt_mode mode = codecvt_mode(0))
2779 const uint8_t* frm_nxt = frm;
2780 if (mode & consume_header)
2782 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2785 for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
2787 uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2788 if ((c1 & 0xFC00) == 0xDC00)
2790 if ((c1 & 0xFC00) != 0xD800)
2798 if (frm_end-frm_nxt < 4)
2800 uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
2801 if ((c2 & 0xFC00) != 0xDC00)
2803 uint32_t t = static_cast<uint32_t>(
2804 ((((c1 & 0x03C0) >> 6) + 1) << 16)
2805 | ((c1 & 0x003F) << 10)
2812 return static_cast<int>(frm_nxt - frm);
2816 codecvt_base::result
2817 ucs4_to_utf16le(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
2818 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2819 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2823 if (mode & generate_header)
2825 if (to_end - to_nxt < 2)
2826 return codecvt_base::partial;
2827 *to_nxt++ = static_cast<uint8_t>(0xFF);
2828 *to_nxt++ = static_cast<uint8_t>(0xFE);
2830 for (; frm_nxt < frm_end; ++frm_nxt)
2832 uint32_t wc = *frm_nxt;
2833 if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
2834 return codecvt_base::error;
2837 if (to_end-to_nxt < 2)
2838 return codecvt_base::partial;
2839 *to_nxt++ = static_cast<uint8_t>(wc);
2840 *to_nxt++ = static_cast<uint8_t>(wc >> 8);
2844 if (to_end-to_nxt < 4)
2845 return codecvt_base::partial;
2846 uint16_t t = static_cast<uint16_t>(
2848 | ((((wc & 0x1F0000) >> 16) - 1) << 6)
2849 | ((wc & 0x00FC00) >> 10));
2850 *to_nxt++ = static_cast<uint8_t>(t);
2851 *to_nxt++ = static_cast<uint8_t>(t >> 8);
2852 t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
2853 *to_nxt++ = static_cast<uint8_t>(t);
2854 *to_nxt++ = static_cast<uint8_t>(t >> 8);
2857 return codecvt_base::ok;
2861 codecvt_base::result
2862 utf16le_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2863 uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2864 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2868 if (mode & consume_header)
2870 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
2873 for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2875 uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
2876 if ((c1 & 0xFC00) == 0xDC00)
2877 return codecvt_base::error;
2878 if ((c1 & 0xFC00) != 0xD800)
2881 return codecvt_base::error;
2882 *to_nxt = static_cast<uint32_t>(c1);
2887 if (frm_end-frm_nxt < 4)
2888 return codecvt_base::partial;
2889 uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
2890 if ((c2 & 0xFC00) != 0xDC00)
2891 return codecvt_base::error;
2892 uint32_t t = static_cast<uint32_t>(
2893 ((((c1 & 0x03C0) >> 6) + 1) << 16)
2894 | ((c1 & 0x003F) << 10)
2897 return codecvt_base::error;
2902 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2907 utf16le_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
2908 size_t mx, unsigned long Maxcode = 0x10FFFF,
2909 codecvt_mode mode = codecvt_mode(0))
2911 const uint8_t* frm_nxt = frm;
2912 if (mode & consume_header)
2914 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
2917 for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
2919 uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
2920 if ((c1 & 0xFC00) == 0xDC00)
2922 if ((c1 & 0xFC00) != 0xD800)
2930 if (frm_end-frm_nxt < 4)
2932 uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
2933 if ((c2 & 0xFC00) != 0xDC00)
2935 uint32_t t = static_cast<uint32_t>(
2936 ((((c1 & 0x03C0) >> 6) + 1) << 16)
2937 | ((c1 & 0x003F) << 10)
2944 return static_cast<int>(frm_nxt - frm);
2948 codecvt_base::result
2949 ucs2_to_utf16be(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
2950 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2951 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2955 if (mode & generate_header)
2957 if (to_end-to_nxt < 2)
2958 return codecvt_base::partial;
2959 *to_nxt++ = static_cast<uint8_t>(0xFE);
2960 *to_nxt++ = static_cast<uint8_t>(0xFF);
2962 for (; frm_nxt < frm_end; ++frm_nxt)
2964 uint16_t wc = *frm_nxt;
2965 if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
2966 return codecvt_base::error;
2967 if (to_end-to_nxt < 2)
2968 return codecvt_base::partial;
2969 *to_nxt++ = static_cast<uint8_t>(wc >> 8);
2970 *to_nxt++ = static_cast<uint8_t>(wc);
2972 return codecvt_base::ok;
2976 codecvt_base::result
2977 utf16be_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2978 uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
2979 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2983 if (mode & consume_header)
2985 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2988 for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2990 uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2991 if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
2992 return codecvt_base::error;
2996 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
3001 utf16be_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
3002 size_t mx, unsigned long Maxcode = 0x10FFFF,
3003 codecvt_mode mode = codecvt_mode(0))
3005 const uint8_t* frm_nxt = frm;
3006 if (mode & consume_header)
3008 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
3011 for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
3013 uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
3014 if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
3018 return static_cast<int>(frm_nxt - frm);
3022 codecvt_base::result
3023 ucs2_to_utf16le(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
3024 uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
3025 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
3029 if (mode & generate_header)
3031 if (to_end-to_nxt < 2)
3032 return codecvt_base::partial;
3033 *to_nxt++ = static_cast<uint8_t>(0xFF);
3034 *to_nxt++ = static_cast<uint8_t>(0xFE);
3036 for (; frm_nxt < frm_end; ++frm_nxt)
3038 uint16_t wc = *frm_nxt;
3039 if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
3040 return codecvt_base::error;
3041 if (to_end-to_nxt < 2)
3042 return codecvt_base::partial;
3043 *to_nxt++ = static_cast<uint8_t>(wc);
3044 *to_nxt++ = static_cast<uint8_t>(wc >> 8);
3046 return codecvt_base::ok;
3050 codecvt_base::result
3051 utf16le_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
3052 uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
3053 unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
3057 if (mode & consume_header)
3059 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
3062 for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
3064 uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
3065 if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
3066 return codecvt_base::error;
3070 return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
3075 utf16le_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
3076 size_t mx, unsigned long Maxcode = 0x10FFFF,
3077 codecvt_mode mode = codecvt_mode(0))
3079 const uint8_t* frm_nxt = frm;
3081 if (mode & consume_header)
3083 if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
3086 for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
3088 uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
3089 if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
3093 return static_cast<int>(frm_nxt - frm);
3096 // template <> class codecvt<char16_t, char, mbstate_t>
3098 locale::id codecvt<char16_t, char, mbstate_t>::id;
3100 codecvt<char16_t, char, mbstate_t>::~codecvt()
3104 codecvt<char16_t, char, mbstate_t>::result
3105 codecvt<char16_t, char, mbstate_t>::do_out(state_type&,
3106 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3107 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3109 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3110 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3111 const uint16_t* _frm_nxt = _frm;
3112 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3113 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3114 uint8_t* _to_nxt = _to;
3115 result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3116 frm_nxt = frm + (_frm_nxt - _frm);
3117 to_nxt = to + (_to_nxt - _to);
3121 codecvt<char16_t, char, mbstate_t>::result
3122 codecvt<char16_t, char, mbstate_t>::do_in(state_type&,
3123 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3124 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3126 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3127 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3128 const uint8_t* _frm_nxt = _frm;
3129 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3130 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3131 uint16_t* _to_nxt = _to;
3132 result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3133 frm_nxt = frm + (_frm_nxt - _frm);
3134 to_nxt = to + (_to_nxt - _to);
3138 codecvt<char16_t, char, mbstate_t>::result
3139 codecvt<char16_t, char, mbstate_t>::do_unshift(state_type&,
3140 extern_type* to, extern_type*, extern_type*& to_nxt) const
3147 codecvt<char16_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
3153 codecvt<char16_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
3159 codecvt<char16_t, char, mbstate_t>::do_length(state_type&,
3160 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3162 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3163 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3164 return utf8_to_utf16_length(_frm, _frm_end, mx);
3168 codecvt<char16_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
3173 // template <> class codecvt<char32_t, char, mbstate_t>
3175 locale::id codecvt<char32_t, char, mbstate_t>::id;
3177 codecvt<char32_t, char, mbstate_t>::~codecvt()
3181 codecvt<char32_t, char, mbstate_t>::result
3182 codecvt<char32_t, char, mbstate_t>::do_out(state_type&,
3183 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3184 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3186 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3187 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3188 const uint32_t* _frm_nxt = _frm;
3189 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3190 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3191 uint8_t* _to_nxt = _to;
3192 result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3193 frm_nxt = frm + (_frm_nxt - _frm);
3194 to_nxt = to + (_to_nxt - _to);
3198 codecvt<char32_t, char, mbstate_t>::result
3199 codecvt<char32_t, char, mbstate_t>::do_in(state_type&,
3200 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3201 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3203 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3204 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3205 const uint8_t* _frm_nxt = _frm;
3206 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3207 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3208 uint32_t* _to_nxt = _to;
3209 result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3210 frm_nxt = frm + (_frm_nxt - _frm);
3211 to_nxt = to + (_to_nxt - _to);
3215 codecvt<char32_t, char, mbstate_t>::result
3216 codecvt<char32_t, char, mbstate_t>::do_unshift(state_type&,
3217 extern_type* to, extern_type*, extern_type*& to_nxt) const
3224 codecvt<char32_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
3230 codecvt<char32_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
3236 codecvt<char32_t, char, mbstate_t>::do_length(state_type&,
3237 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3239 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3240 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3241 return utf8_to_ucs4_length(_frm, _frm_end, mx);
3245 codecvt<char32_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
3250 // __codecvt_utf8<wchar_t>
3252 __codecvt_utf8<wchar_t>::result
3253 __codecvt_utf8<wchar_t>::do_out(state_type&,
3254 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3255 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3257 #if defined(_LIBCPP_SHORT_WCHAR)
3258 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3259 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3260 const uint16_t* _frm_nxt = _frm;
3262 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3263 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3264 const uint32_t* _frm_nxt = _frm;
3266 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3267 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3268 uint8_t* _to_nxt = _to;
3269 #if defined(_LIBCPP_SHORT_WCHAR)
3270 result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3273 result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3276 frm_nxt = frm + (_frm_nxt - _frm);
3277 to_nxt = to + (_to_nxt - _to);
3281 __codecvt_utf8<wchar_t>::result
3282 __codecvt_utf8<wchar_t>::do_in(state_type&,
3283 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3284 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3286 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3287 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3288 const uint8_t* _frm_nxt = _frm;
3289 #if defined(_LIBCPP_SHORT_WCHAR)
3290 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3291 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3292 uint16_t* _to_nxt = _to;
3293 result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3296 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3297 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3298 uint32_t* _to_nxt = _to;
3299 result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3302 frm_nxt = frm + (_frm_nxt - _frm);
3303 to_nxt = to + (_to_nxt - _to);
3307 __codecvt_utf8<wchar_t>::result
3308 __codecvt_utf8<wchar_t>::do_unshift(state_type&,
3309 extern_type* to, extern_type*, extern_type*& to_nxt) const
3316 __codecvt_utf8<wchar_t>::do_encoding() const _NOEXCEPT
3322 __codecvt_utf8<wchar_t>::do_always_noconv() const _NOEXCEPT
3328 __codecvt_utf8<wchar_t>::do_length(state_type&,
3329 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3331 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3332 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3333 return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3337 __codecvt_utf8<wchar_t>::do_max_length() const _NOEXCEPT
3339 if (_Mode_ & consume_header)
3344 // __codecvt_utf8<char16_t>
3346 __codecvt_utf8<char16_t>::result
3347 __codecvt_utf8<char16_t>::do_out(state_type&,
3348 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3349 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3351 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3352 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3353 const uint16_t* _frm_nxt = _frm;
3354 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3355 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3356 uint8_t* _to_nxt = _to;
3357 result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3359 frm_nxt = frm + (_frm_nxt - _frm);
3360 to_nxt = to + (_to_nxt - _to);
3364 __codecvt_utf8<char16_t>::result
3365 __codecvt_utf8<char16_t>::do_in(state_type&,
3366 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3367 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3369 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3370 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3371 const uint8_t* _frm_nxt = _frm;
3372 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3373 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3374 uint16_t* _to_nxt = _to;
3375 result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3377 frm_nxt = frm + (_frm_nxt - _frm);
3378 to_nxt = to + (_to_nxt - _to);
3382 __codecvt_utf8<char16_t>::result
3383 __codecvt_utf8<char16_t>::do_unshift(state_type&,
3384 extern_type* to, extern_type*, extern_type*& to_nxt) const
3391 __codecvt_utf8<char16_t>::do_encoding() const _NOEXCEPT
3397 __codecvt_utf8<char16_t>::do_always_noconv() const _NOEXCEPT
3403 __codecvt_utf8<char16_t>::do_length(state_type&,
3404 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3406 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3407 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3408 return utf8_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3412 __codecvt_utf8<char16_t>::do_max_length() const _NOEXCEPT
3414 if (_Mode_ & consume_header)
3419 // __codecvt_utf8<char32_t>
3421 __codecvt_utf8<char32_t>::result
3422 __codecvt_utf8<char32_t>::do_out(state_type&,
3423 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3424 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3426 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3427 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3428 const uint32_t* _frm_nxt = _frm;
3429 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3430 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3431 uint8_t* _to_nxt = _to;
3432 result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3434 frm_nxt = frm + (_frm_nxt - _frm);
3435 to_nxt = to + (_to_nxt - _to);
3439 __codecvt_utf8<char32_t>::result
3440 __codecvt_utf8<char32_t>::do_in(state_type&,
3441 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3442 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3444 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3445 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3446 const uint8_t* _frm_nxt = _frm;
3447 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3448 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3449 uint32_t* _to_nxt = _to;
3450 result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3452 frm_nxt = frm + (_frm_nxt - _frm);
3453 to_nxt = to + (_to_nxt - _to);
3457 __codecvt_utf8<char32_t>::result
3458 __codecvt_utf8<char32_t>::do_unshift(state_type&,
3459 extern_type* to, extern_type*, extern_type*& to_nxt) const
3466 __codecvt_utf8<char32_t>::do_encoding() const _NOEXCEPT
3472 __codecvt_utf8<char32_t>::do_always_noconv() const _NOEXCEPT
3478 __codecvt_utf8<char32_t>::do_length(state_type&,
3479 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3481 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3482 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3483 return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3487 __codecvt_utf8<char32_t>::do_max_length() const _NOEXCEPT
3489 if (_Mode_ & consume_header)
3494 // __codecvt_utf16<wchar_t, false>
3496 __codecvt_utf16<wchar_t, false>::result
3497 __codecvt_utf16<wchar_t, false>::do_out(state_type&,
3498 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3499 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3501 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3502 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3503 const uint32_t* _frm_nxt = _frm;
3504 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3505 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3506 uint8_t* _to_nxt = _to;
3507 result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3509 frm_nxt = frm + (_frm_nxt - _frm);
3510 to_nxt = to + (_to_nxt - _to);
3514 __codecvt_utf16<wchar_t, false>::result
3515 __codecvt_utf16<wchar_t, false>::do_in(state_type&,
3516 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3517 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3519 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3520 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3521 const uint8_t* _frm_nxt = _frm;
3522 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3523 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3524 uint32_t* _to_nxt = _to;
3525 result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3527 frm_nxt = frm + (_frm_nxt - _frm);
3528 to_nxt = to + (_to_nxt - _to);
3532 __codecvt_utf16<wchar_t, false>::result
3533 __codecvt_utf16<wchar_t, false>::do_unshift(state_type&,
3534 extern_type* to, extern_type*, extern_type*& to_nxt) const
3541 __codecvt_utf16<wchar_t, false>::do_encoding() const _NOEXCEPT
3547 __codecvt_utf16<wchar_t, false>::do_always_noconv() const _NOEXCEPT
3553 __codecvt_utf16<wchar_t, false>::do_length(state_type&,
3554 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3556 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3557 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3558 return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3562 __codecvt_utf16<wchar_t, false>::do_max_length() const _NOEXCEPT
3564 if (_Mode_ & consume_header)
3569 // __codecvt_utf16<wchar_t, true>
3571 __codecvt_utf16<wchar_t, true>::result
3572 __codecvt_utf16<wchar_t, true>::do_out(state_type&,
3573 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3574 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3576 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3577 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3578 const uint32_t* _frm_nxt = _frm;
3579 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3580 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3581 uint8_t* _to_nxt = _to;
3582 result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3584 frm_nxt = frm + (_frm_nxt - _frm);
3585 to_nxt = to + (_to_nxt - _to);
3589 __codecvt_utf16<wchar_t, true>::result
3590 __codecvt_utf16<wchar_t, true>::do_in(state_type&,
3591 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3592 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3594 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3595 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3596 const uint8_t* _frm_nxt = _frm;
3597 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3598 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3599 uint32_t* _to_nxt = _to;
3600 result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3602 frm_nxt = frm + (_frm_nxt - _frm);
3603 to_nxt = to + (_to_nxt - _to);
3607 __codecvt_utf16<wchar_t, true>::result
3608 __codecvt_utf16<wchar_t, true>::do_unshift(state_type&,
3609 extern_type* to, extern_type*, extern_type*& to_nxt) const
3616 __codecvt_utf16<wchar_t, true>::do_encoding() const _NOEXCEPT
3622 __codecvt_utf16<wchar_t, true>::do_always_noconv() const _NOEXCEPT
3628 __codecvt_utf16<wchar_t, true>::do_length(state_type&,
3629 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3631 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3632 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3633 return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3637 __codecvt_utf16<wchar_t, true>::do_max_length() const _NOEXCEPT
3639 if (_Mode_ & consume_header)
3644 // __codecvt_utf16<char16_t, false>
3646 __codecvt_utf16<char16_t, false>::result
3647 __codecvt_utf16<char16_t, false>::do_out(state_type&,
3648 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3649 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3651 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3652 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3653 const uint16_t* _frm_nxt = _frm;
3654 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3655 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3656 uint8_t* _to_nxt = _to;
3657 result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3659 frm_nxt = frm + (_frm_nxt - _frm);
3660 to_nxt = to + (_to_nxt - _to);
3664 __codecvt_utf16<char16_t, false>::result
3665 __codecvt_utf16<char16_t, false>::do_in(state_type&,
3666 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3667 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3669 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3670 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3671 const uint8_t* _frm_nxt = _frm;
3672 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3673 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3674 uint16_t* _to_nxt = _to;
3675 result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3677 frm_nxt = frm + (_frm_nxt - _frm);
3678 to_nxt = to + (_to_nxt - _to);
3682 __codecvt_utf16<char16_t, false>::result
3683 __codecvt_utf16<char16_t, false>::do_unshift(state_type&,
3684 extern_type* to, extern_type*, extern_type*& to_nxt) const
3691 __codecvt_utf16<char16_t, false>::do_encoding() const _NOEXCEPT
3697 __codecvt_utf16<char16_t, false>::do_always_noconv() const _NOEXCEPT
3703 __codecvt_utf16<char16_t, false>::do_length(state_type&,
3704 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3706 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3707 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3708 return utf16be_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3712 __codecvt_utf16<char16_t, false>::do_max_length() const _NOEXCEPT
3714 if (_Mode_ & consume_header)
3719 // __codecvt_utf16<char16_t, true>
3721 __codecvt_utf16<char16_t, true>::result
3722 __codecvt_utf16<char16_t, true>::do_out(state_type&,
3723 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3724 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3726 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3727 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3728 const uint16_t* _frm_nxt = _frm;
3729 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3730 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3731 uint8_t* _to_nxt = _to;
3732 result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3734 frm_nxt = frm + (_frm_nxt - _frm);
3735 to_nxt = to + (_to_nxt - _to);
3739 __codecvt_utf16<char16_t, true>::result
3740 __codecvt_utf16<char16_t, true>::do_in(state_type&,
3741 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3742 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3744 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3745 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3746 const uint8_t* _frm_nxt = _frm;
3747 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3748 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3749 uint16_t* _to_nxt = _to;
3750 result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3752 frm_nxt = frm + (_frm_nxt - _frm);
3753 to_nxt = to + (_to_nxt - _to);
3757 __codecvt_utf16<char16_t, true>::result
3758 __codecvt_utf16<char16_t, true>::do_unshift(state_type&,
3759 extern_type* to, extern_type*, extern_type*& to_nxt) const
3766 __codecvt_utf16<char16_t, true>::do_encoding() const _NOEXCEPT
3772 __codecvt_utf16<char16_t, true>::do_always_noconv() const _NOEXCEPT
3778 __codecvt_utf16<char16_t, true>::do_length(state_type&,
3779 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3781 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3782 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3783 return utf16le_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3787 __codecvt_utf16<char16_t, true>::do_max_length() const _NOEXCEPT
3789 if (_Mode_ & consume_header)
3794 // __codecvt_utf16<char32_t, false>
3796 __codecvt_utf16<char32_t, false>::result
3797 __codecvt_utf16<char32_t, false>::do_out(state_type&,
3798 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3799 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3801 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3802 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3803 const uint32_t* _frm_nxt = _frm;
3804 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3805 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3806 uint8_t* _to_nxt = _to;
3807 result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3809 frm_nxt = frm + (_frm_nxt - _frm);
3810 to_nxt = to + (_to_nxt - _to);
3814 __codecvt_utf16<char32_t, false>::result
3815 __codecvt_utf16<char32_t, false>::do_in(state_type&,
3816 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3817 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3819 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3820 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3821 const uint8_t* _frm_nxt = _frm;
3822 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3823 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3824 uint32_t* _to_nxt = _to;
3825 result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3827 frm_nxt = frm + (_frm_nxt - _frm);
3828 to_nxt = to + (_to_nxt - _to);
3832 __codecvt_utf16<char32_t, false>::result
3833 __codecvt_utf16<char32_t, false>::do_unshift(state_type&,
3834 extern_type* to, extern_type*, extern_type*& to_nxt) const
3841 __codecvt_utf16<char32_t, false>::do_encoding() const _NOEXCEPT
3847 __codecvt_utf16<char32_t, false>::do_always_noconv() const _NOEXCEPT
3853 __codecvt_utf16<char32_t, false>::do_length(state_type&,
3854 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3856 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3857 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3858 return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3862 __codecvt_utf16<char32_t, false>::do_max_length() const _NOEXCEPT
3864 if (_Mode_ & consume_header)
3869 // __codecvt_utf16<char32_t, true>
3871 __codecvt_utf16<char32_t, true>::result
3872 __codecvt_utf16<char32_t, true>::do_out(state_type&,
3873 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3874 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3876 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3877 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3878 const uint32_t* _frm_nxt = _frm;
3879 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3880 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3881 uint8_t* _to_nxt = _to;
3882 result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3884 frm_nxt = frm + (_frm_nxt - _frm);
3885 to_nxt = to + (_to_nxt - _to);
3889 __codecvt_utf16<char32_t, true>::result
3890 __codecvt_utf16<char32_t, true>::do_in(state_type&,
3891 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3892 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3894 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3895 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3896 const uint8_t* _frm_nxt = _frm;
3897 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3898 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3899 uint32_t* _to_nxt = _to;
3900 result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3902 frm_nxt = frm + (_frm_nxt - _frm);
3903 to_nxt = to + (_to_nxt - _to);
3907 __codecvt_utf16<char32_t, true>::result
3908 __codecvt_utf16<char32_t, true>::do_unshift(state_type&,
3909 extern_type* to, extern_type*, extern_type*& to_nxt) const
3916 __codecvt_utf16<char32_t, true>::do_encoding() const _NOEXCEPT
3922 __codecvt_utf16<char32_t, true>::do_always_noconv() const _NOEXCEPT
3928 __codecvt_utf16<char32_t, true>::do_length(state_type&,
3929 const extern_type* frm, const extern_type* frm_end, size_t mx) const
3931 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3932 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3933 return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3937 __codecvt_utf16<char32_t, true>::do_max_length() const _NOEXCEPT
3939 if (_Mode_ & consume_header)
3944 // __codecvt_utf8_utf16<wchar_t>
3946 __codecvt_utf8_utf16<wchar_t>::result
3947 __codecvt_utf8_utf16<wchar_t>::do_out(state_type&,
3948 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3949 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3951 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3952 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3953 const uint32_t* _frm_nxt = _frm;
3954 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3955 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3956 uint8_t* _to_nxt = _to;
3957 result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3959 frm_nxt = frm + (_frm_nxt - _frm);
3960 to_nxt = to + (_to_nxt - _to);
3964 __codecvt_utf8_utf16<wchar_t>::result
3965 __codecvt_utf8_utf16<wchar_t>::do_in(state_type&,
3966 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3967 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3969 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3970 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3971 const uint8_t* _frm_nxt = _frm;
3972 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3973 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3974 uint32_t* _to_nxt = _to;
3975 result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3977 frm_nxt = frm + (_frm_nxt - _frm);
3978 to_nxt = to + (_to_nxt - _to);
3982 __codecvt_utf8_utf16<wchar_t>::result
3983 __codecvt_utf8_utf16<wchar_t>::do_unshift(state_type&,
3984 extern_type* to, extern_type*, extern_type*& to_nxt) const
3991 __codecvt_utf8_utf16<wchar_t>::do_encoding() const _NOEXCEPT
3997 __codecvt_utf8_utf16<wchar_t>::do_always_noconv() const _NOEXCEPT
4003 __codecvt_utf8_utf16<wchar_t>::do_length(state_type&,
4004 const extern_type* frm, const extern_type* frm_end, size_t mx) const
4006 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4007 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4008 return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
4012 __codecvt_utf8_utf16<wchar_t>::do_max_length() const _NOEXCEPT
4014 if (_Mode_ & consume_header)
4019 // __codecvt_utf8_utf16<char16_t>
4021 __codecvt_utf8_utf16<char16_t>::result
4022 __codecvt_utf8_utf16<char16_t>::do_out(state_type&,
4023 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
4024 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
4026 const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
4027 const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
4028 const uint16_t* _frm_nxt = _frm;
4029 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
4030 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
4031 uint8_t* _to_nxt = _to;
4032 result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4034 frm_nxt = frm + (_frm_nxt - _frm);
4035 to_nxt = to + (_to_nxt - _to);
4039 __codecvt_utf8_utf16<char16_t>::result
4040 __codecvt_utf8_utf16<char16_t>::do_in(state_type&,
4041 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
4042 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
4044 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4045 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4046 const uint8_t* _frm_nxt = _frm;
4047 uint16_t* _to = reinterpret_cast<uint16_t*>(to);
4048 uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
4049 uint16_t* _to_nxt = _to;
4050 result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4052 frm_nxt = frm + (_frm_nxt - _frm);
4053 to_nxt = to + (_to_nxt - _to);
4057 __codecvt_utf8_utf16<char16_t>::result
4058 __codecvt_utf8_utf16<char16_t>::do_unshift(state_type&,
4059 extern_type* to, extern_type*, extern_type*& to_nxt) const
4066 __codecvt_utf8_utf16<char16_t>::do_encoding() const _NOEXCEPT
4072 __codecvt_utf8_utf16<char16_t>::do_always_noconv() const _NOEXCEPT
4078 __codecvt_utf8_utf16<char16_t>::do_length(state_type&,
4079 const extern_type* frm, const extern_type* frm_end, size_t mx) const
4081 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4082 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4083 return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
4087 __codecvt_utf8_utf16<char16_t>::do_max_length() const _NOEXCEPT
4089 if (_Mode_ & consume_header)
4094 // __codecvt_utf8_utf16<char32_t>
4096 __codecvt_utf8_utf16<char32_t>::result
4097 __codecvt_utf8_utf16<char32_t>::do_out(state_type&,
4098 const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
4099 extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
4101 const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
4102 const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
4103 const uint32_t* _frm_nxt = _frm;
4104 uint8_t* _to = reinterpret_cast<uint8_t*>(to);
4105 uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
4106 uint8_t* _to_nxt = _to;
4107 result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4109 frm_nxt = frm + (_frm_nxt - _frm);
4110 to_nxt = to + (_to_nxt - _to);
4114 __codecvt_utf8_utf16<char32_t>::result
4115 __codecvt_utf8_utf16<char32_t>::do_in(state_type&,
4116 const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
4117 intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
4119 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4120 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4121 const uint8_t* _frm_nxt = _frm;
4122 uint32_t* _to = reinterpret_cast<uint32_t*>(to);
4123 uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
4124 uint32_t* _to_nxt = _to;
4125 result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4127 frm_nxt = frm + (_frm_nxt - _frm);
4128 to_nxt = to + (_to_nxt - _to);
4132 __codecvt_utf8_utf16<char32_t>::result
4133 __codecvt_utf8_utf16<char32_t>::do_unshift(state_type&,
4134 extern_type* to, extern_type*, extern_type*& to_nxt) const
4141 __codecvt_utf8_utf16<char32_t>::do_encoding() const _NOEXCEPT
4147 __codecvt_utf8_utf16<char32_t>::do_always_noconv() const _NOEXCEPT
4153 __codecvt_utf8_utf16<char32_t>::do_length(state_type&,
4154 const extern_type* frm, const extern_type* frm_end, size_t mx) const
4156 const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4157 const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4158 return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
4162 __codecvt_utf8_utf16<char32_t>::do_max_length() const _NOEXCEPT
4164 if (_Mode_ & consume_header)
4169 // __narrow_to_utf8<16>
4171 __narrow_to_utf8<16>::~__narrow_to_utf8()
4175 // __narrow_to_utf8<32>
4177 __narrow_to_utf8<32>::~__narrow_to_utf8()
4181 // __widen_from_utf8<16>
4183 __widen_from_utf8<16>::~__widen_from_utf8()
4187 // __widen_from_utf8<32>
4189 __widen_from_utf8<32>::~__widen_from_utf8()
4194 static bool checked_string_to_wchar_convert(wchar_t& dest,
4196 __locale_struct* loc) {
4201 size_t ret = __libcpp_mbrtowc_l(&out, ptr, strlen(ptr), &mb, loc);
4202 if (ret == static_cast<size_t>(-1) || ret == static_cast<size_t>(-2)) {
4209 static bool checked_string_to_char_convert(char& dest,
4211 __locale_struct* __loc) {
4218 // First convert the MBS into a wide char then attempt to narrow it using
4221 if (!checked_string_to_wchar_convert(wout, ptr, __loc))
4224 if ((res = __libcpp_wctob_l(wout, __loc)) != char_traits<char>::eof()) {
4228 // FIXME: Work around specific multibyte sequences that we can reasonable
4229 // translate into a different single byte.
4231 case L'\u00A0': // non-breaking space
4237 _LIBCPP_UNREACHABLE();
4241 // numpunct<char> && numpunct<wchar_t>
4243 locale::id numpunct< char >::id;
4244 locale::id numpunct<wchar_t>::id;
4246 numpunct<char>::numpunct(size_t refs)
4247 : locale::facet(refs),
4248 __decimal_point_('.'),
4249 __thousands_sep_(',')
4253 numpunct<wchar_t>::numpunct(size_t refs)
4254 : locale::facet(refs),
4255 __decimal_point_(L'.'),
4256 __thousands_sep_(L',')
4260 numpunct<char>::~numpunct()
4264 numpunct<wchar_t>::~numpunct()
4268 char numpunct< char >::do_decimal_point() const {return __decimal_point_;}
4269 wchar_t numpunct<wchar_t>::do_decimal_point() const {return __decimal_point_;}
4271 char numpunct< char >::do_thousands_sep() const {return __thousands_sep_;}
4272 wchar_t numpunct<wchar_t>::do_thousands_sep() const {return __thousands_sep_;}
4274 string numpunct< char >::do_grouping() const {return __grouping_;}
4275 string numpunct<wchar_t>::do_grouping() const {return __grouping_;}
4277 string numpunct< char >::do_truename() const {return "true";}
4278 wstring numpunct<wchar_t>::do_truename() const {return L"true";}
4280 string numpunct< char >::do_falsename() const {return "false";}
4281 wstring numpunct<wchar_t>::do_falsename() const {return L"false";}
4283 // numpunct_byname<char>
4285 numpunct_byname<char>::numpunct_byname(const char* nm, size_t refs)
4286 : numpunct<char>(refs)
4291 numpunct_byname<char>::numpunct_byname(const string& nm, size_t refs)
4292 : numpunct<char>(refs)
4297 numpunct_byname<char>::~numpunct_byname()
4302 numpunct_byname<char>::__init(const char* nm)
4304 if (strcmp(nm, "C") != 0)
4306 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
4308 __throw_runtime_error("numpunct_byname<char>::numpunct_byname"
4309 " failed to construct for " + string(nm));
4311 lconv* lc = __libcpp_localeconv_l(loc.get());
4312 checked_string_to_char_convert(__decimal_point_, lc->decimal_point,
4314 checked_string_to_char_convert(__thousands_sep_, lc->thousands_sep,
4316 __grouping_ = lc->grouping;
4317 // localization for truename and falsename is not available
4321 // numpunct_byname<wchar_t>
4323 numpunct_byname<wchar_t>::numpunct_byname(const char* nm, size_t refs)
4324 : numpunct<wchar_t>(refs)
4329 numpunct_byname<wchar_t>::numpunct_byname(const string& nm, size_t refs)
4330 : numpunct<wchar_t>(refs)
4335 numpunct_byname<wchar_t>::~numpunct_byname()
4340 numpunct_byname<wchar_t>::__init(const char* nm)
4342 if (strcmp(nm, "C") != 0)
4344 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
4346 __throw_runtime_error("numpunct_byname<wchar_t>::numpunct_byname"
4347 " failed to construct for " + string(nm));
4349 lconv* lc = __libcpp_localeconv_l(loc.get());
4350 checked_string_to_wchar_convert(__decimal_point_, lc->decimal_point,
4352 checked_string_to_wchar_convert(__thousands_sep_, lc->thousands_sep,
4354 __grouping_ = lc->grouping;
4355 // localization for truename and falsename is not available
4362 __num_get_base::__get_base(ios_base& iob)
4364 ios_base::fmtflags __basefield = iob.flags() & ios_base::basefield;
4365 if (__basefield == ios_base::oct)
4367 else if (__basefield == ios_base::hex)
4369 else if (__basefield == 0)
4374 const char __num_get_base::__src[33] = "0123456789abcdefABCDEFxX+-pPiInN";
4377 __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end,
4378 ios_base::iostate& __err)
4380 if (__grouping.size() != 0)
4382 reverse(__g, __g_end);
4383 const char* __ig = __grouping.data();
4384 const char* __eg = __ig + __grouping.size();
4385 for (unsigned* __r = __g; __r < __g_end-1; ++__r)
4387 if (0 < *__ig && *__ig < numeric_limits<char>::max())
4389 if (static_cast<unsigned>(*__ig) != *__r)
4391 __err = ios_base::failbit;
4395 if (__eg - __ig > 1)
4398 if (0 < *__ig && *__ig < numeric_limits<char>::max())
4400 if (static_cast<unsigned>(*__ig) < __g_end[-1] || __g_end[-1] == 0)
4401 __err = ios_base::failbit;
4407 __num_put_base::__format_int(char* __fmtp, const char* __len, bool __signd,
4408 ios_base::fmtflags __flags)
4410 if (__flags & ios_base::showpos)
4412 if (__flags & ios_base::showbase)
4415 *__fmtp++ = *__len++;
4416 if ((__flags & ios_base::basefield) == ios_base::oct)
4418 else if ((__flags & ios_base::basefield) == ios_base::hex)
4420 if (__flags & ios_base::uppercase)
4432 __num_put_base::__format_float(char* __fmtp, const char* __len,
4433 ios_base::fmtflags __flags)
4435 bool specify_precision = true;
4436 if (__flags & ios_base::showpos)
4438 if (__flags & ios_base::showpoint)
4440 ios_base::fmtflags floatfield = __flags & ios_base::floatfield;
4441 bool uppercase = (__flags & ios_base::uppercase) != 0;
4442 if (floatfield == (ios_base::fixed | ios_base::scientific))
4443 specify_precision = false;
4450 *__fmtp++ = *__len++;
4451 if (floatfield == ios_base::fixed)
4458 else if (floatfield == ios_base::scientific)
4465 else if (floatfield == (ios_base::fixed | ios_base::scientific))
4479 return specify_precision;
4483 __num_put_base::__identify_padding(char* __nb, char* __ne,
4484 const ios_base& __iob)
4486 switch (__iob.flags() & ios_base::adjustfield)
4488 case ios_base::internal:
4489 if (__nb[0] == '-' || __nb[0] == '+')
4491 if (__ne - __nb >= 2 && __nb[0] == '0'
4492 && (__nb[1] == 'x' || __nb[1] == 'X'))
4495 case ios_base::left:
4497 case ios_base::right:
4510 static string weeks[14];
4511 weeks[0] = "Sunday";
4512 weeks[1] = "Monday";
4513 weeks[2] = "Tuesday";
4514 weeks[3] = "Wednesday";
4515 weeks[4] = "Thursday";
4516 weeks[5] = "Friday";
4517 weeks[6] = "Saturday";
4532 static wstring weeks[14];
4533 weeks[0] = L"Sunday";
4534 weeks[1] = L"Monday";
4535 weeks[2] = L"Tuesday";
4536 weeks[3] = L"Wednesday";
4537 weeks[4] = L"Thursday";
4538 weeks[5] = L"Friday";
4539 weeks[6] = L"Saturday";
4552 __time_get_c_storage<char>::__weeks() const
4554 static const string* weeks = init_weeks();
4560 __time_get_c_storage<wchar_t>::__weeks() const
4562 static const wstring* weeks = init_wweeks();
4570 static string months[24];
4571 months[0] = "January";
4572 months[1] = "February";
4573 months[2] = "March";
4574 months[3] = "April";
4578 months[7] = "August";
4579 months[8] = "September";
4580 months[9] = "October";
4581 months[10] = "November";
4582 months[11] = "December";
4602 static wstring months[24];
4603 months[0] = L"January";
4604 months[1] = L"February";
4605 months[2] = L"March";
4606 months[3] = L"April";
4608 months[5] = L"June";
4609 months[6] = L"July";
4610 months[7] = L"August";
4611 months[8] = L"September";
4612 months[9] = L"October";
4613 months[10] = L"November";
4614 months[11] = L"December";
4615 months[12] = L"Jan";
4616 months[13] = L"Feb";
4617 months[14] = L"Mar";
4618 months[15] = L"Apr";
4619 months[16] = L"May";
4620 months[17] = L"Jun";
4621 months[18] = L"Jul";
4622 months[19] = L"Aug";
4623 months[20] = L"Sep";
4624 months[21] = L"Oct";
4625 months[22] = L"Nov";
4626 months[23] = L"Dec";
4632 __time_get_c_storage<char>::__months() const
4634 static const string* months = init_months();
4640 __time_get_c_storage<wchar_t>::__months() const
4642 static const wstring* months = init_wmonths();
4650 static string am_pm[24];
4660 static wstring am_pm[24];
4668 __time_get_c_storage<char>::__am_pm() const
4670 static const string* am_pm = init_am_pm();
4676 __time_get_c_storage<wchar_t>::__am_pm() const
4678 static const wstring* am_pm = init_wam_pm();
4684 __time_get_c_storage<char>::__x() const
4686 static string s("%m/%d/%y");
4692 __time_get_c_storage<wchar_t>::__x() const
4694 static wstring s(L"%m/%d/%y");
4700 __time_get_c_storage<char>::__X() const
4702 static string s("%H:%M:%S");
4708 __time_get_c_storage<wchar_t>::__X() const
4710 static wstring s(L"%H:%M:%S");
4716 __time_get_c_storage<char>::__c() const
4718 static string s("%a %b %d %H:%M:%S %Y");
4724 __time_get_c_storage<wchar_t>::__c() const
4726 static wstring s(L"%a %b %d %H:%M:%S %Y");
4732 __time_get_c_storage<char>::__r() const
4734 static string s("%I:%M:%S %p");
4740 __time_get_c_storage<wchar_t>::__r() const
4742 static wstring s(L"%I:%M:%S %p");
4748 __time_get::__time_get(const char* nm)
4749 : __loc_(newlocale(LC_ALL_MASK, nm, 0))
4752 __throw_runtime_error("time_get_byname"
4753 " failed to construct for " + string(nm));
4756 __time_get::__time_get(const string& nm)
4757 : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
4760 __throw_runtime_error("time_get_byname"
4761 " failed to construct for " + nm);
4764 __time_get::~__time_get()
4768 #if defined(__clang__)
4769 #pragma clang diagnostic ignored "-Wmissing-field-initializers"
4771 #if defined(__GNUG__)
4772 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
4777 __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
4793 size_t n = strftime_l(buf, countof(buf), f, &t, __loc_);
4799 if (ct.is(ctype_base::space, *bb))
4801 result.push_back(' ');
4802 for (++bb; bb != be && ct.is(ctype_base::space, *bb); ++bb)
4807 ios_base::iostate err = ios_base::goodbit;
4808 ptrdiff_t i = __scan_keyword(w, be, this->__weeks_, this->__weeks_+14,
4813 result.push_back('%');
4815 result.push_back('A');
4817 result.push_back('a');
4822 i = __scan_keyword(w, be, this->__months_, this->__months_+24,
4827 result.push_back('%');
4829 result.push_back('B');
4831 result.push_back('b');
4832 if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
4833 result.back() = 'm';
4837 if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0)
4840 i = __scan_keyword(w, be, this->__am_pm_, this->__am_pm_+2,
4841 ct, err, false) - this->__am_pm_;
4844 result.push_back('%');
4845 result.push_back('p');
4851 if (ct.is(ctype_base::digit, *bb))
4853 switch(__get_up_to_n_digits(bb, be, err, ct, 4))
4856 result.push_back('%');
4857 result.push_back('w');
4860 result.push_back('%');
4861 result.push_back('u');
4864 result.push_back('%');
4865 result.push_back('I');
4868 result.push_back('%');
4869 result.push_back('m');
4872 result.push_back('%');
4873 result.push_back('H');
4876 result.push_back('%');
4877 result.push_back('d');
4880 result.push_back('%');
4881 result.push_back('M');
4884 result.push_back('%');
4885 result.push_back('S');
4888 result.push_back('%');
4889 result.push_back('y');
4892 result.push_back('%');
4893 result.push_back('j');
4896 result.push_back('%');
4897 result.push_back('Y');
4900 for (; w != bb; ++w)
4901 result.push_back(*w);
4908 result.push_back('%');
4909 result.push_back('%');
4913 result.push_back(*bb);
4919 #if defined(__clang__)
4920 #pragma clang diagnostic ignored "-Wmissing-braces"
4925 __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
4941 strftime_l(buf, countof(buf), f, &t, __loc_);
4943 wchar_t* wbb = wbuf;
4945 const char* bb = buf;
4946 size_t j = __libcpp_mbsrtowcs_l( wbb, &bb, countof(wbuf), &mb, __loc_);
4947 if (j == size_t(-1))
4948 __throw_runtime_error("locale not supported");
4949 wchar_t* wbe = wbb + j;
4953 if (ct.is(ctype_base::space, *wbb))
4955 result.push_back(L' ');
4956 for (++wbb; wbb != wbe && ct.is(ctype_base::space, *wbb); ++wbb)
4961 ios_base::iostate err = ios_base::goodbit;
4962 ptrdiff_t i = __scan_keyword(w, wbe, this->__weeks_, this->__weeks_+14,
4967 result.push_back(L'%');
4969 result.push_back(L'A');
4971 result.push_back(L'a');
4976 i = __scan_keyword(w, wbe, this->__months_, this->__months_+24,
4981 result.push_back(L'%');
4983 result.push_back(L'B');
4985 result.push_back(L'b');
4986 if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
4987 result.back() = L'm';
4991 if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0)
4994 i = __scan_keyword(w, wbe, this->__am_pm_, this->__am_pm_+2,
4995 ct, err, false) - this->__am_pm_;
4998 result.push_back(L'%');
4999 result.push_back(L'p');
5005 if (ct.is(ctype_base::digit, *wbb))
5007 switch(__get_up_to_n_digits(wbb, wbe, err, ct, 4))
5010 result.push_back(L'%');
5011 result.push_back(L'w');
5014 result.push_back(L'%');
5015 result.push_back(L'u');
5018 result.push_back(L'%');
5019 result.push_back(L'I');
5022 result.push_back(L'%');
5023 result.push_back(L'm');
5026 result.push_back(L'%');
5027 result.push_back(L'H');
5030 result.push_back(L'%');
5031 result.push_back(L'd');
5034 result.push_back(L'%');
5035 result.push_back(L'M');
5038 result.push_back(L'%');
5039 result.push_back(L'S');
5042 result.push_back(L'%');
5043 result.push_back(L'y');
5046 result.push_back(L'%');
5047 result.push_back(L'j');
5050 result.push_back(L'%');
5051 result.push_back(L'Y');
5054 for (; w != wbb; ++w)
5055 result.push_back(*w);
5060 if (ct.narrow(*wbb, 0) == '%')
5062 result.push_back(L'%');
5063 result.push_back(L'%');
5067 result.push_back(*wbb);
5075 __time_get_storage<char>::init(const ctype<char>& ct)
5080 for (int i = 0; i < 7; ++i)
5083 strftime_l(buf, countof(buf), "%A", &t, __loc_);
5085 strftime_l(buf, countof(buf), "%a", &t, __loc_);
5086 __weeks_[i+7] = buf;
5089 for (int i = 0; i < 12; ++i)
5092 strftime_l(buf, countof(buf), "%B", &t, __loc_);
5094 strftime_l(buf, countof(buf), "%b", &t, __loc_);
5095 __months_[i+12] = buf;
5099 strftime_l(buf, countof(buf), "%p", &t, __loc_);
5102 strftime_l(buf, countof(buf), "%p", &t, __loc_);
5104 __c_ = __analyze('c', ct);
5105 __r_ = __analyze('r', ct);
5106 __x_ = __analyze('x', ct);
5107 __X_ = __analyze('X', ct);
5112 __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
5120 for (int i = 0; i < 7; ++i)
5123 strftime_l(buf, countof(buf), "%A", &t, __loc_);
5125 const char* bb = buf;
5126 size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5127 if (j == size_t(-1))
5128 __throw_runtime_error("locale not supported");
5130 __weeks_[i].assign(wbuf, wbe);
5131 strftime_l(buf, countof(buf), "%a", &t, __loc_);
5134 j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5135 if (j == size_t(-1))
5136 __throw_runtime_error("locale not supported");
5138 __weeks_[i+7].assign(wbuf, wbe);
5141 for (int i = 0; i < 12; ++i)
5144 strftime_l(buf, countof(buf), "%B", &t, __loc_);
5146 const char* bb = buf;
5147 size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5148 if (j == size_t(-1))
5149 __throw_runtime_error("locale not supported");
5151 __months_[i].assign(wbuf, wbe);
5152 strftime_l(buf, countof(buf), "%b", &t, __loc_);
5155 j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5156 if (j == size_t(-1))
5157 __throw_runtime_error("locale not supported");
5159 __months_[i+12].assign(wbuf, wbe);
5163 strftime_l(buf, countof(buf), "%p", &t, __loc_);
5165 const char* bb = buf;
5166 size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5167 if (j == size_t(-1))
5168 __throw_runtime_error("locale not supported");
5170 __am_pm_[0].assign(wbuf, wbe);
5172 strftime_l(buf, countof(buf), "%p", &t, __loc_);
5175 j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
5176 if (j == size_t(-1))
5177 __throw_runtime_error("locale not supported");
5179 __am_pm_[1].assign(wbuf, wbe);
5180 __c_ = __analyze('c', ct);
5181 __r_ = __analyze('r', ct);
5182 __x_ = __analyze('x', ct);
5183 __X_ = __analyze('X', ct);
5186 template <class CharT>
5187 struct _LIBCPP_HIDDEN __time_get_temp
5188 : public ctype_byname<CharT>
5190 explicit __time_get_temp(const char* nm)
5191 : ctype_byname<CharT>(nm, 1) {}
5192 explicit __time_get_temp(const string& nm)
5193 : ctype_byname<CharT>(nm, 1) {}
5197 __time_get_storage<char>::__time_get_storage(const char* __nm)
5200 const __time_get_temp<char> ct(__nm);
5205 __time_get_storage<char>::__time_get_storage(const string& __nm)
5208 const __time_get_temp<char> ct(__nm);
5213 __time_get_storage<wchar_t>::__time_get_storage(const char* __nm)
5216 const __time_get_temp<wchar_t> ct(__nm);
5221 __time_get_storage<wchar_t>::__time_get_storage(const string& __nm)
5224 const __time_get_temp<wchar_t> ct(__nm);
5229 time_base::dateorder
5230 __time_get_storage<char>::__do_date_order() const
5233 for (i = 0; i < __x_.size(); ++i)
5241 for (++i; i < __x_.size(); ++i)
5244 if (i == __x_.size())
5250 for (++i; i < __x_.size(); ++i)
5253 if (i == __x_.size())
5257 return time_base::ymd;
5260 for (++i; i < __x_.size(); ++i)
5263 if (i == __x_.size())
5267 return time_base::ydm;
5272 for (++i; i < __x_.size(); ++i)
5275 if (i == __x_.size())
5280 for (++i; i < __x_.size(); ++i)
5283 if (i == __x_.size())
5286 if (__x_[i] == 'y' || __x_[i] == 'Y')
5287 return time_base::mdy;
5292 for (++i; i < __x_.size(); ++i)
5295 if (i == __x_.size())
5300 for (++i; i < __x_.size(); ++i)
5303 if (i == __x_.size())
5306 if (__x_[i] == 'y' || __x_[i] == 'Y')
5307 return time_base::dmy;
5312 return time_base::no_order;
5316 time_base::dateorder
5317 __time_get_storage<wchar_t>::__do_date_order() const
5320 for (i = 0; i < __x_.size(); ++i)
5321 if (__x_[i] == L'%')
5328 for (++i; i < __x_.size(); ++i)
5329 if (__x_[i] == L'%')
5331 if (i == __x_.size())
5337 for (++i; i < __x_.size(); ++i)
5338 if (__x_[i] == L'%')
5340 if (i == __x_.size())
5343 if (__x_[i] == L'd')
5344 return time_base::ymd;
5347 for (++i; i < __x_.size(); ++i)
5348 if (__x_[i] == L'%')
5350 if (i == __x_.size())
5353 if (__x_[i] == L'm')
5354 return time_base::ydm;
5359 for (++i; i < __x_.size(); ++i)
5360 if (__x_[i] == L'%')
5362 if (i == __x_.size())
5365 if (__x_[i] == L'd')
5367 for (++i; i < __x_.size(); ++i)
5368 if (__x_[i] == L'%')
5370 if (i == __x_.size())
5373 if (__x_[i] == L'y' || __x_[i] == L'Y')
5374 return time_base::mdy;
5379 for (++i; i < __x_.size(); ++i)
5380 if (__x_[i] == L'%')
5382 if (i == __x_.size())
5385 if (__x_[i] == L'm')
5387 for (++i; i < __x_.size(); ++i)
5388 if (__x_[i] == L'%')
5390 if (i == __x_.size())
5393 if (__x_[i] == L'y' || __x_[i] == L'Y')
5394 return time_base::dmy;
5399 return time_base::no_order;
5404 __time_put::__time_put(const char* nm)
5405 : __loc_(newlocale(LC_ALL_MASK, nm, 0))
5408 __throw_runtime_error("time_put_byname"
5409 " failed to construct for " + string(nm));
5412 __time_put::__time_put(const string& nm)
5413 : __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
5416 __throw_runtime_error("time_put_byname"
5417 " failed to construct for " + nm);
5420 __time_put::~__time_put()
5422 if (__loc_ != _LIBCPP_GET_C_LOCALE)
5427 __time_put::__do_put(char* __nb, char*& __ne, const tm* __tm,
5428 char __fmt, char __mod) const
5430 char fmt[] = {'%', __fmt, __mod, 0};
5432 swap(fmt[1], fmt[2]);
5433 size_t n = strftime_l(__nb, countof(__nb, __ne), fmt, __tm, __loc_);
5438 __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
5439 char __fmt, char __mod) const
5442 char* __ne = __nar + 100;
5443 __do_put(__nar, __ne, __tm, __fmt, __mod);
5445 const char* __nb = __nar;
5446 size_t j = __libcpp_mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_);
5447 if (j == size_t(-1))
5448 __throw_runtime_error("locale not supported");
5452 // moneypunct_byname
5454 template <class charT>
5457 __init_pat(money_base::pattern& pat, basic_string<charT>& __curr_symbol_,
5458 bool intl, char cs_precedes, char sep_by_space, char sign_posn,
5461 const char sign = static_cast<char>(money_base::sign);
5462 const char space = static_cast<char>(money_base::space);
5463 const char none = static_cast<char>(money_base::none);
5464 const char symbol = static_cast<char>(money_base::symbol);
5465 const char value = static_cast<char>(money_base::value);
5466 const bool symbol_contains_sep = intl && __curr_symbol_.size() == 4;
5468 // Comments on case branches reflect 'C11 7.11.2.1 The localeconv
5469 // function'. "Space between sign and symbol or value" means that
5470 // if the sign is adjacent to the symbol, there's a space between
5471 // them, and otherwise there's a space between the sign and value.
5473 // C11's localeconv specifies that the fourth character of an
5474 // international curr_symbol is used to separate the sign and
5475 // value when sep_by_space says to do so. C++ can't represent
5476 // that, so we just use a space. When sep_by_space says to
5477 // separate the symbol and value-or-sign with a space, we rearrange the
5478 // curr_symbol to put its spacing character on the correct side of
5481 // We also need to avoid adding an extra space between the sign
5482 // and value when the currency symbol is suppressed (by not
5483 // setting showbase). We match glibc's strfmon by interpreting
5484 // sep_by_space==1 as "omit the space when the currency symbol is
5487 // Users who want to get this right should use ICU instead.
5489 switch (cs_precedes)
5491 case 0: // value before curr_symbol
5492 if (symbol_contains_sep) {
5493 // Move the separator to before the symbol, to place it
5494 // between the value and symbol.
5495 rotate(__curr_symbol_.begin(), __curr_symbol_.begin() + 3,
5496 __curr_symbol_.end());
5500 case 0: // Parentheses surround the quantity and currency symbol.
5501 pat.field[0] = sign;
5502 pat.field[1] = value;
5503 pat.field[2] = none; // Any space appears in the symbol.
5504 pat.field[3] = symbol;
5505 switch (sep_by_space)
5507 case 0: // No space separates the currency symbol and value.
5508 // This case may have changed between C99 and C11;
5509 // assume the currency symbol matches the intention.
5510 case 2: // Space between sign and currency or value.
5511 // The "sign" is two parentheses, so no space here either.
5513 case 1: // Space between currency-and-sign or currency and value.
5514 if (!symbol_contains_sep) {
5515 // We insert the space into the symbol instead of
5516 // setting pat.field[2]=space so that when
5517 // showbase is not set, the space goes away too.
5518 __curr_symbol_.insert(0, 1, space_char);
5525 case 1: // The sign string precedes the quantity and currency symbol.
5526 pat.field[0] = sign;
5527 pat.field[3] = symbol;
5528 switch (sep_by_space)
5530 case 0: // No space separates the currency symbol and value.
5531 pat.field[1] = value;
5532 pat.field[2] = none;
5534 case 1: // Space between currency-and-sign or currency and value.
5535 pat.field[1] = value;
5536 pat.field[2] = none;
5537 if (!symbol_contains_sep) {
5538 // We insert the space into the symbol instead of
5539 // setting pat.field[2]=space so that when
5540 // showbase is not set, the space goes away too.
5541 __curr_symbol_.insert(0, 1, space_char);
5544 case 2: // Space between sign and currency or value.
5545 pat.field[1] = space;
5546 pat.field[2] = value;
5547 if (symbol_contains_sep) {
5548 // Remove the separator from the symbol, since it
5549 // has already appeared after the sign.
5550 __curr_symbol_.erase(__curr_symbol_.begin());
5557 case 2: // The sign string succeeds the quantity and currency symbol.
5558 pat.field[0] = value;
5559 pat.field[3] = sign;
5560 switch (sep_by_space)
5562 case 0: // No space separates the currency symbol and value.
5563 pat.field[1] = none;
5564 pat.field[2] = symbol;
5566 case 1: // Space between currency-and-sign or currency and value.
5567 if (!symbol_contains_sep) {
5568 // We insert the space into the symbol instead of
5569 // setting pat.field[1]=space so that when
5570 // showbase is not set, the space goes away too.
5571 __curr_symbol_.insert(0, 1, space_char);
5573 pat.field[1] = none;
5574 pat.field[2] = symbol;
5576 case 2: // Space between sign and currency or value.
5577 pat.field[1] = symbol;
5578 pat.field[2] = space;
5579 if (symbol_contains_sep) {
5580 // Remove the separator from the symbol, since it
5581 // should not be removed if showbase is absent.
5582 __curr_symbol_.erase(__curr_symbol_.begin());
5589 case 3: // The sign string immediately precedes the currency symbol.
5590 pat.field[0] = value;
5591 pat.field[3] = symbol;
5592 switch (sep_by_space)
5594 case 0: // No space separates the currency symbol and value.
5595 pat.field[1] = none;
5596 pat.field[2] = sign;
5598 case 1: // Space between currency-and-sign or currency and value.
5599 pat.field[1] = space;
5600 pat.field[2] = sign;
5601 if (symbol_contains_sep) {
5602 // Remove the separator from the symbol, since it
5603 // has already appeared before the sign.
5604 __curr_symbol_.erase(__curr_symbol_.begin());
5607 case 2: // Space between sign and currency or value.
5608 pat.field[1] = sign;
5609 pat.field[2] = none;
5610 if (!symbol_contains_sep) {
5611 // We insert the space into the symbol instead of
5612 // setting pat.field[2]=space so that when
5613 // showbase is not set, the space goes away too.
5614 __curr_symbol_.insert(0, 1, space_char);
5621 case 4: // The sign string immediately succeeds the currency symbol.
5622 pat.field[0] = value;
5623 pat.field[3] = sign;
5624 switch (sep_by_space)
5626 case 0: // No space separates the currency symbol and value.
5627 pat.field[1] = none;
5628 pat.field[2] = symbol;
5630 case 1: // Space between currency-and-sign or currency and value.
5631 pat.field[1] = none;
5632 pat.field[2] = symbol;
5633 if (!symbol_contains_sep) {
5634 // We insert the space into the symbol instead of
5635 // setting pat.field[1]=space so that when
5636 // showbase is not set, the space goes away too.
5637 __curr_symbol_.insert(0, 1, space_char);
5640 case 2: // Space between sign and currency or value.
5641 pat.field[1] = symbol;
5642 pat.field[2] = space;
5643 if (symbol_contains_sep) {
5644 // Remove the separator from the symbol, since it
5645 // should not disappear when showbase is absent.
5646 __curr_symbol_.erase(__curr_symbol_.begin());
5657 case 1: // curr_symbol before value
5660 case 0: // Parentheses surround the quantity and currency symbol.
5661 pat.field[0] = sign;
5662 pat.field[1] = symbol;
5663 pat.field[2] = none; // Any space appears in the symbol.
5664 pat.field[3] = value;
5665 switch (sep_by_space)
5667 case 0: // No space separates the currency symbol and value.
5668 // This case may have changed between C99 and C11;
5669 // assume the currency symbol matches the intention.
5670 case 2: // Space between sign and currency or value.
5671 // The "sign" is two parentheses, so no space here either.
5673 case 1: // Space between currency-and-sign or currency and value.
5674 if (!symbol_contains_sep) {
5675 // We insert the space into the symbol instead of
5676 // setting pat.field[2]=space so that when
5677 // showbase is not set, the space goes away too.
5678 __curr_symbol_.insert(0, 1, space_char);
5685 case 1: // The sign string precedes the quantity and currency symbol.
5686 pat.field[0] = sign;
5687 pat.field[3] = value;
5688 switch (sep_by_space)
5690 case 0: // No space separates the currency symbol and value.
5691 pat.field[1] = symbol;
5692 pat.field[2] = none;
5694 case 1: // Space between currency-and-sign or currency and value.
5695 pat.field[1] = symbol;
5696 pat.field[2] = none;
5697 if (!symbol_contains_sep) {
5698 // We insert the space into the symbol instead of
5699 // setting pat.field[2]=space so that when
5700 // showbase is not set, the space goes away too.
5701 __curr_symbol_.push_back(space_char);
5704 case 2: // Space between sign and currency or value.
5705 pat.field[1] = space;
5706 pat.field[2] = symbol;
5707 if (symbol_contains_sep) {
5708 // Remove the separator from the symbol, since it
5709 // has already appeared after the sign.
5710 __curr_symbol_.pop_back();
5717 case 2: // The sign string succeeds the quantity and currency symbol.
5718 pat.field[0] = symbol;
5719 pat.field[3] = sign;
5720 switch (sep_by_space)
5722 case 0: // No space separates the currency symbol and value.
5723 pat.field[1] = none;
5724 pat.field[2] = value;
5726 case 1: // Space between currency-and-sign or currency and value.
5727 pat.field[1] = none;
5728 pat.field[2] = value;
5729 if (!symbol_contains_sep) {
5730 // We insert the space into the symbol instead of
5731 // setting pat.field[1]=space so that when
5732 // showbase is not set, the space goes away too.
5733 __curr_symbol_.push_back(space_char);
5736 case 2: // Space between sign and currency or value.
5737 pat.field[1] = value;
5738 pat.field[2] = space;
5739 if (symbol_contains_sep) {
5740 // Remove the separator from the symbol, since it
5741 // will appear before the sign.
5742 __curr_symbol_.pop_back();
5749 case 3: // The sign string immediately precedes the currency symbol.
5750 pat.field[0] = sign;
5751 pat.field[3] = value;
5752 switch (sep_by_space)
5754 case 0: // No space separates the currency symbol and value.
5755 pat.field[1] = symbol;
5756 pat.field[2] = none;
5758 case 1: // Space between currency-and-sign or currency and value.
5759 pat.field[1] = symbol;
5760 pat.field[2] = none;
5761 if (!symbol_contains_sep) {
5762 // We insert the space into the symbol instead of
5763 // setting pat.field[2]=space so that when
5764 // showbase is not set, the space goes away too.
5765 __curr_symbol_.push_back(space_char);
5768 case 2: // Space between sign and currency or value.
5769 pat.field[1] = space;
5770 pat.field[2] = symbol;
5771 if (symbol_contains_sep) {
5772 // Remove the separator from the symbol, since it
5773 // has already appeared after the sign.
5774 __curr_symbol_.pop_back();
5781 case 4: // The sign string immediately succeeds the currency symbol.
5782 pat.field[0] = symbol;
5783 pat.field[3] = value;
5784 switch (sep_by_space)
5786 case 0: // No space separates the currency symbol and value.
5787 pat.field[1] = sign;
5788 pat.field[2] = none;
5790 case 1: // Space between currency-and-sign or currency and value.
5791 pat.field[1] = sign;
5792 pat.field[2] = space;
5793 if (symbol_contains_sep) {
5794 // Remove the separator from the symbol, since it
5795 // should not disappear when showbase is absent.
5796 __curr_symbol_.pop_back();
5799 case 2: // Space between sign and currency or value.
5800 pat.field[1] = none;
5801 pat.field[2] = sign;
5802 if (!symbol_contains_sep) {
5803 // We insert the space into the symbol instead of
5804 // setting pat.field[1]=space so that when
5805 // showbase is not set, the space goes away too.
5806 __curr_symbol_.push_back(space_char);
5820 pat.field[0] = symbol;
5821 pat.field[1] = sign;
5822 pat.field[2] = none;
5823 pat.field[3] = value;
5828 moneypunct_byname<char, false>::init(const char* nm)
5830 typedef moneypunct<char, false> base;
5831 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
5833 __throw_runtime_error("moneypunct_byname"
5834 " failed to construct for " + string(nm));
5836 lconv* lc = __libcpp_localeconv_l(loc.get());
5837 if (!checked_string_to_char_convert(__decimal_point_,
5838 lc->mon_decimal_point,
5840 __decimal_point_ = base::do_decimal_point();
5841 if (!checked_string_to_char_convert(__thousands_sep_,
5842 lc->mon_thousands_sep,
5844 __thousands_sep_ = base::do_thousands_sep();
5846 __grouping_ = lc->mon_grouping;
5847 __curr_symbol_ = lc->currency_symbol;
5848 if (lc->frac_digits != CHAR_MAX)
5849 __frac_digits_ = lc->frac_digits;
5851 __frac_digits_ = base::do_frac_digits();
5852 if (lc->p_sign_posn == 0)
5853 __positive_sign_ = "()";
5855 __positive_sign_ = lc->positive_sign;
5856 if (lc->n_sign_posn == 0)
5857 __negative_sign_ = "()";
5859 __negative_sign_ = lc->negative_sign;
5860 // Assume the positive and negative formats will want spaces in
5861 // the same places in curr_symbol since there's no way to
5862 // represent anything else.
5863 string_type __dummy_curr_symbol = __curr_symbol_;
5864 __init_pat(__pos_format_, __dummy_curr_symbol, false,
5865 lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
5866 __init_pat(__neg_format_, __curr_symbol_, false,
5867 lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
5872 moneypunct_byname<char, true>::init(const char* nm)
5874 typedef moneypunct<char, true> base;
5875 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
5877 __throw_runtime_error("moneypunct_byname"
5878 " failed to construct for " + string(nm));
5880 lconv* lc = __libcpp_localeconv_l(loc.get());
5881 if (!checked_string_to_char_convert(__decimal_point_,
5882 lc->mon_decimal_point,
5884 __decimal_point_ = base::do_decimal_point();
5885 if (!checked_string_to_char_convert(__thousands_sep_,
5886 lc->mon_thousands_sep,
5888 __thousands_sep_ = base::do_thousands_sep();
5889 __grouping_ = lc->mon_grouping;
5890 __curr_symbol_ = lc->int_curr_symbol;
5891 if (lc->int_frac_digits != CHAR_MAX)
5892 __frac_digits_ = lc->int_frac_digits;
5894 __frac_digits_ = base::do_frac_digits();
5895 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
5896 if (lc->p_sign_posn == 0)
5897 #else // _LIBCPP_MSVCRT
5898 if (lc->int_p_sign_posn == 0)
5899 #endif // !_LIBCPP_MSVCRT
5900 __positive_sign_ = "()";
5902 __positive_sign_ = lc->positive_sign;
5903 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
5904 if(lc->n_sign_posn == 0)
5905 #else // _LIBCPP_MSVCRT
5906 if (lc->int_n_sign_posn == 0)
5907 #endif // !_LIBCPP_MSVCRT
5908 __negative_sign_ = "()";
5910 __negative_sign_ = lc->negative_sign;
5911 // Assume the positive and negative formats will want spaces in
5912 // the same places in curr_symbol since there's no way to
5913 // represent anything else.
5914 string_type __dummy_curr_symbol = __curr_symbol_;
5915 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
5916 __init_pat(__pos_format_, __dummy_curr_symbol, true,
5917 lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
5918 __init_pat(__neg_format_, __curr_symbol_, true,
5919 lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
5920 #else // _LIBCPP_MSVCRT
5921 __init_pat(__pos_format_, __dummy_curr_symbol, true,
5922 lc->int_p_cs_precedes, lc->int_p_sep_by_space,
5923 lc->int_p_sign_posn, ' ');
5924 __init_pat(__neg_format_, __curr_symbol_, true,
5925 lc->int_n_cs_precedes, lc->int_n_sep_by_space,
5926 lc->int_n_sign_posn, ' ');
5927 #endif // !_LIBCPP_MSVCRT
5932 moneypunct_byname<wchar_t, false>::init(const char* nm)
5934 typedef moneypunct<wchar_t, false> base;
5935 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
5937 __throw_runtime_error("moneypunct_byname"
5938 " failed to construct for " + string(nm));
5939 lconv* lc = __libcpp_localeconv_l(loc.get());
5940 if (!checked_string_to_wchar_convert(__decimal_point_,
5941 lc->mon_decimal_point,
5943 __decimal_point_ = base::do_decimal_point();
5944 if (!checked_string_to_wchar_convert(__thousands_sep_,
5945 lc->mon_thousands_sep,
5947 __thousands_sep_ = base::do_thousands_sep();
5948 __grouping_ = lc->mon_grouping;
5951 const char* bb = lc->currency_symbol;
5952 size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5953 if (j == size_t(-1))
5954 __throw_runtime_error("locale not supported");
5955 wchar_t* wbe = wbuf + j;
5956 __curr_symbol_.assign(wbuf, wbe);
5957 if (lc->frac_digits != CHAR_MAX)
5958 __frac_digits_ = lc->frac_digits;
5960 __frac_digits_ = base::do_frac_digits();
5961 if (lc->p_sign_posn == 0)
5962 __positive_sign_ = L"()";
5966 bb = lc->positive_sign;
5967 j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5968 if (j == size_t(-1))
5969 __throw_runtime_error("locale not supported");
5971 __positive_sign_.assign(wbuf, wbe);
5973 if (lc->n_sign_posn == 0)
5974 __negative_sign_ = L"()";
5978 bb = lc->negative_sign;
5979 j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
5980 if (j == size_t(-1))
5981 __throw_runtime_error("locale not supported");
5983 __negative_sign_.assign(wbuf, wbe);
5985 // Assume the positive and negative formats will want spaces in
5986 // the same places in curr_symbol since there's no way to
5987 // represent anything else.
5988 string_type __dummy_curr_symbol = __curr_symbol_;
5989 __init_pat(__pos_format_, __dummy_curr_symbol, false,
5990 lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
5991 __init_pat(__neg_format_, __curr_symbol_, false,
5992 lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
5997 moneypunct_byname<wchar_t, true>::init(const char* nm)
5999 typedef moneypunct<wchar_t, true> base;
6000 __locale_unique_ptr loc(newlocale(LC_ALL_MASK, nm, 0), freelocale);
6002 __throw_runtime_error("moneypunct_byname"
6003 " failed to construct for " + string(nm));
6005 lconv* lc = __libcpp_localeconv_l(loc.get());
6006 if (!checked_string_to_wchar_convert(__decimal_point_,
6007 lc->mon_decimal_point,
6009 __decimal_point_ = base::do_decimal_point();
6010 if (!checked_string_to_wchar_convert(__thousands_sep_,
6011 lc->mon_thousands_sep,
6013 __thousands_sep_ = base::do_thousands_sep();
6014 __grouping_ = lc->mon_grouping;
6017 const char* bb = lc->int_curr_symbol;
6018 size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
6019 if (j == size_t(-1))
6020 __throw_runtime_error("locale not supported");
6021 wchar_t* wbe = wbuf + j;
6022 __curr_symbol_.assign(wbuf, wbe);
6023 if (lc->int_frac_digits != CHAR_MAX)
6024 __frac_digits_ = lc->int_frac_digits;
6026 __frac_digits_ = base::do_frac_digits();
6027 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
6028 if (lc->p_sign_posn == 0)
6029 #else // _LIBCPP_MSVCRT
6030 if (lc->int_p_sign_posn == 0)
6031 #endif // !_LIBCPP_MSVCRT
6032 __positive_sign_ = L"()";
6036 bb = lc->positive_sign;
6037 j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
6038 if (j == size_t(-1))
6039 __throw_runtime_error("locale not supported");
6041 __positive_sign_.assign(wbuf, wbe);
6043 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
6044 if (lc->n_sign_posn == 0)
6045 #else // _LIBCPP_MSVCRT
6046 if (lc->int_n_sign_posn == 0)
6047 #endif // !_LIBCPP_MSVCRT
6048 __negative_sign_ = L"()";
6052 bb = lc->negative_sign;
6053 j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
6054 if (j == size_t(-1))
6055 __throw_runtime_error("locale not supported");
6057 __negative_sign_.assign(wbuf, wbe);
6059 // Assume the positive and negative formats will want spaces in
6060 // the same places in curr_symbol since there's no way to
6061 // represent anything else.
6062 string_type __dummy_curr_symbol = __curr_symbol_;
6063 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
6064 __init_pat(__pos_format_, __dummy_curr_symbol, true,
6065 lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
6066 __init_pat(__neg_format_, __curr_symbol_, true,
6067 lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
6068 #else // _LIBCPP_MSVCRT
6069 __init_pat(__pos_format_, __dummy_curr_symbol, true,
6070 lc->int_p_cs_precedes, lc->int_p_sep_by_space,
6071 lc->int_p_sign_posn, L' ');
6072 __init_pat(__neg_format_, __curr_symbol_, true,
6073 lc->int_n_cs_precedes, lc->int_n_sep_by_space,
6074 lc->int_n_sign_posn, L' ');
6075 #endif // !_LIBCPP_MSVCRT
6078 void __do_nothing(void*) {}
6080 void __throw_runtime_error(const char* msg)
6082 #ifndef _LIBCPP_NO_EXCEPTIONS
6083 throw runtime_error(msg);
6090 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<char>;
6091 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<wchar_t>;
6093 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<char>;
6094 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<wchar_t>;
6096 template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<char>;
6097 template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<wchar_t>;
6099 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<char>;
6100 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<wchar_t>;
6102 template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<char>;
6103 template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<wchar_t>;
6105 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<char>;
6106 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<wchar_t>;
6108 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<char>;
6109 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<wchar_t>;
6111 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<char>;
6112 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<wchar_t>;
6114 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<char>;
6115 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<wchar_t>;
6117 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, false>;
6118 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, true>;
6119 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, false>;
6120 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, true>;
6122 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, false>;
6123 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, true>;
6124 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, false>;
6125 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, true>;
6127 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<char>;
6128 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<wchar_t>;
6130 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<char>;
6131 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<wchar_t>;
6133 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<char>;
6134 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<wchar_t>;
6136 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<char>;
6137 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<wchar_t>;
6139 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<char>;
6140 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<wchar_t>;
6142 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<char>;
6143 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<wchar_t>;
6145 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char, char, mbstate_t>;
6146 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<wchar_t, char, mbstate_t>;
6147 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char16_t, char, mbstate_t>;
6148 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char32_t, char, mbstate_t>;
6150 template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __vector_base_common<true>;
6152 _LIBCPP_END_NAMESPACE_STD