Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/c++/v1/__cxx03/__locale is written in an unsupported language. File is not indexed.

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___CXX03___LOCALE
0011 #define _LIBCPP___CXX03___LOCALE
0012 
0013 #include <__cxx03/__config>
0014 #include <__cxx03/__locale_dir/locale_base_api.h>
0015 #include <__cxx03/__memory/shared_ptr.h> // __shared_count
0016 #include <__cxx03/__mutex/once_flag.h>
0017 #include <__cxx03/__type_traits/make_unsigned.h>
0018 #include <__cxx03/__utility/no_destroy.h>
0019 #include <__cxx03/__utility/private_constructor_tag.h>
0020 #include <__cxx03/cctype>
0021 #include <__cxx03/clocale>
0022 #include <__cxx03/cstdint>
0023 #include <__cxx03/cstdlib>
0024 #include <__cxx03/string>
0025 
0026 // Some platforms require more includes than others. Keep the includes on all plaforms for now.
0027 #include <__cxx03/cstddef>
0028 #include <__cxx03/cstring>
0029 
0030 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
0031 #  include <__cxx03/cwchar>
0032 #else
0033 #  include <__cxx03/__std_mbstate_t.h>
0034 #endif
0035 
0036 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0037 #  pragma GCC system_header
0038 #endif
0039 
0040 _LIBCPP_BEGIN_NAMESPACE_STD
0041 
0042 class _LIBCPP_EXPORTED_FROM_ABI locale;
0043 
0044 template <class _Facet>
0045 _LIBCPP_HIDE_FROM_ABI bool has_facet(const locale&) _NOEXCEPT;
0046 
0047 template <class _Facet>
0048 _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale&);
0049 
0050 class _LIBCPP_EXPORTED_FROM_ABI locale {
0051 public:
0052   // locale is essentially a shared_ptr that doesn't support weak_ptrs and never got a move constructor.
0053   using __trivially_relocatable = locale;
0054 
0055   // types:
0056   class _LIBCPP_EXPORTED_FROM_ABI facet;
0057   class _LIBCPP_EXPORTED_FROM_ABI id;
0058 
0059   typedef int category;
0060 
0061   static const category // values assigned here are for exposition only
0062       none    = 0,
0063       collate = LC_COLLATE_MASK, ctype = LC_CTYPE_MASK, monetary = LC_MONETARY_MASK, numeric = LC_NUMERIC_MASK,
0064       time = LC_TIME_MASK, messages = LC_MESSAGES_MASK, all = collate | ctype | monetary | numeric | time | messages;
0065 
0066   // construct/copy/destroy:
0067   locale() _NOEXCEPT;
0068   locale(const locale&) _NOEXCEPT;
0069   explicit locale(const char*);
0070   explicit locale(const string&);
0071   locale(const locale&, const char*, category);
0072   locale(const locale&, const string&, category);
0073   template <class _Facet>
0074   _LIBCPP_HIDE_FROM_ABI locale(const locale&, _Facet*);
0075   locale(const locale&, const locale&, category);
0076 
0077   ~locale();
0078 
0079   const locale& operator=(const locale&) _NOEXCEPT;
0080 
0081   template <class _Facet>
0082   _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS locale combine(const locale&) const;
0083 
0084   // locale operations:
0085   string name() const;
0086   bool operator==(const locale&) const;
0087 #if _LIBCPP_STD_VER <= 17
0088   _LIBCPP_HIDE_FROM_ABI bool operator!=(const locale& __y) const { return !(*this == __y); }
0089 #endif
0090   template <class _CharT, class _Traits, class _Allocator>
0091   _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool
0092   operator()(const basic_string<_CharT, _Traits, _Allocator>&, const basic_string<_CharT, _Traits, _Allocator>&) const;
0093 
0094   // global locale objects:
0095   static locale global(const locale&);
0096   static const locale& classic();
0097 
0098 private:
0099   class __imp;
0100   __imp* __locale_;
0101 
0102   template <class>
0103   friend struct __no_destroy;
0104   _LIBCPP_HIDE_FROM_ABI explicit locale(__private_constructor_tag, __imp* __loc) : __locale_(__loc) {}
0105 
0106   void __install_ctor(const locale&, facet*, long);
0107   static locale& __global();
0108   bool has_facet(id&) const;
0109   const facet* use_facet(id&) const;
0110 
0111   template <class _Facet>
0112   friend bool has_facet(const locale&) _NOEXCEPT;
0113   template <class _Facet>
0114   friend const _Facet& use_facet(const locale&);
0115 };
0116 
0117 class _LIBCPP_EXPORTED_FROM_ABI locale::facet : public __shared_count {
0118 protected:
0119   _LIBCPP_HIDE_FROM_ABI explicit facet(size_t __refs = 0) : __shared_count(static_cast<long>(__refs) - 1) {}
0120 
0121   ~facet() override;
0122 
0123   //    facet(const facet&) = delete;     // effectively done in __shared_count
0124   //    void operator=(const facet&) = delete;
0125 
0126 private:
0127   void __on_zero_shared() _NOEXCEPT override;
0128 };
0129 
0130 class _LIBCPP_EXPORTED_FROM_ABI locale::id {
0131   once_flag __flag_;
0132   int32_t __id_;
0133 
0134   static int32_t __next_id;
0135 
0136 public:
0137   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR id() : __id_(0) {}
0138   void operator=(const id&) = delete;
0139   id(const id&)             = delete;
0140 
0141 public: // only needed for tests
0142   long __get();
0143 
0144   friend class locale;
0145   friend class locale::__imp;
0146 };
0147 
0148 template <class _Facet>
0149 inline _LIBCPP_HIDE_FROM_ABI locale::locale(const locale& __other, _Facet* __f) {
0150   __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
0151 }
0152 
0153 template <class _Facet>
0154 locale locale::combine(const locale& __other) const {
0155   if (!std::has_facet<_Facet>(__other))
0156     __throw_runtime_error("locale::combine: locale missing facet");
0157 
0158   return locale(*this, &const_cast<_Facet&>(std::use_facet<_Facet>(__other)));
0159 }
0160 
0161 template <class _Facet>
0162 inline _LIBCPP_HIDE_FROM_ABI bool has_facet(const locale& __l) _NOEXCEPT {
0163   return __l.has_facet(_Facet::id);
0164 }
0165 
0166 template <class _Facet>
0167 inline _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale& __l) {
0168   return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
0169 }
0170 
0171 // template <class _CharT> class collate;
0172 
0173 template <class _CharT>
0174 class _LIBCPP_TEMPLATE_VIS collate : public locale::facet {
0175 public:
0176   typedef _CharT char_type;
0177   typedef basic_string<char_type> string_type;
0178 
0179   _LIBCPP_HIDE_FROM_ABI explicit collate(size_t __refs = 0) : locale::facet(__refs) {}
0180 
0181   _LIBCPP_HIDE_FROM_ABI int
0182   compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const {
0183     return do_compare(__lo1, __hi1, __lo2, __hi2);
0184   }
0185 
0186   // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work
0187   // around a dllimport bug that expects an external instantiation.
0188   _LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE string_type
0189   transform(const char_type* __lo, const char_type* __hi) const {
0190     return do_transform(__lo, __hi);
0191   }
0192 
0193   _LIBCPP_HIDE_FROM_ABI long hash(const char_type* __lo, const char_type* __hi) const { return do_hash(__lo, __hi); }
0194 
0195   static locale::id id;
0196 
0197 protected:
0198   ~collate() override;
0199   virtual int
0200   do_compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const;
0201   virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const {
0202     return string_type(__lo, __hi);
0203   }
0204   virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
0205 };
0206 
0207 template <class _CharT>
0208 locale::id collate<_CharT>::id;
0209 
0210 template <class _CharT>
0211 collate<_CharT>::~collate() {}
0212 
0213 template <class _CharT>
0214 int collate<_CharT>::do_compare(
0215     const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const {
0216   for (; __lo2 != __hi2; ++__lo1, ++__lo2) {
0217     if (__lo1 == __hi1 || *__lo1 < *__lo2)
0218       return -1;
0219     if (*__lo2 < *__lo1)
0220       return 1;
0221   }
0222   return __lo1 != __hi1;
0223 }
0224 
0225 template <class _CharT>
0226 long collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const {
0227   size_t __h          = 0;
0228   const size_t __sr   = __CHAR_BIT__ * sizeof(size_t) - 8;
0229   const size_t __mask = size_t(0xF) << (__sr + 4);
0230   for (const char_type* __p = __lo; __p != __hi; ++__p) {
0231     __h        = (__h << 4) + static_cast<size_t>(*__p);
0232     size_t __g = __h & __mask;
0233     __h ^= __g | (__g >> __sr);
0234   }
0235   return static_cast<long>(__h);
0236 }
0237 
0238 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>;
0239 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
0240 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>;
0241 #endif
0242 
0243 // template <class CharT> class collate_byname;
0244 
0245 template <class _CharT>
0246 class _LIBCPP_TEMPLATE_VIS collate_byname;
0247 
0248 template <>
0249 class _LIBCPP_EXPORTED_FROM_ABI collate_byname<char> : public collate<char> {
0250   locale_t __l_;
0251 
0252 public:
0253   typedef char char_type;
0254   typedef basic_string<char_type> string_type;
0255 
0256   explicit collate_byname(const char* __n, size_t __refs = 0);
0257   explicit collate_byname(const string& __n, size_t __refs = 0);
0258 
0259 protected:
0260   ~collate_byname() override;
0261   int do_compare(
0262       const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const override;
0263   string_type do_transform(const char_type* __lo, const char_type* __hi) const override;
0264 };
0265 
0266 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
0267 template <>
0268 class _LIBCPP_EXPORTED_FROM_ABI collate_byname<wchar_t> : public collate<wchar_t> {
0269   locale_t __l_;
0270 
0271 public:
0272   typedef wchar_t char_type;
0273   typedef basic_string<char_type> string_type;
0274 
0275   explicit collate_byname(const char* __n, size_t __refs = 0);
0276   explicit collate_byname(const string& __n, size_t __refs = 0);
0277 
0278 protected:
0279   ~collate_byname() override;
0280 
0281   int do_compare(
0282       const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const override;
0283   string_type do_transform(const char_type* __lo, const char_type* __hi) const override;
0284 };
0285 #endif
0286 
0287 template <class _CharT, class _Traits, class _Allocator>
0288 bool locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
0289                         const basic_string<_CharT, _Traits, _Allocator>& __y) const {
0290   return std::use_facet<std::collate<_CharT> >(*this).compare(
0291              __x.data(), __x.data() + __x.size(), __y.data(), __y.data() + __y.size()) < 0;
0292 }
0293 
0294 // template <class charT> class ctype
0295 
0296 class _LIBCPP_EXPORTED_FROM_ABI ctype_base {
0297 public:
0298 #if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE)
0299   typedef unsigned long mask;
0300   static const mask space  = 1 << 0;
0301   static const mask print  = 1 << 1;
0302   static const mask cntrl  = 1 << 2;
0303   static const mask upper  = 1 << 3;
0304   static const mask lower  = 1 << 4;
0305   static const mask alpha  = 1 << 5;
0306   static const mask digit  = 1 << 6;
0307   static const mask punct  = 1 << 7;
0308   static const mask xdigit = 1 << 8;
0309   static const mask blank  = 1 << 9;
0310 #  if defined(__BIONIC__)
0311   // Historically this was a part of regex_traits rather than ctype_base. The
0312   // historical value of the constant is preserved for ABI compatibility.
0313   static const mask __regex_word = 0x8000;
0314 #  else
0315   static const mask __regex_word = 1 << 10;
0316 #  endif // defined(__BIONIC__)
0317 #elif defined(__GLIBC__)
0318   typedef unsigned short mask;
0319   static const mask space  = _ISspace;
0320   static const mask print  = _ISprint;
0321   static const mask cntrl  = _IScntrl;
0322   static const mask upper  = _ISupper;
0323   static const mask lower  = _ISlower;
0324   static const mask alpha  = _ISalpha;
0325   static const mask digit  = _ISdigit;
0326   static const mask punct  = _ISpunct;
0327   static const mask xdigit = _ISxdigit;
0328   static const mask blank  = _ISblank;
0329 #  if defined(__mips__) || (BYTE_ORDER == BIG_ENDIAN)
0330   static const mask __regex_word = static_cast<mask>(_ISbit(15));
0331 #  else
0332   static const mask __regex_word = 0x80;
0333 #  endif
0334 #elif defined(_LIBCPP_MSVCRT_LIKE)
0335   typedef unsigned short mask;
0336   static const mask space        = _SPACE;
0337   static const mask print        = _BLANK | _PUNCT | _ALPHA | _DIGIT;
0338   static const mask cntrl        = _CONTROL;
0339   static const mask upper        = _UPPER;
0340   static const mask lower        = _LOWER;
0341   static const mask alpha        = _ALPHA;
0342   static const mask digit        = _DIGIT;
0343   static const mask punct        = _PUNCT;
0344   static const mask xdigit       = _HEX;
0345   static const mask blank        = _BLANK;
0346   static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used
0347 #  define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
0348 #  define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
0349 #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
0350 #  ifdef __APPLE__
0351   typedef __uint32_t mask;
0352 #  elif defined(__FreeBSD__)
0353   typedef unsigned long mask;
0354 #  elif defined(__NetBSD__)
0355   typedef unsigned short mask;
0356 #  endif
0357   static const mask space  = _CTYPE_S;
0358   static const mask print  = _CTYPE_R;
0359   static const mask cntrl  = _CTYPE_C;
0360   static const mask upper  = _CTYPE_U;
0361   static const mask lower  = _CTYPE_L;
0362   static const mask alpha  = _CTYPE_A;
0363   static const mask digit  = _CTYPE_D;
0364   static const mask punct  = _CTYPE_P;
0365   static const mask xdigit = _CTYPE_X;
0366 
0367 #  if defined(__NetBSD__)
0368   static const mask blank = _CTYPE_BL;
0369   // NetBSD defines classes up to 0x2000
0370   // see sys/ctype_bits.h, _CTYPE_Q
0371   static const mask __regex_word = 0x8000;
0372 #  else
0373   static const mask blank        = _CTYPE_B;
0374   static const mask __regex_word = 0x80;
0375 #  endif
0376 #elif defined(_AIX)
0377   typedef unsigned int mask;
0378   static const mask space        = _ISSPACE;
0379   static const mask print        = _ISPRINT;
0380   static const mask cntrl        = _ISCNTRL;
0381   static const mask upper        = _ISUPPER;
0382   static const mask lower        = _ISLOWER;
0383   static const mask alpha        = _ISALPHA;
0384   static const mask digit        = _ISDIGIT;
0385   static const mask punct        = _ISPUNCT;
0386   static const mask xdigit       = _ISXDIGIT;
0387   static const mask blank        = _ISBLANK;
0388   static const mask __regex_word = 0x8000;
0389 #elif defined(_NEWLIB_VERSION)
0390   // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
0391   typedef char mask;
0392   // In case char is signed, static_cast is needed to avoid warning on
0393   // positive value becomming negative.
0394   static const mask space  = static_cast<mask>(_S);
0395   static const mask print  = static_cast<mask>(_P | _U | _L | _N | _B);
0396   static const mask cntrl  = static_cast<mask>(_C);
0397   static const mask upper  = static_cast<mask>(_U);
0398   static const mask lower  = static_cast<mask>(_L);
0399   static const mask alpha  = static_cast<mask>(_U | _L);
0400   static const mask digit  = static_cast<mask>(_N);
0401   static const mask punct  = static_cast<mask>(_P);
0402   static const mask xdigit = static_cast<mask>(_X | _N);
0403   static const mask blank  = static_cast<mask>(_B);
0404   // mask is already fully saturated, use a different type in regex_type_traits.
0405   static const unsigned short __regex_word = 0x100;
0406 #  define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
0407 #  define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
0408 #  define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
0409 #elif defined(__MVS__)
0410 #  if defined(__NATIVE_ASCII_F)
0411   typedef unsigned int mask;
0412   static const mask space  = _ISSPACE_A;
0413   static const mask print  = _ISPRINT_A;
0414   static const mask cntrl  = _ISCNTRL_A;
0415   static const mask upper  = _ISUPPER_A;
0416   static const mask lower  = _ISLOWER_A;
0417   static const mask alpha  = _ISALPHA_A;
0418   static const mask digit  = _ISDIGIT_A;
0419   static const mask punct  = _ISPUNCT_A;
0420   static const mask xdigit = _ISXDIGIT_A;
0421   static const mask blank  = _ISBLANK_A;
0422 #  else
0423   typedef unsigned short mask;
0424   static const mask space  = __ISSPACE;
0425   static const mask print  = __ISPRINT;
0426   static const mask cntrl  = __ISCNTRL;
0427   static const mask upper  = __ISUPPER;
0428   static const mask lower  = __ISLOWER;
0429   static const mask alpha  = __ISALPHA;
0430   static const mask digit  = __ISDIGIT;
0431   static const mask punct  = __ISPUNCT;
0432   static const mask xdigit = __ISXDIGIT;
0433   static const mask blank  = __ISBLANK;
0434 #  endif
0435   static const mask __regex_word = 0x8000;
0436 #else
0437 #  error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?
0438 #endif
0439   static const mask alnum = alpha | digit;
0440   static const mask graph = alnum | punct;
0441 
0442   _LIBCPP_HIDE_FROM_ABI ctype_base() {}
0443 
0444   static_assert((__regex_word & ~(std::make_unsigned<mask>::type)(space | print | cntrl | upper | lower | alpha |
0445                                                                   digit | punct | xdigit | blank)) == __regex_word,
0446                 "__regex_word can't overlap other bits");
0447 };
0448 
0449 template <class _CharT>
0450 class _LIBCPP_TEMPLATE_VIS ctype;
0451 
0452 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
0453 template <>
0454 class _LIBCPP_EXPORTED_FROM_ABI ctype<wchar_t> : public locale::facet, public ctype_base {
0455 public:
0456   typedef wchar_t char_type;
0457 
0458   _LIBCPP_HIDE_FROM_ABI explicit ctype(size_t __refs = 0) : locale::facet(__refs) {}
0459 
0460   _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const { return do_is(__m, __c); }
0461 
0462   _LIBCPP_HIDE_FROM_ABI const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const {
0463     return do_is(__low, __high, __vec);
0464   }
0465 
0466   _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const {
0467     return do_scan_is(__m, __low, __high);
0468   }
0469 
0470   _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const {
0471     return do_scan_not(__m, __low, __high);
0472   }
0473 
0474   _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); }
0475 
0476   _LIBCPP_HIDE_FROM_ABI const char_type* toupper(char_type* __low, const char_type* __high) const {
0477     return do_toupper(__low, __high);
0478   }
0479 
0480   _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); }
0481 
0482   _LIBCPP_HIDE_FROM_ABI const char_type* tolower(char_type* __low, const char_type* __high) const {
0483     return do_tolower(__low, __high);
0484   }
0485 
0486   _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); }
0487 
0488   _LIBCPP_HIDE_FROM_ABI const char* widen(const char* __low, const char* __high, char_type* __to) const {
0489     return do_widen(__low, __high, __to);
0490   }
0491 
0492   _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); }
0493 
0494   _LIBCPP_HIDE_FROM_ABI const char_type*
0495   narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const {
0496     return do_narrow(__low, __high, __dfault, __to);
0497   }
0498 
0499   static locale::id id;
0500 
0501 protected:
0502   ~ctype() override;
0503   virtual bool do_is(mask __m, char_type __c) const;
0504   virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
0505   virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
0506   virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
0507   virtual char_type do_toupper(char_type) const;
0508   virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
0509   virtual char_type do_tolower(char_type) const;
0510   virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
0511   virtual char_type do_widen(char) const;
0512   virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
0513   virtual char do_narrow(char_type, char __dfault) const;
0514   virtual const char_type*
0515   do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
0516 };
0517 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
0518 
0519 template <>
0520 class _LIBCPP_EXPORTED_FROM_ABI ctype<char> : public locale::facet, public ctype_base {
0521   const mask* __tab_;
0522   bool __del_;
0523 
0524 public:
0525   typedef char char_type;
0526 
0527   explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0);
0528 
0529   _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const {
0530     return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) != 0 : false;
0531   }
0532 
0533   _LIBCPP_HIDE_FROM_ABI const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const {
0534     for (; __low != __high; ++__low, ++__vec)
0535       *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
0536     return __low;
0537   }
0538 
0539   _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const {
0540     for (; __low != __high; ++__low)
0541       if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
0542         break;
0543     return __low;
0544   }
0545 
0546   _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const {
0547     for (; __low != __high; ++__low)
0548       if (!isascii(*__low) || !(__tab_[static_cast<int>(*__low)] & __m))
0549         break;
0550     return __low;
0551   }
0552 
0553   _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); }
0554 
0555   _LIBCPP_HIDE_FROM_ABI const char_type* toupper(char_type* __low, const char_type* __high) const {
0556     return do_toupper(__low, __high);
0557   }
0558 
0559   _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); }
0560 
0561   _LIBCPP_HIDE_FROM_ABI const char_type* tolower(char_type* __low, const char_type* __high) const {
0562     return do_tolower(__low, __high);
0563   }
0564 
0565   _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); }
0566 
0567   _LIBCPP_HIDE_FROM_ABI const char* widen(const char* __low, const char* __high, char_type* __to) const {
0568     return do_widen(__low, __high, __to);
0569   }
0570 
0571   _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); }
0572 
0573   _LIBCPP_HIDE_FROM_ABI const char*
0574   narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const {
0575     return do_narrow(__low, __high, __dfault, __to);
0576   }
0577 
0578   static locale::id id;
0579 
0580 #ifdef _CACHED_RUNES
0581   static const size_t table_size = _CACHED_RUNES;
0582 #else
0583   static const size_t table_size = 256; // FIXME: Don't hardcode this.
0584 #endif
0585   _LIBCPP_HIDE_FROM_ABI const mask* table() const _NOEXCEPT { return __tab_; }
0586   static const mask* classic_table() _NOEXCEPT;
0587 #if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
0588   static const int* __classic_upper_table() _NOEXCEPT;
0589   static const int* __classic_lower_table() _NOEXCEPT;
0590 #endif
0591 #if defined(__NetBSD__)
0592   static const short* __classic_upper_table() _NOEXCEPT;
0593   static const short* __classic_lower_table() _NOEXCEPT;
0594 #endif
0595 #if defined(__MVS__)
0596   static const unsigned short* __classic_upper_table() _NOEXCEPT;
0597   static const unsigned short* __classic_lower_table() _NOEXCEPT;
0598 #endif
0599 
0600 protected:
0601   ~ctype() override;
0602   virtual char_type do_toupper(char_type __c) const;
0603   virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
0604   virtual char_type do_tolower(char_type __c) const;
0605   virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
0606   virtual char_type do_widen(char __c) const;
0607   virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
0608   virtual char do_narrow(char_type __c, char __dfault) const;
0609   virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
0610 };
0611 
0612 // template <class CharT> class ctype_byname;
0613 
0614 template <class _CharT>
0615 class _LIBCPP_TEMPLATE_VIS ctype_byname;
0616 
0617 template <>
0618 class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<char> : public ctype<char> {
0619   locale_t __l_;
0620 
0621 public:
0622   explicit ctype_byname(const char*, size_t = 0);
0623   explicit ctype_byname(const string&, size_t = 0);
0624 
0625 protected:
0626   ~ctype_byname() override;
0627   char_type do_toupper(char_type) const override;
0628   const char_type* do_toupper(char_type* __low, const char_type* __high) const override;
0629   char_type do_tolower(char_type) const override;
0630   const char_type* do_tolower(char_type* __low, const char_type* __high) const override;
0631 };
0632 
0633 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
0634 template <>
0635 class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<wchar_t> : public ctype<wchar_t> {
0636   locale_t __l_;
0637 
0638 public:
0639   explicit ctype_byname(const char*, size_t = 0);
0640   explicit ctype_byname(const string&, size_t = 0);
0641 
0642 protected:
0643   ~ctype_byname() override;
0644   bool do_is(mask __m, char_type __c) const override;
0645   const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const override;
0646   const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const override;
0647   const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const override;
0648   char_type do_toupper(char_type) const override;
0649   const char_type* do_toupper(char_type* __low, const char_type* __high) const override;
0650   char_type do_tolower(char_type) const override;
0651   const char_type* do_tolower(char_type* __low, const char_type* __high) const override;
0652   char_type do_widen(char) const override;
0653   const char* do_widen(const char* __low, const char* __high, char_type* __dest) const override;
0654   char do_narrow(char_type, char __dfault) const override;
0655   const char_type*
0656   do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const override;
0657 };
0658 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
0659 
0660 template <class _CharT>
0661 inline _LIBCPP_HIDE_FROM_ABI bool isspace(_CharT __c, const locale& __loc) {
0662   return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
0663 }
0664 
0665 template <class _CharT>
0666 inline _LIBCPP_HIDE_FROM_ABI bool isprint(_CharT __c, const locale& __loc) {
0667   return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
0668 }
0669 
0670 template <class _CharT>
0671 inline _LIBCPP_HIDE_FROM_ABI bool iscntrl(_CharT __c, const locale& __loc) {
0672   return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
0673 }
0674 
0675 template <class _CharT>
0676 inline _LIBCPP_HIDE_FROM_ABI bool isupper(_CharT __c, const locale& __loc) {
0677   return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
0678 }
0679 
0680 template <class _CharT>
0681 inline _LIBCPP_HIDE_FROM_ABI bool islower(_CharT __c, const locale& __loc) {
0682   return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
0683 }
0684 
0685 template <class _CharT>
0686 inline _LIBCPP_HIDE_FROM_ABI bool isalpha(_CharT __c, const locale& __loc) {
0687   return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
0688 }
0689 
0690 template <class _CharT>
0691 inline _LIBCPP_HIDE_FROM_ABI bool isdigit(_CharT __c, const locale& __loc) {
0692   return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
0693 }
0694 
0695 template <class _CharT>
0696 inline _LIBCPP_HIDE_FROM_ABI bool ispunct(_CharT __c, const locale& __loc) {
0697   return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
0698 }
0699 
0700 template <class _CharT>
0701 inline _LIBCPP_HIDE_FROM_ABI bool isxdigit(_CharT __c, const locale& __loc) {
0702   return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
0703 }
0704 
0705 template <class _CharT>
0706 inline _LIBCPP_HIDE_FROM_ABI bool isalnum(_CharT __c, const locale& __loc) {
0707   return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
0708 }
0709 
0710 template <class _CharT>
0711 inline _LIBCPP_HIDE_FROM_ABI bool isgraph(_CharT __c, const locale& __loc) {
0712   return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
0713 }
0714 
0715 template <class _CharT>
0716 _LIBCPP_HIDE_FROM_ABI bool isblank(_CharT __c, const locale& __loc) {
0717   return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::blank, __c);
0718 }
0719 
0720 template <class _CharT>
0721 inline _LIBCPP_HIDE_FROM_ABI _CharT toupper(_CharT __c, const locale& __loc) {
0722   return std::use_facet<ctype<_CharT> >(__loc).toupper(__c);
0723 }
0724 
0725 template <class _CharT>
0726 inline _LIBCPP_HIDE_FROM_ABI _CharT tolower(_CharT __c, const locale& __loc) {
0727   return std::use_facet<ctype<_CharT> >(__loc).tolower(__c);
0728 }
0729 
0730 // codecvt_base
0731 
0732 class _LIBCPP_EXPORTED_FROM_ABI codecvt_base {
0733 public:
0734   _LIBCPP_HIDE_FROM_ABI codecvt_base() {}
0735   enum result { ok, partial, error, noconv };
0736 };
0737 
0738 // template <class internT, class externT, class stateT> class codecvt;
0739 
0740 template <class _InternT, class _ExternT, class _StateT>
0741 class _LIBCPP_TEMPLATE_VIS codecvt;
0742 
0743 // template <> class codecvt<char, char, mbstate_t>
0744 
0745 template <>
0746 class _LIBCPP_EXPORTED_FROM_ABI codecvt<char, char, mbstate_t> : public locale::facet, public codecvt_base {
0747 public:
0748   typedef char intern_type;
0749   typedef char extern_type;
0750   typedef mbstate_t state_type;
0751 
0752   _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
0753 
0754   _LIBCPP_HIDE_FROM_ABI result
0755   out(state_type& __st,
0756       const intern_type* __frm,
0757       const intern_type* __frm_end,
0758       const intern_type*& __frm_nxt,
0759       extern_type* __to,
0760       extern_type* __to_end,
0761       extern_type*& __to_nxt) const {
0762     return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
0763   }
0764 
0765   _LIBCPP_HIDE_FROM_ABI result
0766   unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {
0767     return do_unshift(__st, __to, __to_end, __to_nxt);
0768   }
0769 
0770   _LIBCPP_HIDE_FROM_ABI result
0771   in(state_type& __st,
0772      const extern_type* __frm,
0773      const extern_type* __frm_end,
0774      const extern_type*& __frm_nxt,
0775      intern_type* __to,
0776      intern_type* __to_end,
0777      intern_type*& __to_nxt) const {
0778     return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
0779   }
0780 
0781   _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }
0782 
0783   _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }
0784 
0785   _LIBCPP_HIDE_FROM_ABI int
0786   length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {
0787     return do_length(__st, __frm, __end, __mx);
0788   }
0789 
0790   _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }
0791 
0792   static locale::id id;
0793 
0794 protected:
0795   _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}
0796 
0797   ~codecvt() override;
0798 
0799   virtual result
0800   do_out(state_type& __st,
0801          const intern_type* __frm,
0802          const intern_type* __frm_end,
0803          const intern_type*& __frm_nxt,
0804          extern_type* __to,
0805          extern_type* __to_end,
0806          extern_type*& __to_nxt) const;
0807   virtual result
0808   do_in(state_type& __st,
0809         const extern_type* __frm,
0810         const extern_type* __frm_end,
0811         const extern_type*& __frm_nxt,
0812         intern_type* __to,
0813         intern_type* __to_end,
0814         intern_type*& __to_nxt) const;
0815   virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
0816   virtual int do_encoding() const _NOEXCEPT;
0817   virtual bool do_always_noconv() const _NOEXCEPT;
0818   virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
0819   virtual int do_max_length() const _NOEXCEPT;
0820 };
0821 
0822 // template <> class codecvt<wchar_t, char, mbstate_t>
0823 
0824 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
0825 template <>
0826 class _LIBCPP_EXPORTED_FROM_ABI codecvt<wchar_t, char, mbstate_t> : public locale::facet, public codecvt_base {
0827   locale_t __l_;
0828 
0829 public:
0830   typedef wchar_t intern_type;
0831   typedef char extern_type;
0832   typedef mbstate_t state_type;
0833 
0834   explicit codecvt(size_t __refs = 0);
0835 
0836   _LIBCPP_HIDE_FROM_ABI result
0837   out(state_type& __st,
0838       const intern_type* __frm,
0839       const intern_type* __frm_end,
0840       const intern_type*& __frm_nxt,
0841       extern_type* __to,
0842       extern_type* __to_end,
0843       extern_type*& __to_nxt) const {
0844     return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
0845   }
0846 
0847   _LIBCPP_HIDE_FROM_ABI result
0848   unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {
0849     return do_unshift(__st, __to, __to_end, __to_nxt);
0850   }
0851 
0852   _LIBCPP_HIDE_FROM_ABI result
0853   in(state_type& __st,
0854      const extern_type* __frm,
0855      const extern_type* __frm_end,
0856      const extern_type*& __frm_nxt,
0857      intern_type* __to,
0858      intern_type* __to_end,
0859      intern_type*& __to_nxt) const {
0860     return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
0861   }
0862 
0863   _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }
0864 
0865   _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }
0866 
0867   _LIBCPP_HIDE_FROM_ABI int
0868   length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {
0869     return do_length(__st, __frm, __end, __mx);
0870   }
0871 
0872   _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }
0873 
0874   static locale::id id;
0875 
0876 protected:
0877   explicit codecvt(const char*, size_t __refs = 0);
0878 
0879   ~codecvt() override;
0880 
0881   virtual result
0882   do_out(state_type& __st,
0883          const intern_type* __frm,
0884          const intern_type* __frm_end,
0885          const intern_type*& __frm_nxt,
0886          extern_type* __to,
0887          extern_type* __to_end,
0888          extern_type*& __to_nxt) const;
0889   virtual result
0890   do_in(state_type& __st,
0891         const extern_type* __frm,
0892         const extern_type* __frm_end,
0893         const extern_type*& __frm_nxt,
0894         intern_type* __to,
0895         intern_type* __to_end,
0896         intern_type*& __to_nxt) const;
0897   virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
0898   virtual int do_encoding() const _NOEXCEPT;
0899   virtual bool do_always_noconv() const _NOEXCEPT;
0900   virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
0901   virtual int do_max_length() const _NOEXCEPT;
0902 };
0903 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
0904 
0905 // template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20
0906 
0907 template <>
0908 class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char, mbstate_t>
0909     : public locale::facet, public codecvt_base {
0910 public:
0911   typedef char16_t intern_type;
0912   typedef char extern_type;
0913   typedef mbstate_t state_type;
0914 
0915   _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
0916 
0917   _LIBCPP_HIDE_FROM_ABI result
0918   out(state_type& __st,
0919       const intern_type* __frm,
0920       const intern_type* __frm_end,
0921       const intern_type*& __frm_nxt,
0922       extern_type* __to,
0923       extern_type* __to_end,
0924       extern_type*& __to_nxt) const {
0925     return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
0926   }
0927 
0928   _LIBCPP_HIDE_FROM_ABI result
0929   unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {
0930     return do_unshift(__st, __to, __to_end, __to_nxt);
0931   }
0932 
0933   _LIBCPP_HIDE_FROM_ABI result
0934   in(state_type& __st,
0935      const extern_type* __frm,
0936      const extern_type* __frm_end,
0937      const extern_type*& __frm_nxt,
0938      intern_type* __to,
0939      intern_type* __to_end,
0940      intern_type*& __to_nxt) const {
0941     return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
0942   }
0943 
0944   _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }
0945 
0946   _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }
0947 
0948   _LIBCPP_HIDE_FROM_ABI int
0949   length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {
0950     return do_length(__st, __frm, __end, __mx);
0951   }
0952 
0953   _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }
0954 
0955   static locale::id id;
0956 
0957 protected:
0958   _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}
0959 
0960   ~codecvt() override;
0961 
0962   virtual result
0963   do_out(state_type& __st,
0964          const intern_type* __frm,
0965          const intern_type* __frm_end,
0966          const intern_type*& __frm_nxt,
0967          extern_type* __to,
0968          extern_type* __to_end,
0969          extern_type*& __to_nxt) const;
0970   virtual result
0971   do_in(state_type& __st,
0972         const extern_type* __frm,
0973         const extern_type* __frm_end,
0974         const extern_type*& __frm_nxt,
0975         intern_type* __to,
0976         intern_type* __to_end,
0977         intern_type*& __to_nxt) const;
0978   virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
0979   virtual int do_encoding() const _NOEXCEPT;
0980   virtual bool do_always_noconv() const _NOEXCEPT;
0981   virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
0982   virtual int do_max_length() const _NOEXCEPT;
0983 };
0984 
0985 #ifndef _LIBCPP_HAS_NO_CHAR8_T
0986 
0987 // template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20
0988 
0989 template <>
0990 class _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char8_t, mbstate_t> : public locale::facet, public codecvt_base {
0991 public:
0992   typedef char16_t intern_type;
0993   typedef char8_t extern_type;
0994   typedef mbstate_t state_type;
0995 
0996   _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
0997 
0998   _LIBCPP_HIDE_FROM_ABI result
0999   out(state_type& __st,
1000       const intern_type* __frm,
1001       const intern_type* __frm_end,
1002       const intern_type*& __frm_nxt,
1003       extern_type* __to,
1004       extern_type* __to_end,
1005       extern_type*& __to_nxt) const {
1006     return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1007   }
1008 
1009   _LIBCPP_HIDE_FROM_ABI result
1010   unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {
1011     return do_unshift(__st, __to, __to_end, __to_nxt);
1012   }
1013 
1014   _LIBCPP_HIDE_FROM_ABI result
1015   in(state_type& __st,
1016      const extern_type* __frm,
1017      const extern_type* __frm_end,
1018      const extern_type*& __frm_nxt,
1019      intern_type* __to,
1020      intern_type* __to_end,
1021      intern_type*& __to_nxt) const {
1022     return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1023   }
1024 
1025   _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }
1026 
1027   _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }
1028 
1029   _LIBCPP_HIDE_FROM_ABI int
1030   length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {
1031     return do_length(__st, __frm, __end, __mx);
1032   }
1033 
1034   _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }
1035 
1036   static locale::id id;
1037 
1038 protected:
1039   _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}
1040 
1041   ~codecvt() override;
1042 
1043   virtual result
1044   do_out(state_type& __st,
1045          const intern_type* __frm,
1046          const intern_type* __frm_end,
1047          const intern_type*& __frm_nxt,
1048          extern_type* __to,
1049          extern_type* __to_end,
1050          extern_type*& __to_nxt) const;
1051   virtual result
1052   do_in(state_type& __st,
1053         const extern_type* __frm,
1054         const extern_type* __frm_end,
1055         const extern_type*& __frm_nxt,
1056         intern_type* __to,
1057         intern_type* __to_end,
1058         intern_type*& __to_nxt) const;
1059   virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1060   virtual int do_encoding() const _NOEXCEPT;
1061   virtual bool do_always_noconv() const _NOEXCEPT;
1062   virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1063   virtual int do_max_length() const _NOEXCEPT;
1064 };
1065 
1066 #endif
1067 
1068 // template <> class codecvt<char32_t, char, mbstate_t> // deprecated in C++20
1069 
1070 template <>
1071 class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char, mbstate_t>
1072     : public locale::facet, public codecvt_base {
1073 public:
1074   typedef char32_t intern_type;
1075   typedef char extern_type;
1076   typedef mbstate_t state_type;
1077 
1078   _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
1079 
1080   _LIBCPP_HIDE_FROM_ABI result
1081   out(state_type& __st,
1082       const intern_type* __frm,
1083       const intern_type* __frm_end,
1084       const intern_type*& __frm_nxt,
1085       extern_type* __to,
1086       extern_type* __to_end,
1087       extern_type*& __to_nxt) const {
1088     return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1089   }
1090 
1091   _LIBCPP_HIDE_FROM_ABI result
1092   unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {
1093     return do_unshift(__st, __to, __to_end, __to_nxt);
1094   }
1095 
1096   _LIBCPP_HIDE_FROM_ABI result
1097   in(state_type& __st,
1098      const extern_type* __frm,
1099      const extern_type* __frm_end,
1100      const extern_type*& __frm_nxt,
1101      intern_type* __to,
1102      intern_type* __to_end,
1103      intern_type*& __to_nxt) const {
1104     return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1105   }
1106 
1107   _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }
1108 
1109   _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }
1110 
1111   _LIBCPP_HIDE_FROM_ABI int
1112   length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {
1113     return do_length(__st, __frm, __end, __mx);
1114   }
1115 
1116   _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }
1117 
1118   static locale::id id;
1119 
1120 protected:
1121   _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}
1122 
1123   ~codecvt() override;
1124 
1125   virtual result
1126   do_out(state_type& __st,
1127          const intern_type* __frm,
1128          const intern_type* __frm_end,
1129          const intern_type*& __frm_nxt,
1130          extern_type* __to,
1131          extern_type* __to_end,
1132          extern_type*& __to_nxt) const;
1133   virtual result
1134   do_in(state_type& __st,
1135         const extern_type* __frm,
1136         const extern_type* __frm_end,
1137         const extern_type*& __frm_nxt,
1138         intern_type* __to,
1139         intern_type* __to_end,
1140         intern_type*& __to_nxt) const;
1141   virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1142   virtual int do_encoding() const _NOEXCEPT;
1143   virtual bool do_always_noconv() const _NOEXCEPT;
1144   virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1145   virtual int do_max_length() const _NOEXCEPT;
1146 };
1147 
1148 #ifndef _LIBCPP_HAS_NO_CHAR8_T
1149 
1150 // template <> class codecvt<char32_t, char8_t, mbstate_t> // C++20
1151 
1152 template <>
1153 class _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char8_t, mbstate_t> : public locale::facet, public codecvt_base {
1154 public:
1155   typedef char32_t intern_type;
1156   typedef char8_t extern_type;
1157   typedef mbstate_t state_type;
1158 
1159   _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
1160 
1161   _LIBCPP_HIDE_FROM_ABI result
1162   out(state_type& __st,
1163       const intern_type* __frm,
1164       const intern_type* __frm_end,
1165       const intern_type*& __frm_nxt,
1166       extern_type* __to,
1167       extern_type* __to_end,
1168       extern_type*& __to_nxt) const {
1169     return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1170   }
1171 
1172   _LIBCPP_HIDE_FROM_ABI result
1173   unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {
1174     return do_unshift(__st, __to, __to_end, __to_nxt);
1175   }
1176 
1177   _LIBCPP_HIDE_FROM_ABI result
1178   in(state_type& __st,
1179      const extern_type* __frm,
1180      const extern_type* __frm_end,
1181      const extern_type*& __frm_nxt,
1182      intern_type* __to,
1183      intern_type* __to_end,
1184      intern_type*& __to_nxt) const {
1185     return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1186   }
1187 
1188   _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }
1189 
1190   _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }
1191 
1192   _LIBCPP_HIDE_FROM_ABI int
1193   length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {
1194     return do_length(__st, __frm, __end, __mx);
1195   }
1196 
1197   _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }
1198 
1199   static locale::id id;
1200 
1201 protected:
1202   _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}
1203 
1204   ~codecvt() override;
1205 
1206   virtual result
1207   do_out(state_type& __st,
1208          const intern_type* __frm,
1209          const intern_type* __frm_end,
1210          const intern_type*& __frm_nxt,
1211          extern_type* __to,
1212          extern_type* __to_end,
1213          extern_type*& __to_nxt) const;
1214   virtual result
1215   do_in(state_type& __st,
1216         const extern_type* __frm,
1217         const extern_type* __frm_end,
1218         const extern_type*& __frm_nxt,
1219         intern_type* __to,
1220         intern_type* __to_end,
1221         intern_type*& __to_nxt) const;
1222   virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1223   virtual int do_encoding() const _NOEXCEPT;
1224   virtual bool do_always_noconv() const _NOEXCEPT;
1225   virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1226   virtual int do_max_length() const _NOEXCEPT;
1227 };
1228 
1229 #endif
1230 
1231 // template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
1232 
1233 template <class _InternT, class _ExternT, class _StateT>
1234 class _LIBCPP_TEMPLATE_VIS codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> {
1235 public:
1236   _LIBCPP_HIDE_FROM_ABI explicit codecvt_byname(const char* __nm, size_t __refs = 0)
1237       : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
1238   _LIBCPP_HIDE_FROM_ABI explicit codecvt_byname(const string& __nm, size_t __refs = 0)
1239       : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
1240 
1241 protected:
1242   ~codecvt_byname() override;
1243 };
1244 
1245 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1246 template <class _InternT, class _ExternT, class _StateT>
1247 codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() {}
1248 _LIBCPP_SUPPRESS_DEPRECATED_POP
1249 
1250 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>;
1251 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1252 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>;
1253 #endif
1254 extern template class _LIBCPP_DEPRECATED_IN_CXX20
1255 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>; // deprecated in C++20
1256 extern template class _LIBCPP_DEPRECATED_IN_CXX20
1257 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>; // deprecated in C++20
1258 #ifndef _LIBCPP_HAS_NO_CHAR8_T
1259 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>; // C++20
1260 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>; // C++20
1261 #endif
1262 
1263 template <size_t _Np>
1264 struct __narrow_to_utf8 {
1265   template <class _OutputIterator, class _CharT>
1266   _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
1267 };
1268 
1269 template <>
1270 struct __narrow_to_utf8<8> {
1271   template <class _OutputIterator, class _CharT>
1272   _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const {
1273     for (; __wb < __we; ++__wb, ++__s)
1274       *__s = *__wb;
1275     return __s;
1276   }
1277 };
1278 
1279 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1280 template <>
1281 struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<16> : public codecvt<char16_t, char, mbstate_t> {
1282   _LIBCPP_HIDE_FROM_ABI __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1283   _LIBCPP_SUPPRESS_DEPRECATED_POP
1284 
1285   ~__narrow_to_utf8() override;
1286 
1287   template <class _OutputIterator, class _CharT>
1288   _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const {
1289     result __r = ok;
1290     mbstate_t __mb;
1291     while (__wb < __we && __r != error) {
1292       const int __sz = 32;
1293       char __buf[__sz];
1294       char* __bn;
1295       const char16_t* __wn = (const char16_t*)__wb;
1296       __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn, __buf, __buf + __sz, __bn);
1297       if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
1298         __throw_runtime_error("locale not supported");
1299       for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1300         *__s = *__p;
1301       __wb = (const _CharT*)__wn;
1302     }
1303     return __s;
1304   }
1305 };
1306 
1307 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1308 template <>
1309 struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<32> : public codecvt<char32_t, char, mbstate_t> {
1310   _LIBCPP_HIDE_FROM_ABI __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1311   _LIBCPP_SUPPRESS_DEPRECATED_POP
1312 
1313   ~__narrow_to_utf8() override;
1314 
1315   template <class _OutputIterator, class _CharT>
1316   _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const {
1317     result __r = ok;
1318     mbstate_t __mb;
1319     while (__wb < __we && __r != error) {
1320       const int __sz = 32;
1321       char __buf[__sz];
1322       char* __bn;
1323       const char32_t* __wn = (const char32_t*)__wb;
1324       __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn, __buf, __buf + __sz, __bn);
1325       if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
1326         __throw_runtime_error("locale not supported");
1327       for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1328         *__s = *__p;
1329       __wb = (const _CharT*)__wn;
1330     }
1331     return __s;
1332   }
1333 };
1334 
1335 template <size_t _Np>
1336 struct __widen_from_utf8 {
1337   template <class _OutputIterator>
1338   _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
1339 };
1340 
1341 template <>
1342 struct __widen_from_utf8<8> {
1343   template <class _OutputIterator>
1344   _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const {
1345     for (; __nb < __ne; ++__nb, ++__s)
1346       *__s = *__nb;
1347     return __s;
1348   }
1349 };
1350 
1351 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1352 template <>
1353 struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<16> : public codecvt<char16_t, char, mbstate_t> {
1354   _LIBCPP_HIDE_FROM_ABI __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1355   _LIBCPP_SUPPRESS_DEPRECATED_POP
1356 
1357   ~__widen_from_utf8() override;
1358 
1359   template <class _OutputIterator>
1360   _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const {
1361     result __r = ok;
1362     mbstate_t __mb;
1363     while (__nb < __ne && __r != error) {
1364       const int __sz = 32;
1365       char16_t __buf[__sz];
1366       char16_t* __bn;
1367       const char* __nn = __nb;
1368       __r              = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn);
1369       if (__r == codecvt_base::error || __nn == __nb)
1370         __throw_runtime_error("locale not supported");
1371       for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
1372         *__s = *__p;
1373       __nb = __nn;
1374     }
1375     return __s;
1376   }
1377 };
1378 
1379 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1380 template <>
1381 struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<32> : public codecvt<char32_t, char, mbstate_t> {
1382   _LIBCPP_HIDE_FROM_ABI __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1383   _LIBCPP_SUPPRESS_DEPRECATED_POP
1384 
1385   ~__widen_from_utf8() override;
1386 
1387   template <class _OutputIterator>
1388   _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const {
1389     result __r = ok;
1390     mbstate_t __mb;
1391     while (__nb < __ne && __r != error) {
1392       const int __sz = 32;
1393       char32_t __buf[__sz];
1394       char32_t* __bn;
1395       const char* __nn = __nb;
1396       __r              = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn);
1397       if (__r == codecvt_base::error || __nn == __nb)
1398         __throw_runtime_error("locale not supported");
1399       for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
1400         *__s = *__p;
1401       __nb = __nn;
1402     }
1403     return __s;
1404   }
1405 };
1406 
1407 // template <class charT> class numpunct
1408 
1409 template <class _CharT>
1410 class _LIBCPP_TEMPLATE_VIS numpunct;
1411 
1412 template <>
1413 class _LIBCPP_EXPORTED_FROM_ABI numpunct<char> : public locale::facet {
1414 public:
1415   typedef char char_type;
1416   typedef basic_string<char_type> string_type;
1417 
1418   explicit numpunct(size_t __refs = 0);
1419 
1420   _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); }
1421   _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); }
1422   _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); }
1423   _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); }
1424   _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); }
1425 
1426   static locale::id id;
1427 
1428 protected:
1429   ~numpunct() override;
1430   virtual char_type do_decimal_point() const;
1431   virtual char_type do_thousands_sep() const;
1432   virtual string do_grouping() const;
1433   virtual string_type do_truename() const;
1434   virtual string_type do_falsename() const;
1435 
1436   char_type __decimal_point_;
1437   char_type __thousands_sep_;
1438   string __grouping_;
1439 };
1440 
1441 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1442 template <>
1443 class _LIBCPP_EXPORTED_FROM_ABI numpunct<wchar_t> : public locale::facet {
1444 public:
1445   typedef wchar_t char_type;
1446   typedef basic_string<char_type> string_type;
1447 
1448   explicit numpunct(size_t __refs = 0);
1449 
1450   _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); }
1451   _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); }
1452   _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); }
1453   _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); }
1454   _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); }
1455 
1456   static locale::id id;
1457 
1458 protected:
1459   ~numpunct() override;
1460   virtual char_type do_decimal_point() const;
1461   virtual char_type do_thousands_sep() const;
1462   virtual string do_grouping() const;
1463   virtual string_type do_truename() const;
1464   virtual string_type do_falsename() const;
1465 
1466   char_type __decimal_point_;
1467   char_type __thousands_sep_;
1468   string __grouping_;
1469 };
1470 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1471 
1472 // template <class charT> class numpunct_byname
1473 
1474 template <class _CharT>
1475 class _LIBCPP_TEMPLATE_VIS numpunct_byname;
1476 
1477 template <>
1478 class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<char> : public numpunct<char> {
1479 public:
1480   typedef char char_type;
1481   typedef basic_string<char_type> string_type;
1482 
1483   explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1484   explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1485 
1486 protected:
1487   ~numpunct_byname() override;
1488 
1489 private:
1490   void __init(const char*);
1491 };
1492 
1493 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1494 template <>
1495 class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<wchar_t> : public numpunct<wchar_t> {
1496 public:
1497   typedef wchar_t char_type;
1498   typedef basic_string<char_type> string_type;
1499 
1500   explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1501   explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1502 
1503 protected:
1504   ~numpunct_byname() override;
1505 
1506 private:
1507   void __init(const char*);
1508 };
1509 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1510 
1511 _LIBCPP_END_NAMESPACE_STD
1512 
1513 #endif // _LIBCPP___CXX03___LOCALE