Path: blob/main/system/lib/libcxx/src/locale.cpp
6175 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include <__utility/no_destroy.h>9#include <algorithm>10#include <clocale>11#include <codecvt>12#include <cstddef>13#include <cstdio>14#include <cstdlib>15#include <cstring>16#include <locale>17#include <new>18#include <string>19#include <type_traits>20#include <typeinfo>21#include <utility>22#include <vector>2324#if _LIBCPP_HAS_WIDE_CHARACTERS25# include <cwctype>26#endif2728#if defined(_AIX)29# include <sys/localedef.h> // for __lc_ctype_ptr30#endif3132#if defined(_LIBCPP_MSVCRT)33# define _CTYPE_DISABLE_MACROS34#endif3536#include "include/atomic_support.h"37#include "include/sso_allocator.h"3839// On Linux, wint_t and wchar_t have different signed-ness, and this causes40// lots of noise in the build log, but no bugs that I know of.41_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wsign-conversion")4243_LIBCPP_PUSH_MACROS44#include <__undef_macros>4546_LIBCPP_BEGIN_NAMESPACE_STD4748struct __libcpp_unique_locale {49__libcpp_unique_locale(const char* nm) : __loc_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm, 0)) {}5051~__libcpp_unique_locale() {52if (__loc_)53__locale::__freelocale(__loc_);54}5556explicit operator bool() const { return __loc_; }5758__locale::__locale_t& get() { return __loc_; }5960__locale::__locale_t __loc_;6162private:63__libcpp_unique_locale(__libcpp_unique_locale const&);64__libcpp_unique_locale& operator=(__libcpp_unique_locale const&);65};6667#ifdef __cloc_defined68__locale::__locale_t __cloc() {69// In theory this could create a race condition. In practice70// the race condition is non-fatal since it will just create71// a little resource leak. Better approach would be appreciated.72static __locale::__locale_t result = __locale::__newlocale(_LIBCPP_ALL_MASK, "C", 0);73return result;74}75#endif // __cloc_defined7677namespace {7879struct releaser {80void operator()(locale::facet* p) { p->__release_shared(); }81};8283template <class T, class... Args>84T& make(Args... args) {85alignas(T) static std::byte buf[sizeof(T)];86auto* obj = ::new (&buf) T(args...);87return *obj;88}8990template <typename T, size_t N>91inline constexpr size_t countof(const T (&)[N]) {92return N;93}9495template <typename T>96inline constexpr size_t countof(const T* const begin, const T* const end) {97return static_cast<size_t>(end - begin);98}99100string build_name(const string& other, const string& one, locale::category c) {101if (other == "*" || one == "*")102return "*";103if (c == locale::none || other == one)104return other;105106// FIXME: Handle the more complicated cases, such as when the locale has107// different names for different categories.108return "*";109}110111} // namespace112113const locale::category locale::none;114const locale::category locale::collate;115const locale::category locale::ctype;116const locale::category locale::monetary;117const locale::category locale::numeric;118const locale::category locale::time;119const locale::category locale::messages;120const locale::category locale::all;121122class _LIBCPP_HIDDEN locale::__imp : public facet {123enum { N = 30 };124vector<facet*, __sso_allocator<facet*, N> > facets_;125string name_;126127public:128explicit __imp(size_t refs = 0);129explicit __imp(const string& name, size_t refs = 0);130__imp(const __imp&);131__imp(const __imp&, const string&, locale::category c);132__imp(const __imp& other, const __imp& one, locale::category c);133__imp(const __imp&, facet* f, long id);134~__imp();135136const string& name() const { return name_; }137bool has_facet(long id) const { return static_cast<size_t>(id) < facets_.size() && facets_[static_cast<size_t>(id)]; }138const locale::facet* use_facet(long id) const;139140void acquire();141void release();142static __no_destroy<__imp> classic_locale_imp_;143144private:145void install(facet* f, long id);146template <class F>147void install(F* f) {148install(f, f->id.__get());149}150template <class F>151void install_from(const __imp& other);152};153154locale::__imp::__imp(size_t refs) : facet(refs), facets_(N), name_("C") {155facets_.clear();156install(&make<std::collate<char> >(1u));157#if _LIBCPP_HAS_WIDE_CHARACTERS158install(&make<std::collate<wchar_t> >(1u));159#endif160install(&make<std::ctype<char> >(nullptr, false, 1u));161#if _LIBCPP_HAS_WIDE_CHARACTERS162install(&make<std::ctype<wchar_t> >(1u));163#endif164install(&make<codecvt<char, char, mbstate_t> >(1u));165#if _LIBCPP_HAS_WIDE_CHARACTERS166install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));167#endif168_LIBCPP_SUPPRESS_DEPRECATED_PUSH169install(&make<codecvt<char16_t, char, mbstate_t> >(1u));170install(&make<codecvt<char32_t, char, mbstate_t> >(1u));171_LIBCPP_SUPPRESS_DEPRECATED_POP172#if _LIBCPP_HAS_CHAR8_T173install(&make<codecvt<char16_t, char8_t, mbstate_t> >(1u));174install(&make<codecvt<char32_t, char8_t, mbstate_t> >(1u));175#endif176install(&make<numpunct<char> >(1u));177#if _LIBCPP_HAS_WIDE_CHARACTERS178install(&make<numpunct<wchar_t> >(1u));179#endif180install(&make<num_get<char> >(1u));181#if _LIBCPP_HAS_WIDE_CHARACTERS182install(&make<num_get<wchar_t> >(1u));183#endif184install(&make<num_put<char> >(1u));185#if _LIBCPP_HAS_WIDE_CHARACTERS186install(&make<num_put<wchar_t> >(1u));187#endif188install(&make<moneypunct<char, false> >(1u));189install(&make<moneypunct<char, true> >(1u));190#if _LIBCPP_HAS_WIDE_CHARACTERS191install(&make<moneypunct<wchar_t, false> >(1u));192install(&make<moneypunct<wchar_t, true> >(1u));193#endif194install(&make<money_get<char> >(1u));195#if _LIBCPP_HAS_WIDE_CHARACTERS196install(&make<money_get<wchar_t> >(1u));197#endif198install(&make<money_put<char> >(1u));199#if _LIBCPP_HAS_WIDE_CHARACTERS200install(&make<money_put<wchar_t> >(1u));201#endif202install(&make<time_get<char> >(1u));203#if _LIBCPP_HAS_WIDE_CHARACTERS204install(&make<time_get<wchar_t> >(1u));205#endif206install(&make<time_put<char> >(1u));207#if _LIBCPP_HAS_WIDE_CHARACTERS208install(&make<time_put<wchar_t> >(1u));209#endif210install(&make<std::messages<char> >(1u));211#if _LIBCPP_HAS_WIDE_CHARACTERS212install(&make<std::messages<wchar_t> >(1u));213#endif214}215216locale::__imp::__imp(const string& name, size_t refs) : facet(refs), facets_(N), name_(name) {217#if _LIBCPP_HAS_EXCEPTIONS218try {219#endif // _LIBCPP_HAS_EXCEPTIONS220facets_ = locale::classic().__locale_->facets_;221for (unsigned i = 0; i < facets_.size(); ++i)222if (facets_[i])223facets_[i]->__add_shared();224install(new collate_byname<char>(name_));225#if _LIBCPP_HAS_WIDE_CHARACTERS226install(new collate_byname<wchar_t>(name_));227#endif228install(new ctype_byname<char>(name_));229#if _LIBCPP_HAS_WIDE_CHARACTERS230install(new ctype_byname<wchar_t>(name_));231#endif232install(new codecvt_byname<char, char, mbstate_t>(name_));233#if _LIBCPP_HAS_WIDE_CHARACTERS234install(new codecvt_byname<wchar_t, char, mbstate_t>(name_));235#endif236_LIBCPP_SUPPRESS_DEPRECATED_PUSH237install(new codecvt_byname<char16_t, char, mbstate_t>(name_));238install(new codecvt_byname<char32_t, char, mbstate_t>(name_));239_LIBCPP_SUPPRESS_DEPRECATED_POP240#if _LIBCPP_HAS_CHAR8_T241install(new codecvt_byname<char16_t, char8_t, mbstate_t>(name_));242install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name_));243#endif244install(new numpunct_byname<char>(name_));245#if _LIBCPP_HAS_WIDE_CHARACTERS246install(new numpunct_byname<wchar_t>(name_));247#endif248install(new moneypunct_byname<char, false>(name_));249install(new moneypunct_byname<char, true>(name_));250#if _LIBCPP_HAS_WIDE_CHARACTERS251install(new moneypunct_byname<wchar_t, false>(name_));252install(new moneypunct_byname<wchar_t, true>(name_));253#endif254install(new time_get_byname<char>(name_));255#if _LIBCPP_HAS_WIDE_CHARACTERS256install(new time_get_byname<wchar_t>(name_));257#endif258install(new time_put_byname<char>(name_));259#if _LIBCPP_HAS_WIDE_CHARACTERS260install(new time_put_byname<wchar_t>(name_));261#endif262install(new messages_byname<char>(name_));263#if _LIBCPP_HAS_WIDE_CHARACTERS264install(new messages_byname<wchar_t>(name_));265#endif266#if _LIBCPP_HAS_EXCEPTIONS267} catch (...) {268for (unsigned i = 0; i < facets_.size(); ++i)269if (facets_[i])270facets_[i]->__release_shared();271throw;272}273#endif // _LIBCPP_HAS_EXCEPTIONS274}275276locale::__imp::__imp(const __imp& other) : facets_(max<size_t>(N, other.facets_.size())), name_(other.name_) {277facets_ = other.facets_;278for (unsigned i = 0; i < facets_.size(); ++i)279if (facets_[i])280facets_[i]->__add_shared();281}282283locale::__imp::__imp(const __imp& other, const string& name, locale::category c)284: facets_(N), name_(build_name(other.name_, name, c)) {285facets_ = other.facets_;286for (unsigned i = 0; i < facets_.size(); ++i)287if (facets_[i])288facets_[i]->__add_shared();289#if _LIBCPP_HAS_EXCEPTIONS290try {291#endif // _LIBCPP_HAS_EXCEPTIONS292if (c & locale::collate) {293install(new collate_byname<char>(name));294#if _LIBCPP_HAS_WIDE_CHARACTERS295install(new collate_byname<wchar_t>(name));296#endif297}298if (c & locale::ctype) {299install(new ctype_byname<char>(name));300#if _LIBCPP_HAS_WIDE_CHARACTERS301install(new ctype_byname<wchar_t>(name));302#endif303install(new codecvt_byname<char, char, mbstate_t>(name));304#if _LIBCPP_HAS_WIDE_CHARACTERS305install(new codecvt_byname<wchar_t, char, mbstate_t>(name));306#endif307_LIBCPP_SUPPRESS_DEPRECATED_PUSH308install(new codecvt_byname<char16_t, char, mbstate_t>(name));309install(new codecvt_byname<char32_t, char, mbstate_t>(name));310_LIBCPP_SUPPRESS_DEPRECATED_POP311#if _LIBCPP_HAS_CHAR8_T312install(new codecvt_byname<char16_t, char8_t, mbstate_t>(name));313install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name));314#endif315}316if (c & locale::monetary) {317install(new moneypunct_byname<char, false>(name));318install(new moneypunct_byname<char, true>(name));319#if _LIBCPP_HAS_WIDE_CHARACTERS320install(new moneypunct_byname<wchar_t, false>(name));321install(new moneypunct_byname<wchar_t, true>(name));322#endif323}324if (c & locale::numeric) {325install(new numpunct_byname<char>(name));326#if _LIBCPP_HAS_WIDE_CHARACTERS327install(new numpunct_byname<wchar_t>(name));328#endif329}330if (c & locale::time) {331install(new time_get_byname<char>(name));332#if _LIBCPP_HAS_WIDE_CHARACTERS333install(new time_get_byname<wchar_t>(name));334#endif335install(new time_put_byname<char>(name));336#if _LIBCPP_HAS_WIDE_CHARACTERS337install(new time_put_byname<wchar_t>(name));338#endif339}340if (c & locale::messages) {341install(new messages_byname<char>(name));342#if _LIBCPP_HAS_WIDE_CHARACTERS343install(new messages_byname<wchar_t>(name));344#endif345}346#if _LIBCPP_HAS_EXCEPTIONS347} catch (...) {348for (unsigned i = 0; i < facets_.size(); ++i)349if (facets_[i])350facets_[i]->__release_shared();351throw;352}353#endif // _LIBCPP_HAS_EXCEPTIONS354}355356template <class F>357inline void locale::__imp::install_from(const locale::__imp& one) {358long id = F::id.__get();359install(const_cast<F*>(static_cast<const F*>(one.use_facet(id))), id);360}361362locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)363: facets_(N), name_(build_name(other.name_, one.name_, c)) {364facets_ = other.facets_;365for (unsigned i = 0; i < facets_.size(); ++i)366if (facets_[i])367facets_[i]->__add_shared();368#if _LIBCPP_HAS_EXCEPTIONS369try {370#endif // _LIBCPP_HAS_EXCEPTIONS371if (c & locale::collate) {372install_from<std::collate<char> >(one);373#if _LIBCPP_HAS_WIDE_CHARACTERS374install_from<std::collate<wchar_t> >(one);375#endif376}377if (c & locale::ctype) {378install_from<std::ctype<char> >(one);379#if _LIBCPP_HAS_WIDE_CHARACTERS380install_from<std::ctype<wchar_t> >(one);381#endif382install_from<std::codecvt<char, char, mbstate_t> >(one);383_LIBCPP_SUPPRESS_DEPRECATED_PUSH384install_from<std::codecvt<char16_t, char, mbstate_t> >(one);385install_from<std::codecvt<char32_t, char, mbstate_t> >(one);386_LIBCPP_SUPPRESS_DEPRECATED_POP387#if _LIBCPP_HAS_CHAR8_T388install_from<std::codecvt<char16_t, char8_t, mbstate_t> >(one);389install_from<std::codecvt<char32_t, char8_t, mbstate_t> >(one);390#endif391#if _LIBCPP_HAS_WIDE_CHARACTERS392install_from<std::codecvt<wchar_t, char, mbstate_t> >(one);393#endif394}395if (c & locale::monetary) {396install_from<moneypunct<char, false> >(one);397install_from<moneypunct<char, true> >(one);398#if _LIBCPP_HAS_WIDE_CHARACTERS399install_from<moneypunct<wchar_t, false> >(one);400install_from<moneypunct<wchar_t, true> >(one);401#endif402install_from<money_get<char> >(one);403#if _LIBCPP_HAS_WIDE_CHARACTERS404install_from<money_get<wchar_t> >(one);405#endif406install_from<money_put<char> >(one);407#if _LIBCPP_HAS_WIDE_CHARACTERS408install_from<money_put<wchar_t> >(one);409#endif410}411if (c & locale::numeric) {412install_from<numpunct<char> >(one);413#if _LIBCPP_HAS_WIDE_CHARACTERS414install_from<numpunct<wchar_t> >(one);415#endif416install_from<num_get<char> >(one);417#if _LIBCPP_HAS_WIDE_CHARACTERS418install_from<num_get<wchar_t> >(one);419#endif420install_from<num_put<char> >(one);421#if _LIBCPP_HAS_WIDE_CHARACTERS422install_from<num_put<wchar_t> >(one);423#endif424}425if (c & locale::time) {426install_from<time_get<char> >(one);427#if _LIBCPP_HAS_WIDE_CHARACTERS428install_from<time_get<wchar_t> >(one);429#endif430install_from<time_put<char> >(one);431#if _LIBCPP_HAS_WIDE_CHARACTERS432install_from<time_put<wchar_t> >(one);433#endif434}435if (c & locale::messages) {436install_from<std::messages<char> >(one);437#if _LIBCPP_HAS_WIDE_CHARACTERS438install_from<std::messages<wchar_t> >(one);439#endif440}441#if _LIBCPP_HAS_EXCEPTIONS442} catch (...) {443for (unsigned i = 0; i < facets_.size(); ++i)444if (facets_[i])445facets_[i]->__release_shared();446throw;447}448#endif // _LIBCPP_HAS_EXCEPTIONS449}450451locale::__imp::__imp(const __imp& other, facet* f, long id)452: facets_(max<size_t>(N, other.facets_.size() + 1)), name_("*") {453f->__add_shared();454unique_ptr<facet, releaser> hold(f);455facets_ = other.facets_;456for (unsigned i = 0; i < other.facets_.size(); ++i)457if (facets_[i])458facets_[i]->__add_shared();459install(hold.get(), id);460}461462locale::__imp::~__imp() {463for (unsigned i = 0; i < facets_.size(); ++i)464if (facets_[i])465facets_[i]->__release_shared();466}467468void locale::__imp::install(facet* f, long id) {469f->__add_shared();470unique_ptr<facet, releaser> hold(f);471if (static_cast<size_t>(id) >= facets_.size())472facets_.resize(static_cast<size_t>(id + 1));473if (facets_[static_cast<size_t>(id)])474facets_[static_cast<size_t>(id)]->__release_shared();475facets_[static_cast<size_t>(id)] = hold.release();476}477478const locale::facet* locale::__imp::use_facet(long id) const {479if (!has_facet(id))480std::__throw_bad_cast();481return facets_[static_cast<size_t>(id)];482}483484// locale485486// We don't do reference counting on the classic locale.487// It's never destroyed anyway, but atomic reference counting may be very488// expensive in parallel applications. The classic locale is used by default489// in all streams. Note: if a new global locale is installed, then we lose490// the benefit of no reference counting.491constinit __no_destroy<locale::__imp>492locale::__imp::classic_locale_imp_(__uninitialized_tag{}); // initialized below in classic()493494const locale& locale::classic() {495static const __no_destroy<locale> classic_locale(__private_constructor_tag{}, [] {496// executed exactly once on first initialization of `classic_locale`497locale::__imp::classic_locale_imp_.__emplace(1u);498return &locale::__imp::classic_locale_imp_.__get();499}());500return classic_locale.__get();501}502503locale& locale::__global() {504static __no_destroy<locale> g(locale::classic());505return g.__get();506}507508void locale::__imp::acquire() {509if (this != &locale::__imp::classic_locale_imp_.__get())510__add_shared();511}512513void locale::__imp::release() {514if (this != &locale::__imp::classic_locale_imp_.__get())515__release_shared();516}517518locale::locale() noexcept : __locale_(__global().__locale_) { __locale_->acquire(); }519520locale::locale(const locale& l) noexcept : __locale_(l.__locale_) { __locale_->acquire(); }521522locale::~locale() { __locale_->release(); }523524const locale& locale::operator=(const locale& other) noexcept {525other.__locale_->acquire();526__locale_->release();527__locale_ = other.__locale_;528return *this;529}530531locale::locale(const char* name)532: __locale_(name ? new __imp(name) : (__throw_runtime_error("locale constructed with null"), nullptr)) {533__locale_->acquire();534}535536locale::locale(const string& name) : __locale_(new __imp(name)) { __locale_->acquire(); }537538locale::locale(const locale& other, const char* name, category c)539: __locale_(name ? new __imp(*other.__locale_, name, c)540: (__throw_runtime_error("locale constructed with null"), nullptr)) {541__locale_->acquire();542}543544locale::locale(const locale& other, const string& name, category c) : __locale_(new __imp(*other.__locale_, name, c)) {545__locale_->acquire();546}547548locale::locale(const locale& other, const locale& one, category c)549: __locale_(new __imp(*other.__locale_, *one.__locale_, c)) {550__locale_->acquire();551}552553string locale::name() const { return __locale_->name(); }554555void locale::__install_ctor(const locale& other, facet* f, long facet_id) {556if (f)557__locale_ = new __imp(*other.__locale_, f, facet_id);558else559__locale_ = other.__locale_;560__locale_->acquire();561}562563locale locale::global(const locale& loc) {564locale& g = __global();565locale r = g;566g = loc;567if (g.name() != "*")568__locale::__setlocale(_LIBCPP_LC_ALL, g.name().c_str());569return r;570}571572bool locale::has_facet(id& x) const { return __locale_->has_facet(x.__get()); }573574const locale::facet* locale::use_facet(id& x) const { return __locale_->use_facet(x.__get()); }575576bool locale::operator==(const locale& y) const {577return (__locale_ == y.__locale_) || (__locale_->name() != "*" && __locale_->name() == y.__locale_->name());578}579580// locale::facet581582locale::facet::~facet() {}583584void locale::facet::__on_zero_shared() noexcept { delete this; }585586// locale::id587588constinit int32_t locale::id::__next_id = 0;589590long locale::id::__get() {591call_once(__flag_, [&] { __id_ = __libcpp_atomic_add(&__next_id, 1); });592return __id_ - 1;593}594595// template <> class collate_byname<char>596597collate_byname<char>::collate_byname(const char* n, size_t refs)598: collate<char>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, n, 0)) {599if (__l_ == 0)600std::__throw_runtime_error(601("collate_byname<char>::collate_byname"602" failed to construct for " +603string(n))604.c_str());605}606607collate_byname<char>::collate_byname(const string& name, size_t refs)608: collate<char>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name.c_str(), 0)) {609if (__l_ == 0)610std::__throw_runtime_error(611("collate_byname<char>::collate_byname"612" failed to construct for " +613name)614.c_str());615}616617collate_byname<char>::~collate_byname() { __locale::__freelocale(__l_); }618619int collate_byname<char>::do_compare(620const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const {621string_type lhs(__lo1, __hi1);622string_type rhs(__lo2, __hi2);623int r = __locale::__strcoll(lhs.c_str(), rhs.c_str(), __l_);624if (r < 0)625return -1;626if (r > 0)627return 1;628return r;629}630631collate_byname<char>::string_type collate_byname<char>::do_transform(const char_type* lo, const char_type* hi) const {632const string_type in(lo, hi);633string_type out(__locale::__strxfrm(0, in.c_str(), 0, __l_), char());634__locale::__strxfrm(const_cast<char*>(out.c_str()), in.c_str(), out.size() + 1, __l_);635return out;636}637638// template <> class collate_byname<wchar_t>639640#if _LIBCPP_HAS_WIDE_CHARACTERS641collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)642: collate<wchar_t>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, n, 0)) {643if (__l_ == 0)644std::__throw_runtime_error(645("collate_byname<wchar_t>::collate_byname(size_t refs)"646" failed to construct for " +647string(n))648.c_str());649}650651collate_byname<wchar_t>::collate_byname(const string& name, size_t refs)652: collate<wchar_t>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name.c_str(), 0)) {653if (__l_ == 0)654std::__throw_runtime_error(655("collate_byname<wchar_t>::collate_byname(size_t refs)"656" failed to construct for " +657name)658.c_str());659}660661collate_byname<wchar_t>::~collate_byname() { __locale::__freelocale(__l_); }662663int collate_byname<wchar_t>::do_compare(664const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const {665string_type lhs(__lo1, __hi1);666string_type rhs(__lo2, __hi2);667int r = __locale::__wcscoll(lhs.c_str(), rhs.c_str(), __l_);668if (r < 0)669return -1;670if (r > 0)671return 1;672return r;673}674675collate_byname<wchar_t>::string_type676collate_byname<wchar_t>::do_transform(const char_type* lo, const char_type* hi) const {677const string_type in(lo, hi);678string_type out(__locale::__wcsxfrm(0, in.c_str(), 0, __l_), wchar_t());679__locale::__wcsxfrm(const_cast<wchar_t*>(out.c_str()), in.c_str(), out.size() + 1, __l_);680return out;681}682#endif // _LIBCPP_HAS_WIDE_CHARACTERS683684const ctype_base::mask ctype_base::space;685const ctype_base::mask ctype_base::print;686const ctype_base::mask ctype_base::cntrl;687const ctype_base::mask ctype_base::upper;688const ctype_base::mask ctype_base::lower;689const ctype_base::mask ctype_base::alpha;690const ctype_base::mask ctype_base::digit;691const ctype_base::mask ctype_base::punct;692const ctype_base::mask ctype_base::xdigit;693const ctype_base::mask ctype_base::blank;694const ctype_base::mask ctype_base::alnum;695const ctype_base::mask ctype_base::graph;696697// template <> class ctype<wchar_t>;698699template <class CharT>700static CharT to_upper_impl(CharT c) {701if (c < 'a' || c > 'z')702return c;703return c & ~0x20;704}705706template <class CharT>707static CharT to_lower_impl(CharT c) {708if (c < 'A' || c > 'Z')709return c;710return c | 0x20;711}712713#if _LIBCPP_HAS_WIDE_CHARACTERS714constinit locale::id ctype<wchar_t>::id;715716ctype<wchar_t>::~ctype() {}717718bool ctype<wchar_t>::do_is(mask m, char_type c) const {719return std::__libcpp_isascii(c) ? (ctype<char>::classic_table()[c] & m) != 0 : false;720}721722const wchar_t* ctype<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const {723for (; low != high; ++low, ++vec)724*vec = static_cast<mask>(std::__libcpp_isascii(*low) ? ctype<char>::classic_table()[*low] : 0);725return low;726}727728const wchar_t* ctype<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const {729for (; low != high; ++low)730if (std::__libcpp_isascii(*low) && (ctype<char>::classic_table()[*low] & m))731break;732return low;733}734735const wchar_t* ctype<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const {736for (; low != high; ++low)737if (!(std::__libcpp_isascii(*low) && (ctype<char>::classic_table()[*low] & m)))738break;739return low;740}741742wchar_t ctype<wchar_t>::do_toupper(char_type c) const { return to_upper_impl(c); }743744const wchar_t* ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const {745for (; low != high; ++low)746*low = to_upper_impl(*low);747return low;748}749750wchar_t ctype<wchar_t>::do_tolower(char_type c) const { return to_lower_impl(c); }751752const wchar_t* ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const {753for (; low != high; ++low)754*low = to_lower_impl(*low);755return low;756}757758wchar_t ctype<wchar_t>::do_widen(char c) const { return c; }759760const char* ctype<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const {761for (; low != high; ++low, ++dest)762*dest = *low;763return low;764}765766char ctype<wchar_t>::do_narrow(char_type c, char dfault) const {767if (std::__libcpp_isascii(c))768return static_cast<char>(c);769return dfault;770}771772const wchar_t* ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const {773for (; low != high; ++low, ++dest)774if (std::__libcpp_isascii(*low))775*dest = static_cast<char>(*low);776else777*dest = dfault;778return low;779}780#endif // _LIBCPP_HAS_WIDE_CHARACTERS781782// template <> class ctype<char>;783784constinit locale::id ctype<char>::id;785786const size_t ctype<char>::table_size;787788ctype<char>::ctype(const mask* tab, bool del, size_t refs) : locale::facet(refs), __tab_(tab), __del_(del) {789if (__tab_ == 0)790__tab_ = classic_table();791}792793ctype<char>::~ctype() {794if (__tab_ && __del_)795delete[] __tab_;796}797798char ctype<char>::do_toupper(char_type c) const { return to_upper_impl(c); }799800const char* ctype<char>::do_toupper(char_type* low, const char_type* high) const {801for (; low != high; ++low)802*low = to_upper_impl(*low);803return low;804}805806char ctype<char>::do_tolower(char_type c) const { return to_lower_impl(c); }807808const char* ctype<char>::do_tolower(char_type* low, const char_type* high) const {809for (; low != high; ++low)810*low = to_lower_impl(*low);811return low;812}813814char ctype<char>::do_widen(char c) const { return c; }815816const char* ctype<char>::do_widen(const char* low, const char* high, char_type* dest) const {817for (; low != high; ++low, ++dest)818*dest = *low;819return low;820}821822char ctype<char>::do_narrow(char_type c, char dfault) const {823if (std::__libcpp_isascii(c))824return static_cast<char>(c);825return dfault;826}827828const char* ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const {829for (; low != high; ++low, ++dest)830if (std::__libcpp_isascii(*low))831*dest = *low;832else833*dest = dfault;834return low;835}836837#if defined(__EMSCRIPTEN__)838extern "C" const unsigned short** __ctype_b_loc();839extern "C" const int** __ctype_tolower_loc();840extern "C" const int** __ctype_toupper_loc();841#endif842843#ifdef _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE844const ctype<char>::mask* ctype<char>::classic_table() noexcept {845// clang-format off846static constexpr const ctype<char>::mask builtin_table[table_size] = {847cntrl, cntrl,848cntrl, cntrl,849cntrl, cntrl,850cntrl, cntrl,851cntrl, cntrl | space | blank,852cntrl | space, cntrl | space,853cntrl | space, cntrl | space,854cntrl, cntrl,855cntrl, cntrl,856cntrl, cntrl,857cntrl, cntrl,858cntrl, cntrl,859cntrl, cntrl,860cntrl, cntrl,861cntrl, cntrl,862cntrl, cntrl,863space | blank | print, punct | print,864punct | print, punct | print,865punct | print, punct | print,866punct | print, punct | print,867punct | print, punct | print,868punct | print, punct | print,869punct | print, punct | print,870punct | print, punct | print,871digit | print | xdigit, digit | print | xdigit,872digit | print | xdigit, digit | print | xdigit,873digit | print | xdigit, digit | print | xdigit,874digit | print | xdigit, digit | print | xdigit,875digit | print | xdigit, digit | print | xdigit,876punct | print, punct | print,877punct | print, punct | print,878punct | print, punct | print,879punct | print, upper | xdigit | print | alpha,880upper | xdigit | print | alpha, upper | xdigit | print | alpha,881upper | xdigit | print | alpha, upper | xdigit | print | alpha,882upper | xdigit | print | alpha, upper | print | alpha,883upper | print | alpha, upper | print | alpha,884upper | print | alpha, upper | print | alpha,885upper | print | alpha, upper | print | alpha,886upper | print | alpha, upper | print | alpha,887upper | print | alpha, upper | print | alpha,888upper | print | alpha, upper | print | alpha,889upper | print | alpha, upper | print | alpha,890upper | print | alpha, upper | print | alpha,891upper | print | alpha, upper | print | alpha,892upper | print | alpha, punct | print,893punct | print, punct | print,894punct | print, punct | print,895punct | print, lower | xdigit | print | alpha,896lower | xdigit | print | alpha, lower | xdigit | print | alpha,897lower | xdigit | print | alpha, lower | xdigit | print | alpha,898lower | xdigit | print | alpha, lower | print | alpha,899lower | print | alpha, lower | print | alpha,900lower | print | alpha, lower | print | alpha,901lower | print | alpha, lower | print | alpha,902lower | print | alpha, lower | print | alpha,903lower | print | alpha, lower | print | alpha,904lower | print | alpha, lower | print | alpha,905lower | print | alpha, lower | print | alpha,906lower | print | alpha, lower | print | alpha,907lower | print | alpha, lower | print | alpha,908lower | print | alpha, punct | print,909punct | print, punct | print,910punct | print, cntrl,9110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,9120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,9130, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,9140, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,9150, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,9160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,9170, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,9180, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0919};920// clang-format on921return builtin_table;922}923#else924const ctype<char>::mask* ctype<char>::classic_table() noexcept {925# if defined(__APPLE__) || defined(__FreeBSD__)926return _DefaultRuneLocale.__runetype;927# elif defined(__NetBSD__)928return _C_ctype_tab_ + 1;929# elif defined(__GLIBC__)930return _LIBCPP_GET_C_LOCALE->__ctype_b;931# elif defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)932return __pctype_func();933# elif defined(__EMSCRIPTEN__)934return *__ctype_b_loc();935# elif defined(_NEWLIB_VERSION)936// Newlib has a 257-entry table in ctype_.c, where (char)0 starts at [1].937return _ctype_ + 1;938# elif defined(_AIX)939return (const unsigned int*)__lc_ctype_ptr->obj->mask;940# elif defined(__MVS__)941# if defined(__NATIVE_ASCII_F)942return const_cast<const ctype<char>::mask*>(__OBJ_DATA(__lc_ctype_a)->mask);943# else944return const_cast<const ctype<char>::mask*>(__ctypec);945# endif946# else947// Platform not supported: abort so the person doing the port knows what to948// fix949# warning ctype<char>::classic_table() is not implemented950printf("ctype<char>::classic_table() is not implemented\n");951abort();952return nullptr;953# endif954}955#endif956957// template <> class ctype_byname<char>958959ctype_byname<char>::ctype_byname(const char* name, size_t refs)960: ctype<char>(0, false, refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name, 0)) {961if (__l_ == 0)962std::__throw_runtime_error(963("ctype_byname<char>::ctype_byname"964" failed to construct for " +965string(name))966.c_str());967}968969ctype_byname<char>::ctype_byname(const string& name, size_t refs)970: ctype<char>(0, false, refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name.c_str(), 0)) {971if (__l_ == 0)972std::__throw_runtime_error(973("ctype_byname<char>::ctype_byname"974" failed to construct for " +975name)976.c_str());977}978979ctype_byname<char>::~ctype_byname() { __locale::__freelocale(__l_); }980981char ctype_byname<char>::do_toupper(char_type c) const {982return static_cast<char>(__locale::__toupper(static_cast<unsigned char>(c), __l_));983}984985const char* ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const {986for (; low != high; ++low)987*low = static_cast<char>(__locale::__toupper(static_cast<unsigned char>(*low), __l_));988return low;989}990991char ctype_byname<char>::do_tolower(char_type c) const {992return static_cast<char>(__locale::__tolower(static_cast<unsigned char>(c), __l_));993}994995const char* ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const {996for (; low != high; ++low)997*low = static_cast<char>(__locale::__tolower(static_cast<unsigned char>(*low), __l_));998return low;999}10001001// template <> class ctype_byname<wchar_t>10021003#if _LIBCPP_HAS_WIDE_CHARACTERS1004ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)1005: ctype<wchar_t>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name, 0)) {1006if (__l_ == 0)1007std::__throw_runtime_error(1008("ctype_byname<wchar_t>::ctype_byname"1009" failed to construct for " +1010string(name))1011.c_str());1012}10131014ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)1015: ctype<wchar_t>(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, name.c_str(), 0)) {1016if (__l_ == 0)1017std::__throw_runtime_error(1018("ctype_byname<wchar_t>::ctype_byname"1019" failed to construct for " +1020name)1021.c_str());1022}10231024ctype_byname<wchar_t>::~ctype_byname() { __locale::__freelocale(__l_); }10251026bool ctype_byname<wchar_t>::do_is(mask m, char_type c) const {1027wint_t ch = static_cast<wint_t>(c);1028# ifdef _LIBCPP_WCTYPE_IS_MASK1029return static_cast<bool>(__locale::__iswctype(ch, m, __l_));1030# else1031bool result = false;1032if ((m & space) == space)1033result |= (__locale::__iswspace(ch, __l_) != 0);1034if ((m & print) == print)1035result |= (__locale::__iswprint(ch, __l_) != 0);1036if ((m & cntrl) == cntrl)1037result |= (__locale::__iswcntrl(ch, __l_) != 0);1038if ((m & upper) == upper)1039result |= (__locale::__iswupper(ch, __l_) != 0);1040if ((m & lower) == lower)1041result |= (__locale::__iswlower(ch, __l_) != 0);1042if ((m & alpha) == alpha)1043result |= (__locale::__iswalpha(ch, __l_) != 0);1044if ((m & digit) == digit)1045result |= (__locale::__iswdigit(ch, __l_) != 0);1046if ((m & punct) == punct)1047result |= (__locale::__iswpunct(ch, __l_) != 0);1048if ((m & xdigit) == xdigit)1049result |= (__locale::__iswxdigit(ch, __l_) != 0);1050if ((m & blank) == blank)1051result |= (__locale::__iswblank(ch, __l_) != 0);1052return result;1053# endif1054}10551056const wchar_t* ctype_byname<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const {1057for (; low != high; ++low, ++vec) {1058if (std::__libcpp_isascii(*low))1059*vec = static_cast<mask>(ctype<char>::classic_table()[*low]);1060else {1061*vec = 0;1062wint_t ch = static_cast<wint_t>(*low);1063if (__locale::__iswspace(ch, __l_))1064*vec |= space;1065# ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT1066if (__locale::__iswprint(ch, __l_))1067*vec |= print;1068# endif1069if (__locale::__iswcntrl(ch, __l_))1070*vec |= cntrl;1071if (__locale::__iswupper(ch, __l_))1072*vec |= upper;1073if (__locale::__iswlower(ch, __l_))1074*vec |= lower;1075# ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA1076if (__locale::__iswalpha(ch, __l_))1077*vec |= alpha;1078# endif1079if (__locale::__iswdigit(ch, __l_))1080*vec |= digit;1081if (__locale::__iswpunct(ch, __l_))1082*vec |= punct;1083# ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT1084if (__locale::__iswxdigit(ch, __l_))1085*vec |= xdigit;1086# endif1087if (__locale::__iswblank(ch, __l_))1088*vec |= blank;1089}1090}1091return low;1092}10931094const wchar_t* ctype_byname<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const {1095for (; low != high; ++low) {1096# ifdef _LIBCPP_WCTYPE_IS_MASK1097if (__locale::__iswctype(static_cast<wint_t>(*low), m, __l_))1098break;1099# else1100wint_t ch = static_cast<wint_t>(*low);1101if ((m & space) == space && __locale::__iswspace(ch, __l_))1102break;1103if ((m & print) == print && __locale::__iswprint(ch, __l_))1104break;1105if ((m & cntrl) == cntrl && __locale::__iswcntrl(ch, __l_))1106break;1107if ((m & upper) == upper && __locale::__iswupper(ch, __l_))1108break;1109if ((m & lower) == lower && __locale::__iswlower(ch, __l_))1110break;1111if ((m & alpha) == alpha && __locale::__iswalpha(ch, __l_))1112break;1113if ((m & digit) == digit && __locale::__iswdigit(ch, __l_))1114break;1115if ((m & punct) == punct && __locale::__iswpunct(ch, __l_))1116break;1117if ((m & xdigit) == xdigit && __locale::__iswxdigit(ch, __l_))1118break;1119if ((m & blank) == blank && __locale::__iswblank(ch, __l_))1120break;1121# endif1122}1123return low;1124}11251126const wchar_t* ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const {1127for (; low != high; ++low) {1128wint_t ch = static_cast<wint_t>(*low);1129# ifdef _LIBCPP_WCTYPE_IS_MASK1130if (!__locale::__iswctype(ch, m, __l_))1131break;1132# else1133if ((m & space) == space && __locale::__iswspace(ch, __l_))1134continue;1135if ((m & print) == print && __locale::__iswprint(ch, __l_))1136continue;1137if ((m & cntrl) == cntrl && __locale::__iswcntrl(ch, __l_))1138continue;1139if ((m & upper) == upper && __locale::__iswupper(ch, __l_))1140continue;1141if ((m & lower) == lower && __locale::__iswlower(ch, __l_))1142continue;1143if ((m & alpha) == alpha && __locale::__iswalpha(ch, __l_))1144continue;1145if ((m & digit) == digit && __locale::__iswdigit(ch, __l_))1146continue;1147if ((m & punct) == punct && __locale::__iswpunct(ch, __l_))1148continue;1149if ((m & xdigit) == xdigit && __locale::__iswxdigit(ch, __l_))1150continue;1151if ((m & blank) == blank && __locale::__iswblank(ch, __l_))1152continue;1153break;1154# endif1155}1156return low;1157}11581159wchar_t ctype_byname<wchar_t>::do_toupper(char_type c) const { return __locale::__towupper(c, __l_); }11601161const wchar_t* ctype_byname<wchar_t>::do_toupper(char_type* low, const char_type* high) const {1162for (; low != high; ++low)1163*low = __locale::__towupper(*low, __l_);1164return low;1165}11661167wchar_t ctype_byname<wchar_t>::do_tolower(char_type c) const { return __locale::__towlower(c, __l_); }11681169const wchar_t* ctype_byname<wchar_t>::do_tolower(char_type* low, const char_type* high) const {1170for (; low != high; ++low)1171*low = __locale::__towlower(*low, __l_);1172return low;1173}11741175wchar_t ctype_byname<wchar_t>::do_widen(char c) const { return __locale::__btowc(c, __l_); }11761177const char* ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const {1178for (; low != high; ++low, ++dest)1179*dest = __locale::__btowc(*low, __l_);1180return low;1181}11821183char ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const {1184int r = __locale::__wctob(c, __l_);1185return (r != EOF) ? static_cast<char>(r) : dfault;1186}11871188const wchar_t*1189ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const {1190for (; low != high; ++low, ++dest) {1191int r = __locale::__wctob(*low, __l_);1192*dest = (r != EOF) ? static_cast<char>(r) : dfault;1193}1194return low;1195}1196#endif // _LIBCPP_HAS_WIDE_CHARACTERS11971198// template <> class codecvt<char, char, mbstate_t>11991200constinit locale::id codecvt<char, char, mbstate_t>::id;12011202codecvt<char, char, mbstate_t>::~codecvt() {}12031204codecvt<char, char, mbstate_t>::result codecvt<char, char, mbstate_t>::do_out(1205state_type&,1206const intern_type* frm,1207const intern_type*,1208const intern_type*& frm_nxt,1209extern_type* to,1210extern_type*,1211extern_type*& to_nxt) const {1212frm_nxt = frm;1213to_nxt = to;1214return noconv;1215}12161217codecvt<char, char, mbstate_t>::result codecvt<char, char, mbstate_t>::do_in(1218state_type&,1219const extern_type* frm,1220const extern_type*,1221const extern_type*& frm_nxt,1222intern_type* to,1223intern_type*,1224intern_type*& to_nxt) const {1225frm_nxt = frm;1226to_nxt = to;1227return noconv;1228}12291230codecvt<char, char, mbstate_t>::result1231codecvt<char, char, mbstate_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {1232to_nxt = to;1233return noconv;1234}12351236int codecvt<char, char, mbstate_t>::do_encoding() const noexcept { return 1; }12371238bool codecvt<char, char, mbstate_t>::do_always_noconv() const noexcept { return true; }12391240int codecvt<char, char, mbstate_t>::do_length(1241state_type&, const extern_type* frm, const extern_type* end, size_t mx) const {1242return static_cast<int>(min<size_t>(mx, static_cast<size_t>(end - frm)));1243}12441245int codecvt<char, char, mbstate_t>::do_max_length() const noexcept { return 1; }12461247// template <> class codecvt<wchar_t, char, mbstate_t>12481249#if _LIBCPP_HAS_WIDE_CHARACTERS1250constinit locale::id codecvt<wchar_t, char, mbstate_t>::id;12511252codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs) : locale::facet(refs), __l_(_LIBCPP_GET_C_LOCALE) {}12531254codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs)1255: locale::facet(refs), __l_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm, 0)) {1256if (__l_ == 0)1257std::__throw_runtime_error(1258("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname"1259" failed to construct for " +1260string(nm))1261.c_str());1262}12631264codecvt<wchar_t, char, mbstate_t>::~codecvt() {1265if (__l_ != _LIBCPP_GET_C_LOCALE)1266__locale::__freelocale(__l_);1267}12681269codecvt<wchar_t, char, mbstate_t>::result codecvt<wchar_t, char, mbstate_t>::do_out(1270state_type& st,1271const intern_type* frm,1272const intern_type* frm_end,1273const intern_type*& frm_nxt,1274extern_type* to,1275extern_type* to_end,1276extern_type*& to_nxt) const {1277// look for first internal null in frm1278const intern_type* fend = frm;1279for (; fend != frm_end; ++fend)1280if (*fend == 0)1281break;1282// loop over all null-terminated sequences in frm1283to_nxt = to;1284for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt) {1285// save state in case it is needed to recover to_nxt on error1286mbstate_t save_state = st;1287size_t n = __locale::__wcsnrtombs(1288to, &frm_nxt, static_cast<size_t>(fend - frm), static_cast<size_t>(to_end - to), &st, __l_);1289if (n == size_t(-1)) {1290// need to recover to_nxt1291for (to_nxt = to; frm != frm_nxt; ++frm) {1292n = __locale::__wcrtomb(to_nxt, *frm, &save_state, __l_);1293if (n == size_t(-1))1294break;1295to_nxt += n;1296}1297frm_nxt = frm;1298return error;1299}1300if (n == 0)1301return partial;1302to_nxt += n;1303if (to_nxt == to_end)1304break;1305if (fend != frm_end) // set up next null terminated sequence1306{1307// Try to write the terminating null1308extern_type tmp[MB_LEN_MAX];1309n = __locale::__wcrtomb(tmp, intern_type(), &st, __l_);1310if (n == size_t(-1)) // on error1311return error;1312if (n > static_cast<size_t>(to_end - to_nxt)) // is there room?1313return partial;1314for (extern_type* p = tmp; n; --n) // write it1315*to_nxt++ = *p++;1316++frm_nxt;1317// look for next null in frm1318for (fend = frm_nxt; fend != frm_end; ++fend)1319if (*fend == 0)1320break;1321}1322}1323return frm_nxt == frm_end ? ok : partial;1324}13251326codecvt<wchar_t, char, mbstate_t>::result codecvt<wchar_t, char, mbstate_t>::do_in(1327state_type& st,1328const extern_type* frm,1329const extern_type* frm_end,1330const extern_type*& frm_nxt,1331intern_type* to,1332intern_type* to_end,1333intern_type*& to_nxt) const {1334// look for first internal null in frm1335const extern_type* fend = frm;1336for (; fend != frm_end; ++fend)1337if (*fend == 0)1338break;1339// loop over all null-terminated sequences in frm1340to_nxt = to;1341for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt) {1342// save state in case it is needed to recover to_nxt on error1343mbstate_t save_state = st;1344size_t n = __locale::__mbsnrtowcs(1345to, &frm_nxt, static_cast<size_t>(fend - frm), static_cast<size_t>(to_end - to), &st, __l_);1346if (n == size_t(-1)) {1347// need to recover to_nxt1348for (to_nxt = to; frm != frm_nxt; ++to_nxt) {1349n = __locale::__mbrtowc(to_nxt, frm, static_cast<size_t>(fend - frm), &save_state, __l_);1350switch (n) {1351case 0:1352++frm;1353break;1354case size_t(-1):1355frm_nxt = frm;1356return error;1357case size_t(-2):1358frm_nxt = frm;1359return partial;1360default:1361frm += n;1362break;1363}1364}1365frm_nxt = frm;1366return frm_nxt == frm_end ? ok : partial;1367}1368if (n == size_t(-1))1369return error;1370to_nxt += n;1371if (to_nxt == to_end)1372break;1373if (fend != frm_end) // set up next null terminated sequence1374{1375// Try to write the terminating null1376n = __locale::__mbrtowc(to_nxt, frm_nxt, 1, &st, __l_);1377if (n != 0) // on error1378return error;1379++to_nxt;1380++frm_nxt;1381// look for next null in frm1382for (fend = frm_nxt; fend != frm_end; ++fend)1383if (*fend == 0)1384break;1385}1386}1387return frm_nxt == frm_end ? ok : partial;1388}13891390codecvt<wchar_t, char, mbstate_t>::result codecvt<wchar_t, char, mbstate_t>::do_unshift(1391state_type& st, extern_type* to, extern_type* to_end, extern_type*& to_nxt) const {1392to_nxt = to;1393extern_type tmp[MB_LEN_MAX];1394size_t n = __locale::__wcrtomb(tmp, intern_type(), &st, __l_);1395if (n == size_t(-1) || n == 0) // on error1396return error;1397--n;1398if (n > static_cast<size_t>(to_end - to_nxt)) // is there room?1399return partial;1400for (extern_type* p = tmp; n; --n) // write it1401*to_nxt++ = *p++;1402return ok;1403}14041405int codecvt<wchar_t, char, mbstate_t>::do_encoding() const noexcept {1406if (__locale::__mbtowc(nullptr, nullptr, MB_LEN_MAX, __l_) != 0)1407return -1;14081409// stateless encoding1410if (__l_ == 0 || __locale::__mb_len_max(__l_) == 1) // there are no known constant length encodings1411return 1; // which take more than 1 char to form a wchar_t1412return 0;1413}14141415bool codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const noexcept { return false; }14161417int codecvt<wchar_t, char, mbstate_t>::do_length(1418state_type& st, const extern_type* frm, const extern_type* frm_end, size_t mx) const {1419int nbytes = 0;1420for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t) {1421size_t n = __locale::__mbrlen(frm, static_cast<size_t>(frm_end - frm), &st, __l_);1422switch (n) {1423case 0:1424++nbytes;1425++frm;1426break;1427case size_t(-1):1428case size_t(-2):1429return nbytes;1430default:1431nbytes += n;1432frm += n;1433break;1434}1435}1436return nbytes;1437}14381439int codecvt<wchar_t, char, mbstate_t>::do_max_length() const noexcept {1440return __l_ == 0 ? 1 : static_cast<int>(__locale::__mb_len_max(__l_));1441}1442#endif // _LIBCPP_HAS_WIDE_CHARACTERS14431444// Valid UTF ranges1445// UTF-32 UTF-16 UTF-8 # of code points1446// first second first second third fourth1447// 000000 - 00007F 0000 - 007F 00 - 7F 1271448// 000080 - 0007FF 0080 - 07FF C2 - DF, 80 - BF 19201449// 000800 - 000FFF 0800 - 0FFF E0 - E0, A0 - BF, 80 - BF 20481450// 001000 - 00CFFF 1000 - CFFF E1 - EC, 80 - BF, 80 - BF 491521451// 00D000 - 00D7FF D000 - D7FF ED - ED, 80 - 9F, 80 - BF 20481452// 00D800 - 00DFFF invalid1453// 00E000 - 00FFFF E000 - FFFF EE - EF, 80 - BF, 80 - BF 81921454// 010000 - 03FFFF D800 - D8BF, DC00 - DFFF F0 - F0, 90 - BF, 80 - BF, 80 - BF 1966081455// 040000 - 0FFFFF D8C0 - DBBF, DC00 - DFFF F1 - F3, 80 - BF, 80 - BF, 80 - BF 7864321456// 100000 - 10FFFF DBC0 - DBFF, DC00 - DFFF F4 - F4, 80 - 8F, 80 - BF, 80 - BF 6553614571458_LIBCPP_SUPPRESS_DEPRECATED_PUSH1459static codecvt_base::result utf16_to_utf8(1460const uint16_t* frm,1461const uint16_t* frm_end,1462const uint16_t*& frm_nxt,1463uint8_t* to,1464uint8_t* to_end,1465uint8_t*& to_nxt,1466unsigned long Maxcode = 0x10FFFF,1467codecvt_mode mode = codecvt_mode(0)) {1468frm_nxt = frm;1469to_nxt = to;1470if (mode & generate_header) {1471if (to_end - to_nxt < 3)1472return codecvt_base::partial;1473*to_nxt++ = static_cast<uint8_t>(0xEF);1474*to_nxt++ = static_cast<uint8_t>(0xBB);1475*to_nxt++ = static_cast<uint8_t>(0xBF);1476}1477for (; frm_nxt < frm_end; ++frm_nxt) {1478uint16_t wc1 = *frm_nxt;1479if (wc1 > Maxcode)1480return codecvt_base::error;1481if (wc1 < 0x0080) {1482if (to_end - to_nxt < 1)1483return codecvt_base::partial;1484*to_nxt++ = static_cast<uint8_t>(wc1);1485} else if (wc1 < 0x0800) {1486if (to_end - to_nxt < 2)1487return codecvt_base::partial;1488*to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));1489*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));1490} else if (wc1 < 0xD800) {1491if (to_end - to_nxt < 3)1492return codecvt_base::partial;1493*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));1494*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));1495*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));1496} else if (wc1 < 0xDC00) {1497if (frm_end - frm_nxt < 2)1498return codecvt_base::partial;1499uint16_t wc2 = frm_nxt[1];1500if ((wc2 & 0xFC00) != 0xDC00)1501return codecvt_base::error;1502if (to_end - to_nxt < 4)1503return codecvt_base::partial;1504if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) + ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)1505return codecvt_base::error;1506++frm_nxt;1507uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;1508*to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));1509*to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));1510*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));1511*to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));1512} else if (wc1 < 0xE000) {1513return codecvt_base::error;1514} else {1515if (to_end - to_nxt < 3)1516return codecvt_base::partial;1517*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));1518*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));1519*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));1520}1521}1522return codecvt_base::ok;1523}15241525static codecvt_base::result utf16_to_utf8(1526const uint32_t* frm,1527const uint32_t* frm_end,1528const uint32_t*& frm_nxt,1529uint8_t* to,1530uint8_t* to_end,1531uint8_t*& to_nxt,1532unsigned long Maxcode = 0x10FFFF,1533codecvt_mode mode = codecvt_mode(0)) {1534frm_nxt = frm;1535to_nxt = to;1536if (mode & generate_header) {1537if (to_end - to_nxt < 3)1538return codecvt_base::partial;1539*to_nxt++ = static_cast<uint8_t>(0xEF);1540*to_nxt++ = static_cast<uint8_t>(0xBB);1541*to_nxt++ = static_cast<uint8_t>(0xBF);1542}1543for (; frm_nxt < frm_end; ++frm_nxt) {1544uint16_t wc1 = static_cast<uint16_t>(*frm_nxt);1545if (wc1 > Maxcode)1546return codecvt_base::error;1547if (wc1 < 0x0080) {1548if (to_end - to_nxt < 1)1549return codecvt_base::partial;1550*to_nxt++ = static_cast<uint8_t>(wc1);1551} else if (wc1 < 0x0800) {1552if (to_end - to_nxt < 2)1553return codecvt_base::partial;1554*to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));1555*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));1556} else if (wc1 < 0xD800) {1557if (to_end - to_nxt < 3)1558return codecvt_base::partial;1559*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));1560*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));1561*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));1562} else if (wc1 < 0xDC00) {1563if (frm_end - frm_nxt < 2)1564return codecvt_base::partial;1565uint16_t wc2 = static_cast<uint16_t>(frm_nxt[1]);1566if ((wc2 & 0xFC00) != 0xDC00)1567return codecvt_base::error;1568if (to_end - to_nxt < 4)1569return codecvt_base::partial;1570if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) + ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)1571return codecvt_base::error;1572++frm_nxt;1573uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;1574*to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));1575*to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));1576*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));1577*to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));1578} else if (wc1 < 0xE000) {1579return codecvt_base::error;1580} else {1581if (to_end - to_nxt < 3)1582return codecvt_base::partial;1583*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));1584*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));1585*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));1586}1587}1588return codecvt_base::ok;1589}15901591static codecvt_base::result utf8_to_utf16(1592const uint8_t* frm,1593const uint8_t* frm_end,1594const uint8_t*& frm_nxt,1595uint16_t* to,1596uint16_t* to_end,1597uint16_t*& to_nxt,1598unsigned long Maxcode = 0x10FFFF,1599codecvt_mode mode = codecvt_mode(0)) {1600frm_nxt = frm;1601to_nxt = to;1602if (mode & consume_header) {1603if (frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF)1604frm_nxt += 3;1605}1606for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) {1607uint8_t c1 = *frm_nxt;1608if (c1 > Maxcode)1609return codecvt_base::error;1610if (c1 < 0x80) {1611*to_nxt = static_cast<uint16_t>(c1);1612++frm_nxt;1613} else if (c1 < 0xC2) {1614return codecvt_base::error;1615} else if (c1 < 0xE0) {1616if (frm_end - frm_nxt < 2)1617return codecvt_base::partial;1618uint8_t c2 = frm_nxt[1];1619if ((c2 & 0xC0) != 0x80)1620return codecvt_base::error;1621uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));1622if (t > Maxcode)1623return codecvt_base::error;1624*to_nxt = t;1625frm_nxt += 2;1626} else if (c1 < 0xF0) {1627if (frm_end - frm_nxt < 2)1628return codecvt_base::partial;1629uint8_t c2 = frm_nxt[1];1630switch (c1) {1631case 0xE0:1632if ((c2 & 0xE0) != 0xA0)1633return codecvt_base::error;1634break;1635case 0xED:1636if ((c2 & 0xE0) != 0x80)1637return codecvt_base::error;1638break;1639default:1640if ((c2 & 0xC0) != 0x80)1641return codecvt_base::error;1642break;1643}1644if (frm_end - frm_nxt < 3)1645return codecvt_base::partial;1646uint8_t c3 = frm_nxt[2];1647if ((c3 & 0xC0) != 0x80)1648return codecvt_base::error;1649uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));1650if (t > Maxcode)1651return codecvt_base::error;1652*to_nxt = t;1653frm_nxt += 3;1654} else if (c1 < 0xF5) {1655if (frm_end - frm_nxt < 2)1656return codecvt_base::partial;1657uint8_t c2 = frm_nxt[1];1658switch (c1) {1659case 0xF0:1660if (!(0x90 <= c2 && c2 <= 0xBF))1661return codecvt_base::error;1662break;1663case 0xF4:1664if ((c2 & 0xF0) != 0x80)1665return codecvt_base::error;1666break;1667default:1668if ((c2 & 0xC0) != 0x80)1669return codecvt_base::error;1670break;1671}1672if (frm_end - frm_nxt < 3)1673return codecvt_base::partial;1674uint8_t c3 = frm_nxt[2];1675if ((c3 & 0xC0) != 0x80)1676return codecvt_base::error;1677if (frm_end - frm_nxt < 4)1678return codecvt_base::partial;1679uint8_t c4 = frm_nxt[3];1680if ((c4 & 0xC0) != 0x80)1681return codecvt_base::error;1682if (to_end - to_nxt < 2)1683return codecvt_base::partial;1684if ((((c1 & 7UL) << 18) + ((c2 & 0x3FUL) << 12) + ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)1685return codecvt_base::error;1686*to_nxt = static_cast<uint16_t>(16870xD800 | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6) | ((c2 & 0x0F) << 2) | ((c3 & 0x30) >> 4));1688*++to_nxt = static_cast<uint16_t>(0xDC00 | ((c3 & 0x0F) << 6) | (c4 & 0x3F));1689frm_nxt += 4;1690} else {1691return codecvt_base::error;1692}1693}1694return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;1695}16961697static codecvt_base::result utf8_to_utf16(1698const uint8_t* frm,1699const uint8_t* frm_end,1700const uint8_t*& frm_nxt,1701uint32_t* to,1702uint32_t* to_end,1703uint32_t*& to_nxt,1704unsigned long Maxcode = 0x10FFFF,1705codecvt_mode mode = codecvt_mode(0)) {1706frm_nxt = frm;1707to_nxt = to;1708if (mode & consume_header) {1709if (frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF)1710frm_nxt += 3;1711}1712for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) {1713uint8_t c1 = *frm_nxt;1714if (c1 > Maxcode)1715return codecvt_base::error;1716if (c1 < 0x80) {1717*to_nxt = static_cast<uint32_t>(c1);1718++frm_nxt;1719} else if (c1 < 0xC2) {1720return codecvt_base::error;1721} else if (c1 < 0xE0) {1722if (frm_end - frm_nxt < 2)1723return codecvt_base::partial;1724uint8_t c2 = frm_nxt[1];1725if ((c2 & 0xC0) != 0x80)1726return codecvt_base::error;1727uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));1728if (t > Maxcode)1729return codecvt_base::error;1730*to_nxt = static_cast<uint32_t>(t);1731frm_nxt += 2;1732} else if (c1 < 0xF0) {1733if (frm_end - frm_nxt < 2)1734return codecvt_base::partial;1735uint8_t c2 = frm_nxt[1];1736switch (c1) {1737case 0xE0:1738if ((c2 & 0xE0) != 0xA0)1739return codecvt_base::error;1740break;1741case 0xED:1742if ((c2 & 0xE0) != 0x80)1743return codecvt_base::error;1744break;1745default:1746if ((c2 & 0xC0) != 0x80)1747return codecvt_base::error;1748break;1749}1750if (frm_end - frm_nxt < 3)1751return codecvt_base::partial;1752uint8_t c3 = frm_nxt[2];1753if ((c3 & 0xC0) != 0x80)1754return codecvt_base::error;1755uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));1756if (t > Maxcode)1757return codecvt_base::error;1758*to_nxt = static_cast<uint32_t>(t);1759frm_nxt += 3;1760} else if (c1 < 0xF5) {1761if (frm_end - frm_nxt < 2)1762return codecvt_base::partial;1763uint8_t c2 = frm_nxt[1];1764switch (c1) {1765case 0xF0:1766if (!(0x90 <= c2 && c2 <= 0xBF))1767return codecvt_base::error;1768break;1769case 0xF4:1770if ((c2 & 0xF0) != 0x80)1771return codecvt_base::error;1772break;1773default:1774if ((c2 & 0xC0) != 0x80)1775return codecvt_base::error;1776break;1777}1778if (frm_end - frm_nxt < 3)1779return codecvt_base::partial;1780uint8_t c3 = frm_nxt[2];1781if ((c3 & 0xC0) != 0x80)1782return codecvt_base::error;1783if (frm_end - frm_nxt < 4)1784return codecvt_base::partial;1785uint8_t c4 = frm_nxt[3];1786if ((c4 & 0xC0) != 0x80)1787return codecvt_base::error;1788if (to_end - to_nxt < 2)1789return codecvt_base::partial;1790if ((((c1 & 7UL) << 18) + ((c2 & 0x3FUL) << 12) + ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)1791return codecvt_base::error;1792*to_nxt = static_cast<uint32_t>(17930xD800 | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6) | ((c2 & 0x0F) << 2) | ((c3 & 0x30) >> 4));1794*++to_nxt = static_cast<uint32_t>(0xDC00 | ((c3 & 0x0F) << 6) | (c4 & 0x3F));1795frm_nxt += 4;1796} else {1797return codecvt_base::error;1798}1799}1800return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;1801}18021803static int utf8_to_utf16_length(1804const uint8_t* frm,1805const uint8_t* frm_end,1806size_t mx,1807unsigned long Maxcode = 0x10FFFF,1808codecvt_mode mode = codecvt_mode(0)) {1809const uint8_t* frm_nxt = frm;1810if (mode & consume_header) {1811if (frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF)1812frm_nxt += 3;1813}1814for (size_t nchar16_t = 0; frm_nxt < frm_end && nchar16_t < mx; ++nchar16_t) {1815uint8_t c1 = *frm_nxt;1816if (c1 > Maxcode)1817break;1818if (c1 < 0x80) {1819++frm_nxt;1820} else if (c1 < 0xC2) {1821break;1822} else if (c1 < 0xE0) {1823if ((frm_end - frm_nxt < 2) || (frm_nxt[1] & 0xC0) != 0x80)1824break;1825uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F));1826if (t > Maxcode)1827break;1828frm_nxt += 2;1829} else if (c1 < 0xF0) {1830if (frm_end - frm_nxt < 3)1831break;1832uint8_t c2 = frm_nxt[1];1833uint8_t c3 = frm_nxt[2];1834switch (c1) {1835case 0xE0:1836if ((c2 & 0xE0) != 0xA0)1837return static_cast<int>(frm_nxt - frm);1838break;1839case 0xED:1840if ((c2 & 0xE0) != 0x80)1841return static_cast<int>(frm_nxt - frm);1842break;1843default:1844if ((c2 & 0xC0) != 0x80)1845return static_cast<int>(frm_nxt - frm);1846break;1847}1848if ((c3 & 0xC0) != 0x80)1849break;1850if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)1851break;1852frm_nxt += 3;1853} else if (c1 < 0xF5) {1854if (frm_end - frm_nxt < 4 || mx - nchar16_t < 2)1855break;1856uint8_t c2 = frm_nxt[1];1857uint8_t c3 = frm_nxt[2];1858uint8_t c4 = frm_nxt[3];1859switch (c1) {1860case 0xF0:1861if (!(0x90 <= c2 && c2 <= 0xBF))1862return static_cast<int>(frm_nxt - frm);1863break;1864case 0xF4:1865if ((c2 & 0xF0) != 0x80)1866return static_cast<int>(frm_nxt - frm);1867break;1868default:1869if ((c2 & 0xC0) != 0x80)1870return static_cast<int>(frm_nxt - frm);1871break;1872}1873if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)1874break;1875if ((((c1 & 7UL) << 18) + ((c2 & 0x3FUL) << 12) + ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)1876break;1877++nchar16_t;1878frm_nxt += 4;1879} else {1880break;1881}1882}1883return static_cast<int>(frm_nxt - frm);1884}18851886static codecvt_base::result ucs4_to_utf8(1887const uint32_t* frm,1888const uint32_t* frm_end,1889const uint32_t*& frm_nxt,1890uint8_t* to,1891uint8_t* to_end,1892uint8_t*& to_nxt,1893unsigned long Maxcode = 0x10FFFF,1894codecvt_mode mode = codecvt_mode(0)) {1895frm_nxt = frm;1896to_nxt = to;1897if (mode & generate_header) {1898if (to_end - to_nxt < 3)1899return codecvt_base::partial;1900*to_nxt++ = static_cast<uint8_t>(0xEF);1901*to_nxt++ = static_cast<uint8_t>(0xBB);1902*to_nxt++ = static_cast<uint8_t>(0xBF);1903}1904for (; frm_nxt < frm_end; ++frm_nxt) {1905uint32_t wc = *frm_nxt;1906if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)1907return codecvt_base::error;1908if (wc < 0x000080) {1909if (to_end - to_nxt < 1)1910return codecvt_base::partial;1911*to_nxt++ = static_cast<uint8_t>(wc);1912} else if (wc < 0x000800) {1913if (to_end - to_nxt < 2)1914return codecvt_base::partial;1915*to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));1916*to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));1917} else if (wc < 0x010000) {1918if (to_end - to_nxt < 3)1919return codecvt_base::partial;1920*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));1921*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));1922*to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));1923} else // if (wc < 0x110000)1924{1925if (to_end - to_nxt < 4)1926return codecvt_base::partial;1927*to_nxt++ = static_cast<uint8_t>(0xF0 | (wc >> 18));1928*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x03F000) >> 12));1929*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x000FC0) >> 6));1930*to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x00003F));1931}1932}1933return codecvt_base::ok;1934}19351936static codecvt_base::result utf8_to_ucs4(1937const uint8_t* frm,1938const uint8_t* frm_end,1939const uint8_t*& frm_nxt,1940uint32_t* to,1941uint32_t* to_end,1942uint32_t*& to_nxt,1943unsigned long Maxcode = 0x10FFFF,1944codecvt_mode mode = codecvt_mode(0)) {1945frm_nxt = frm;1946to_nxt = to;1947if (mode & consume_header) {1948if (frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF)1949frm_nxt += 3;1950}1951for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) {1952uint8_t c1 = static_cast<uint8_t>(*frm_nxt);1953if (c1 < 0x80) {1954if (c1 > Maxcode)1955return codecvt_base::error;1956*to_nxt = static_cast<uint32_t>(c1);1957++frm_nxt;1958} else if (c1 < 0xC2) {1959return codecvt_base::error;1960} else if (c1 < 0xE0) {1961if (frm_end - frm_nxt < 2)1962return codecvt_base::partial;1963uint8_t c2 = frm_nxt[1];1964if ((c2 & 0xC0) != 0x80)1965return codecvt_base::error;1966uint32_t t = static_cast<uint32_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));1967if (t > Maxcode)1968return codecvt_base::error;1969*to_nxt = t;1970frm_nxt += 2;1971} else if (c1 < 0xF0) {1972if (frm_end - frm_nxt < 2)1973return codecvt_base::partial;1974uint8_t c2 = frm_nxt[1];1975switch (c1) {1976case 0xE0:1977if ((c2 & 0xE0) != 0xA0)1978return codecvt_base::error;1979break;1980case 0xED:1981if ((c2 & 0xE0) != 0x80)1982return codecvt_base::error;1983break;1984default:1985if ((c2 & 0xC0) != 0x80)1986return codecvt_base::error;1987break;1988}1989if (frm_end - frm_nxt < 3)1990return codecvt_base::partial;1991uint8_t c3 = frm_nxt[2];1992if ((c3 & 0xC0) != 0x80)1993return codecvt_base::error;1994uint32_t t = static_cast<uint32_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));1995if (t > Maxcode)1996return codecvt_base::error;1997*to_nxt = t;1998frm_nxt += 3;1999} else if (c1 < 0xF5) {2000if (frm_end - frm_nxt < 2)2001return codecvt_base::partial;2002uint8_t c2 = frm_nxt[1];2003switch (c1) {2004case 0xF0:2005if (!(0x90 <= c2 && c2 <= 0xBF))2006return codecvt_base::error;2007break;2008case 0xF4:2009if ((c2 & 0xF0) != 0x80)2010return codecvt_base::error;2011break;2012default:2013if ((c2 & 0xC0) != 0x80)2014return codecvt_base::error;2015break;2016}2017if (frm_end - frm_nxt < 3)2018return codecvt_base::partial;2019uint8_t c3 = frm_nxt[2];2020if ((c3 & 0xC0) != 0x80)2021return codecvt_base::error;2022if (frm_end - frm_nxt < 4)2023return codecvt_base::partial;2024uint8_t c4 = frm_nxt[3];2025if ((c4 & 0xC0) != 0x80)2026return codecvt_base::error;2027uint32_t t = static_cast<uint32_t>(((c1 & 0x07) << 18) | ((c2 & 0x3F) << 12) | ((c3 & 0x3F) << 6) | (c4 & 0x3F));2028if (t > Maxcode)2029return codecvt_base::error;2030*to_nxt = t;2031frm_nxt += 4;2032} else {2033return codecvt_base::error;2034}2035}2036return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;2037}20382039static int utf8_to_ucs4_length(2040const uint8_t* frm,2041const uint8_t* frm_end,2042size_t mx,2043unsigned long Maxcode = 0x10FFFF,2044codecvt_mode mode = codecvt_mode(0)) {2045const uint8_t* frm_nxt = frm;2046if (mode & consume_header) {2047if (frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF)2048frm_nxt += 3;2049}2050for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t) {2051uint8_t c1 = static_cast<uint8_t>(*frm_nxt);2052if (c1 < 0x80) {2053if (c1 > Maxcode)2054break;2055++frm_nxt;2056} else if (c1 < 0xC2) {2057break;2058} else if (c1 < 0xE0) {2059if ((frm_end - frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))2060break;2061if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)2062break;2063frm_nxt += 2;2064} else if (c1 < 0xF0) {2065if (frm_end - frm_nxt < 3)2066break;2067uint8_t c2 = frm_nxt[1];2068uint8_t c3 = frm_nxt[2];2069switch (c1) {2070case 0xE0:2071if ((c2 & 0xE0) != 0xA0)2072return static_cast<int>(frm_nxt - frm);2073break;2074case 0xED:2075if ((c2 & 0xE0) != 0x80)2076return static_cast<int>(frm_nxt - frm);2077break;2078default:2079if ((c2 & 0xC0) != 0x80)2080return static_cast<int>(frm_nxt - frm);2081break;2082}2083if ((c3 & 0xC0) != 0x80)2084break;2085if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)2086break;2087frm_nxt += 3;2088} else if (c1 < 0xF5) {2089if (frm_end - frm_nxt < 4)2090break;2091uint8_t c2 = frm_nxt[1];2092uint8_t c3 = frm_nxt[2];2093uint8_t c4 = frm_nxt[3];2094switch (c1) {2095case 0xF0:2096if (!(0x90 <= c2 && c2 <= 0xBF))2097return static_cast<int>(frm_nxt - frm);2098break;2099case 0xF4:2100if ((c2 & 0xF0) != 0x80)2101return static_cast<int>(frm_nxt - frm);2102break;2103default:2104if ((c2 & 0xC0) != 0x80)2105return static_cast<int>(frm_nxt - frm);2106break;2107}2108if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)2109break;2110if ((((c1 & 0x07u) << 18) | ((c2 & 0x3Fu) << 12) | ((c3 & 0x3Fu) << 6) | (c4 & 0x3Fu)) > Maxcode)2111break;2112frm_nxt += 4;2113} else {2114break;2115}2116}2117return static_cast<int>(frm_nxt - frm);2118}21192120static codecvt_base::result ucs2_to_utf8(2121const uint16_t* frm,2122const uint16_t* frm_end,2123const uint16_t*& frm_nxt,2124uint8_t* to,2125uint8_t* to_end,2126uint8_t*& to_nxt,2127unsigned long Maxcode = 0x10FFFF,2128codecvt_mode mode = codecvt_mode(0)) {2129frm_nxt = frm;2130to_nxt = to;2131if (mode & generate_header) {2132if (to_end - to_nxt < 3)2133return codecvt_base::partial;2134*to_nxt++ = static_cast<uint8_t>(0xEF);2135*to_nxt++ = static_cast<uint8_t>(0xBB);2136*to_nxt++ = static_cast<uint8_t>(0xBF);2137}2138for (; frm_nxt < frm_end; ++frm_nxt) {2139uint16_t wc = *frm_nxt;2140if ((wc & 0xF800) == 0xD800 || wc > Maxcode)2141return codecvt_base::error;2142if (wc < 0x0080) {2143if (to_end - to_nxt < 1)2144return codecvt_base::partial;2145*to_nxt++ = static_cast<uint8_t>(wc);2146} else if (wc < 0x0800) {2147if (to_end - to_nxt < 2)2148return codecvt_base::partial;2149*to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));2150*to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));2151} else // if (wc <= 0xFFFF)2152{2153if (to_end - to_nxt < 3)2154return codecvt_base::partial;2155*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));2156*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));2157*to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));2158}2159}2160return codecvt_base::ok;2161}21622163static codecvt_base::result utf8_to_ucs2(2164const uint8_t* frm,2165const uint8_t* frm_end,2166const uint8_t*& frm_nxt,2167uint16_t* to,2168uint16_t* to_end,2169uint16_t*& to_nxt,2170unsigned long Maxcode = 0x10FFFF,2171codecvt_mode mode = codecvt_mode(0)) {2172frm_nxt = frm;2173to_nxt = to;2174if (mode & consume_header) {2175if (frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF)2176frm_nxt += 3;2177}2178for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt) {2179uint8_t c1 = static_cast<uint8_t>(*frm_nxt);2180if (c1 < 0x80) {2181if (c1 > Maxcode)2182return codecvt_base::error;2183*to_nxt = static_cast<uint16_t>(c1);2184++frm_nxt;2185} else if (c1 < 0xC2) {2186return codecvt_base::error;2187} else if (c1 < 0xE0) {2188if (frm_end - frm_nxt < 2)2189return codecvt_base::partial;2190uint8_t c2 = frm_nxt[1];2191if ((c2 & 0xC0) != 0x80)2192return codecvt_base::error;2193uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));2194if (t > Maxcode)2195return codecvt_base::error;2196*to_nxt = t;2197frm_nxt += 2;2198} else if (c1 < 0xF0) {2199if (frm_end - frm_nxt < 2)2200return codecvt_base::partial;2201uint8_t c2 = frm_nxt[1];2202switch (c1) {2203case 0xE0:2204if ((c2 & 0xE0) != 0xA0)2205return codecvt_base::error;2206break;2207case 0xED:2208if ((c2 & 0xE0) != 0x80)2209return codecvt_base::error;2210break;2211default:2212if ((c2 & 0xC0) != 0x80)2213return codecvt_base::error;2214break;2215}2216if (frm_end - frm_nxt < 3)2217return codecvt_base::partial;2218uint8_t c3 = frm_nxt[2];2219if ((c3 & 0xC0) != 0x80)2220return codecvt_base::error;2221uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));2222if (t > Maxcode)2223return codecvt_base::error;2224*to_nxt = t;2225frm_nxt += 3;2226} else {2227return codecvt_base::error;2228}2229}2230return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;2231}22322233static int utf8_to_ucs2_length(2234const uint8_t* frm,2235const uint8_t* frm_end,2236size_t mx,2237unsigned long Maxcode = 0x10FFFF,2238codecvt_mode mode = codecvt_mode(0)) {2239const uint8_t* frm_nxt = frm;2240if (mode & consume_header) {2241if (frm_end - frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB && frm_nxt[2] == 0xBF)2242frm_nxt += 3;2243}2244for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t) {2245uint8_t c1 = static_cast<uint8_t>(*frm_nxt);2246if (c1 < 0x80) {2247if (c1 > Maxcode)2248break;2249++frm_nxt;2250} else if (c1 < 0xC2) {2251break;2252} else if (c1 < 0xE0) {2253if ((frm_end - frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))2254break;2255if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)2256break;2257frm_nxt += 2;2258} else if (c1 < 0xF0) {2259if (frm_end - frm_nxt < 3)2260break;2261uint8_t c2 = frm_nxt[1];2262uint8_t c3 = frm_nxt[2];2263switch (c1) {2264case 0xE0:2265if ((c2 & 0xE0) != 0xA0)2266return static_cast<int>(frm_nxt - frm);2267break;2268case 0xED:2269if ((c2 & 0xE0) != 0x80)2270return static_cast<int>(frm_nxt - frm);2271break;2272default:2273if ((c2 & 0xC0) != 0x80)2274return static_cast<int>(frm_nxt - frm);2275break;2276}2277if ((c3 & 0xC0) != 0x80)2278break;2279if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)2280break;2281frm_nxt += 3;2282} else {2283break;2284}2285}2286return static_cast<int>(frm_nxt - frm);2287}22882289static codecvt_base::result ucs4_to_utf16be(2290const uint32_t* frm,2291const uint32_t* frm_end,2292const uint32_t*& frm_nxt,2293uint8_t* to,2294uint8_t* to_end,2295uint8_t*& to_nxt,2296unsigned long Maxcode = 0x10FFFF,2297codecvt_mode mode = codecvt_mode(0)) {2298frm_nxt = frm;2299to_nxt = to;2300if (mode & generate_header) {2301if (to_end - to_nxt < 2)2302return codecvt_base::partial;2303*to_nxt++ = static_cast<uint8_t>(0xFE);2304*to_nxt++ = static_cast<uint8_t>(0xFF);2305}2306for (; frm_nxt < frm_end; ++frm_nxt) {2307uint32_t wc = *frm_nxt;2308if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)2309return codecvt_base::error;2310if (wc < 0x010000) {2311if (to_end - to_nxt < 2)2312return codecvt_base::partial;2313*to_nxt++ = static_cast<uint8_t>(wc >> 8);2314*to_nxt++ = static_cast<uint8_t>(wc);2315} else {2316if (to_end - to_nxt < 4)2317return codecvt_base::partial;2318uint16_t t = static_cast<uint16_t>(0xD800 | ((((wc & 0x1F0000) >> 16) - 1) << 6) | ((wc & 0x00FC00) >> 10));2319*to_nxt++ = static_cast<uint8_t>(t >> 8);2320*to_nxt++ = static_cast<uint8_t>(t);2321t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));2322*to_nxt++ = static_cast<uint8_t>(t >> 8);2323*to_nxt++ = static_cast<uint8_t>(t);2324}2325}2326return codecvt_base::ok;2327}23282329static codecvt_base::result utf16be_to_ucs4(2330const uint8_t* frm,2331const uint8_t* frm_end,2332const uint8_t*& frm_nxt,2333uint32_t* to,2334uint32_t* to_end,2335uint32_t*& to_nxt,2336unsigned long Maxcode = 0x10FFFF,2337codecvt_mode mode = codecvt_mode(0)) {2338frm_nxt = frm;2339to_nxt = to;2340if (mode & consume_header) {2341if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)2342frm_nxt += 2;2343}2344for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) {2345uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);2346if ((c1 & 0xFC00) == 0xDC00)2347return codecvt_base::error;2348if ((c1 & 0xFC00) != 0xD800) {2349if (c1 > Maxcode)2350return codecvt_base::error;2351*to_nxt = static_cast<uint32_t>(c1);2352frm_nxt += 2;2353} else {2354if (frm_end - frm_nxt < 4)2355return codecvt_base::partial;2356uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);2357if ((c2 & 0xFC00) != 0xDC00)2358return codecvt_base::error;2359uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF));2360if (t > Maxcode)2361return codecvt_base::error;2362*to_nxt = t;2363frm_nxt += 4;2364}2365}2366return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;2367}23682369static int utf16be_to_ucs4_length(2370const uint8_t* frm,2371const uint8_t* frm_end,2372size_t mx,2373unsigned long Maxcode = 0x10FFFF,2374codecvt_mode mode = codecvt_mode(0)) {2375const uint8_t* frm_nxt = frm;2376if (mode & consume_header) {2377if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)2378frm_nxt += 2;2379}2380for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t) {2381uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);2382if ((c1 & 0xFC00) == 0xDC00)2383break;2384if ((c1 & 0xFC00) != 0xD800) {2385if (c1 > Maxcode)2386break;2387frm_nxt += 2;2388} else {2389if (frm_end - frm_nxt < 4)2390break;2391uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);2392if ((c2 & 0xFC00) != 0xDC00)2393break;2394uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF));2395if (t > Maxcode)2396break;2397frm_nxt += 4;2398}2399}2400return static_cast<int>(frm_nxt - frm);2401}24022403static codecvt_base::result ucs4_to_utf16le(2404const uint32_t* frm,2405const uint32_t* frm_end,2406const uint32_t*& frm_nxt,2407uint8_t* to,2408uint8_t* to_end,2409uint8_t*& to_nxt,2410unsigned long Maxcode = 0x10FFFF,2411codecvt_mode mode = codecvt_mode(0)) {2412frm_nxt = frm;2413to_nxt = to;2414if (mode & generate_header) {2415if (to_end - to_nxt < 2)2416return codecvt_base::partial;2417*to_nxt++ = static_cast<uint8_t>(0xFF);2418*to_nxt++ = static_cast<uint8_t>(0xFE);2419}2420for (; frm_nxt < frm_end; ++frm_nxt) {2421uint32_t wc = *frm_nxt;2422if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)2423return codecvt_base::error;2424if (wc < 0x010000) {2425if (to_end - to_nxt < 2)2426return codecvt_base::partial;2427*to_nxt++ = static_cast<uint8_t>(wc);2428*to_nxt++ = static_cast<uint8_t>(wc >> 8);2429} else {2430if (to_end - to_nxt < 4)2431return codecvt_base::partial;2432uint16_t t = static_cast<uint16_t>(0xD800 | ((((wc & 0x1F0000) >> 16) - 1) << 6) | ((wc & 0x00FC00) >> 10));2433*to_nxt++ = static_cast<uint8_t>(t);2434*to_nxt++ = static_cast<uint8_t>(t >> 8);2435t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));2436*to_nxt++ = static_cast<uint8_t>(t);2437*to_nxt++ = static_cast<uint8_t>(t >> 8);2438}2439}2440return codecvt_base::ok;2441}24422443static codecvt_base::result utf16le_to_ucs4(2444const uint8_t* frm,2445const uint8_t* frm_end,2446const uint8_t*& frm_nxt,2447uint32_t* to,2448uint32_t* to_end,2449uint32_t*& to_nxt,2450unsigned long Maxcode = 0x10FFFF,2451codecvt_mode mode = codecvt_mode(0)) {2452frm_nxt = frm;2453to_nxt = to;2454if (mode & consume_header) {2455if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)2456frm_nxt += 2;2457}2458for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) {2459uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);2460if ((c1 & 0xFC00) == 0xDC00)2461return codecvt_base::error;2462if ((c1 & 0xFC00) != 0xD800) {2463if (c1 > Maxcode)2464return codecvt_base::error;2465*to_nxt = static_cast<uint32_t>(c1);2466frm_nxt += 2;2467} else {2468if (frm_end - frm_nxt < 4)2469return codecvt_base::partial;2470uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);2471if ((c2 & 0xFC00) != 0xDC00)2472return codecvt_base::error;2473uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF));2474if (t > Maxcode)2475return codecvt_base::error;2476*to_nxt = t;2477frm_nxt += 4;2478}2479}2480return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;2481}24822483static int utf16le_to_ucs4_length(2484const uint8_t* frm,2485const uint8_t* frm_end,2486size_t mx,2487unsigned long Maxcode = 0x10FFFF,2488codecvt_mode mode = codecvt_mode(0)) {2489const uint8_t* frm_nxt = frm;2490if (mode & consume_header) {2491if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)2492frm_nxt += 2;2493}2494for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t) {2495uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);2496if ((c1 & 0xFC00) == 0xDC00)2497break;2498if ((c1 & 0xFC00) != 0xD800) {2499if (c1 > Maxcode)2500break;2501frm_nxt += 2;2502} else {2503if (frm_end - frm_nxt < 4)2504break;2505uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);2506if ((c2 & 0xFC00) != 0xDC00)2507break;2508uint32_t t = static_cast<uint32_t>(((((c1 & 0x03C0) >> 6) + 1) << 16) | ((c1 & 0x003F) << 10) | (c2 & 0x03FF));2509if (t > Maxcode)2510break;2511frm_nxt += 4;2512}2513}2514return static_cast<int>(frm_nxt - frm);2515}25162517static codecvt_base::result ucs2_to_utf16be(2518const uint16_t* frm,2519const uint16_t* frm_end,2520const uint16_t*& frm_nxt,2521uint8_t* to,2522uint8_t* to_end,2523uint8_t*& to_nxt,2524unsigned long Maxcode = 0x10FFFF,2525codecvt_mode mode = codecvt_mode(0)) {2526frm_nxt = frm;2527to_nxt = to;2528if (mode & generate_header) {2529if (to_end - to_nxt < 2)2530return codecvt_base::partial;2531*to_nxt++ = static_cast<uint8_t>(0xFE);2532*to_nxt++ = static_cast<uint8_t>(0xFF);2533}2534for (; frm_nxt < frm_end; ++frm_nxt) {2535uint16_t wc = *frm_nxt;2536if ((wc & 0xF800) == 0xD800 || wc > Maxcode)2537return codecvt_base::error;2538if (to_end - to_nxt < 2)2539return codecvt_base::partial;2540*to_nxt++ = static_cast<uint8_t>(wc >> 8);2541*to_nxt++ = static_cast<uint8_t>(wc);2542}2543return codecvt_base::ok;2544}25452546static codecvt_base::result utf16be_to_ucs2(2547const uint8_t* frm,2548const uint8_t* frm_end,2549const uint8_t*& frm_nxt,2550uint16_t* to,2551uint16_t* to_end,2552uint16_t*& to_nxt,2553unsigned long Maxcode = 0x10FFFF,2554codecvt_mode mode = codecvt_mode(0)) {2555frm_nxt = frm;2556to_nxt = to;2557if (mode & consume_header) {2558if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)2559frm_nxt += 2;2560}2561for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) {2562uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);2563if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)2564return codecvt_base::error;2565*to_nxt = c1;2566frm_nxt += 2;2567}2568return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;2569}25702571static int utf16be_to_ucs2_length(2572const uint8_t* frm,2573const uint8_t* frm_end,2574size_t mx,2575unsigned long Maxcode = 0x10FFFF,2576codecvt_mode mode = codecvt_mode(0)) {2577const uint8_t* frm_nxt = frm;2578if (mode & consume_header) {2579if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)2580frm_nxt += 2;2581}2582for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t) {2583uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);2584if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)2585break;2586frm_nxt += 2;2587}2588return static_cast<int>(frm_nxt - frm);2589}25902591static codecvt_base::result ucs2_to_utf16le(2592const uint16_t* frm,2593const uint16_t* frm_end,2594const uint16_t*& frm_nxt,2595uint8_t* to,2596uint8_t* to_end,2597uint8_t*& to_nxt,2598unsigned long Maxcode = 0x10FFFF,2599codecvt_mode mode = codecvt_mode(0)) {2600frm_nxt = frm;2601to_nxt = to;2602if (mode & generate_header) {2603if (to_end - to_nxt < 2)2604return codecvt_base::partial;2605*to_nxt++ = static_cast<uint8_t>(0xFF);2606*to_nxt++ = static_cast<uint8_t>(0xFE);2607}2608for (; frm_nxt < frm_end; ++frm_nxt) {2609uint16_t wc = *frm_nxt;2610if ((wc & 0xF800) == 0xD800 || wc > Maxcode)2611return codecvt_base::error;2612if (to_end - to_nxt < 2)2613return codecvt_base::partial;2614*to_nxt++ = static_cast<uint8_t>(wc);2615*to_nxt++ = static_cast<uint8_t>(wc >> 8);2616}2617return codecvt_base::ok;2618}26192620static codecvt_base::result utf16le_to_ucs2(2621const uint8_t* frm,2622const uint8_t* frm_end,2623const uint8_t*& frm_nxt,2624uint16_t* to,2625uint16_t* to_end,2626uint16_t*& to_nxt,2627unsigned long Maxcode = 0x10FFFF,2628codecvt_mode mode = codecvt_mode(0)) {2629frm_nxt = frm;2630to_nxt = to;2631if (mode & consume_header) {2632if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)2633frm_nxt += 2;2634}2635for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt) {2636uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);2637if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)2638return codecvt_base::error;2639*to_nxt = c1;2640frm_nxt += 2;2641}2642return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;2643}26442645static int utf16le_to_ucs2_length(2646const uint8_t* frm,2647const uint8_t* frm_end,2648size_t mx,2649unsigned long Maxcode = 0x10FFFF,2650codecvt_mode mode = codecvt_mode(0)) {2651const uint8_t* frm_nxt = frm;2652frm_nxt = frm;2653if (mode & consume_header) {2654if (frm_end - frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)2655frm_nxt += 2;2656}2657for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t) {2658uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);2659if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)2660break;2661frm_nxt += 2;2662}2663return static_cast<int>(frm_nxt - frm);2664}26652666_LIBCPP_SUPPRESS_DEPRECATED_POP26672668// template <> class codecvt<char16_t, char, mbstate_t>26692670constinit locale::id codecvt<char16_t, char, mbstate_t>::id;26712672codecvt<char16_t, char, mbstate_t>::~codecvt() {}26732674codecvt<char16_t, char, mbstate_t>::result codecvt<char16_t, char, mbstate_t>::do_out(2675state_type&,2676const intern_type* frm,2677const intern_type* frm_end,2678const intern_type*& frm_nxt,2679extern_type* to,2680extern_type* to_end,2681extern_type*& to_nxt) const {2682const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);2683const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);2684const uint16_t* _frm_nxt = _frm;2685uint8_t* _to = reinterpret_cast<uint8_t*>(to);2686uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);2687uint8_t* _to_nxt = _to;2688result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);2689frm_nxt = frm + (_frm_nxt - _frm);2690to_nxt = to + (_to_nxt - _to);2691return r;2692}26932694codecvt<char16_t, char, mbstate_t>::result codecvt<char16_t, char, mbstate_t>::do_in(2695state_type&,2696const extern_type* frm,2697const extern_type* frm_end,2698const extern_type*& frm_nxt,2699intern_type* to,2700intern_type* to_end,2701intern_type*& to_nxt) const {2702const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);2703const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);2704const uint8_t* _frm_nxt = _frm;2705uint16_t* _to = reinterpret_cast<uint16_t*>(to);2706uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);2707uint16_t* _to_nxt = _to;2708result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);2709frm_nxt = frm + (_frm_nxt - _frm);2710to_nxt = to + (_to_nxt - _to);2711return r;2712}27132714codecvt<char16_t, char, mbstate_t>::result2715codecvt<char16_t, char, mbstate_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {2716to_nxt = to;2717return noconv;2718}27192720int codecvt<char16_t, char, mbstate_t>::do_encoding() const noexcept { return 0; }27212722bool codecvt<char16_t, char, mbstate_t>::do_always_noconv() const noexcept { return false; }27232724int codecvt<char16_t, char, mbstate_t>::do_length(2725state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {2726const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);2727const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);2728return utf8_to_utf16_length(_frm, _frm_end, mx);2729}27302731int codecvt<char16_t, char, mbstate_t>::do_max_length() const noexcept { return 4; }27322733#if _LIBCPP_HAS_CHAR8_T27342735// template <> class codecvt<char16_t, char8_t, mbstate_t>27362737constinit locale::id codecvt<char16_t, char8_t, mbstate_t>::id;27382739codecvt<char16_t, char8_t, mbstate_t>::~codecvt() {}27402741codecvt<char16_t, char8_t, mbstate_t>::result codecvt<char16_t, char8_t, mbstate_t>::do_out(2742state_type&,2743const intern_type* frm,2744const intern_type* frm_end,2745const intern_type*& frm_nxt,2746extern_type* to,2747extern_type* to_end,2748extern_type*& to_nxt) const {2749const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);2750const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);2751const uint16_t* _frm_nxt = _frm;2752uint8_t* _to = reinterpret_cast<uint8_t*>(to);2753uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);2754uint8_t* _to_nxt = _to;2755result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);2756frm_nxt = frm + (_frm_nxt - _frm);2757to_nxt = to + (_to_nxt - _to);2758return r;2759}27602761codecvt<char16_t, char8_t, mbstate_t>::result codecvt<char16_t, char8_t, mbstate_t>::do_in(2762state_type&,2763const extern_type* frm,2764const extern_type* frm_end,2765const extern_type*& frm_nxt,2766intern_type* to,2767intern_type* to_end,2768intern_type*& to_nxt) const {2769const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);2770const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);2771const uint8_t* _frm_nxt = _frm;2772uint16_t* _to = reinterpret_cast<uint16_t*>(to);2773uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);2774uint16_t* _to_nxt = _to;2775result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);2776frm_nxt = frm + (_frm_nxt - _frm);2777to_nxt = to + (_to_nxt - _to);2778return r;2779}27802781codecvt<char16_t, char8_t, mbstate_t>::result codecvt<char16_t, char8_t, mbstate_t>::do_unshift(2782state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {2783to_nxt = to;2784return noconv;2785}27862787int codecvt<char16_t, char8_t, mbstate_t>::do_encoding() const noexcept { return 0; }27882789bool codecvt<char16_t, char8_t, mbstate_t>::do_always_noconv() const noexcept { return false; }27902791int codecvt<char16_t, char8_t, mbstate_t>::do_length(2792state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {2793const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);2794const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);2795return utf8_to_utf16_length(_frm, _frm_end, mx);2796}27972798int codecvt<char16_t, char8_t, mbstate_t>::do_max_length() const noexcept { return 4; }27992800#endif28012802// template <> class codecvt<char32_t, char, mbstate_t>28032804constinit locale::id codecvt<char32_t, char, mbstate_t>::id;28052806codecvt<char32_t, char, mbstate_t>::~codecvt() {}28072808codecvt<char32_t, char, mbstate_t>::result codecvt<char32_t, char, mbstate_t>::do_out(2809state_type&,2810const intern_type* frm,2811const intern_type* frm_end,2812const intern_type*& frm_nxt,2813extern_type* to,2814extern_type* to_end,2815extern_type*& to_nxt) const {2816const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);2817const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);2818const uint32_t* _frm_nxt = _frm;2819uint8_t* _to = reinterpret_cast<uint8_t*>(to);2820uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);2821uint8_t* _to_nxt = _to;2822result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);2823frm_nxt = frm + (_frm_nxt - _frm);2824to_nxt = to + (_to_nxt - _to);2825return r;2826}28272828codecvt<char32_t, char, mbstate_t>::result codecvt<char32_t, char, mbstate_t>::do_in(2829state_type&,2830const extern_type* frm,2831const extern_type* frm_end,2832const extern_type*& frm_nxt,2833intern_type* to,2834intern_type* to_end,2835intern_type*& to_nxt) const {2836const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);2837const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);2838const uint8_t* _frm_nxt = _frm;2839uint32_t* _to = reinterpret_cast<uint32_t*>(to);2840uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);2841uint32_t* _to_nxt = _to;2842result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);2843frm_nxt = frm + (_frm_nxt - _frm);2844to_nxt = to + (_to_nxt - _to);2845return r;2846}28472848codecvt<char32_t, char, mbstate_t>::result2849codecvt<char32_t, char, mbstate_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {2850to_nxt = to;2851return noconv;2852}28532854int codecvt<char32_t, char, mbstate_t>::do_encoding() const noexcept { return 0; }28552856bool codecvt<char32_t, char, mbstate_t>::do_always_noconv() const noexcept { return false; }28572858int codecvt<char32_t, char, mbstate_t>::do_length(2859state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {2860const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);2861const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);2862return utf8_to_ucs4_length(_frm, _frm_end, mx);2863}28642865int codecvt<char32_t, char, mbstate_t>::do_max_length() const noexcept { return 4; }28662867#if _LIBCPP_HAS_CHAR8_T28682869// template <> class codecvt<char32_t, char8_t, mbstate_t>28702871constinit locale::id codecvt<char32_t, char8_t, mbstate_t>::id;28722873codecvt<char32_t, char8_t, mbstate_t>::~codecvt() {}28742875codecvt<char32_t, char8_t, mbstate_t>::result codecvt<char32_t, char8_t, mbstate_t>::do_out(2876state_type&,2877const intern_type* frm,2878const intern_type* frm_end,2879const intern_type*& frm_nxt,2880extern_type* to,2881extern_type* to_end,2882extern_type*& to_nxt) const {2883const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);2884const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);2885const uint32_t* _frm_nxt = _frm;2886uint8_t* _to = reinterpret_cast<uint8_t*>(to);2887uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);2888uint8_t* _to_nxt = _to;2889result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);2890frm_nxt = frm + (_frm_nxt - _frm);2891to_nxt = to + (_to_nxt - _to);2892return r;2893}28942895codecvt<char32_t, char8_t, mbstate_t>::result codecvt<char32_t, char8_t, mbstate_t>::do_in(2896state_type&,2897const extern_type* frm,2898const extern_type* frm_end,2899const extern_type*& frm_nxt,2900intern_type* to,2901intern_type* to_end,2902intern_type*& to_nxt) const {2903const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);2904const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);2905const uint8_t* _frm_nxt = _frm;2906uint32_t* _to = reinterpret_cast<uint32_t*>(to);2907uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);2908uint32_t* _to_nxt = _to;2909result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);2910frm_nxt = frm + (_frm_nxt - _frm);2911to_nxt = to + (_to_nxt - _to);2912return r;2913}29142915codecvt<char32_t, char8_t, mbstate_t>::result codecvt<char32_t, char8_t, mbstate_t>::do_unshift(2916state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {2917to_nxt = to;2918return noconv;2919}29202921int codecvt<char32_t, char8_t, mbstate_t>::do_encoding() const noexcept { return 0; }29222923bool codecvt<char32_t, char8_t, mbstate_t>::do_always_noconv() const noexcept { return false; }29242925int codecvt<char32_t, char8_t, mbstate_t>::do_length(2926state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {2927const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);2928const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);2929return utf8_to_ucs4_length(_frm, _frm_end, mx);2930}29312932int codecvt<char32_t, char8_t, mbstate_t>::do_max_length() const noexcept { return 4; }29332934#endif29352936// __codecvt_utf8<wchar_t>29372938#if _LIBCPP_HAS_WIDE_CHARACTERS2939__codecvt_utf8<wchar_t>::result __codecvt_utf8<wchar_t>::do_out(2940state_type&,2941const intern_type* frm,2942const intern_type* frm_end,2943const intern_type*& frm_nxt,2944extern_type* to,2945extern_type* to_end,2946extern_type*& to_nxt) const {2947# if defined(_LIBCPP_SHORT_WCHAR)2948const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);2949const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);2950const uint16_t* _frm_nxt = _frm;2951# else2952const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);2953const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);2954const uint32_t* _frm_nxt = _frm;2955# endif2956uint8_t* _to = reinterpret_cast<uint8_t*>(to);2957uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);2958uint8_t* _to_nxt = _to;2959# if defined(_LIBCPP_SHORT_WCHAR)2960result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);2961# else2962result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);2963# endif2964frm_nxt = frm + (_frm_nxt - _frm);2965to_nxt = to + (_to_nxt - _to);2966return r;2967}29682969__codecvt_utf8<wchar_t>::result __codecvt_utf8<wchar_t>::do_in(2970state_type&,2971const extern_type* frm,2972const extern_type* frm_end,2973const extern_type*& frm_nxt,2974intern_type* to,2975intern_type* to_end,2976intern_type*& to_nxt) const {2977const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);2978const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);2979const uint8_t* _frm_nxt = _frm;2980# if defined(_LIBCPP_SHORT_WCHAR)2981uint16_t* _to = reinterpret_cast<uint16_t*>(to);2982uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);2983uint16_t* _to_nxt = _to;2984result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);2985# else2986uint32_t* _to = reinterpret_cast<uint32_t*>(to);2987uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);2988uint32_t* _to_nxt = _to;2989result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);2990# endif2991frm_nxt = frm + (_frm_nxt - _frm);2992to_nxt = to + (_to_nxt - _to);2993return r;2994}29952996__codecvt_utf8<wchar_t>::result2997__codecvt_utf8<wchar_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {2998to_nxt = to;2999return noconv;3000}30013002int __codecvt_utf8<wchar_t>::do_encoding() const noexcept { return 0; }30033004bool __codecvt_utf8<wchar_t>::do_always_noconv() const noexcept { return false; }30053006int __codecvt_utf8<wchar_t>::do_length(3007state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {3008const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3009const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3010# if defined(_LIBCPP_SHORT_WCHAR)3011return utf8_to_ucs2_length(_frm, _frm_end, mx, __maxcode_, __mode_);3012# else3013return utf8_to_ucs4_length(_frm, _frm_end, mx, __maxcode_, __mode_);3014# endif3015}30163017_LIBCPP_SUPPRESS_DEPRECATED_PUSH3018int __codecvt_utf8<wchar_t>::do_max_length() const noexcept {3019# if defined(_LIBCPP_SHORT_WCHAR)3020if (__mode_ & consume_header)3021return 6;3022return 3;3023# else3024if (__mode_ & consume_header)3025return 7;3026return 4;3027# endif3028}3029#endif // _LIBCPP_HAS_WIDE_CHARACTERS30303031// __codecvt_utf8<char16_t>30323033__codecvt_utf8<char16_t>::result __codecvt_utf8<char16_t>::do_out(3034state_type&,3035const intern_type* frm,3036const intern_type* frm_end,3037const intern_type*& frm_nxt,3038extern_type* to,3039extern_type* to_end,3040extern_type*& to_nxt) const {3041const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);3042const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);3043const uint16_t* _frm_nxt = _frm;3044uint8_t* _to = reinterpret_cast<uint8_t*>(to);3045uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);3046uint8_t* _to_nxt = _to;3047result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3048frm_nxt = frm + (_frm_nxt - _frm);3049to_nxt = to + (_to_nxt - _to);3050return r;3051}30523053__codecvt_utf8<char16_t>::result __codecvt_utf8<char16_t>::do_in(3054state_type&,3055const extern_type* frm,3056const extern_type* frm_end,3057const extern_type*& frm_nxt,3058intern_type* to,3059intern_type* to_end,3060intern_type*& to_nxt) const {3061const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3062const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3063const uint8_t* _frm_nxt = _frm;3064uint16_t* _to = reinterpret_cast<uint16_t*>(to);3065uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);3066uint16_t* _to_nxt = _to;3067result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3068frm_nxt = frm + (_frm_nxt - _frm);3069to_nxt = to + (_to_nxt - _to);3070return r;3071}30723073__codecvt_utf8<char16_t>::result3074__codecvt_utf8<char16_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {3075to_nxt = to;3076return noconv;3077}30783079int __codecvt_utf8<char16_t>::do_encoding() const noexcept { return 0; }30803081bool __codecvt_utf8<char16_t>::do_always_noconv() const noexcept { return false; }30823083int __codecvt_utf8<char16_t>::do_length(3084state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {3085const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3086const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3087return utf8_to_ucs2_length(_frm, _frm_end, mx, __maxcode_, __mode_);3088}30893090_LIBCPP_SUPPRESS_DEPRECATED_PUSH3091int __codecvt_utf8<char16_t>::do_max_length() const noexcept {3092if (__mode_ & consume_header)3093return 6;3094return 3;3095}3096_LIBCPP_SUPPRESS_DEPRECATED_POP30973098// __codecvt_utf8<char32_t>30993100__codecvt_utf8<char32_t>::result __codecvt_utf8<char32_t>::do_out(3101state_type&,3102const intern_type* frm,3103const intern_type* frm_end,3104const intern_type*& frm_nxt,3105extern_type* to,3106extern_type* to_end,3107extern_type*& to_nxt) const {3108const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);3109const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);3110const uint32_t* _frm_nxt = _frm;3111uint8_t* _to = reinterpret_cast<uint8_t*>(to);3112uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);3113uint8_t* _to_nxt = _to;3114result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3115frm_nxt = frm + (_frm_nxt - _frm);3116to_nxt = to + (_to_nxt - _to);3117return r;3118}31193120__codecvt_utf8<char32_t>::result __codecvt_utf8<char32_t>::do_in(3121state_type&,3122const extern_type* frm,3123const extern_type* frm_end,3124const extern_type*& frm_nxt,3125intern_type* to,3126intern_type* to_end,3127intern_type*& to_nxt) const {3128const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3129const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3130const uint8_t* _frm_nxt = _frm;3131uint32_t* _to = reinterpret_cast<uint32_t*>(to);3132uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);3133uint32_t* _to_nxt = _to;3134result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3135frm_nxt = frm + (_frm_nxt - _frm);3136to_nxt = to + (_to_nxt - _to);3137return r;3138}31393140__codecvt_utf8<char32_t>::result3141__codecvt_utf8<char32_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {3142to_nxt = to;3143return noconv;3144}31453146int __codecvt_utf8<char32_t>::do_encoding() const noexcept { return 0; }31473148bool __codecvt_utf8<char32_t>::do_always_noconv() const noexcept { return false; }31493150int __codecvt_utf8<char32_t>::do_length(3151state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {3152const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3153const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3154return utf8_to_ucs4_length(_frm, _frm_end, mx, __maxcode_, __mode_);3155}31563157_LIBCPP_SUPPRESS_DEPRECATED_PUSH3158int __codecvt_utf8<char32_t>::do_max_length() const noexcept {3159if (__mode_ & consume_header)3160return 7;3161return 4;3162}3163_LIBCPP_SUPPRESS_DEPRECATED_POP31643165// __codecvt_utf16<wchar_t, false>31663167#if _LIBCPP_HAS_WIDE_CHARACTERS3168__codecvt_utf16<wchar_t, false>::result __codecvt_utf16<wchar_t, false>::do_out(3169state_type&,3170const intern_type* frm,3171const intern_type* frm_end,3172const intern_type*& frm_nxt,3173extern_type* to,3174extern_type* to_end,3175extern_type*& to_nxt) const {3176# if defined(_LIBCPP_SHORT_WCHAR)3177const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);3178const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);3179const uint16_t* _frm_nxt = _frm;3180# else3181const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);3182const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);3183const uint32_t* _frm_nxt = _frm;3184# endif3185uint8_t* _to = reinterpret_cast<uint8_t*>(to);3186uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);3187uint8_t* _to_nxt = _to;3188# if defined(_LIBCPP_SHORT_WCHAR)3189result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3190# else3191result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3192# endif3193frm_nxt = frm + (_frm_nxt - _frm);3194to_nxt = to + (_to_nxt - _to);3195return r;3196}31973198__codecvt_utf16<wchar_t, false>::result __codecvt_utf16<wchar_t, false>::do_in(3199state_type&,3200const extern_type* frm,3201const extern_type* frm_end,3202const extern_type*& frm_nxt,3203intern_type* to,3204intern_type* to_end,3205intern_type*& to_nxt) const {3206const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3207const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3208const uint8_t* _frm_nxt = _frm;3209# if defined(_LIBCPP_SHORT_WCHAR)3210uint16_t* _to = reinterpret_cast<uint16_t*>(to);3211uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);3212uint16_t* _to_nxt = _to;3213result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3214# else3215uint32_t* _to = reinterpret_cast<uint32_t*>(to);3216uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);3217uint32_t* _to_nxt = _to;3218result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3219# endif3220frm_nxt = frm + (_frm_nxt - _frm);3221to_nxt = to + (_to_nxt - _to);3222return r;3223}32243225__codecvt_utf16<wchar_t, false>::result3226__codecvt_utf16<wchar_t, false>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {3227to_nxt = to;3228return noconv;3229}32303231int __codecvt_utf16<wchar_t, false>::do_encoding() const noexcept { return 0; }32323233bool __codecvt_utf16<wchar_t, false>::do_always_noconv() const noexcept { return false; }32343235int __codecvt_utf16<wchar_t, false>::do_length(3236state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {3237const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3238const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3239# if defined(_LIBCPP_SHORT_WCHAR)3240return utf16be_to_ucs2_length(_frm, _frm_end, mx, __maxcode_, __mode_);3241# else3242return utf16be_to_ucs4_length(_frm, _frm_end, mx, __maxcode_, __mode_);3243# endif3244}32453246int __codecvt_utf16<wchar_t, false>::do_max_length() const noexcept {3247# if defined(_LIBCPP_SHORT_WCHAR)3248if (__mode_ & consume_header)3249return 4;3250return 2;3251# else3252if (__mode_ & consume_header)3253return 6;3254return 4;3255# endif3256}32573258// __codecvt_utf16<wchar_t, true>32593260__codecvt_utf16<wchar_t, true>::result __codecvt_utf16<wchar_t, true>::do_out(3261state_type&,3262const intern_type* frm,3263const intern_type* frm_end,3264const intern_type*& frm_nxt,3265extern_type* to,3266extern_type* to_end,3267extern_type*& to_nxt) const {3268# if defined(_LIBCPP_SHORT_WCHAR)3269const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);3270const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);3271const uint16_t* _frm_nxt = _frm;3272# else3273const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);3274const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);3275const uint32_t* _frm_nxt = _frm;3276# endif3277uint8_t* _to = reinterpret_cast<uint8_t*>(to);3278uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);3279uint8_t* _to_nxt = _to;3280# if defined(_LIBCPP_SHORT_WCHAR)3281result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3282# else3283result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3284# endif3285frm_nxt = frm + (_frm_nxt - _frm);3286to_nxt = to + (_to_nxt - _to);3287return r;3288}32893290__codecvt_utf16<wchar_t, true>::result __codecvt_utf16<wchar_t, true>::do_in(3291state_type&,3292const extern_type* frm,3293const extern_type* frm_end,3294const extern_type*& frm_nxt,3295intern_type* to,3296intern_type* to_end,3297intern_type*& to_nxt) const {3298const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3299const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3300const uint8_t* _frm_nxt = _frm;3301# if defined(_LIBCPP_SHORT_WCHAR)3302uint16_t* _to = reinterpret_cast<uint16_t*>(to);3303uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);3304uint16_t* _to_nxt = _to;3305result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3306# else3307uint32_t* _to = reinterpret_cast<uint32_t*>(to);3308uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);3309uint32_t* _to_nxt = _to;3310result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3311# endif3312frm_nxt = frm + (_frm_nxt - _frm);3313to_nxt = to + (_to_nxt - _to);3314return r;3315}33163317__codecvt_utf16<wchar_t, true>::result3318__codecvt_utf16<wchar_t, true>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {3319to_nxt = to;3320return noconv;3321}33223323int __codecvt_utf16<wchar_t, true>::do_encoding() const noexcept { return 0; }33243325bool __codecvt_utf16<wchar_t, true>::do_always_noconv() const noexcept { return false; }33263327int __codecvt_utf16<wchar_t, true>::do_length(3328state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {3329const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3330const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3331# if defined(_LIBCPP_SHORT_WCHAR)3332return utf16le_to_ucs2_length(_frm, _frm_end, mx, __maxcode_, __mode_);3333# else3334return utf16le_to_ucs4_length(_frm, _frm_end, mx, __maxcode_, __mode_);3335# endif3336}33373338int __codecvt_utf16<wchar_t, true>::do_max_length() const noexcept {3339# if defined(_LIBCPP_SHORT_WCHAR)3340if (__mode_ & consume_header)3341return 4;3342return 2;3343# else3344if (__mode_ & consume_header)3345return 6;3346return 4;3347# endif3348}3349#endif // _LIBCPP_HAS_WIDE_CHARACTERS33503351// __codecvt_utf16<char16_t, false>33523353__codecvt_utf16<char16_t, false>::result __codecvt_utf16<char16_t, false>::do_out(3354state_type&,3355const intern_type* frm,3356const intern_type* frm_end,3357const intern_type*& frm_nxt,3358extern_type* to,3359extern_type* to_end,3360extern_type*& to_nxt) const {3361const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);3362const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);3363const uint16_t* _frm_nxt = _frm;3364uint8_t* _to = reinterpret_cast<uint8_t*>(to);3365uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);3366uint8_t* _to_nxt = _to;3367result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3368frm_nxt = frm + (_frm_nxt - _frm);3369to_nxt = to + (_to_nxt - _to);3370return r;3371}33723373__codecvt_utf16<char16_t, false>::result __codecvt_utf16<char16_t, false>::do_in(3374state_type&,3375const extern_type* frm,3376const extern_type* frm_end,3377const extern_type*& frm_nxt,3378intern_type* to,3379intern_type* to_end,3380intern_type*& to_nxt) const {3381const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3382const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3383const uint8_t* _frm_nxt = _frm;3384uint16_t* _to = reinterpret_cast<uint16_t*>(to);3385uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);3386uint16_t* _to_nxt = _to;3387result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3388frm_nxt = frm + (_frm_nxt - _frm);3389to_nxt = to + (_to_nxt - _to);3390return r;3391}33923393__codecvt_utf16<char16_t, false>::result3394__codecvt_utf16<char16_t, false>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {3395to_nxt = to;3396return noconv;3397}33983399int __codecvt_utf16<char16_t, false>::do_encoding() const noexcept { return 0; }34003401bool __codecvt_utf16<char16_t, false>::do_always_noconv() const noexcept { return false; }34023403int __codecvt_utf16<char16_t, false>::do_length(3404state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {3405const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3406const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3407return utf16be_to_ucs2_length(_frm, _frm_end, mx, __maxcode_, __mode_);3408}34093410_LIBCPP_SUPPRESS_DEPRECATED_PUSH3411int __codecvt_utf16<char16_t, false>::do_max_length() const noexcept {3412if (__mode_ & consume_header)3413return 4;3414return 2;3415}3416_LIBCPP_SUPPRESS_DEPRECATED_POP34173418// __codecvt_utf16<char16_t, true>34193420__codecvt_utf16<char16_t, true>::result __codecvt_utf16<char16_t, true>::do_out(3421state_type&,3422const intern_type* frm,3423const intern_type* frm_end,3424const intern_type*& frm_nxt,3425extern_type* to,3426extern_type* to_end,3427extern_type*& to_nxt) const {3428const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);3429const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);3430const uint16_t* _frm_nxt = _frm;3431uint8_t* _to = reinterpret_cast<uint8_t*>(to);3432uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);3433uint8_t* _to_nxt = _to;3434result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3435frm_nxt = frm + (_frm_nxt - _frm);3436to_nxt = to + (_to_nxt - _to);3437return r;3438}34393440__codecvt_utf16<char16_t, true>::result __codecvt_utf16<char16_t, true>::do_in(3441state_type&,3442const extern_type* frm,3443const extern_type* frm_end,3444const extern_type*& frm_nxt,3445intern_type* to,3446intern_type* to_end,3447intern_type*& to_nxt) const {3448const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3449const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3450const uint8_t* _frm_nxt = _frm;3451uint16_t* _to = reinterpret_cast<uint16_t*>(to);3452uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);3453uint16_t* _to_nxt = _to;3454result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3455frm_nxt = frm + (_frm_nxt - _frm);3456to_nxt = to + (_to_nxt - _to);3457return r;3458}34593460__codecvt_utf16<char16_t, true>::result3461__codecvt_utf16<char16_t, true>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {3462to_nxt = to;3463return noconv;3464}34653466int __codecvt_utf16<char16_t, true>::do_encoding() const noexcept { return 0; }34673468bool __codecvt_utf16<char16_t, true>::do_always_noconv() const noexcept { return false; }34693470int __codecvt_utf16<char16_t, true>::do_length(3471state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {3472const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3473const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3474return utf16le_to_ucs2_length(_frm, _frm_end, mx, __maxcode_, __mode_);3475}34763477_LIBCPP_SUPPRESS_DEPRECATED_PUSH3478int __codecvt_utf16<char16_t, true>::do_max_length() const noexcept {3479if (__mode_ & consume_header)3480return 4;3481return 2;3482}3483_LIBCPP_SUPPRESS_DEPRECATED_POP34843485// __codecvt_utf16<char32_t, false>34863487__codecvt_utf16<char32_t, false>::result __codecvt_utf16<char32_t, false>::do_out(3488state_type&,3489const intern_type* frm,3490const intern_type* frm_end,3491const intern_type*& frm_nxt,3492extern_type* to,3493extern_type* to_end,3494extern_type*& to_nxt) const {3495const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);3496const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);3497const uint32_t* _frm_nxt = _frm;3498uint8_t* _to = reinterpret_cast<uint8_t*>(to);3499uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);3500uint8_t* _to_nxt = _to;3501result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3502frm_nxt = frm + (_frm_nxt - _frm);3503to_nxt = to + (_to_nxt - _to);3504return r;3505}35063507__codecvt_utf16<char32_t, false>::result __codecvt_utf16<char32_t, false>::do_in(3508state_type&,3509const extern_type* frm,3510const extern_type* frm_end,3511const extern_type*& frm_nxt,3512intern_type* to,3513intern_type* to_end,3514intern_type*& to_nxt) const {3515const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3516const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3517const uint8_t* _frm_nxt = _frm;3518uint32_t* _to = reinterpret_cast<uint32_t*>(to);3519uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);3520uint32_t* _to_nxt = _to;3521result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3522frm_nxt = frm + (_frm_nxt - _frm);3523to_nxt = to + (_to_nxt - _to);3524return r;3525}35263527__codecvt_utf16<char32_t, false>::result3528__codecvt_utf16<char32_t, false>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {3529to_nxt = to;3530return noconv;3531}35323533int __codecvt_utf16<char32_t, false>::do_encoding() const noexcept { return 0; }35343535bool __codecvt_utf16<char32_t, false>::do_always_noconv() const noexcept { return false; }35363537int __codecvt_utf16<char32_t, false>::do_length(3538state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {3539const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3540const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3541return utf16be_to_ucs4_length(_frm, _frm_end, mx, __maxcode_, __mode_);3542}35433544_LIBCPP_SUPPRESS_DEPRECATED_PUSH3545int __codecvt_utf16<char32_t, false>::do_max_length() const noexcept {3546if (__mode_ & consume_header)3547return 6;3548return 4;3549}3550_LIBCPP_SUPPRESS_DEPRECATED_POP35513552// __codecvt_utf16<char32_t, true>35533554__codecvt_utf16<char32_t, true>::result __codecvt_utf16<char32_t, true>::do_out(3555state_type&,3556const intern_type* frm,3557const intern_type* frm_end,3558const intern_type*& frm_nxt,3559extern_type* to,3560extern_type* to_end,3561extern_type*& to_nxt) const {3562const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);3563const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);3564const uint32_t* _frm_nxt = _frm;3565uint8_t* _to = reinterpret_cast<uint8_t*>(to);3566uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);3567uint8_t* _to_nxt = _to;3568result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3569frm_nxt = frm + (_frm_nxt - _frm);3570to_nxt = to + (_to_nxt - _to);3571return r;3572}35733574__codecvt_utf16<char32_t, true>::result __codecvt_utf16<char32_t, true>::do_in(3575state_type&,3576const extern_type* frm,3577const extern_type* frm_end,3578const extern_type*& frm_nxt,3579intern_type* to,3580intern_type* to_end,3581intern_type*& to_nxt) const {3582const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3583const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3584const uint8_t* _frm_nxt = _frm;3585uint32_t* _to = reinterpret_cast<uint32_t*>(to);3586uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);3587uint32_t* _to_nxt = _to;3588result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3589frm_nxt = frm + (_frm_nxt - _frm);3590to_nxt = to + (_to_nxt - _to);3591return r;3592}35933594__codecvt_utf16<char32_t, true>::result3595__codecvt_utf16<char32_t, true>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {3596to_nxt = to;3597return noconv;3598}35993600int __codecvt_utf16<char32_t, true>::do_encoding() const noexcept { return 0; }36013602bool __codecvt_utf16<char32_t, true>::do_always_noconv() const noexcept { return false; }36033604int __codecvt_utf16<char32_t, true>::do_length(3605state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {3606const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3607const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3608return utf16le_to_ucs4_length(_frm, _frm_end, mx, __maxcode_, __mode_);3609}36103611_LIBCPP_SUPPRESS_DEPRECATED_PUSH3612int __codecvt_utf16<char32_t, true>::do_max_length() const noexcept {3613if (__mode_ & consume_header)3614return 6;3615return 4;3616}3617_LIBCPP_SUPPRESS_DEPRECATED_POP36183619// __codecvt_utf8_utf16<wchar_t>36203621#if _LIBCPP_HAS_WIDE_CHARACTERS3622__codecvt_utf8_utf16<wchar_t>::result __codecvt_utf8_utf16<wchar_t>::do_out(3623state_type&,3624const intern_type* frm,3625const intern_type* frm_end,3626const intern_type*& frm_nxt,3627extern_type* to,3628extern_type* to_end,3629extern_type*& to_nxt) const {3630# if defined(_LIBCPP_SHORT_WCHAR)3631const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);3632const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);3633const uint16_t* _frm_nxt = _frm;3634# else3635const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);3636const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);3637const uint32_t* _frm_nxt = _frm;3638# endif3639uint8_t* _to = reinterpret_cast<uint8_t*>(to);3640uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);3641uint8_t* _to_nxt = _to;3642result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3643frm_nxt = frm + (_frm_nxt - _frm);3644to_nxt = to + (_to_nxt - _to);3645return r;3646}36473648__codecvt_utf8_utf16<wchar_t>::result __codecvt_utf8_utf16<wchar_t>::do_in(3649state_type&,3650const extern_type* frm,3651const extern_type* frm_end,3652const extern_type*& frm_nxt,3653intern_type* to,3654intern_type* to_end,3655intern_type*& to_nxt) const {3656const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3657const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3658const uint8_t* _frm_nxt = _frm;3659# if defined(_LIBCPP_SHORT_WCHAR)3660uint16_t* _to = reinterpret_cast<uint16_t*>(to);3661uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);3662uint16_t* _to_nxt = _to;3663# else3664uint32_t* _to = reinterpret_cast<uint32_t*>(to);3665uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);3666uint32_t* _to_nxt = _to;3667# endif3668result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3669frm_nxt = frm + (_frm_nxt - _frm);3670to_nxt = to + (_to_nxt - _to);3671return r;3672}36733674__codecvt_utf8_utf16<wchar_t>::result3675__codecvt_utf8_utf16<wchar_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {3676to_nxt = to;3677return noconv;3678}36793680int __codecvt_utf8_utf16<wchar_t>::do_encoding() const noexcept { return 0; }36813682bool __codecvt_utf8_utf16<wchar_t>::do_always_noconv() const noexcept { return false; }36833684int __codecvt_utf8_utf16<wchar_t>::do_length(3685state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {3686const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3687const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3688return utf8_to_utf16_length(_frm, _frm_end, mx, __maxcode_, __mode_);3689}36903691int __codecvt_utf8_utf16<wchar_t>::do_max_length() const noexcept {3692if (__mode_ & consume_header)3693return 7;3694return 4;3695}3696#endif // _LIBCPP_HAS_WIDE_CHARACTERS36973698// __codecvt_utf8_utf16<char16_t>36993700__codecvt_utf8_utf16<char16_t>::result __codecvt_utf8_utf16<char16_t>::do_out(3701state_type&,3702const intern_type* frm,3703const intern_type* frm_end,3704const intern_type*& frm_nxt,3705extern_type* to,3706extern_type* to_end,3707extern_type*& to_nxt) const {3708const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);3709const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);3710const uint16_t* _frm_nxt = _frm;3711uint8_t* _to = reinterpret_cast<uint8_t*>(to);3712uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);3713uint8_t* _to_nxt = _to;3714result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3715frm_nxt = frm + (_frm_nxt - _frm);3716to_nxt = to + (_to_nxt - _to);3717return r;3718}37193720__codecvt_utf8_utf16<char16_t>::result __codecvt_utf8_utf16<char16_t>::do_in(3721state_type&,3722const extern_type* frm,3723const extern_type* frm_end,3724const extern_type*& frm_nxt,3725intern_type* to,3726intern_type* to_end,3727intern_type*& to_nxt) const {3728const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3729const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3730const uint8_t* _frm_nxt = _frm;3731uint16_t* _to = reinterpret_cast<uint16_t*>(to);3732uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);3733uint16_t* _to_nxt = _to;3734result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3735frm_nxt = frm + (_frm_nxt - _frm);3736to_nxt = to + (_to_nxt - _to);3737return r;3738}37393740__codecvt_utf8_utf16<char16_t>::result3741__codecvt_utf8_utf16<char16_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {3742to_nxt = to;3743return noconv;3744}37453746int __codecvt_utf8_utf16<char16_t>::do_encoding() const noexcept { return 0; }37473748bool __codecvt_utf8_utf16<char16_t>::do_always_noconv() const noexcept { return false; }37493750int __codecvt_utf8_utf16<char16_t>::do_length(3751state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {3752const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3753const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3754return utf8_to_utf16_length(_frm, _frm_end, mx, __maxcode_, __mode_);3755}37563757_LIBCPP_SUPPRESS_DEPRECATED_PUSH3758int __codecvt_utf8_utf16<char16_t>::do_max_length() const noexcept {3759if (__mode_ & consume_header)3760return 7;3761return 4;3762}3763_LIBCPP_SUPPRESS_DEPRECATED_POP37643765// __codecvt_utf8_utf16<char32_t>37663767__codecvt_utf8_utf16<char32_t>::result __codecvt_utf8_utf16<char32_t>::do_out(3768state_type&,3769const intern_type* frm,3770const intern_type* frm_end,3771const intern_type*& frm_nxt,3772extern_type* to,3773extern_type* to_end,3774extern_type*& to_nxt) const {3775const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);3776const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);3777const uint32_t* _frm_nxt = _frm;3778uint8_t* _to = reinterpret_cast<uint8_t*>(to);3779uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);3780uint8_t* _to_nxt = _to;3781result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3782frm_nxt = frm + (_frm_nxt - _frm);3783to_nxt = to + (_to_nxt - _to);3784return r;3785}37863787__codecvt_utf8_utf16<char32_t>::result __codecvt_utf8_utf16<char32_t>::do_in(3788state_type&,3789const extern_type* frm,3790const extern_type* frm_end,3791const extern_type*& frm_nxt,3792intern_type* to,3793intern_type* to_end,3794intern_type*& to_nxt) const {3795const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3796const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3797const uint8_t* _frm_nxt = _frm;3798uint32_t* _to = reinterpret_cast<uint32_t*>(to);3799uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);3800uint32_t* _to_nxt = _to;3801result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt, __maxcode_, __mode_);3802frm_nxt = frm + (_frm_nxt - _frm);3803to_nxt = to + (_to_nxt - _to);3804return r;3805}38063807__codecvt_utf8_utf16<char32_t>::result3808__codecvt_utf8_utf16<char32_t>::do_unshift(state_type&, extern_type* to, extern_type*, extern_type*& to_nxt) const {3809to_nxt = to;3810return noconv;3811}38123813int __codecvt_utf8_utf16<char32_t>::do_encoding() const noexcept { return 0; }38143815bool __codecvt_utf8_utf16<char32_t>::do_always_noconv() const noexcept { return false; }38163817int __codecvt_utf8_utf16<char32_t>::do_length(3818state_type&, const extern_type* frm, const extern_type* frm_end, size_t mx) const {3819const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);3820const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);3821return utf8_to_utf16_length(_frm, _frm_end, mx, __maxcode_, __mode_);3822}38233824_LIBCPP_SUPPRESS_DEPRECATED_PUSH3825int __codecvt_utf8_utf16<char32_t>::do_max_length() const noexcept {3826if (__mode_ & consume_header)3827return 7;3828return 4;3829}3830_LIBCPP_SUPPRESS_DEPRECATED_POP38313832// __narrow_to_utf8<16>38333834__narrow_to_utf8<16>::~__narrow_to_utf8() {}38353836// __narrow_to_utf8<32>38373838__narrow_to_utf8<32>::~__narrow_to_utf8() {}38393840// __widen_from_utf8<16>38413842__widen_from_utf8<16>::~__widen_from_utf8() {}38433844// __widen_from_utf8<32>38453846__widen_from_utf8<32>::~__widen_from_utf8() {}38473848#if _LIBCPP_HAS_WIDE_CHARACTERS3849static bool checked_string_to_wchar_convert(wchar_t& dest, const char* ptr, __locale::__locale_t loc) {3850if (*ptr == '\0')3851return false;3852mbstate_t mb = {};3853wchar_t out;3854size_t ret = __locale::__mbrtowc(&out, ptr, strlen(ptr), &mb, loc);3855if (ret == static_cast<size_t>(-1) || ret == static_cast<size_t>(-2)) {3856return false;3857}3858dest = out;3859return true;3860}3861#endif // _LIBCPP_HAS_WIDE_CHARACTERS38623863#if !_LIBCPP_HAS_WIDE_CHARACTERS3864static bool is_narrow_non_breaking_space(const char* ptr) {3865// https://www.fileformat.info/info/unicode/char/202f/index.htm3866return ptr[0] == '\xe2' && ptr[1] == '\x80' && ptr[2] == '\xaf';3867}38683869static bool is_non_breaking_space(const char* ptr) {3870// https://www.fileformat.info/info/unicode/char/a0/index.htm3871return ptr[0] == '\xc2' && ptr[1] == '\xa0';3872}3873#endif // _LIBCPP_HAS_WIDE_CHARACTERS38743875static bool checked_string_to_char_convert(char& dest, const char* ptr, __locale::__locale_t __loc) {3876if (*ptr == '\0')3877return false;3878if (!ptr[1]) {3879dest = *ptr;3880return true;3881}38823883#if _LIBCPP_HAS_WIDE_CHARACTERS3884// First convert the MBS into a wide char then attempt to narrow it using3885// wctob_l.3886wchar_t wout;3887if (!checked_string_to_wchar_convert(wout, ptr, __loc))3888return false;3889int res;3890if ((res = __locale::__wctob(wout, __loc)) != char_traits<char>::eof()) {3891dest = res;3892return true;3893}3894// FIXME: Work around specific multibyte sequences that we can reasonably3895// translate into a different single byte.3896switch (wout) {3897case L'\u202F': // narrow non-breaking space3898case L'\u00A0': // non-breaking space3899dest = ' ';3900return true;3901default:3902return false;3903}3904#else // _LIBCPP_HAS_WIDE_CHARACTERS3905// FIXME: Work around specific multibyte sequences that we can reasonably3906// translate into a different single byte.3907if (is_narrow_non_breaking_space(ptr) || is_non_breaking_space(ptr)) {3908dest = ' ';3909return true;3910}39113912return false;3913#endif // _LIBCPP_HAS_WIDE_CHARACTERS3914__libcpp_unreachable();3915}39163917// numpunct<char> && numpunct<wchar_t>39183919constinit locale::id numpunct<char>::id;3920#if _LIBCPP_HAS_WIDE_CHARACTERS3921constinit locale::id numpunct<wchar_t>::id;3922#endif39233924numpunct<char>::numpunct(size_t refs) : locale::facet(refs), __decimal_point_('.'), __thousands_sep_(',') {}39253926#if _LIBCPP_HAS_WIDE_CHARACTERS3927numpunct<wchar_t>::numpunct(size_t refs) : locale::facet(refs), __decimal_point_(L'.'), __thousands_sep_(L',') {}3928#endif39293930numpunct<char>::~numpunct() {}39313932#if _LIBCPP_HAS_WIDE_CHARACTERS3933numpunct<wchar_t>::~numpunct() {}3934#endif39353936char numpunct< char >::do_decimal_point() const { return __decimal_point_; }3937#if _LIBCPP_HAS_WIDE_CHARACTERS3938wchar_t numpunct<wchar_t>::do_decimal_point() const { return __decimal_point_; }3939#endif39403941char numpunct< char >::do_thousands_sep() const { return __thousands_sep_; }3942#if _LIBCPP_HAS_WIDE_CHARACTERS3943wchar_t numpunct<wchar_t>::do_thousands_sep() const { return __thousands_sep_; }3944#endif39453946string numpunct< char >::do_grouping() const { return __grouping_; }3947#if _LIBCPP_HAS_WIDE_CHARACTERS3948string numpunct<wchar_t>::do_grouping() const { return __grouping_; }3949#endif39503951string numpunct< char >::do_truename() const { return "true"; }3952#if _LIBCPP_HAS_WIDE_CHARACTERS3953wstring numpunct<wchar_t>::do_truename() const { return L"true"; }3954#endif39553956string numpunct< char >::do_falsename() const { return "false"; }3957#if _LIBCPP_HAS_WIDE_CHARACTERS3958wstring numpunct<wchar_t>::do_falsename() const { return L"false"; }3959#endif39603961// numpunct_byname<char>39623963numpunct_byname<char>::numpunct_byname(const char* nm, size_t refs) : numpunct<char>(refs) { __init(nm); }39643965numpunct_byname<char>::numpunct_byname(const string& nm, size_t refs) : numpunct<char>(refs) { __init(nm.c_str()); }39663967numpunct_byname<char>::~numpunct_byname() {}39683969void numpunct_byname<char>::__init(const char* nm) {3970typedef numpunct<char> base;3971if (strcmp(nm, "C") != 0) {3972__libcpp_unique_locale loc(nm);3973if (!loc)3974std::__throw_runtime_error(3975("numpunct_byname<char>::numpunct_byname"3976" failed to construct for " +3977string(nm))3978.c_str());39793980__locale::__lconv_t* lc = __locale::__localeconv(loc.get());3981if (!checked_string_to_char_convert(__decimal_point_, lc->decimal_point, loc.get()))3982__decimal_point_ = base::do_decimal_point();3983if (!checked_string_to_char_convert(__thousands_sep_, lc->thousands_sep, loc.get()))3984__thousands_sep_ = base::do_thousands_sep();3985__grouping_ = lc->grouping;3986// localization for truename and falsename is not available3987}3988}39893990// numpunct_byname<wchar_t>39913992#if _LIBCPP_HAS_WIDE_CHARACTERS3993numpunct_byname<wchar_t>::numpunct_byname(const char* nm, size_t refs) : numpunct<wchar_t>(refs) { __init(nm); }39943995numpunct_byname<wchar_t>::numpunct_byname(const string& nm, size_t refs) : numpunct<wchar_t>(refs) {3996__init(nm.c_str());3997}39983999numpunct_byname<wchar_t>::~numpunct_byname() {}40004001void numpunct_byname<wchar_t>::__init(const char* nm) {4002if (strcmp(nm, "C") != 0) {4003__libcpp_unique_locale loc(nm);4004if (!loc)4005std::__throw_runtime_error(4006("numpunct_byname<wchar_t>::numpunct_byname"4007" failed to construct for " +4008string(nm))4009.c_str());40104011__locale::__lconv_t* lc = __locale::__localeconv(loc.get());4012checked_string_to_wchar_convert(__decimal_point_, lc->decimal_point, loc.get());4013checked_string_to_wchar_convert(__thousands_sep_, lc->thousands_sep, loc.get());4014__grouping_ = lc->grouping;4015// localization for truename and falsename is not available4016}4017}4018#endif // _LIBCPP_HAS_WIDE_CHARACTERS40194020// num_get helpers40214022int __num_get_base::__get_base(ios_base& iob) {4023ios_base::fmtflags __basefield = iob.flags() & ios_base::basefield;4024if (__basefield == ios_base::oct)4025return 8;4026else if (__basefield == ios_base::hex)4027return 16;4028else if (__basefield == 0)4029return 0;4030return 10;4031}40324033const char __num_get_base::__src[33] = "0123456789abcdefABCDEFxX+-pPiInN";40344035void __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end, ios_base::iostate& __err) {4036// if the grouping pattern is empty _or_ there are no grouping bits, then do nothing4037// we always have at least a single entry in [__g, __g_end); the end of the input sequence4038if (__grouping.size() != 0 && __g_end - __g > 1) {4039reverse(__g, __g_end);4040const char* __ig = __grouping.data();4041const char* __eg = __ig + __grouping.size();4042for (unsigned* __r = __g; __r < __g_end - 1; ++__r) {4043if (0 < *__ig && *__ig < numeric_limits<char>::max()) {4044if (static_cast<unsigned>(*__ig) != *__r) {4045__err = ios_base::failbit;4046return;4047}4048}4049if (__eg - __ig > 1)4050++__ig;4051}4052if (0 < *__ig && *__ig < numeric_limits<char>::max()) {4053if (static_cast<unsigned>(*__ig) < __g_end[-1] || __g_end[-1] == 0)4054__err = ios_base::failbit;4055}4056}4057}40584059void __num_put_base::__format_int(char* __fmtp, const char* __len, bool __signd, ios_base::fmtflags __flags) {4060if ((__flags & ios_base::showpos) && (__flags & ios_base::basefield) != ios_base::oct &&4061(__flags & ios_base::basefield) != ios_base::hex && __signd)4062*__fmtp++ = '+';4063if (__flags & ios_base::showbase)4064*__fmtp++ = '#';4065while (*__len)4066*__fmtp++ = *__len++;4067if ((__flags & ios_base::basefield) == ios_base::oct)4068*__fmtp = 'o';4069else if ((__flags & ios_base::basefield) == ios_base::hex) {4070if (__flags & ios_base::uppercase)4071*__fmtp = 'X';4072else4073*__fmtp = 'x';4074} else if (__signd)4075*__fmtp = 'd';4076else4077*__fmtp = 'u';4078}40794080bool __num_put_base::__format_float(char* __fmtp, const char* __len, ios_base::fmtflags __flags) {4081bool specify_precision = true;4082if (__flags & ios_base::showpos)4083*__fmtp++ = '+';4084if (__flags & ios_base::showpoint)4085*__fmtp++ = '#';4086ios_base::fmtflags floatfield = __flags & ios_base::floatfield;4087bool uppercase = (__flags & ios_base::uppercase) != 0;4088if (floatfield == (ios_base::fixed | ios_base::scientific))4089specify_precision = false;4090else {4091*__fmtp++ = '.';4092*__fmtp++ = '*';4093}4094while (*__len)4095*__fmtp++ = *__len++;4096if (floatfield == ios_base::fixed) {4097if (uppercase)4098*__fmtp = 'F';4099else4100*__fmtp = 'f';4101} else if (floatfield == ios_base::scientific) {4102if (uppercase)4103*__fmtp = 'E';4104else4105*__fmtp = 'e';4106} else if (floatfield == (ios_base::fixed | ios_base::scientific)) {4107if (uppercase)4108*__fmtp = 'A';4109else4110*__fmtp = 'a';4111} else {4112if (uppercase)4113*__fmtp = 'G';4114else4115*__fmtp = 'g';4116}4117return specify_precision;4118}41194120char* __num_put_base::__identify_padding(char* __nb, char* __ne, const ios_base& __iob) {4121switch (__iob.flags() & ios_base::adjustfield) {4122case ios_base::internal:4123if (__nb[0] == '-' || __nb[0] == '+')4124return __nb + 1;4125if (__ne - __nb >= 2 && __nb[0] == '0' && (__nb[1] == 'x' || __nb[1] == 'X'))4126return __nb + 2;4127break;4128case ios_base::left:4129return __ne;4130case ios_base::right:4131default:4132break;4133}4134return __nb;4135}41364137// time_get41384139static string* init_weeks() {4140static string weeks[14];4141weeks[0] = "Sunday";4142weeks[1] = "Monday";4143weeks[2] = "Tuesday";4144weeks[3] = "Wednesday";4145weeks[4] = "Thursday";4146weeks[5] = "Friday";4147weeks[6] = "Saturday";4148weeks[7] = "Sun";4149weeks[8] = "Mon";4150weeks[9] = "Tue";4151weeks[10] = "Wed";4152weeks[11] = "Thu";4153weeks[12] = "Fri";4154weeks[13] = "Sat";4155return weeks;4156}41574158#if _LIBCPP_HAS_WIDE_CHARACTERS4159static wstring* init_wweeks() {4160static wstring weeks[14];4161weeks[0] = L"Sunday";4162weeks[1] = L"Monday";4163weeks[2] = L"Tuesday";4164weeks[3] = L"Wednesday";4165weeks[4] = L"Thursday";4166weeks[5] = L"Friday";4167weeks[6] = L"Saturday";4168weeks[7] = L"Sun";4169weeks[8] = L"Mon";4170weeks[9] = L"Tue";4171weeks[10] = L"Wed";4172weeks[11] = L"Thu";4173weeks[12] = L"Fri";4174weeks[13] = L"Sat";4175return weeks;4176}4177#endif41784179template <>4180const string* __time_get_c_storage<char>::__weeks() const {4181static const string* weeks = init_weeks();4182return weeks;4183}41844185#if _LIBCPP_HAS_WIDE_CHARACTERS4186template <>4187const wstring* __time_get_c_storage<wchar_t>::__weeks() const {4188static const wstring* weeks = init_wweeks();4189return weeks;4190}4191#endif41924193static string* init_months() {4194static string months[24];4195months[0] = "January";4196months[1] = "February";4197months[2] = "March";4198months[3] = "April";4199months[4] = "May";4200months[5] = "June";4201months[6] = "July";4202months[7] = "August";4203months[8] = "September";4204months[9] = "October";4205months[10] = "November";4206months[11] = "December";4207months[12] = "Jan";4208months[13] = "Feb";4209months[14] = "Mar";4210months[15] = "Apr";4211months[16] = "May";4212months[17] = "Jun";4213months[18] = "Jul";4214months[19] = "Aug";4215months[20] = "Sep";4216months[21] = "Oct";4217months[22] = "Nov";4218months[23] = "Dec";4219return months;4220}42214222#if _LIBCPP_HAS_WIDE_CHARACTERS4223static wstring* init_wmonths() {4224static wstring months[24];4225months[0] = L"January";4226months[1] = L"February";4227months[2] = L"March";4228months[3] = L"April";4229months[4] = L"May";4230months[5] = L"June";4231months[6] = L"July";4232months[7] = L"August";4233months[8] = L"September";4234months[9] = L"October";4235months[10] = L"November";4236months[11] = L"December";4237months[12] = L"Jan";4238months[13] = L"Feb";4239months[14] = L"Mar";4240months[15] = L"Apr";4241months[16] = L"May";4242months[17] = L"Jun";4243months[18] = L"Jul";4244months[19] = L"Aug";4245months[20] = L"Sep";4246months[21] = L"Oct";4247months[22] = L"Nov";4248months[23] = L"Dec";4249return months;4250}4251#endif42524253template <>4254const string* __time_get_c_storage<char>::__months() const {4255static const string* months = init_months();4256return months;4257}42584259#if _LIBCPP_HAS_WIDE_CHARACTERS4260template <>4261const wstring* __time_get_c_storage<wchar_t>::__months() const {4262static const wstring* months = init_wmonths();4263return months;4264}4265#endif42664267static string* init_am_pm() {4268static string am_pm[2];4269am_pm[0] = "AM";4270am_pm[1] = "PM";4271return am_pm;4272}42734274#if _LIBCPP_HAS_WIDE_CHARACTERS4275static wstring* init_wam_pm() {4276static wstring am_pm[2];4277am_pm[0] = L"AM";4278am_pm[1] = L"PM";4279return am_pm;4280}4281#endif42824283template <>4284const string* __time_get_c_storage<char>::__am_pm() const {4285static const string* am_pm = init_am_pm();4286return am_pm;4287}42884289#if _LIBCPP_HAS_WIDE_CHARACTERS4290template <>4291const wstring* __time_get_c_storage<wchar_t>::__am_pm() const {4292static const wstring* am_pm = init_wam_pm();4293return am_pm;4294}4295#endif42964297template <>4298const string& __time_get_c_storage<char>::__x() const {4299static string s("%m/%d/%y");4300return s;4301}43024303#if _LIBCPP_HAS_WIDE_CHARACTERS4304template <>4305const wstring& __time_get_c_storage<wchar_t>::__x() const {4306static wstring s(L"%m/%d/%y");4307return s;4308}4309#endif43104311template <>4312const string& __time_get_c_storage<char>::__X() const {4313static string s("%H:%M:%S");4314return s;4315}43164317#if _LIBCPP_HAS_WIDE_CHARACTERS4318template <>4319const wstring& __time_get_c_storage<wchar_t>::__X() const {4320static wstring s(L"%H:%M:%S");4321return s;4322}4323#endif43244325template <>4326const string& __time_get_c_storage<char>::__c() const {4327static string s("%a %b %d %H:%M:%S %Y");4328return s;4329}43304331#if _LIBCPP_HAS_WIDE_CHARACTERS4332template <>4333const wstring& __time_get_c_storage<wchar_t>::__c() const {4334static wstring s(L"%a %b %d %H:%M:%S %Y");4335return s;4336}4337#endif43384339template <>4340const string& __time_get_c_storage<char>::__r() const {4341static string s("%I:%M:%S %p");4342return s;4343}43444345#if _LIBCPP_HAS_WIDE_CHARACTERS4346template <>4347const wstring& __time_get_c_storage<wchar_t>::__r() const {4348static wstring s(L"%I:%M:%S %p");4349return s;4350}4351#endif43524353// time_get_byname43544355__time_get::__time_get(const char* nm) : __loc_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm, 0)) {4356if (__loc_ == 0)4357std::__throw_runtime_error(("time_get_byname failed to construct for " + string(nm)).c_str());4358}43594360__time_get::__time_get(const string& nm) : __loc_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm.c_str(), 0)) {4361if (__loc_ == 0)4362std::__throw_runtime_error(("time_get_byname failed to construct for " + nm).c_str());4363}43644365__time_get::~__time_get() { __locale::__freelocale(__loc_); }43664367_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-field-initializers")43684369template <>4370string __time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct) {4371tm t = {0};4372t.tm_sec = 59;4373t.tm_min = 55;4374t.tm_hour = 23;4375t.tm_mday = 31;4376t.tm_mon = 11;4377t.tm_year = 161;4378t.tm_wday = 6;4379t.tm_yday = 364;4380t.tm_isdst = -1;4381char buf[100];4382char f[3] = {0};4383f[0] = '%';4384f[1] = fmt;4385size_t n = __locale::__strftime(buf, countof(buf), f, &t, __loc_);4386char* bb = buf;4387char* be = buf + n;4388string result;4389while (bb != be) {4390if (ct.is(ctype_base::space, *bb)) {4391result.push_back(' ');4392for (++bb; bb != be && ct.is(ctype_base::space, *bb); ++bb)4393;4394continue;4395}4396char* w = bb;4397ios_base::iostate err = ios_base::goodbit;4398ptrdiff_t i = __scan_keyword(w, be, this->__weeks_, this->__weeks_ + 14, ct, err, false) - this->__weeks_;4399if (i < 14) {4400result.push_back('%');4401if (i < 7)4402result.push_back('A');4403else4404result.push_back('a');4405bb = w;4406continue;4407}4408w = bb;4409i = __scan_keyword(w, be, this->__months_, this->__months_ + 24, ct, err, false) - this->__months_;4410if (i < 24) {4411result.push_back('%');4412if (i < 12)4413result.push_back('B');4414else4415result.push_back('b');4416if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))4417result.back() = 'm';4418bb = w;4419continue;4420}4421if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0) {4422w = bb;4423i = __scan_keyword(w, be, this->__am_pm_, this->__am_pm_ + 2, ct, err, false) - this->__am_pm_;4424if (i < 2) {4425result.push_back('%');4426result.push_back('p');4427bb = w;4428continue;4429}4430}4431w = bb;4432if (ct.is(ctype_base::digit, *bb)) {4433switch (__get_up_to_n_digits(bb, be, err, ct, 4)) {4434case 6:4435result.push_back('%');4436result.push_back('w');4437break;4438case 7:4439result.push_back('%');4440result.push_back('u');4441break;4442case 11:4443result.push_back('%');4444result.push_back('I');4445break;4446case 12:4447result.push_back('%');4448result.push_back('m');4449break;4450case 23:4451result.push_back('%');4452result.push_back('H');4453break;4454case 31:4455result.push_back('%');4456result.push_back('d');4457break;4458case 55:4459result.push_back('%');4460result.push_back('M');4461break;4462case 59:4463result.push_back('%');4464result.push_back('S');4465break;4466case 61:4467result.push_back('%');4468result.push_back('y');4469break;4470case 364:4471result.push_back('%');4472result.push_back('j');4473break;4474case 2061:4475result.push_back('%');4476result.push_back('Y');4477break;4478default:4479for (; w != bb; ++w)4480result.push_back(*w);4481break;4482}4483continue;4484}4485if (*bb == '%') {4486result.push_back('%');4487result.push_back('%');4488++bb;4489continue;4490}4491result.push_back(*bb);4492++bb;4493}4494return result;4495}44964497_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-braces")44984499#if _LIBCPP_HAS_WIDE_CHARACTERS4500template <>4501wstring __time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct) {4502tm t = {0};4503t.tm_sec = 59;4504t.tm_min = 55;4505t.tm_hour = 23;4506t.tm_mday = 31;4507t.tm_mon = 11;4508t.tm_year = 161;4509t.tm_wday = 6;4510t.tm_yday = 364;4511t.tm_isdst = -1;4512char buf[100];4513char f[3] = {0};4514f[0] = '%';4515f[1] = fmt;4516__locale::__strftime(buf, countof(buf), f, &t, __loc_);4517wchar_t wbuf[100];4518wchar_t* wbb = wbuf;4519mbstate_t mb = {0};4520const char* bb = buf;4521size_t j = __locale::__mbsrtowcs(wbb, &bb, countof(wbuf), &mb, __loc_);4522if (j == size_t(-1))4523std::__throw_runtime_error("locale not supported");4524wchar_t* wbe = wbb + j;4525wstring result;4526while (wbb != wbe) {4527if (ct.is(ctype_base::space, *wbb)) {4528result.push_back(L' ');4529for (++wbb; wbb != wbe && ct.is(ctype_base::space, *wbb); ++wbb)4530;4531continue;4532}4533wchar_t* w = wbb;4534ios_base::iostate err = ios_base::goodbit;4535ptrdiff_t i = __scan_keyword(w, wbe, this->__weeks_, this->__weeks_ + 14, ct, err, false) - this->__weeks_;4536if (i < 14) {4537result.push_back(L'%');4538if (i < 7)4539result.push_back(L'A');4540else4541result.push_back(L'a');4542wbb = w;4543continue;4544}4545w = wbb;4546i = __scan_keyword(w, wbe, this->__months_, this->__months_ + 24, ct, err, false) - this->__months_;4547if (i < 24) {4548result.push_back(L'%');4549if (i < 12)4550result.push_back(L'B');4551else4552result.push_back(L'b');4553if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))4554result.back() = L'm';4555wbb = w;4556continue;4557}4558if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0) {4559w = wbb;4560i = __scan_keyword(w, wbe, this->__am_pm_, this->__am_pm_ + 2, ct, err, false) - this->__am_pm_;4561if (i < 2) {4562result.push_back(L'%');4563result.push_back(L'p');4564wbb = w;4565continue;4566}4567}4568w = wbb;4569if (ct.is(ctype_base::digit, *wbb)) {4570switch (__get_up_to_n_digits(wbb, wbe, err, ct, 4)) {4571case 6:4572result.push_back(L'%');4573result.push_back(L'w');4574break;4575case 7:4576result.push_back(L'%');4577result.push_back(L'u');4578break;4579case 11:4580result.push_back(L'%');4581result.push_back(L'I');4582break;4583case 12:4584result.push_back(L'%');4585result.push_back(L'm');4586break;4587case 23:4588result.push_back(L'%');4589result.push_back(L'H');4590break;4591case 31:4592result.push_back(L'%');4593result.push_back(L'd');4594break;4595case 55:4596result.push_back(L'%');4597result.push_back(L'M');4598break;4599case 59:4600result.push_back(L'%');4601result.push_back(L'S');4602break;4603case 61:4604result.push_back(L'%');4605result.push_back(L'y');4606break;4607case 364:4608result.push_back(L'%');4609result.push_back(L'j');4610break;4611case 2061:4612result.push_back(L'%');4613result.push_back(L'Y');4614break;4615default:4616for (; w != wbb; ++w)4617result.push_back(*w);4618break;4619}4620continue;4621}4622if (ct.narrow(*wbb, 0) == '%') {4623result.push_back(L'%');4624result.push_back(L'%');4625++wbb;4626continue;4627}4628result.push_back(*wbb);4629++wbb;4630}4631return result;4632}4633#endif // _LIBCPP_HAS_WIDE_CHARACTERS46344635template <>4636void __time_get_storage<char>::init(const ctype<char>& ct) {4637tm t = {0};4638char buf[100];4639// __weeks_4640for (int i = 0; i < 7; ++i) {4641t.tm_wday = i;4642__locale::__strftime(buf, countof(buf), "%A", &t, __loc_);4643__weeks_[i] = buf;4644__locale::__strftime(buf, countof(buf), "%a", &t, __loc_);4645__weeks_[i + 7] = buf;4646}4647// __months_4648for (int i = 0; i < 12; ++i) {4649t.tm_mon = i;4650__locale::__strftime(buf, countof(buf), "%B", &t, __loc_);4651__months_[i] = buf;4652__locale::__strftime(buf, countof(buf), "%b", &t, __loc_);4653__months_[i + 12] = buf;4654}4655// __am_pm_4656t.tm_hour = 1;4657__locale::__strftime(buf, countof(buf), "%p", &t, __loc_);4658__am_pm_[0] = buf;4659t.tm_hour = 13;4660__locale::__strftime(buf, countof(buf), "%p", &t, __loc_);4661__am_pm_[1] = buf;4662__c_ = __analyze('c', ct);4663__r_ = __analyze('r', ct);4664__x_ = __analyze('x', ct);4665__X_ = __analyze('X', ct);4666}46674668#if _LIBCPP_HAS_WIDE_CHARACTERS4669template <>4670void __time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct) {4671tm t = {0};4672char buf[100];4673wchar_t wbuf[100];4674wchar_t* wbe;4675mbstate_t mb = {0};4676// __weeks_4677for (int i = 0; i < 7; ++i) {4678t.tm_wday = i;4679__locale::__strftime(buf, countof(buf), "%A", &t, __loc_);4680mb = mbstate_t();4681const char* bb = buf;4682size_t j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);4683if (j == size_t(-1) || j == 0)4684std::__throw_runtime_error("locale not supported");4685wbe = wbuf + j;4686__weeks_[i].assign(wbuf, wbe);4687__locale::__strftime(buf, countof(buf), "%a", &t, __loc_);4688mb = mbstate_t();4689bb = buf;4690j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);4691if (j == size_t(-1) || j == 0)4692std::__throw_runtime_error("locale not supported");4693wbe = wbuf + j;4694__weeks_[i + 7].assign(wbuf, wbe);4695}4696// __months_4697for (int i = 0; i < 12; ++i) {4698t.tm_mon = i;4699__locale::__strftime(buf, countof(buf), "%B", &t, __loc_);4700mb = mbstate_t();4701const char* bb = buf;4702size_t j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);4703if (j == size_t(-1) || j == 0)4704std::__throw_runtime_error("locale not supported");4705wbe = wbuf + j;4706__months_[i].assign(wbuf, wbe);4707__locale::__strftime(buf, countof(buf), "%b", &t, __loc_);4708mb = mbstate_t();4709bb = buf;4710j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);4711if (j == size_t(-1) || j == 0)4712std::__throw_runtime_error("locale not supported");4713wbe = wbuf + j;4714__months_[i + 12].assign(wbuf, wbe);4715}4716// __am_pm_4717t.tm_hour = 1;4718__locale::__strftime(buf, countof(buf), "%p", &t, __loc_);4719mb = mbstate_t();4720const char* bb = buf;4721size_t j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);4722if (j == size_t(-1))4723std::__throw_runtime_error("locale not supported");4724wbe = wbuf + j;4725__am_pm_[0].assign(wbuf, wbe);4726t.tm_hour = 13;4727__locale::__strftime(buf, countof(buf), "%p", &t, __loc_);4728mb = mbstate_t();4729bb = buf;4730j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, __loc_);4731if (j == size_t(-1))4732std::__throw_runtime_error("locale not supported");4733wbe = wbuf + j;4734__am_pm_[1].assign(wbuf, wbe);4735__c_ = __analyze('c', ct);4736__r_ = __analyze('r', ct);4737__x_ = __analyze('x', ct);4738__X_ = __analyze('X', ct);4739}4740#endif // _LIBCPP_HAS_WIDE_CHARACTERS47414742template <class CharT>4743struct _LIBCPP_HIDDEN __time_get_temp : public ctype_byname<CharT> {4744explicit __time_get_temp(const char* nm) : ctype_byname<CharT>(nm, 1) {}4745explicit __time_get_temp(const string& nm) : ctype_byname<CharT>(nm, 1) {}4746};47474748template <>4749__time_get_storage<char>::__time_get_storage(const char* __nm) : __time_get(__nm) {4750const __time_get_temp<char> ct(__nm);4751init(ct);4752}47534754template <>4755__time_get_storage<char>::__time_get_storage(const string& __nm) : __time_get(__nm) {4756const __time_get_temp<char> ct(__nm);4757init(ct);4758}47594760#if _LIBCPP_HAS_WIDE_CHARACTERS4761template <>4762__time_get_storage<wchar_t>::__time_get_storage(const char* __nm) : __time_get(__nm) {4763const __time_get_temp<wchar_t> ct(__nm);4764init(ct);4765}47664767template <>4768__time_get_storage<wchar_t>::__time_get_storage(const string& __nm) : __time_get(__nm) {4769const __time_get_temp<wchar_t> ct(__nm);4770init(ct);4771}4772#endif // _LIBCPP_HAS_WIDE_CHARACTERS47734774template <>4775time_base::dateorder __time_get_storage<char>::__do_date_order() const {4776unsigned i;4777for (i = 0; i < __x_.size(); ++i)4778if (__x_[i] == '%')4779break;4780++i;4781switch (__x_[i]) {4782case 'y':4783case 'Y':4784for (++i; i < __x_.size(); ++i)4785if (__x_[i] == '%')4786break;4787if (i == __x_.size())4788break;4789++i;4790switch (__x_[i]) {4791case 'm':4792for (++i; i < __x_.size(); ++i)4793if (__x_[i] == '%')4794break;4795if (i == __x_.size())4796break;4797++i;4798if (__x_[i] == 'd')4799return time_base::ymd;4800break;4801case 'd':4802for (++i; i < __x_.size(); ++i)4803if (__x_[i] == '%')4804break;4805if (i == __x_.size())4806break;4807++i;4808if (__x_[i] == 'm')4809return time_base::ydm;4810break;4811}4812break;4813case 'm':4814for (++i; i < __x_.size(); ++i)4815if (__x_[i] == '%')4816break;4817if (i == __x_.size())4818break;4819++i;4820if (__x_[i] == 'd') {4821for (++i; i < __x_.size(); ++i)4822if (__x_[i] == '%')4823break;4824if (i == __x_.size())4825break;4826++i;4827if (__x_[i] == 'y' || __x_[i] == 'Y')4828return time_base::mdy;4829break;4830}4831break;4832case 'd':4833for (++i; i < __x_.size(); ++i)4834if (__x_[i] == '%')4835break;4836if (i == __x_.size())4837break;4838++i;4839if (__x_[i] == 'm') {4840for (++i; i < __x_.size(); ++i)4841if (__x_[i] == '%')4842break;4843if (i == __x_.size())4844break;4845++i;4846if (__x_[i] == 'y' || __x_[i] == 'Y')4847return time_base::dmy;4848break;4849}4850break;4851}4852return time_base::no_order;4853}48544855#if _LIBCPP_HAS_WIDE_CHARACTERS4856template <>4857time_base::dateorder __time_get_storage<wchar_t>::__do_date_order() const {4858unsigned i;4859for (i = 0; i < __x_.size(); ++i)4860if (__x_[i] == L'%')4861break;4862++i;4863switch (__x_[i]) {4864case L'y':4865case L'Y':4866for (++i; i < __x_.size(); ++i)4867if (__x_[i] == L'%')4868break;4869if (i == __x_.size())4870break;4871++i;4872switch (__x_[i]) {4873case L'm':4874for (++i; i < __x_.size(); ++i)4875if (__x_[i] == L'%')4876break;4877if (i == __x_.size())4878break;4879++i;4880if (__x_[i] == L'd')4881return time_base::ymd;4882break;4883case L'd':4884for (++i; i < __x_.size(); ++i)4885if (__x_[i] == L'%')4886break;4887if (i == __x_.size())4888break;4889++i;4890if (__x_[i] == L'm')4891return time_base::ydm;4892break;4893}4894break;4895case L'm':4896for (++i; i < __x_.size(); ++i)4897if (__x_[i] == L'%')4898break;4899if (i == __x_.size())4900break;4901++i;4902if (__x_[i] == L'd') {4903for (++i; i < __x_.size(); ++i)4904if (__x_[i] == L'%')4905break;4906if (i == __x_.size())4907break;4908++i;4909if (__x_[i] == L'y' || __x_[i] == L'Y')4910return time_base::mdy;4911break;4912}4913break;4914case L'd':4915for (++i; i < __x_.size(); ++i)4916if (__x_[i] == L'%')4917break;4918if (i == __x_.size())4919break;4920++i;4921if (__x_[i] == L'm') {4922for (++i; i < __x_.size(); ++i)4923if (__x_[i] == L'%')4924break;4925if (i == __x_.size())4926break;4927++i;4928if (__x_[i] == L'y' || __x_[i] == L'Y')4929return time_base::dmy;4930break;4931}4932break;4933}4934return time_base::no_order;4935}4936#endif // _LIBCPP_HAS_WIDE_CHARACTERS49374938// time_put49394940__time_put::__time_put(const char* nm) : __loc_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm, 0)) {4941if (__loc_ == 0)4942std::__throw_runtime_error(("time_put_byname failed to construct for " + string(nm)).c_str());4943}49444945__time_put::__time_put(const string& nm) : __loc_(__locale::__newlocale(_LIBCPP_ALL_MASK, nm.c_str(), 0)) {4946if (__loc_ == 0)4947std::__throw_runtime_error(("time_put_byname failed to construct for " + nm).c_str());4948}49494950__time_put::~__time_put() {4951if (__loc_ != _LIBCPP_GET_C_LOCALE)4952__locale::__freelocale(__loc_);4953}49544955void __time_put::__do_put(char* __nb, char*& __ne, const tm* __tm, char __fmt, char __mod) const {4956char fmt[] = {'%', __fmt, __mod, 0};4957if (__mod != 0)4958swap(fmt[1], fmt[2]);4959size_t n = __locale::__strftime(__nb, countof(__nb, __ne), fmt, __tm, __loc_);4960__ne = __nb + n;4961}49624963#if _LIBCPP_HAS_WIDE_CHARACTERS4964void __time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm, char __fmt, char __mod) const {4965char __nar[100];4966char* __ne = __nar + 100;4967__do_put(__nar, __ne, __tm, __fmt, __mod);4968mbstate_t mb = {0};4969const char* __nb = __nar;4970size_t j = __locale::__mbsrtowcs(__wb, &__nb, countof(__wb, __we), &mb, __loc_);4971if (j == size_t(-1))4972std::__throw_runtime_error("locale not supported");4973__we = __wb + j;4974}4975#endif // _LIBCPP_HAS_WIDE_CHARACTERS49764977// moneypunct_byname49784979template <class charT>4980static void __init_pat(4981money_base::pattern& pat,4982basic_string<charT>& __curr_symbol_,4983bool intl,4984char cs_precedes,4985char sep_by_space,4986char sign_posn,4987charT space_char) {4988const char sign = static_cast<char>(money_base::sign);4989const char space = static_cast<char>(money_base::space);4990const char none = static_cast<char>(money_base::none);4991const char symbol = static_cast<char>(money_base::symbol);4992const char value = static_cast<char>(money_base::value);4993const bool symbol_contains_sep = intl && __curr_symbol_.size() == 4;49944995// Comments on case branches reflect 'C11 7.11.2.1 The localeconv4996// function'. "Space between sign and symbol or value" means that4997// if the sign is adjacent to the symbol, there's a space between4998// them, and otherwise there's a space between the sign and value.4999//5000// C11's localeconv specifies that the fourth character of an5001// international curr_symbol is used to separate the sign and5002// value when sep_by_space says to do so. C++ can't represent5003// that, so we just use a space. When sep_by_space says to5004// separate the symbol and value-or-sign with a space, we rearrange the5005// curr_symbol to put its spacing character on the correct side of5006// the symbol.5007//5008// We also need to avoid adding an extra space between the sign5009// and value when the currency symbol is suppressed (by not5010// setting showbase). We match glibc's strfmon by interpreting5011// sep_by_space==1 as "omit the space when the currency symbol is5012// absent".5013//5014// Users who want to get this right should use ICU instead.50155016switch (cs_precedes) {5017case 0: // value before curr_symbol5018if (symbol_contains_sep) {5019// Move the separator to before the symbol, to place it5020// between the value and symbol.5021rotate(__curr_symbol_.begin(), __curr_symbol_.begin() + 3, __curr_symbol_.end());5022}5023switch (sign_posn) {5024case 0: // Parentheses surround the quantity and currency symbol.5025pat.field[0] = sign;5026pat.field[1] = value;5027pat.field[2] = none; // Any space appears in the symbol.5028pat.field[3] = symbol;5029switch (sep_by_space) {5030case 0: // No space separates the currency symbol and value.5031// This case may have changed between C99 and C11;5032// assume the currency symbol matches the intention.5033case 2: // Space between sign and currency or value.5034// The "sign" is two parentheses, so no space here either.5035return;5036case 1: // Space between currency-and-sign or currency and value.5037if (!symbol_contains_sep) {5038// We insert the space into the symbol instead of5039// setting pat.field[2]=space so that when5040// showbase is not set, the space goes away too.5041__curr_symbol_.insert(0, 1, space_char);5042}5043return;5044default:5045break;5046}5047break;5048case 1: // The sign string precedes the quantity and currency symbol.5049pat.field[0] = sign;5050pat.field[3] = symbol;5051switch (sep_by_space) {5052case 0: // No space separates the currency symbol and value.5053pat.field[1] = value;5054pat.field[2] = none;5055return;5056case 1: // Space between currency-and-sign or currency and value.5057pat.field[1] = value;5058pat.field[2] = none;5059if (!symbol_contains_sep) {5060// We insert the space into the symbol instead of5061// setting pat.field[2]=space so that when5062// showbase is not set, the space goes away too.5063__curr_symbol_.insert(0, 1, space_char);5064}5065return;5066case 2: // Space between sign and currency or value.5067pat.field[1] = space;5068pat.field[2] = value;5069if (symbol_contains_sep) {5070// Remove the separator from the symbol, since it5071// has already appeared after the sign.5072__curr_symbol_.erase(__curr_symbol_.begin());5073}5074return;5075default:5076break;5077}5078break;5079case 2: // The sign string succeeds the quantity and currency symbol.5080pat.field[0] = value;5081pat.field[3] = sign;5082switch (sep_by_space) {5083case 0: // No space separates the currency symbol and value.5084pat.field[1] = none;5085pat.field[2] = symbol;5086return;5087case 1: // Space between currency-and-sign or currency and value.5088if (!symbol_contains_sep) {5089// We insert the space into the symbol instead of5090// setting pat.field[1]=space so that when5091// showbase is not set, the space goes away too.5092__curr_symbol_.insert(0, 1, space_char);5093}5094pat.field[1] = none;5095pat.field[2] = symbol;5096return;5097case 2: // Space between sign and currency or value.5098pat.field[1] = symbol;5099pat.field[2] = space;5100if (symbol_contains_sep) {5101// Remove the separator from the symbol, since it5102// should not be removed if showbase is absent.5103__curr_symbol_.erase(__curr_symbol_.begin());5104}5105return;5106default:5107break;5108}5109break;5110case 3: // The sign string immediately precedes the currency symbol.5111pat.field[0] = value;5112pat.field[3] = symbol;5113switch (sep_by_space) {5114case 0: // No space separates the currency symbol and value.5115pat.field[1] = none;5116pat.field[2] = sign;5117return;5118case 1: // Space between currency-and-sign or currency and value.5119pat.field[1] = space;5120pat.field[2] = sign;5121if (symbol_contains_sep) {5122// Remove the separator from the symbol, since it5123// has already appeared before the sign.5124__curr_symbol_.erase(__curr_symbol_.begin());5125}5126return;5127case 2: // Space between sign and currency or value.5128pat.field[1] = sign;5129pat.field[2] = none;5130if (!symbol_contains_sep) {5131// We insert the space into the symbol instead of5132// setting pat.field[2]=space so that when5133// showbase is not set, the space goes away too.5134__curr_symbol_.insert(0, 1, space_char);5135}5136return;5137default:5138break;5139}5140break;5141case 4: // The sign string immediately succeeds the currency symbol.5142pat.field[0] = value;5143pat.field[3] = sign;5144switch (sep_by_space) {5145case 0: // No space separates the currency symbol and value.5146pat.field[1] = none;5147pat.field[2] = symbol;5148return;5149case 1: // Space between currency-and-sign or currency and value.5150pat.field[1] = none;5151pat.field[2] = symbol;5152if (!symbol_contains_sep) {5153// We insert the space into the symbol instead of5154// setting pat.field[1]=space so that when5155// showbase is not set, the space goes away too.5156__curr_symbol_.insert(0, 1, space_char);5157}5158return;5159case 2: // Space between sign and currency or value.5160pat.field[1] = symbol;5161pat.field[2] = space;5162if (symbol_contains_sep) {5163// Remove the separator from the symbol, since it5164// should not disappear when showbase is absent.5165__curr_symbol_.erase(__curr_symbol_.begin());5166}5167return;5168default:5169break;5170}5171break;5172default:5173break;5174}5175break;5176case 1: // curr_symbol before value5177switch (sign_posn) {5178case 0: // Parentheses surround the quantity and currency symbol.5179pat.field[0] = sign;5180pat.field[1] = symbol;5181pat.field[2] = none; // Any space appears in the symbol.5182pat.field[3] = value;5183switch (sep_by_space) {5184case 0: // No space separates the currency symbol and value.5185// This case may have changed between C99 and C11;5186// assume the currency symbol matches the intention.5187case 2: // Space between sign and currency or value.5188// The "sign" is two parentheses, so no space here either.5189return;5190case 1: // Space between currency-and-sign or currency and value.5191if (!symbol_contains_sep) {5192// We insert the space into the symbol instead of5193// setting pat.field[2]=space so that when5194// showbase is not set, the space goes away too.5195__curr_symbol_.insert(0, 1, space_char);5196}5197return;5198default:5199break;5200}5201break;5202case 1: // The sign string precedes the quantity and currency symbol.5203pat.field[0] = sign;5204pat.field[3] = value;5205switch (sep_by_space) {5206case 0: // No space separates the currency symbol and value.5207pat.field[1] = symbol;5208pat.field[2] = none;5209return;5210case 1: // Space between currency-and-sign or currency and value.5211pat.field[1] = symbol;5212pat.field[2] = none;5213if (!symbol_contains_sep) {5214// We insert the space into the symbol instead of5215// setting pat.field[2]=space so that when5216// showbase is not set, the space goes away too.5217__curr_symbol_.push_back(space_char);5218}5219return;5220case 2: // Space between sign and currency or value.5221pat.field[1] = space;5222pat.field[2] = symbol;5223if (symbol_contains_sep) {5224// Remove the separator from the symbol, since it5225// has already appeared after the sign.5226__curr_symbol_.pop_back();5227}5228return;5229default:5230break;5231}5232break;5233case 2: // The sign string succeeds the quantity and currency symbol.5234pat.field[0] = symbol;5235pat.field[3] = sign;5236switch (sep_by_space) {5237case 0: // No space separates the currency symbol and value.5238pat.field[1] = none;5239pat.field[2] = value;5240return;5241case 1: // Space between currency-and-sign or currency and value.5242pat.field[1] = none;5243pat.field[2] = value;5244if (!symbol_contains_sep) {5245// We insert the space into the symbol instead of5246// setting pat.field[1]=space so that when5247// showbase is not set, the space goes away too.5248__curr_symbol_.push_back(space_char);5249}5250return;5251case 2: // Space between sign and currency or value.5252pat.field[1] = value;5253pat.field[2] = space;5254if (symbol_contains_sep) {5255// Remove the separator from the symbol, since it5256// will appear before the sign.5257__curr_symbol_.pop_back();5258}5259return;5260default:5261break;5262}5263break;5264case 3: // The sign string immediately precedes the currency symbol.5265pat.field[0] = sign;5266pat.field[3] = value;5267switch (sep_by_space) {5268case 0: // No space separates the currency symbol and value.5269pat.field[1] = symbol;5270pat.field[2] = none;5271return;5272case 1: // Space between currency-and-sign or currency and value.5273pat.field[1] = symbol;5274pat.field[2] = none;5275if (!symbol_contains_sep) {5276// We insert the space into the symbol instead of5277// setting pat.field[2]=space so that when5278// showbase is not set, the space goes away too.5279__curr_symbol_.push_back(space_char);5280}5281return;5282case 2: // Space between sign and currency or value.5283pat.field[1] = space;5284pat.field[2] = symbol;5285if (symbol_contains_sep) {5286// Remove the separator from the symbol, since it5287// has already appeared after the sign.5288__curr_symbol_.pop_back();5289}5290return;5291default:5292break;5293}5294break;5295case 4: // The sign string immediately succeeds the currency symbol.5296pat.field[0] = symbol;5297pat.field[3] = value;5298switch (sep_by_space) {5299case 0: // No space separates the currency symbol and value.5300pat.field[1] = sign;5301pat.field[2] = none;5302return;5303case 1: // Space between currency-and-sign or currency and value.5304pat.field[1] = sign;5305pat.field[2] = space;5306if (symbol_contains_sep) {5307// Remove the separator from the symbol, since it5308// should not disappear when showbase is absent.5309__curr_symbol_.pop_back();5310}5311return;5312case 2: // Space between sign and currency or value.5313pat.field[1] = none;5314pat.field[2] = sign;5315if (!symbol_contains_sep) {5316// We insert the space into the symbol instead of5317// setting pat.field[1]=space so that when5318// showbase is not set, the space goes away too.5319__curr_symbol_.push_back(space_char);5320}5321return;5322default:5323break;5324}5325break;5326default:5327break;5328}5329break;5330default:5331break;5332}5333pat.field[0] = symbol;5334pat.field[1] = sign;5335pat.field[2] = none;5336pat.field[3] = value;5337}53385339template <>5340void moneypunct_byname<char, false>::init(const char* nm) {5341typedef moneypunct<char, false> base;5342__libcpp_unique_locale loc(nm);5343if (!loc)5344std::__throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());53455346__locale::__lconv_t* lc = __locale::__localeconv(loc.get());5347if (!checked_string_to_char_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))5348__decimal_point_ = base::do_decimal_point();5349if (!checked_string_to_char_convert(__thousands_sep_, lc->mon_thousands_sep, loc.get()))5350__thousands_sep_ = base::do_thousands_sep();53515352__grouping_ = lc->mon_grouping;5353__curr_symbol_ = lc->currency_symbol;5354if (lc->frac_digits != CHAR_MAX)5355__frac_digits_ = lc->frac_digits;5356else5357__frac_digits_ = base::do_frac_digits();5358if (lc->p_sign_posn == 0)5359__positive_sign_ = "()";5360else5361__positive_sign_ = lc->positive_sign;5362if (lc->n_sign_posn == 0)5363__negative_sign_ = "()";5364else5365__negative_sign_ = lc->negative_sign;5366// Assume the positive and negative formats will want spaces in5367// the same places in curr_symbol since there's no way to5368// represent anything else.5369string_type __dummy_curr_symbol = __curr_symbol_;5370__init_pat(__pos_format_, __dummy_curr_symbol, false, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');5371__init_pat(__neg_format_, __curr_symbol_, false, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');5372}53735374template <>5375void moneypunct_byname<char, true>::init(const char* nm) {5376typedef moneypunct<char, true> base;5377__libcpp_unique_locale loc(nm);5378if (!loc)5379std::__throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());53805381__locale::__lconv_t* lc = __locale::__localeconv(loc.get());5382if (!checked_string_to_char_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))5383__decimal_point_ = base::do_decimal_point();5384if (!checked_string_to_char_convert(__thousands_sep_, lc->mon_thousands_sep, loc.get()))5385__thousands_sep_ = base::do_thousands_sep();5386__grouping_ = lc->mon_grouping;5387__curr_symbol_ = lc->int_curr_symbol;5388if (lc->int_frac_digits != CHAR_MAX)5389__frac_digits_ = lc->int_frac_digits;5390else5391__frac_digits_ = base::do_frac_digits();5392#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)5393if (lc->p_sign_posn == 0)5394#else // _LIBCPP_MSVCRT5395if (lc->int_p_sign_posn == 0)5396#endif // !_LIBCPP_MSVCRT5397__positive_sign_ = "()";5398else5399__positive_sign_ = lc->positive_sign;5400#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)5401if (lc->n_sign_posn == 0)5402#else // _LIBCPP_MSVCRT5403if (lc->int_n_sign_posn == 0)5404#endif // !_LIBCPP_MSVCRT5405__negative_sign_ = "()";5406else5407__negative_sign_ = lc->negative_sign;5408// Assume the positive and negative formats will want spaces in5409// the same places in curr_symbol since there's no way to5410// represent anything else.5411string_type __dummy_curr_symbol = __curr_symbol_;5412#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)5413__init_pat(__pos_format_, __dummy_curr_symbol, true, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');5414__init_pat(__neg_format_, __curr_symbol_, true, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');5415#else // _LIBCPP_MSVCRT5416__init_pat(5417__pos_format_,5418__dummy_curr_symbol,5419true,5420lc->int_p_cs_precedes,5421lc->int_p_sep_by_space,5422lc->int_p_sign_posn,5423' ');5424__init_pat(5425__neg_format_, __curr_symbol_, true, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn, ' ');5426#endif // !_LIBCPP_MSVCRT5427}54285429#if _LIBCPP_HAS_WIDE_CHARACTERS5430template <>5431void moneypunct_byname<wchar_t, false>::init(const char* nm) {5432typedef moneypunct<wchar_t, false> base;5433__libcpp_unique_locale loc(nm);5434if (!loc)5435std::__throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());5436__locale::__lconv_t* lc = __locale::__localeconv(loc.get());5437if (!checked_string_to_wchar_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))5438__decimal_point_ = base::do_decimal_point();5439if (!checked_string_to_wchar_convert(__thousands_sep_, lc->mon_thousands_sep, loc.get()))5440__thousands_sep_ = base::do_thousands_sep();5441__grouping_ = lc->mon_grouping;5442wchar_t wbuf[100];5443mbstate_t mb = {0};5444const char* bb = lc->currency_symbol;5445size_t j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());5446if (j == size_t(-1))5447std::__throw_runtime_error("locale not supported");5448wchar_t* wbe = wbuf + j;5449__curr_symbol_.assign(wbuf, wbe);5450if (lc->frac_digits != CHAR_MAX)5451__frac_digits_ = lc->frac_digits;5452else5453__frac_digits_ = base::do_frac_digits();5454if (lc->p_sign_posn == 0)5455__positive_sign_ = L"()";5456else {5457mb = mbstate_t();5458bb = lc->positive_sign;5459j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());5460if (j == size_t(-1))5461std::__throw_runtime_error("locale not supported");5462wbe = wbuf + j;5463__positive_sign_.assign(wbuf, wbe);5464}5465if (lc->n_sign_posn == 0)5466__negative_sign_ = L"()";5467else {5468mb = mbstate_t();5469bb = lc->negative_sign;5470j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());5471if (j == size_t(-1))5472std::__throw_runtime_error("locale not supported");5473wbe = wbuf + j;5474__negative_sign_.assign(wbuf, wbe);5475}5476// Assume the positive and negative formats will want spaces in5477// the same places in curr_symbol since there's no way to5478// represent anything else.5479string_type __dummy_curr_symbol = __curr_symbol_;5480__init_pat(__pos_format_, __dummy_curr_symbol, false, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');5481__init_pat(__neg_format_, __curr_symbol_, false, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');5482}54835484template <>5485void moneypunct_byname<wchar_t, true>::init(const char* nm) {5486typedef moneypunct<wchar_t, true> base;5487__libcpp_unique_locale loc(nm);5488if (!loc)5489std::__throw_runtime_error(("moneypunct_byname failed to construct for " + string(nm)).c_str());54905491__locale::__lconv_t* lc = __locale::__localeconv(loc.get());5492if (!checked_string_to_wchar_convert(__decimal_point_, lc->mon_decimal_point, loc.get()))5493__decimal_point_ = base::do_decimal_point();5494if (!checked_string_to_wchar_convert(__thousands_sep_, lc->mon_thousands_sep, loc.get()))5495__thousands_sep_ = base::do_thousands_sep();5496__grouping_ = lc->mon_grouping;5497wchar_t wbuf[100];5498mbstate_t mb = {0};5499const char* bb = lc->int_curr_symbol;5500size_t j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());5501if (j == size_t(-1))5502std::__throw_runtime_error("locale not supported");5503wchar_t* wbe = wbuf + j;5504__curr_symbol_.assign(wbuf, wbe);5505if (lc->int_frac_digits != CHAR_MAX)5506__frac_digits_ = lc->int_frac_digits;5507else5508__frac_digits_ = base::do_frac_digits();5509# if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)5510if (lc->p_sign_posn == 0)5511# else // _LIBCPP_MSVCRT5512if (lc->int_p_sign_posn == 0)5513# endif // !_LIBCPP_MSVCRT5514__positive_sign_ = L"()";5515else {5516mb = mbstate_t();5517bb = lc->positive_sign;5518j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());5519if (j == size_t(-1))5520std::__throw_runtime_error("locale not supported");5521wbe = wbuf + j;5522__positive_sign_.assign(wbuf, wbe);5523}5524# if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)5525if (lc->n_sign_posn == 0)5526# else // _LIBCPP_MSVCRT5527if (lc->int_n_sign_posn == 0)5528# endif // !_LIBCPP_MSVCRT5529__negative_sign_ = L"()";5530else {5531mb = mbstate_t();5532bb = lc->negative_sign;5533j = __locale::__mbsrtowcs(wbuf, &bb, countof(wbuf), &mb, loc.get());5534if (j == size_t(-1))5535std::__throw_runtime_error("locale not supported");5536wbe = wbuf + j;5537__negative_sign_.assign(wbuf, wbe);5538}5539// Assume the positive and negative formats will want spaces in5540// the same places in curr_symbol since there's no way to5541// represent anything else.5542string_type __dummy_curr_symbol = __curr_symbol_;5543# if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)5544__init_pat(__pos_format_, __dummy_curr_symbol, true, lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');5545__init_pat(__neg_format_, __curr_symbol_, true, lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');5546# else // _LIBCPP_MSVCRT5547__init_pat(5548__pos_format_,5549__dummy_curr_symbol,5550true,5551lc->int_p_cs_precedes,5552lc->int_p_sep_by_space,5553lc->int_p_sign_posn,5554L' ');5555__init_pat(5556__neg_format_, __curr_symbol_, true, lc->int_n_cs_precedes, lc->int_n_sep_by_space, lc->int_n_sign_posn, L' ');5557# endif // !_LIBCPP_MSVCRT5558}5559#endif // _LIBCPP_HAS_WIDE_CHARACTERS55605561void __do_nothing(void*) {}55625563// Legacy ABI __num_get functions - the new ones are _LIBCPP_HIDE_FROM_ABI5564template <class _CharT>5565string __num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep) {5566locale __loc = __iob.getloc();5567std::use_facet<ctype<_CharT> >(__loc).widen(__src, __src + __int_chr_cnt, __atoms);5568const numpunct<_CharT>& __np = std::use_facet<numpunct<_CharT> >(__loc);5569__thousands_sep = __np.thousands_sep();5570return __np.grouping();5571}55725573template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<char>;5574_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<wchar_t>;)55755576template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<char>;5577_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<wchar_t>;)55785579template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<char>;5580_LIBCPP_IF_WIDE_CHARACTERS(template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<wchar_t>;)55815582template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<char>;5583_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<wchar_t>;)55845585template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<char>;5586_LIBCPP_IF_WIDE_CHARACTERS(template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<wchar_t>;)55875588template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<char>;5589_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<wchar_t>;)55905591template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<char>;5592_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<wchar_t>;)55935594template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<char>;5595_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<wchar_t>;)55965597template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<char>;5598_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<wchar_t>;)55995600template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, false>;5601template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, true>;5602_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, false>;)5603_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, true>;)56045605template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, false>;5606template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, true>;5607_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, false>;)5608_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, true>;)56095610template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<char>;5611_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<wchar_t>;)56125613template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<char>;5614_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<wchar_t>;)56155616template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<char>;5617_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<wchar_t>;)56185619template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<char>;5620_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<wchar_t>;)56215622template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<char>;5623_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<wchar_t>;)56245625template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<char>;5626_LIBCPP_IF_WIDE_CHARACTERS(template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<wchar_t>;)56275628template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char, char, mbstate_t>;5629_LIBCPP_IF_WIDE_CHARACTERS(5630template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<wchar_t, char, mbstate_t>;)5631template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS5632codecvt_byname<char16_t, char, mbstate_t>;5633template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS5634codecvt_byname<char32_t, char, mbstate_t>;5635#if _LIBCPP_HAS_CHAR8_T5636template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char16_t, char8_t, mbstate_t>;5637template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char32_t, char8_t, mbstate_t>;5638#endif56395640_LIBCPP_END_NAMESPACE_STD56415642_LIBCPP_POP_MACROS564356445645