LCOV - code coverage report
Current view: top level - v1 - __locale (source / functions) Coverage Total Hit
Test: vrml_testfiles.info Lines: 100.0 % 4 4
Test Date: 2024-03-08 16:12:17 Functions: 100.0 % 2 2

            Line data    Source code
       1              : // -*- C++ -*-
       2              : //===----------------------------------------------------------------------===//
       3              : //
       4              : // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
       5              : // See https://llvm.org/LICENSE.txt for license information.
       6              : // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
       7              : //
       8              : //===----------------------------------------------------------------------===//
       9              : 
      10              : #ifndef _LIBCPP___LOCALE
      11              : #define _LIBCPP___LOCALE
      12              : 
      13              : #include <__availability>
      14              : #include <__config>
      15              : #include <cctype>
      16              : #include <cstdint>
      17              : #include <locale.h>
      18              : #include <mutex>
      19              : #include <string>
      20              : 
      21              : // Some platforms require more includes than others. Keep the includes on all plaforms for now.
      22              : #include <cstddef>
      23              : #include <cstring>
      24              : 
      25              : #if defined(_LIBCPP_MSVCRT_LIKE)
      26              : # include <__support/win32/locale_win32.h>
      27              : #elif defined(_AIX) || defined(__MVS__)
      28              : # include <__support/ibm/xlocale.h>
      29              : #elif defined(__ANDROID__)
      30              : # include <__support/android/locale_bionic.h>
      31              : #elif defined(__sun__)
      32              : # include <__support/solaris/xlocale.h>
      33              : # include <xlocale.h>
      34              : #elif defined(_NEWLIB_VERSION)
      35              : # include <__support/newlib/xlocale.h>
      36              : #elif defined(__OpenBSD__)
      37              : # include <__support/openbsd/xlocale.h>
      38              : #elif (defined(__APPLE__) || defined(__FreeBSD__))
      39              : #   if defined(_LIBCPP_ON_SEP)
      40              : #       include <__support/sepos/xlocale.h>
      41              : #   else
      42              : #       include <xlocale.h>
      43              : #   endif
      44              : #elif defined(__Fuchsia__)
      45              : # include <__support/fuchsia/xlocale.h>
      46              : #elif defined(__wasi__)
      47              : // WASI libc uses musl's locales support.
      48              : # include <__support/musl/xlocale.h>
      49              : #elif defined(_LIBCPP_HAS_MUSL_LIBC)
      50              : # include <__support/musl/xlocale.h>
      51              : #endif
      52              : 
      53              : #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
      54              : #  pragma GCC system_header
      55              : #endif
      56              : 
      57              : _LIBCPP_BEGIN_NAMESPACE_STD
      58              : 
      59              : #if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
      60              : struct __libcpp_locale_guard {
      61              :   _LIBCPP_INLINE_VISIBILITY
      62              :   __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
      63              : 
      64              :   _LIBCPP_INLINE_VISIBILITY
      65              :   ~__libcpp_locale_guard() {
      66              :     if (__old_loc_)
      67              :       uselocale(__old_loc_);
      68              :   }
      69              : 
      70              :   locale_t __old_loc_;
      71              : private:
      72              :   __libcpp_locale_guard(__libcpp_locale_guard const&);
      73              :   __libcpp_locale_guard& operator=(__libcpp_locale_guard const&);
      74              : };
      75              : #elif defined(_LIBCPP_MSVCRT_LIKE)
      76              : struct __libcpp_locale_guard {
      77              :     __libcpp_locale_guard(locale_t __l) :
      78              :         __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) {
      79              :       // Setting the locale can be expensive even when the locale given is
      80              :       // already the current locale, so do an explicit check to see if the
      81              :       // current locale is already the one we want.
      82              :       const char* __lc = __setlocale(nullptr);
      83              :       // If every category is the same, the locale string will simply be the
      84              :       // locale name, otherwise it will be a semicolon-separated string listing
      85              :       // each category.  In the second case, we know at least one category won't
      86              :       // be what we want, so we only have to check the first case.
      87              :       if (_VSTD::strcmp(__l.__get_locale(), __lc) != 0) {
      88              :         __locale_all = _strdup(__lc);
      89              :         if (__locale_all == nullptr)
      90              :           __throw_bad_alloc();
      91              :         __setlocale(__l.__get_locale());
      92              :       }
      93              :     }
      94              :     ~__libcpp_locale_guard() {
      95              :       // The CRT documentation doesn't explicitly say, but setlocale() does the
      96              :       // right thing when given a semicolon-separated list of locale settings
      97              :       // for the different categories in the same format as returned by
      98              :       // setlocale(LC_ALL, nullptr).
      99              :       if (__locale_all != nullptr) {
     100              :         __setlocale(__locale_all);
     101              :         free(__locale_all);
     102              :       }
     103              :       _configthreadlocale(__status);
     104              :     }
     105              :     static const char* __setlocale(const char* __locale) {
     106              :       const char* __new_locale = setlocale(LC_ALL, __locale);
     107              :       if (__new_locale == nullptr)
     108              :         __throw_bad_alloc();
     109              :       return __new_locale;
     110              :     }
     111              :     int __status;
     112              :     char* __locale_all = nullptr;
     113              : };
     114              : #endif
     115              : 
     116              : class _LIBCPP_TYPE_VIS locale;
     117              : 
     118              : template <class _Facet>
     119              : _LIBCPP_INLINE_VISIBILITY
     120              : bool
     121              : has_facet(const locale&) _NOEXCEPT;
     122              : 
     123              : template <class _Facet>
     124              : _LIBCPP_INLINE_VISIBILITY
     125              : const _Facet&
     126              : use_facet(const locale&);
     127              : 
     128              : class _LIBCPP_TYPE_VIS locale
     129              : {
     130              : public:
     131              :     // types:
     132              :     class _LIBCPP_TYPE_VIS facet;
     133              :     class _LIBCPP_TYPE_VIS id;
     134              : 
     135              :     typedef int category;
     136              :     _LIBCPP_AVAILABILITY_LOCALE_CATEGORY
     137              :     static const category // values assigned here are for exposition only
     138              :         none     = 0,
     139              :         collate  = LC_COLLATE_MASK,
     140              :         ctype    = LC_CTYPE_MASK,
     141              :         monetary = LC_MONETARY_MASK,
     142              :         numeric  = LC_NUMERIC_MASK,
     143              :         time     = LC_TIME_MASK,
     144              :         messages = LC_MESSAGES_MASK,
     145              :         all = collate | ctype | monetary | numeric | time | messages;
     146              : 
     147              :     // construct/copy/destroy:
     148              :     locale()  _NOEXCEPT;
     149              :     locale(const locale&)  _NOEXCEPT;
     150              :     explicit locale(const char*);
     151              :     explicit locale(const string&);
     152              :     locale(const locale&, const char*, category);
     153              :     locale(const locale&, const string&, category);
     154              :     template <class _Facet>
     155              :         _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
     156              :     locale(const locale&, const locale&, category);
     157              : 
     158              :     ~locale();
     159              : 
     160              :     const locale& operator=(const locale&)  _NOEXCEPT;
     161              : 
     162              :     template <class _Facet>
     163              :       _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
     164              :       locale combine(const locale&) const;
     165              : 
     166              :     // locale operations:
     167              :     string name() const;
     168              :     bool operator==(const locale&) const;
     169              :     bool operator!=(const locale& __y) const {return !(*this == __y);}
     170              :     template <class _CharT, class _Traits, class _Allocator>
     171              :       _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
     172              :       bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
     173              :                       const basic_string<_CharT, _Traits, _Allocator>&) const;
     174              : 
     175              :     // global locale objects:
     176              :     static locale global(const locale&);
     177              :     static const locale& classic();
     178              : 
     179              : private:
     180              :     class __imp;
     181              :     __imp* __locale_;
     182              : 
     183              :     void __install_ctor(const locale&, facet*, long);
     184              :     static locale& __global();
     185              :     bool has_facet(id&) const;
     186              :     const facet* use_facet(id&) const;
     187              : 
     188              :     template <class _Facet> friend bool has_facet(const locale&)  _NOEXCEPT;
     189              :     template <class _Facet> friend const _Facet& use_facet(const locale&);
     190              : };
     191              : 
     192              : class _LIBCPP_TYPE_VIS locale::facet
     193              :     : public __shared_count
     194              : {
     195              : protected:
     196              :     _LIBCPP_INLINE_VISIBILITY
     197              :     explicit facet(size_t __refs = 0)
     198              :         : __shared_count(static_cast<long>(__refs)-1) {}
     199              : 
     200              :     ~facet() override;
     201              : 
     202              : //    facet(const facet&) = delete;     // effectively done in __shared_count
     203              : //    void operator=(const facet&) = delete;
     204              : private:
     205              :     void __on_zero_shared() _NOEXCEPT override;
     206              : };
     207              : 
     208              : class _LIBCPP_TYPE_VIS locale::id
     209              : {
     210              :     once_flag      __flag_;
     211              :     int32_t        __id_;
     212              : 
     213              :     static int32_t __next_id;
     214              : public:
     215              :     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
     216              :     void operator=(const id&) = delete;
     217              :     id(const id&) = delete;
     218              : 
     219              : private:
     220              :     void __init();
     221              : public:  // only needed for tests
     222              :     long __get();
     223              : 
     224              :     friend class locale;
     225              :     friend class locale::__imp;
     226              : };
     227              : 
     228              : template <class _Facet>
     229              : inline _LIBCPP_INLINE_VISIBILITY
     230              : locale::locale(const locale& __other, _Facet* __f)
     231              : {
     232              :     __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
     233              : }
     234              : 
     235              : template <class _Facet>
     236              : locale
     237              : locale::combine(const locale& __other) const
     238              : {
     239              :     if (!_VSTD::has_facet<_Facet>(__other))
     240              :         __throw_runtime_error("locale::combine: locale missing facet");
     241              : 
     242              :     return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
     243              : }
     244              : 
     245              : template <class _Facet>
     246              : inline _LIBCPP_INLINE_VISIBILITY
     247              : bool
     248              : has_facet(const locale& __l)  _NOEXCEPT
     249              : {
     250              :     return __l.has_facet(_Facet::id);
     251              : }
     252              : 
     253              : template <class _Facet>
     254              : inline _LIBCPP_INLINE_VISIBILITY
     255              : const _Facet&
     256          820 : use_facet(const locale& __l)
     257              : {
     258          820 :     return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
     259              : }
     260              : 
     261              : // template <class _CharT> class collate;
     262              : 
     263              : template <class _CharT>
     264              : class _LIBCPP_TEMPLATE_VIS collate
     265              :     : public locale::facet
     266              : {
     267              : public:
     268              :     typedef _CharT char_type;
     269              :     typedef basic_string<char_type> string_type;
     270              : 
     271              :     _LIBCPP_INLINE_VISIBILITY
     272              :     explicit collate(size_t __refs = 0)
     273              :         : locale::facet(__refs) {}
     274              : 
     275              :     _LIBCPP_INLINE_VISIBILITY
     276              :     int compare(const char_type* __lo1, const char_type* __hi1,
     277              :                 const char_type* __lo2, const char_type* __hi2) const
     278              :     {
     279              :         return do_compare(__lo1, __hi1, __lo2, __hi2);
     280              :     }
     281              : 
     282              :     // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work
     283              :     // around a dllimport bug that expects an external instantiation.
     284              :     _LIBCPP_INLINE_VISIBILITY
     285              :     _LIBCPP_ALWAYS_INLINE
     286              :     string_type transform(const char_type* __lo, const char_type* __hi) const
     287              :     {
     288              :         return do_transform(__lo, __hi);
     289              :     }
     290              : 
     291              :     _LIBCPP_INLINE_VISIBILITY
     292              :     long hash(const char_type* __lo, const char_type* __hi) const
     293              :     {
     294              :         return do_hash(__lo, __hi);
     295              :     }
     296              : 
     297              :     static locale::id id;
     298              : 
     299              : protected:
     300              :     ~collate() override;
     301              :     virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
     302              :                            const char_type* __lo2, const char_type* __hi2) const;
     303              :     virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
     304              :         {return string_type(__lo, __hi);}
     305              :     virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
     306              : };
     307              : 
     308              : template <class _CharT> locale::id collate<_CharT>::id;
     309              : 
     310              : template <class _CharT>
     311              : collate<_CharT>::~collate()
     312              : {
     313              : }
     314              : 
     315              : template <class _CharT>
     316              : int
     317              : collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
     318              :                             const char_type* __lo2, const char_type* __hi2) const
     319              : {
     320              :     for (; __lo2 != __hi2; ++__lo1, ++__lo2)
     321              :     {
     322              :         if (__lo1 == __hi1 || *__lo1 < *__lo2)
     323              :             return -1;
     324              :         if (*__lo2 < *__lo1)
     325              :             return 1;
     326              :     }
     327              :     return __lo1 != __hi1;
     328              : }
     329              : 
     330              : template <class _CharT>
     331              : long
     332              : collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
     333              : {
     334              :     size_t __h = 0;
     335              :     const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
     336              :     const size_t __mask = size_t(0xF) << (__sr + 4);
     337              :     for(const char_type* __p = __lo; __p != __hi; ++__p)
     338              :     {
     339              :         __h = (__h << 4) + static_cast<size_t>(*__p);
     340              :         size_t __g = __h & __mask;
     341              :         __h ^= __g | (__g >> __sr);
     342              :     }
     343              :     return static_cast<long>(__h);
     344              : }
     345              : 
     346              : extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>;
     347              : #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     348              : extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>;
     349              : #endif
     350              : 
     351              : // template <class CharT> class collate_byname;
     352              : 
     353              : template <class _CharT> class _LIBCPP_TEMPLATE_VIS collate_byname;
     354              : 
     355              : template <>
     356              : class _LIBCPP_TYPE_VIS collate_byname<char>
     357              :     : public collate<char>
     358              : {
     359              :     locale_t __l_;
     360              : public:
     361              :     typedef char char_type;
     362              :     typedef basic_string<char_type> string_type;
     363              : 
     364              :     explicit collate_byname(const char* __n, size_t __refs = 0);
     365              :     explicit collate_byname(const string& __n, size_t __refs = 0);
     366              : 
     367              : protected:
     368              :     ~collate_byname() override;
     369              :     int do_compare(const char_type* __lo1, const char_type* __hi1,
     370              :                    const char_type* __lo2, const char_type* __hi2) const override;
     371              :     string_type do_transform(const char_type* __lo, const char_type* __hi) const override;
     372              : };
     373              : 
     374              : #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     375              : template <>
     376              : class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
     377              :     : public collate<wchar_t>
     378              : {
     379              :     locale_t __l_;
     380              : public:
     381              :     typedef wchar_t char_type;
     382              :     typedef basic_string<char_type> string_type;
     383              : 
     384              :     explicit collate_byname(const char* __n, size_t __refs = 0);
     385              :     explicit collate_byname(const string& __n, size_t __refs = 0);
     386              : 
     387              : protected:
     388              :     ~collate_byname() override;
     389              : 
     390              :     int do_compare(const char_type* __lo1, const char_type* __hi1,
     391              :                    const char_type* __lo2, const char_type* __hi2) const override;
     392              :     string_type do_transform(const char_type* __lo, const char_type* __hi) const override;
     393              : };
     394              : #endif
     395              : 
     396              : template <class _CharT, class _Traits, class _Allocator>
     397              : bool
     398              : locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
     399              :                    const basic_string<_CharT, _Traits, _Allocator>& __y) const
     400              : {
     401              :     return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
     402              :                                        __x.data(), __x.data() + __x.size(),
     403              :                                        __y.data(), __y.data() + __y.size()) < 0;
     404              : }
     405              : 
     406              : // template <class charT> class ctype
     407              : 
     408              : class _LIBCPP_TYPE_VIS ctype_base
     409              : {
     410              : public:
     411              : #if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE)
     412              :     typedef unsigned long mask;
     413              :     static const mask space  = 1<<0;
     414              :     static const mask print  = 1<<1;
     415              :     static const mask cntrl  = 1<<2;
     416              :     static const mask upper  = 1<<3;
     417              :     static const mask lower  = 1<<4;
     418              :     static const mask alpha  = 1<<5;
     419              :     static const mask digit  = 1<<6;
     420              :     static const mask punct  = 1<<7;
     421              :     static const mask xdigit = 1<<8;
     422              :     static const mask blank  = 1<<9;
     423              : #if defined(__BIONIC__)
     424              :     // Historically this was a part of regex_traits rather than ctype_base. The
     425              :     // historical value of the constant is preserved for ABI compatibility.
     426              :     static const mask __regex_word = 0x8000;
     427              : #else
     428              :     static const mask __regex_word = 1<<10;
     429              : #endif // defined(__BIONIC__)
     430              : #elif defined(__GLIBC__)
     431              :     typedef unsigned short mask;
     432              :     static const mask space  = _ISspace;
     433              :     static const mask print  = _ISprint;
     434              :     static const mask cntrl  = _IScntrl;
     435              :     static const mask upper  = _ISupper;
     436              :     static const mask lower  = _ISlower;
     437              :     static const mask alpha  = _ISalpha;
     438              :     static const mask digit  = _ISdigit;
     439              :     static const mask punct  = _ISpunct;
     440              :     static const mask xdigit = _ISxdigit;
     441              :     static const mask blank  = _ISblank;
     442              : #if defined(__mips__)
     443              :     static const mask __regex_word = static_cast<mask>(_ISbit(15));
     444              : #else
     445              :     static const mask __regex_word = 0x80;
     446              : #endif
     447              : #elif defined(_LIBCPP_MSVCRT_LIKE)
     448              :     typedef unsigned short mask;
     449              :     static const mask space  = _SPACE;
     450              :     static const mask print  = _BLANK|_PUNCT|_ALPHA|_DIGIT;
     451              :     static const mask cntrl  = _CONTROL;
     452              :     static const mask upper  = _UPPER;
     453              :     static const mask lower  = _LOWER;
     454              :     static const mask alpha  = _ALPHA;
     455              :     static const mask digit  = _DIGIT;
     456              :     static const mask punct  = _PUNCT;
     457              :     static const mask xdigit = _HEX;
     458              :     static const mask blank  = _BLANK;
     459              :     static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used
     460              : # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
     461              : # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
     462              : #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
     463              : # ifdef __APPLE__
     464              :     typedef __uint32_t mask;
     465              : # elif defined(__FreeBSD__)
     466              :     typedef unsigned long mask;
     467              : # elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
     468              :     typedef unsigned short mask;
     469              : # endif
     470              :     static const mask space  = _CTYPE_S;
     471              :     static const mask print  = _CTYPE_R;
     472              :     static const mask cntrl  = _CTYPE_C;
     473              :     static const mask upper  = _CTYPE_U;
     474              :     static const mask lower  = _CTYPE_L;
     475              :     static const mask alpha  = _CTYPE_A;
     476              :     static const mask digit  = _CTYPE_D;
     477              :     static const mask punct  = _CTYPE_P;
     478              :     static const mask xdigit = _CTYPE_X;
     479              : 
     480              : # if defined(__NetBSD__)
     481              :     static const mask blank  = _CTYPE_BL;
     482              :     // NetBSD defines classes up to 0x2000
     483              :     // see sys/ctype_bits.h, _CTYPE_Q
     484              :     static const mask __regex_word = 0x8000;
     485              : # else
     486              :     static const mask blank  = _CTYPE_B;
     487              :     static const mask __regex_word = 0x80;
     488              : # endif
     489              : #elif defined(__sun__) || defined(_AIX)
     490              :     typedef unsigned int mask;
     491              :     static const mask space  = _ISSPACE;
     492              :     static const mask print  = _ISPRINT;
     493              :     static const mask cntrl  = _ISCNTRL;
     494              :     static const mask upper  = _ISUPPER;
     495              :     static const mask lower  = _ISLOWER;
     496              :     static const mask alpha  = _ISALPHA;
     497              :     static const mask digit  = _ISDIGIT;
     498              :     static const mask punct  = _ISPUNCT;
     499              :     static const mask xdigit = _ISXDIGIT;
     500              :     static const mask blank  = _ISBLANK;
     501              : # if defined(_AIX)
     502              :     static const mask __regex_word = 0x8000;
     503              : # else
     504              :     static const mask __regex_word = 0x80;
     505              : # endif
     506              : #elif defined(_NEWLIB_VERSION)
     507              :     // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
     508              :     typedef char mask;
     509              :     static const mask space  = _S;
     510              :     static const mask print  = _P | _U | _L | _N | _B;
     511              :     static const mask cntrl  = _C;
     512              :     static const mask upper  = _U;
     513              :     static const mask lower  = _L;
     514              :     static const mask alpha  = _U | _L;
     515              :     static const mask digit  = _N;
     516              :     static const mask punct  = _P;
     517              :     static const mask xdigit = _X | _N;
     518              :     static const mask blank  = _B;
     519              :     // mask is already fully saturated, use a different type in regex_type_traits.
     520              :     static const unsigned short __regex_word = 0x100;
     521              : # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
     522              : # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
     523              : # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
     524              : #elif defined(__MVS__)
     525              : # if defined(__NATIVE_ASCII_F)
     526              :     typedef unsigned int mask;
     527              :     static const mask space  = _ISSPACE_A;
     528              :     static const mask print  = _ISPRINT_A;
     529              :     static const mask cntrl  = _ISCNTRL_A;
     530              :     static const mask upper  = _ISUPPER_A;
     531              :     static const mask lower  = _ISLOWER_A;
     532              :     static const mask alpha  = _ISALPHA_A;
     533              :     static const mask digit  = _ISDIGIT_A;
     534              :     static const mask punct  = _ISPUNCT_A;
     535              :     static const mask xdigit = _ISXDIGIT_A;
     536              :     static const mask blank  = _ISBLANK_A;
     537              : # else
     538              :     typedef unsigned short mask;
     539              :     static const mask space  = __ISSPACE;
     540              :     static const mask print  = __ISPRINT;
     541              :     static const mask cntrl  = __ISCNTRL;
     542              :     static const mask upper  = __ISUPPER;
     543              :     static const mask lower  = __ISLOWER;
     544              :     static const mask alpha  = __ISALPHA;
     545              :     static const mask digit  = __ISDIGIT;
     546              :     static const mask punct  = __ISPUNCT;
     547              :     static const mask xdigit = __ISXDIGIT;
     548              :     static const mask blank  = __ISBLANK;
     549              : # endif
     550              :     static const mask __regex_word = 0x8000;
     551              : #else
     552              : # error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?
     553              : #endif
     554              :     static const mask alnum  = alpha | digit;
     555              :     static const mask graph  = alnum | punct;
     556              : 
     557              :     _LIBCPP_INLINE_VISIBILITY ctype_base() {}
     558              : 
     559              :     static_assert((__regex_word & ~(std::make_unsigned<mask>::type)(space | print | cntrl | upper | lower | alpha |
     560              :                                                                     digit | punct | xdigit | blank)) == __regex_word,
     561              :                   "__regex_word can't overlap other bits");
     562              : };
     563              : 
     564              : template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
     565              : 
     566              : #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     567              : template <>
     568              : class _LIBCPP_TYPE_VIS ctype<wchar_t>
     569              :     : public locale::facet,
     570              :       public ctype_base
     571              : {
     572              : public:
     573              :     typedef wchar_t char_type;
     574              : 
     575              :     _LIBCPP_INLINE_VISIBILITY
     576              :     explicit ctype(size_t __refs = 0)
     577              :         : locale::facet(__refs) {}
     578              : 
     579              :     _LIBCPP_INLINE_VISIBILITY
     580              :     bool is(mask __m, char_type __c) const
     581              :     {
     582              :         return do_is(__m, __c);
     583              :     }
     584              : 
     585              :     _LIBCPP_INLINE_VISIBILITY
     586              :     const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
     587              :     {
     588              :         return do_is(__low, __high, __vec);
     589              :     }
     590              : 
     591              :     _LIBCPP_INLINE_VISIBILITY
     592              :     const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
     593              :     {
     594              :         return do_scan_is(__m, __low, __high);
     595              :     }
     596              : 
     597              :     _LIBCPP_INLINE_VISIBILITY
     598              :     const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
     599              :     {
     600              :         return do_scan_not(__m, __low, __high);
     601              :     }
     602              : 
     603              :     _LIBCPP_INLINE_VISIBILITY
     604              :     char_type toupper(char_type __c) const
     605              :     {
     606              :         return do_toupper(__c);
     607              :     }
     608              : 
     609              :     _LIBCPP_INLINE_VISIBILITY
     610              :     const char_type* toupper(char_type* __low, const char_type* __high) const
     611              :     {
     612              :         return do_toupper(__low, __high);
     613              :     }
     614              : 
     615              :     _LIBCPP_INLINE_VISIBILITY
     616              :     char_type tolower(char_type __c) const
     617              :     {
     618              :         return do_tolower(__c);
     619              :     }
     620              : 
     621              :     _LIBCPP_INLINE_VISIBILITY
     622              :     const char_type* tolower(char_type* __low, const char_type* __high) const
     623              :     {
     624              :         return do_tolower(__low, __high);
     625              :     }
     626              : 
     627              :     _LIBCPP_INLINE_VISIBILITY
     628              :     char_type widen(char __c) const
     629              :     {
     630              :         return do_widen(__c);
     631              :     }
     632              : 
     633              :     _LIBCPP_INLINE_VISIBILITY
     634              :     const char* widen(const char* __low, const char* __high, char_type* __to) const
     635              :     {
     636              :         return do_widen(__low, __high, __to);
     637              :     }
     638              : 
     639              :     _LIBCPP_INLINE_VISIBILITY
     640              :     char narrow(char_type __c, char __dfault) const
     641              :     {
     642              :         return do_narrow(__c, __dfault);
     643              :     }
     644              : 
     645              :     _LIBCPP_INLINE_VISIBILITY
     646              :     const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
     647              :     {
     648              :         return do_narrow(__low, __high, __dfault, __to);
     649              :     }
     650              : 
     651              :     static locale::id id;
     652              : 
     653              : protected:
     654              :     ~ctype() override;
     655              :     virtual bool do_is(mask __m, char_type __c) const;
     656              :     virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
     657              :     virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
     658              :     virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
     659              :     virtual char_type do_toupper(char_type) const;
     660              :     virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
     661              :     virtual char_type do_tolower(char_type) const;
     662              :     virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
     663              :     virtual char_type do_widen(char) const;
     664              :     virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
     665              :     virtual char do_narrow(char_type, char __dfault) const;
     666              :     virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
     667              : };
     668              : #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
     669              : 
     670              : template <>
     671              : class _LIBCPP_TYPE_VIS ctype<char>
     672              :     : public locale::facet, public ctype_base
     673              : {
     674              :     const mask* __tab_;
     675              :     bool        __del_;
     676              : public:
     677              :     typedef char char_type;
     678              : 
     679              :     explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0);
     680              : 
     681              :     _LIBCPP_INLINE_VISIBILITY
     682              :     bool is(mask __m, char_type __c) const
     683              :     {
     684              :         return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false;
     685              :     }
     686              : 
     687              :     _LIBCPP_INLINE_VISIBILITY
     688              :     const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
     689              :     {
     690              :         for (; __low != __high; ++__low, ++__vec)
     691              :             *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
     692              :         return __low;
     693              :     }
     694              : 
     695              :     _LIBCPP_INLINE_VISIBILITY
     696              :     const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
     697              :     {
     698              :         for (; __low != __high; ++__low)
     699              :             if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
     700              :                 break;
     701              :         return __low;
     702              :     }
     703              : 
     704              :     _LIBCPP_INLINE_VISIBILITY
     705              :     const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
     706              :     {
     707              :         for (; __low != __high; ++__low)
     708              :             if (!isascii(*__low) || !(__tab_[static_cast<int>(*__low)] & __m))
     709              :                 break;
     710              :         return __low;
     711              :     }
     712              : 
     713              :     _LIBCPP_INLINE_VISIBILITY
     714              :     char_type toupper(char_type __c) const
     715              :     {
     716              :         return do_toupper(__c);
     717              :     }
     718              : 
     719              :     _LIBCPP_INLINE_VISIBILITY
     720              :     const char_type* toupper(char_type* __low, const char_type* __high) const
     721              :     {
     722              :         return do_toupper(__low, __high);
     723              :     }
     724              : 
     725              :     _LIBCPP_INLINE_VISIBILITY
     726              :     char_type tolower(char_type __c) const
     727              :     {
     728              :         return do_tolower(__c);
     729              :     }
     730              : 
     731              :     _LIBCPP_INLINE_VISIBILITY
     732              :     const char_type* tolower(char_type* __low, const char_type* __high) const
     733              :     {
     734              :         return do_tolower(__low, __high);
     735              :     }
     736              : 
     737              :     _LIBCPP_INLINE_VISIBILITY
     738          820 :     char_type widen(char __c) const
     739              :     {
     740          820 :         return do_widen(__c);
     741              :     }
     742              : 
     743              :     _LIBCPP_INLINE_VISIBILITY
     744              :     const char* widen(const char* __low, const char* __high, char_type* __to) const
     745              :     {
     746              :         return do_widen(__low, __high, __to);
     747              :     }
     748              : 
     749              :     _LIBCPP_INLINE_VISIBILITY
     750              :     char narrow(char_type __c, char __dfault) const
     751              :     {
     752              :         return do_narrow(__c, __dfault);
     753              :     }
     754              : 
     755              :     _LIBCPP_INLINE_VISIBILITY
     756              :     const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
     757              :     {
     758              :         return do_narrow(__low, __high, __dfault, __to);
     759              :     }
     760              : 
     761              :     static locale::id id;
     762              : 
     763              : #ifdef _CACHED_RUNES
     764              :     static const size_t table_size = _CACHED_RUNES;
     765              : #else
     766              :     static const size_t table_size = 256;  // FIXME: Don't hardcode this.
     767              : #endif
     768              :     _LIBCPP_INLINE_VISIBILITY const mask* table() const  _NOEXCEPT {return __tab_;}
     769              :     static const mask* classic_table()  _NOEXCEPT;
     770              : #if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
     771              :     static const int* __classic_upper_table() _NOEXCEPT;
     772              :     static const int* __classic_lower_table() _NOEXCEPT;
     773              : #endif
     774              : #if defined(__NetBSD__)
     775              :     static const short* __classic_upper_table() _NOEXCEPT;
     776              :     static const short* __classic_lower_table() _NOEXCEPT;
     777              : #endif
     778              : #if defined(__MVS__)
     779              :     static const unsigned short* __classic_upper_table() _NOEXCEPT;
     780              :     static const unsigned short* __classic_lower_table() _NOEXCEPT;
     781              : #endif
     782              : 
     783              : protected:
     784              :     ~ctype() override;
     785              :     virtual char_type do_toupper(char_type __c) const;
     786              :     virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
     787              :     virtual char_type do_tolower(char_type __c) const;
     788              :     virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
     789              :     virtual char_type do_widen(char __c) const;
     790              :     virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
     791              :     virtual char do_narrow(char_type __c, char __dfault) const;
     792              :     virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
     793              : };
     794              : 
     795              : // template <class CharT> class ctype_byname;
     796              : 
     797              : template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype_byname;
     798              : 
     799              : template <>
     800              : class _LIBCPP_TYPE_VIS ctype_byname<char>
     801              :     : public ctype<char>
     802              : {
     803              :     locale_t __l_;
     804              : 
     805              : public:
     806              :     explicit ctype_byname(const char*, size_t = 0);
     807              :     explicit ctype_byname(const string&, size_t = 0);
     808              : 
     809              : protected:
     810              :     ~ctype_byname() override;
     811              :     char_type do_toupper(char_type) const override;
     812              :     const char_type* do_toupper(char_type* __low, const char_type* __high) const override;
     813              :     char_type do_tolower(char_type) const override;
     814              :     const char_type* do_tolower(char_type* __low, const char_type* __high) const override;
     815              : };
     816              : 
     817              : #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
     818              : template <>
     819              : class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
     820              :     : public ctype<wchar_t>
     821              : {
     822              :     locale_t __l_;
     823              : 
     824              : public:
     825              :     explicit ctype_byname(const char*, size_t = 0);
     826              :     explicit ctype_byname(const string&, size_t = 0);
     827              : 
     828              : protected:
     829              :     ~ctype_byname() override;
     830              :     bool do_is(mask __m, char_type __c) const override;
     831              :     const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const override;
     832              :     const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const override;
     833              :     const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const override;
     834              :     char_type do_toupper(char_type) const override;
     835              :     const char_type* do_toupper(char_type* __low, const char_type* __high) const override;
     836              :     char_type do_tolower(char_type) const override;
     837              :     const char_type* do_tolower(char_type* __low, const char_type* __high) const override;
     838              :     char_type do_widen(char) const override;
     839              :     const char* do_widen(const char* __low, const char* __high, char_type* __dest) const override;
     840              :     char do_narrow(char_type, char __dfault) const override;
     841              :     const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const override;
     842              : };
     843              : #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
     844              : 
     845              : template <class _CharT>
     846              : inline _LIBCPP_INLINE_VISIBILITY
     847              : bool
     848              : isspace(_CharT __c, const locale& __loc)
     849              : {
     850              :     return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
     851              : }
     852              : 
     853              : template <class _CharT>
     854              : inline _LIBCPP_INLINE_VISIBILITY
     855              : bool
     856              : isprint(_CharT __c, const locale& __loc)
     857              : {
     858              :     return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
     859              : }
     860              : 
     861              : template <class _CharT>
     862              : inline _LIBCPP_INLINE_VISIBILITY
     863              : bool
     864              : iscntrl(_CharT __c, const locale& __loc)
     865              : {
     866              :     return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
     867              : }
     868              : 
     869              : template <class _CharT>
     870              : inline _LIBCPP_INLINE_VISIBILITY
     871              : bool
     872              : isupper(_CharT __c, const locale& __loc)
     873              : {
     874              :     return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
     875              : }
     876              : 
     877              : template <class _CharT>
     878              : inline _LIBCPP_INLINE_VISIBILITY
     879              : bool
     880              : islower(_CharT __c, const locale& __loc)
     881              : {
     882              :     return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
     883              : }
     884              : 
     885              : template <class _CharT>
     886              : inline _LIBCPP_INLINE_VISIBILITY
     887              : bool
     888              : isalpha(_CharT __c, const locale& __loc)
     889              : {
     890              :     return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
     891              : }
     892              : 
     893              : template <class _CharT>
     894              : inline _LIBCPP_INLINE_VISIBILITY
     895              : bool
     896              : isdigit(_CharT __c, const locale& __loc)
     897              : {
     898              :     return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
     899              : }
     900              : 
     901              : template <class _CharT>
     902              : inline _LIBCPP_INLINE_VISIBILITY
     903              : bool
     904              : ispunct(_CharT __c, const locale& __loc)
     905              : {
     906              :     return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
     907              : }
     908              : 
     909              : template <class _CharT>
     910              : inline _LIBCPP_INLINE_VISIBILITY
     911              : bool
     912              : isxdigit(_CharT __c, const locale& __loc)
     913              : {
     914              :     return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
     915              : }
     916              : 
     917              : template <class _CharT>
     918              : inline _LIBCPP_INLINE_VISIBILITY
     919              : bool
     920              : isalnum(_CharT __c, const locale& __loc)
     921              : {
     922              :     return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
     923              : }
     924              : 
     925              : template <class _CharT>
     926              : inline _LIBCPP_INLINE_VISIBILITY
     927              : bool
     928              : isgraph(_CharT __c, const locale& __loc)
     929              : {
     930              :     return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
     931              : }
     932              : 
     933              : template <class _CharT>
     934              : inline _LIBCPP_INLINE_VISIBILITY
     935              : _CharT
     936              : toupper(_CharT __c, const locale& __loc)
     937              : {
     938              :     return std::use_facet<ctype<_CharT> >(__loc).toupper(__c);
     939              : }
     940              : 
     941              : template <class _CharT>
     942              : inline _LIBCPP_INLINE_VISIBILITY
     943              : _CharT
     944              : tolower(_CharT __c, const locale& __loc)
     945              : {
     946              :     return std::use_facet<ctype<_CharT> >(__loc).tolower(__c);
     947              : }
     948              : 
     949              : // codecvt_base
     950              : 
     951              : class _LIBCPP_TYPE_VIS codecvt_base
     952              : {
     953              : public:
     954              :     _LIBCPP_INLINE_VISIBILITY codecvt_base() {}
     955              :     enum result {ok, partial, error, noconv};
     956              : };
     957              : 
     958              : // template <class internT, class externT, class stateT> class codecvt;
     959              : 
     960              : template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TEMPLATE_VIS codecvt;
     961              : 
     962              : // template <> class codecvt<char, char, mbstate_t>
     963              : 
     964              : template <>
     965              : class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
     966              :     : public locale::facet,
     967              :       public codecvt_base
     968              : {
     969              : public:
     970              :     typedef char      intern_type;
     971              :     typedef char      extern_type;
     972              :     typedef mbstate_t state_type;
     973              : 
     974              :     _LIBCPP_INLINE_VISIBILITY
     975              :     explicit codecvt(size_t __refs = 0)
     976              :         : locale::facet(__refs) {}
     977              : 
     978              :     _LIBCPP_INLINE_VISIBILITY
     979              :     result out(state_type& __st,
     980              :                const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
     981              :                extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
     982              :     {
     983              :         return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
     984              :     }
     985              : 
     986              :     _LIBCPP_INLINE_VISIBILITY
     987              :     result unshift(state_type& __st,
     988              :                    extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
     989              :     {
     990              :         return do_unshift(__st, __to, __to_end, __to_nxt);
     991              :     }
     992              : 
     993              :     _LIBCPP_INLINE_VISIBILITY
     994              :     result in(state_type& __st,
     995              :               const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
     996              :               intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
     997              :     {
     998              :         return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
     999              :     }
    1000              : 
    1001              :     _LIBCPP_INLINE_VISIBILITY
    1002              :     int encoding() const  _NOEXCEPT
    1003              :     {
    1004              :         return do_encoding();
    1005              :     }
    1006              : 
    1007              :     _LIBCPP_INLINE_VISIBILITY
    1008              :     bool always_noconv() const  _NOEXCEPT
    1009              :     {
    1010              :         return do_always_noconv();
    1011              :     }
    1012              : 
    1013              :     _LIBCPP_INLINE_VISIBILITY
    1014              :     int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
    1015              :     {
    1016              :         return do_length(__st, __frm, __end, __mx);
    1017              :     }
    1018              : 
    1019              :     _LIBCPP_INLINE_VISIBILITY
    1020              :     int max_length() const  _NOEXCEPT
    1021              :     {
    1022              :         return do_max_length();
    1023              :     }
    1024              : 
    1025              :     static locale::id id;
    1026              : 
    1027              : protected:
    1028              :     _LIBCPP_INLINE_VISIBILITY
    1029              :     explicit codecvt(const char*, size_t __refs = 0)
    1030              :         : locale::facet(__refs) {}
    1031              : 
    1032              :     ~codecvt() override;
    1033              : 
    1034              :     virtual result do_out(state_type& __st,
    1035              :                           const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
    1036              :                           extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
    1037              :     virtual result do_in(state_type& __st,
    1038              :                          const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
    1039              :                          intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
    1040              :     virtual result do_unshift(state_type& __st,
    1041              :                               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
    1042              :     virtual int do_encoding() const  _NOEXCEPT;
    1043              :     virtual bool do_always_noconv() const  _NOEXCEPT;
    1044              :     virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
    1045              :     virtual int do_max_length() const  _NOEXCEPT;
    1046              : };
    1047              : 
    1048              : // template <> class codecvt<wchar_t, char, mbstate_t>
    1049              : 
    1050              : #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
    1051              : template <>
    1052              : class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
    1053              :     : public locale::facet,
    1054              :       public codecvt_base
    1055              : {
    1056              :     locale_t __l_;
    1057              : public:
    1058              :     typedef wchar_t   intern_type;
    1059              :     typedef char      extern_type;
    1060              :     typedef mbstate_t state_type;
    1061              : 
    1062              :     explicit codecvt(size_t __refs = 0);
    1063              : 
    1064              :     _LIBCPP_INLINE_VISIBILITY
    1065              :     result out(state_type& __st,
    1066              :                const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
    1067              :                extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
    1068              :     {
    1069              :         return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
    1070              :     }
    1071              : 
    1072              :     _LIBCPP_INLINE_VISIBILITY
    1073              :     result unshift(state_type& __st,
    1074              :                    extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
    1075              :     {
    1076              :         return do_unshift(__st, __to, __to_end, __to_nxt);
    1077              :     }
    1078              : 
    1079              :     _LIBCPP_INLINE_VISIBILITY
    1080              :     result in(state_type& __st,
    1081              :               const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
    1082              :               intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
    1083              :     {
    1084              :         return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
    1085              :     }
    1086              : 
    1087              :     _LIBCPP_INLINE_VISIBILITY
    1088              :     int encoding() const  _NOEXCEPT
    1089              :     {
    1090              :         return do_encoding();
    1091              :     }
    1092              : 
    1093              :     _LIBCPP_INLINE_VISIBILITY
    1094              :     bool always_noconv() const  _NOEXCEPT
    1095              :     {
    1096              :         return do_always_noconv();
    1097              :     }
    1098              : 
    1099              :     _LIBCPP_INLINE_VISIBILITY
    1100              :     int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
    1101              :     {
    1102              :         return do_length(__st, __frm, __end, __mx);
    1103              :     }
    1104              : 
    1105              :     _LIBCPP_INLINE_VISIBILITY
    1106              :     int max_length() const  _NOEXCEPT
    1107              :     {
    1108              :         return do_max_length();
    1109              :     }
    1110              : 
    1111              :     static locale::id id;
    1112              : 
    1113              : protected:
    1114              :     explicit codecvt(const char*, size_t __refs = 0);
    1115              : 
    1116              :     ~codecvt() override;
    1117              : 
    1118              :     virtual result do_out(state_type& __st,
    1119              :                           const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
    1120              :                           extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
    1121              :     virtual result do_in(state_type& __st,
    1122              :                          const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
    1123              :                          intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
    1124              :     virtual result do_unshift(state_type& __st,
    1125              :                               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
    1126              :     virtual int do_encoding() const  _NOEXCEPT;
    1127              :     virtual bool do_always_noconv() const  _NOEXCEPT;
    1128              :     virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
    1129              :     virtual int do_max_length() const  _NOEXCEPT;
    1130              : };
    1131              : #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
    1132              : 
    1133              : // template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20
    1134              : 
    1135              : template <>
    1136              : class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
    1137              :     : public locale::facet,
    1138              :       public codecvt_base
    1139              : {
    1140              : public:
    1141              :     typedef char16_t  intern_type;
    1142              :     typedef char      extern_type;
    1143              :     typedef mbstate_t state_type;
    1144              : 
    1145              :     _LIBCPP_INLINE_VISIBILITY
    1146              :     explicit codecvt(size_t __refs = 0)
    1147              :         : locale::facet(__refs) {}
    1148              : 
    1149              :     _LIBCPP_INLINE_VISIBILITY
    1150              :     result out(state_type& __st,
    1151              :                const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
    1152              :                extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
    1153              :     {
    1154              :         return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
    1155              :     }
    1156              : 
    1157              :     _LIBCPP_INLINE_VISIBILITY
    1158              :     result unshift(state_type& __st,
    1159              :                    extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
    1160              :     {
    1161              :         return do_unshift(__st, __to, __to_end, __to_nxt);
    1162              :     }
    1163              : 
    1164              :     _LIBCPP_INLINE_VISIBILITY
    1165              :     result in(state_type& __st,
    1166              :               const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
    1167              :               intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
    1168              :     {
    1169              :         return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
    1170              :     }
    1171              : 
    1172              :     _LIBCPP_INLINE_VISIBILITY
    1173              :     int encoding() const  _NOEXCEPT
    1174              :     {
    1175              :         return do_encoding();
    1176              :     }
    1177              : 
    1178              :     _LIBCPP_INLINE_VISIBILITY
    1179              :     bool always_noconv() const  _NOEXCEPT
    1180              :     {
    1181              :         return do_always_noconv();
    1182              :     }
    1183              : 
    1184              :     _LIBCPP_INLINE_VISIBILITY
    1185              :     int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
    1186              :     {
    1187              :         return do_length(__st, __frm, __end, __mx);
    1188              :     }
    1189              : 
    1190              :     _LIBCPP_INLINE_VISIBILITY
    1191              :     int max_length() const  _NOEXCEPT
    1192              :     {
    1193              :         return do_max_length();
    1194              :     }
    1195              : 
    1196              :     static locale::id id;
    1197              : 
    1198              : protected:
    1199              :     _LIBCPP_INLINE_VISIBILITY
    1200              :     explicit codecvt(const char*, size_t __refs = 0)
    1201              :         : locale::facet(__refs) {}
    1202              : 
    1203              :     ~codecvt() override;
    1204              : 
    1205              :     virtual result do_out(state_type& __st,
    1206              :                           const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
    1207              :                           extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
    1208              :     virtual result do_in(state_type& __st,
    1209              :                          const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
    1210              :                          intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
    1211              :     virtual result do_unshift(state_type& __st,
    1212              :                               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
    1213              :     virtual int do_encoding() const  _NOEXCEPT;
    1214              :     virtual bool do_always_noconv() const  _NOEXCEPT;
    1215              :     virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
    1216              :     virtual int do_max_length() const  _NOEXCEPT;
    1217              : };
    1218              : 
    1219              : #ifndef _LIBCPP_HAS_NO_CHAR8_T
    1220              : 
    1221              : // template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20
    1222              : 
    1223              : template <>
    1224              : class _LIBCPP_TYPE_VIS codecvt<char16_t, char8_t, mbstate_t>
    1225              :     : public locale::facet,
    1226              :       public codecvt_base
    1227              : {
    1228              : public:
    1229              :     typedef char16_t  intern_type;
    1230              :     typedef char8_t   extern_type;
    1231              :     typedef mbstate_t state_type;
    1232              : 
    1233              :     _LIBCPP_INLINE_VISIBILITY
    1234              :     explicit codecvt(size_t __refs = 0)
    1235              :         : locale::facet(__refs) {}
    1236              : 
    1237              :     _LIBCPP_INLINE_VISIBILITY
    1238              :     result out(state_type& __st,
    1239              :                const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
    1240              :                extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
    1241              :     {
    1242              :         return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
    1243              :     }
    1244              : 
    1245              :     _LIBCPP_INLINE_VISIBILITY
    1246              :     result unshift(state_type& __st,
    1247              :                    extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
    1248              :     {
    1249              :         return do_unshift(__st, __to, __to_end, __to_nxt);
    1250              :     }
    1251              : 
    1252              :     _LIBCPP_INLINE_VISIBILITY
    1253              :     result in(state_type& __st,
    1254              :               const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
    1255              :               intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
    1256              :     {
    1257              :         return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
    1258              :     }
    1259              : 
    1260              :     _LIBCPP_INLINE_VISIBILITY
    1261              :     int encoding() const  _NOEXCEPT
    1262              :     {
    1263              :         return do_encoding();
    1264              :     }
    1265              : 
    1266              :     _LIBCPP_INLINE_VISIBILITY
    1267              :     bool always_noconv() const  _NOEXCEPT
    1268              :     {
    1269              :         return do_always_noconv();
    1270              :     }
    1271              : 
    1272              :     _LIBCPP_INLINE_VISIBILITY
    1273              :     int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
    1274              :     {
    1275              :         return do_length(__st, __frm, __end, __mx);
    1276              :     }
    1277              : 
    1278              :     _LIBCPP_INLINE_VISIBILITY
    1279              :     int max_length() const  _NOEXCEPT
    1280              :     {
    1281              :         return do_max_length();
    1282              :     }
    1283              : 
    1284              :     static locale::id id;
    1285              : 
    1286              : protected:
    1287              :     _LIBCPP_INLINE_VISIBILITY
    1288              :     explicit codecvt(const char*, size_t __refs = 0)
    1289              :         : locale::facet(__refs) {}
    1290              : 
    1291              :     ~codecvt() override;
    1292              : 
    1293              :     virtual result do_out(state_type& __st,
    1294              :                           const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
    1295              :                           extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
    1296              :     virtual result do_in(state_type& __st,
    1297              :                          const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
    1298              :                          intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
    1299              :     virtual result do_unshift(state_type& __st,
    1300              :                               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
    1301              :     virtual int do_encoding() const  _NOEXCEPT;
    1302              :     virtual bool do_always_noconv() const  _NOEXCEPT;
    1303              :     virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
    1304              :     virtual int do_max_length() const  _NOEXCEPT;
    1305              : };
    1306              : 
    1307              : #endif
    1308              : 
    1309              : // template <> class codecvt<char32_t, char, mbstate_t> // deprecated in C++20
    1310              : 
    1311              : template <>
    1312              : class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
    1313              :     : public locale::facet,
    1314              :       public codecvt_base
    1315              : {
    1316              : public:
    1317              :     typedef char32_t  intern_type;
    1318              :     typedef char      extern_type;
    1319              :     typedef mbstate_t state_type;
    1320              : 
    1321              :     _LIBCPP_INLINE_VISIBILITY
    1322              :     explicit codecvt(size_t __refs = 0)
    1323              :         : locale::facet(__refs) {}
    1324              : 
    1325              :     _LIBCPP_INLINE_VISIBILITY
    1326              :     result out(state_type& __st,
    1327              :                const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
    1328              :                extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
    1329              :     {
    1330              :         return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
    1331              :     }
    1332              : 
    1333              :     _LIBCPP_INLINE_VISIBILITY
    1334              :     result unshift(state_type& __st,
    1335              :                    extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
    1336              :     {
    1337              :         return do_unshift(__st, __to, __to_end, __to_nxt);
    1338              :     }
    1339              : 
    1340              :     _LIBCPP_INLINE_VISIBILITY
    1341              :     result in(state_type& __st,
    1342              :               const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
    1343              :               intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
    1344              :     {
    1345              :         return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
    1346              :     }
    1347              : 
    1348              :     _LIBCPP_INLINE_VISIBILITY
    1349              :     int encoding() const  _NOEXCEPT
    1350              :     {
    1351              :         return do_encoding();
    1352              :     }
    1353              : 
    1354              :     _LIBCPP_INLINE_VISIBILITY
    1355              :     bool always_noconv() const  _NOEXCEPT
    1356              :     {
    1357              :         return do_always_noconv();
    1358              :     }
    1359              : 
    1360              :     _LIBCPP_INLINE_VISIBILITY
    1361              :     int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
    1362              :     {
    1363              :         return do_length(__st, __frm, __end, __mx);
    1364              :     }
    1365              : 
    1366              :     _LIBCPP_INLINE_VISIBILITY
    1367              :     int max_length() const  _NOEXCEPT
    1368              :     {
    1369              :         return do_max_length();
    1370              :     }
    1371              : 
    1372              :     static locale::id id;
    1373              : 
    1374              : protected:
    1375              :     _LIBCPP_INLINE_VISIBILITY
    1376              :     explicit codecvt(const char*, size_t __refs = 0)
    1377              :         : locale::facet(__refs) {}
    1378              : 
    1379              :     ~codecvt() override;
    1380              : 
    1381              :     virtual result do_out(state_type& __st,
    1382              :                           const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
    1383              :                           extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
    1384              :     virtual result do_in(state_type& __st,
    1385              :                          const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
    1386              :                          intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
    1387              :     virtual result do_unshift(state_type& __st,
    1388              :                               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
    1389              :     virtual int do_encoding() const  _NOEXCEPT;
    1390              :     virtual bool do_always_noconv() const  _NOEXCEPT;
    1391              :     virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
    1392              :     virtual int do_max_length() const  _NOEXCEPT;
    1393              : };
    1394              : 
    1395              : #ifndef _LIBCPP_HAS_NO_CHAR8_T
    1396              : 
    1397              : // template <> class codecvt<char32_t, char8_t, mbstate_t> // C++20
    1398              : 
    1399              : template <>
    1400              : class _LIBCPP_TYPE_VIS codecvt<char32_t, char8_t, mbstate_t>
    1401              :     : public locale::facet,
    1402              :       public codecvt_base
    1403              : {
    1404              : public:
    1405              :     typedef char32_t  intern_type;
    1406              :     typedef char8_t   extern_type;
    1407              :     typedef mbstate_t state_type;
    1408              : 
    1409              :     _LIBCPP_INLINE_VISIBILITY
    1410              :     explicit codecvt(size_t __refs = 0)
    1411              :         : locale::facet(__refs) {}
    1412              : 
    1413              :     _LIBCPP_INLINE_VISIBILITY
    1414              :     result out(state_type& __st,
    1415              :                const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
    1416              :                extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
    1417              :     {
    1418              :         return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
    1419              :     }
    1420              : 
    1421              :     _LIBCPP_INLINE_VISIBILITY
    1422              :     result unshift(state_type& __st,
    1423              :                    extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
    1424              :     {
    1425              :         return do_unshift(__st, __to, __to_end, __to_nxt);
    1426              :     }
    1427              : 
    1428              :     _LIBCPP_INLINE_VISIBILITY
    1429              :     result in(state_type& __st,
    1430              :               const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
    1431              :               intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
    1432              :     {
    1433              :         return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
    1434              :     }
    1435              : 
    1436              :     _LIBCPP_INLINE_VISIBILITY
    1437              :     int encoding() const  _NOEXCEPT
    1438              :     {
    1439              :         return do_encoding();
    1440              :     }
    1441              : 
    1442              :     _LIBCPP_INLINE_VISIBILITY
    1443              :     bool always_noconv() const  _NOEXCEPT
    1444              :     {
    1445              :         return do_always_noconv();
    1446              :     }
    1447              : 
    1448              :     _LIBCPP_INLINE_VISIBILITY
    1449              :     int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
    1450              :     {
    1451              :         return do_length(__st, __frm, __end, __mx);
    1452              :     }
    1453              : 
    1454              :     _LIBCPP_INLINE_VISIBILITY
    1455              :     int max_length() const  _NOEXCEPT
    1456              :     {
    1457              :         return do_max_length();
    1458              :     }
    1459              : 
    1460              :     static locale::id id;
    1461              : 
    1462              : protected:
    1463              :     _LIBCPP_INLINE_VISIBILITY
    1464              :     explicit codecvt(const char*, size_t __refs = 0)
    1465              :         : locale::facet(__refs) {}
    1466              : 
    1467              :     ~codecvt() override;
    1468              : 
    1469              :     virtual result do_out(state_type& __st,
    1470              :                           const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
    1471              :                           extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
    1472              :     virtual result do_in(state_type& __st,
    1473              :                          const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
    1474              :                          intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
    1475              :     virtual result do_unshift(state_type& __st,
    1476              :                               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
    1477              :     virtual int do_encoding() const  _NOEXCEPT;
    1478              :     virtual bool do_always_noconv() const  _NOEXCEPT;
    1479              :     virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
    1480              :     virtual int do_max_length() const  _NOEXCEPT;
    1481              : };
    1482              : 
    1483              : #endif
    1484              : 
    1485              : // template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
    1486              : 
    1487              : template <class _InternT, class _ExternT, class _StateT>
    1488              : class _LIBCPP_TEMPLATE_VIS codecvt_byname
    1489              :     : public codecvt<_InternT, _ExternT, _StateT>
    1490              : {
    1491              : public:
    1492              :     _LIBCPP_INLINE_VISIBILITY
    1493              :     explicit codecvt_byname(const char* __nm, size_t __refs = 0)
    1494              :         : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
    1495              :     _LIBCPP_INLINE_VISIBILITY
    1496              :     explicit codecvt_byname(const string& __nm, size_t __refs = 0)
    1497              :         : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
    1498              : protected:
    1499              :     ~codecvt_byname() override;
    1500              : };
    1501              : 
    1502              : _LIBCPP_SUPPRESS_DEPRECATED_PUSH
    1503              : template <class _InternT, class _ExternT, class _StateT>
    1504              : codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
    1505              : {
    1506              : }
    1507              : _LIBCPP_SUPPRESS_DEPRECATED_POP
    1508              : 
    1509              : extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>;
    1510              : #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
    1511              : extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>;
    1512              : #endif
    1513              : extern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>; // deprecated in C++20
    1514              : extern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>; // deprecated in C++20
    1515              : #ifndef _LIBCPP_HAS_NO_CHAR8_T
    1516              : extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>; // C++20
    1517              : extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>; // C++20
    1518              : #endif
    1519              : 
    1520              : template <size_t _Np>
    1521              : struct __narrow_to_utf8
    1522              : {
    1523              :     template <class _OutputIterator, class _CharT>
    1524              :     _OutputIterator
    1525              :     operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
    1526              : };
    1527              : 
    1528              : template <>
    1529              : struct __narrow_to_utf8<8>
    1530              : {
    1531              :     template <class _OutputIterator, class _CharT>
    1532              :     _LIBCPP_INLINE_VISIBILITY
    1533              :     _OutputIterator
    1534              :     operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
    1535              :     {
    1536              :         for (; __wb < __we; ++__wb, ++__s)
    1537              :             *__s = *__wb;
    1538              :         return __s;
    1539              :     }
    1540              : };
    1541              : 
    1542              : _LIBCPP_SUPPRESS_DEPRECATED_PUSH
    1543              : template <>
    1544              : struct _LIBCPP_TYPE_VIS __narrow_to_utf8<16>
    1545              :     : public codecvt<char16_t, char, mbstate_t>
    1546              : {
    1547              :     _LIBCPP_INLINE_VISIBILITY
    1548              :     __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
    1549              : _LIBCPP_SUPPRESS_DEPRECATED_POP
    1550              : 
    1551              :     ~__narrow_to_utf8() override;
    1552              : 
    1553              :     template <class _OutputIterator, class _CharT>
    1554              :     _LIBCPP_INLINE_VISIBILITY
    1555              :     _OutputIterator
    1556              :     operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
    1557              :     {
    1558              :         result __r = ok;
    1559              :         mbstate_t __mb;
    1560              :         while (__wb < __we && __r != error)
    1561              :         {
    1562              :             const int __sz = 32;
    1563              :             char __buf[__sz];
    1564              :             char* __bn;
    1565              :             const char16_t* __wn = (const char16_t*)__wb;
    1566              :             __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
    1567              :                          __buf, __buf+__sz, __bn);
    1568              :             if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
    1569              :                 __throw_runtime_error("locale not supported");
    1570              :             for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
    1571              :                 *__s = *__p;
    1572              :             __wb = (const _CharT*)__wn;
    1573              :         }
    1574              :         return __s;
    1575              :     }
    1576              : };
    1577              : 
    1578              : _LIBCPP_SUPPRESS_DEPRECATED_PUSH
    1579              : template <>
    1580              : struct _LIBCPP_TYPE_VIS __narrow_to_utf8<32>
    1581              :     : public codecvt<char32_t, char, mbstate_t>
    1582              : {
    1583              :     _LIBCPP_INLINE_VISIBILITY
    1584              :     __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
    1585              : _LIBCPP_SUPPRESS_DEPRECATED_POP
    1586              : 
    1587              :     ~__narrow_to_utf8() override;
    1588              : 
    1589              :     template <class _OutputIterator, class _CharT>
    1590              :     _LIBCPP_INLINE_VISIBILITY
    1591              :     _OutputIterator
    1592              :     operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
    1593              :     {
    1594              :         result __r = ok;
    1595              :         mbstate_t __mb;
    1596              :         while (__wb < __we && __r != error)
    1597              :         {
    1598              :             const int __sz = 32;
    1599              :             char __buf[__sz];
    1600              :             char* __bn;
    1601              :             const char32_t* __wn = (const char32_t*)__wb;
    1602              :             __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
    1603              :                          __buf, __buf+__sz, __bn);
    1604              :             if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
    1605              :                 __throw_runtime_error("locale not supported");
    1606              :             for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
    1607              :                 *__s = *__p;
    1608              :             __wb = (const _CharT*)__wn;
    1609              :         }
    1610              :         return __s;
    1611              :     }
    1612              : };
    1613              : 
    1614              : template <size_t _Np>
    1615              : struct __widen_from_utf8
    1616              : {
    1617              :     template <class _OutputIterator>
    1618              :     _OutputIterator
    1619              :     operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
    1620              : };
    1621              : 
    1622              : template <>
    1623              : struct __widen_from_utf8<8>
    1624              : {
    1625              :     template <class _OutputIterator>
    1626              :     _LIBCPP_INLINE_VISIBILITY
    1627              :     _OutputIterator
    1628              :     operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
    1629              :     {
    1630              :         for (; __nb < __ne; ++__nb, ++__s)
    1631              :             *__s = *__nb;
    1632              :         return __s;
    1633              :     }
    1634              : };
    1635              : 
    1636              : _LIBCPP_SUPPRESS_DEPRECATED_PUSH
    1637              : template <>
    1638              : struct _LIBCPP_TYPE_VIS __widen_from_utf8<16>
    1639              :     : public codecvt<char16_t, char, mbstate_t>
    1640              : {
    1641              :     _LIBCPP_INLINE_VISIBILITY
    1642              :     __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
    1643              : _LIBCPP_SUPPRESS_DEPRECATED_POP
    1644              : 
    1645              :     ~__widen_from_utf8() override;
    1646              : 
    1647              :     template <class _OutputIterator>
    1648              :     _LIBCPP_INLINE_VISIBILITY
    1649              :     _OutputIterator
    1650              :     operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
    1651              :     {
    1652              :         result __r = ok;
    1653              :         mbstate_t __mb;
    1654              :         while (__nb < __ne && __r != error)
    1655              :         {
    1656              :             const int __sz = 32;
    1657              :             char16_t __buf[__sz];
    1658              :             char16_t* __bn;
    1659              :             const char* __nn = __nb;
    1660              :             __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
    1661              :                         __buf, __buf+__sz, __bn);
    1662              :             if (__r == codecvt_base::error || __nn == __nb)
    1663              :                 __throw_runtime_error("locale not supported");
    1664              :             for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
    1665              :                 *__s = *__p;
    1666              :             __nb = __nn;
    1667              :         }
    1668              :         return __s;
    1669              :     }
    1670              : };
    1671              : 
    1672              : _LIBCPP_SUPPRESS_DEPRECATED_PUSH
    1673              : template <>
    1674              : struct _LIBCPP_TYPE_VIS __widen_from_utf8<32>
    1675              :     : public codecvt<char32_t, char, mbstate_t>
    1676              : {
    1677              :     _LIBCPP_INLINE_VISIBILITY
    1678              :     __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
    1679              : _LIBCPP_SUPPRESS_DEPRECATED_POP
    1680              : 
    1681              :     ~__widen_from_utf8() override;
    1682              : 
    1683              :     template <class _OutputIterator>
    1684              :     _LIBCPP_INLINE_VISIBILITY
    1685              :     _OutputIterator
    1686              :     operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
    1687              :     {
    1688              :         result __r = ok;
    1689              :         mbstate_t __mb;
    1690              :         while (__nb < __ne && __r != error)
    1691              :         {
    1692              :             const int __sz = 32;
    1693              :             char32_t __buf[__sz];
    1694              :             char32_t* __bn;
    1695              :             const char* __nn = __nb;
    1696              :             __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
    1697              :                         __buf, __buf+__sz, __bn);
    1698              :             if (__r == codecvt_base::error || __nn == __nb)
    1699              :                 __throw_runtime_error("locale not supported");
    1700              :             for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
    1701              :                 *__s = *__p;
    1702              :             __nb = __nn;
    1703              :         }
    1704              :         return __s;
    1705              :     }
    1706              : };
    1707              : 
    1708              : // template <class charT> class numpunct
    1709              : 
    1710              : template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct;
    1711              : 
    1712              : template <>
    1713              : class _LIBCPP_TYPE_VIS numpunct<char>
    1714              :     : public locale::facet
    1715              : {
    1716              : public:
    1717              :     typedef char char_type;
    1718              :     typedef basic_string<char_type> string_type;
    1719              : 
    1720              :     explicit numpunct(size_t __refs = 0);
    1721              : 
    1722              :     _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
    1723              :     _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
    1724              :     _LIBCPP_INLINE_VISIBILITY string grouping() const         {return do_grouping();}
    1725              :     _LIBCPP_INLINE_VISIBILITY string_type truename() const    {return do_truename();}
    1726              :     _LIBCPP_INLINE_VISIBILITY string_type falsename() const   {return do_falsename();}
    1727              : 
    1728              :     static locale::id id;
    1729              : 
    1730              : protected:
    1731              :     ~numpunct() override;
    1732              :     virtual char_type do_decimal_point() const;
    1733              :     virtual char_type do_thousands_sep() const;
    1734              :     virtual string do_grouping() const;
    1735              :     virtual string_type do_truename() const;
    1736              :     virtual string_type do_falsename() const;
    1737              : 
    1738              :     char_type __decimal_point_;
    1739              :     char_type __thousands_sep_;
    1740              :     string __grouping_;
    1741              : };
    1742              : 
    1743              : #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
    1744              : template <>
    1745              : class _LIBCPP_TYPE_VIS numpunct<wchar_t>
    1746              :     : public locale::facet
    1747              : {
    1748              : public:
    1749              :     typedef wchar_t char_type;
    1750              :     typedef basic_string<char_type> string_type;
    1751              : 
    1752              :     explicit numpunct(size_t __refs = 0);
    1753              : 
    1754              :     _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
    1755              :     _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
    1756              :     _LIBCPP_INLINE_VISIBILITY string grouping() const         {return do_grouping();}
    1757              :     _LIBCPP_INLINE_VISIBILITY string_type truename() const    {return do_truename();}
    1758              :     _LIBCPP_INLINE_VISIBILITY string_type falsename() const   {return do_falsename();}
    1759              : 
    1760              :     static locale::id id;
    1761              : 
    1762              : protected:
    1763              :     ~numpunct() override;
    1764              :     virtual char_type do_decimal_point() const;
    1765              :     virtual char_type do_thousands_sep() const;
    1766              :     virtual string do_grouping() const;
    1767              :     virtual string_type do_truename() const;
    1768              :     virtual string_type do_falsename() const;
    1769              : 
    1770              :     char_type __decimal_point_;
    1771              :     char_type __thousands_sep_;
    1772              :     string __grouping_;
    1773              : };
    1774              : #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
    1775              : 
    1776              : // template <class charT> class numpunct_byname
    1777              : 
    1778              : template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct_byname;
    1779              : 
    1780              : template <>
    1781              : class _LIBCPP_TYPE_VIS numpunct_byname<char>
    1782              : : public numpunct<char>
    1783              : {
    1784              : public:
    1785              :     typedef char char_type;
    1786              :     typedef basic_string<char_type> string_type;
    1787              : 
    1788              :     explicit numpunct_byname(const char* __nm, size_t __refs = 0);
    1789              :     explicit numpunct_byname(const string& __nm, size_t __refs = 0);
    1790              : 
    1791              : protected:
    1792              :     ~numpunct_byname() override;
    1793              : 
    1794              : private:
    1795              :     void __init(const char*);
    1796              : };
    1797              : 
    1798              : #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
    1799              : template <>
    1800              : class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
    1801              : : public numpunct<wchar_t>
    1802              : {
    1803              : public:
    1804              :     typedef wchar_t char_type;
    1805              :     typedef basic_string<char_type> string_type;
    1806              : 
    1807              :     explicit numpunct_byname(const char* __nm, size_t __refs = 0);
    1808              :     explicit numpunct_byname(const string& __nm, size_t __refs = 0);
    1809              : 
    1810              : protected:
    1811              :     ~numpunct_byname() override;
    1812              : 
    1813              : private:
    1814              :     void __init(const char*);
    1815              : };
    1816              : #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
    1817              : 
    1818              : _LIBCPP_END_NAMESPACE_STD
    1819              : 
    1820              : #endif // _LIBCPP___LOCALE
        

Generated by: LCOV version 2.0-1