brintos

brintos / llvm-project-archived public Read only

0
0
Text · 51.4 KiB · e9cbc1f Raw
1496 lines · plain
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP___CXX03___LOCALE11#define _LIBCPP___CXX03___LOCALE12 13#include <__cxx03/__config>14#include <__cxx03/__locale_dir/locale_base_api.h>15#include <__cxx03/__memory/shared_ptr.h> // __shared_count16#include <__cxx03/__mutex/once_flag.h>17#include <__cxx03/__type_traits/make_unsigned.h>18#include <__cxx03/__utility/no_destroy.h>19#include <__cxx03/__utility/private_constructor_tag.h>20#include <__cxx03/cctype>21#include <__cxx03/clocale>22#include <__cxx03/cstdint>23#include <__cxx03/cstdlib>24#include <__cxx03/string>25 26// Some platforms require more includes than others. Keep the includes on all plaforms for now.27#include <__cxx03/cstddef>28#include <__cxx03/cstring>29 30#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS31#  include <__cxx03/cwchar>32#else33#  include <__cxx03/__std_mbstate_t.h>34#endif35 36#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)37#  pragma GCC system_header38#endif39 40_LIBCPP_BEGIN_NAMESPACE_STD41 42class _LIBCPP_EXPORTED_FROM_ABI locale;43 44template <class _Facet>45_LIBCPP_HIDE_FROM_ABI bool has_facet(const locale&) _NOEXCEPT;46 47template <class _Facet>48_LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale&);49 50class _LIBCPP_EXPORTED_FROM_ABI locale {51public:52  // locale is essentially a shared_ptr that doesn't support weak_ptrs and never got a move constructor.53  using __trivially_relocatable = locale;54 55  // types:56  class _LIBCPP_EXPORTED_FROM_ABI facet;57  class _LIBCPP_EXPORTED_FROM_ABI id;58 59  typedef int category;60 61  static const category // values assigned here are for exposition only62      none    = 0,63      collate = LC_COLLATE_MASK, ctype = LC_CTYPE_MASK, monetary = LC_MONETARY_MASK, numeric = LC_NUMERIC_MASK,64      time = LC_TIME_MASK, messages = LC_MESSAGES_MASK, all = collate | ctype | monetary | numeric | time | messages;65 66  // construct/copy/destroy:67  locale() _NOEXCEPT;68  locale(const locale&) _NOEXCEPT;69  explicit locale(const char*);70  explicit locale(const string&);71  locale(const locale&, const char*, category);72  locale(const locale&, const string&, category);73  template <class _Facet>74  _LIBCPP_HIDE_FROM_ABI locale(const locale&, _Facet*);75  locale(const locale&, const locale&, category);76 77  ~locale();78 79  const locale& operator=(const locale&) _NOEXCEPT;80 81  template <class _Facet>82  _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS locale combine(const locale&) const;83 84  // locale operations:85  string name() const;86  bool operator==(const locale&) const;87  _LIBCPP_HIDE_FROM_ABI bool operator!=(const locale& __y) const { return !(*this == __y); }88  template <class _CharT, class _Traits, class _Allocator>89  _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool90  operator()(const basic_string<_CharT, _Traits, _Allocator>&, const basic_string<_CharT, _Traits, _Allocator>&) const;91 92  // global locale objects:93  static locale global(const locale&);94  static const locale& classic();95 96private:97  class __imp;98  __imp* __locale_;99 100  template <class>101  friend struct __no_destroy;102  _LIBCPP_HIDE_FROM_ABI explicit locale(__private_constructor_tag, __imp* __loc) : __locale_(__loc) {}103 104  void __install_ctor(const locale&, facet*, long);105  static locale& __global();106  bool has_facet(id&) const;107  const facet* use_facet(id&) const;108 109  template <class _Facet>110  friend bool has_facet(const locale&) _NOEXCEPT;111  template <class _Facet>112  friend const _Facet& use_facet(const locale&);113};114 115class _LIBCPP_EXPORTED_FROM_ABI locale::facet : public __shared_count {116protected:117  _LIBCPP_HIDE_FROM_ABI explicit facet(size_t __refs = 0) : __shared_count(static_cast<long>(__refs) - 1) {}118 119  ~facet() override;120 121  //    facet(const facet&) = delete;     // effectively done in __shared_count122  //    void operator=(const facet&) = delete;123 124private:125  void __on_zero_shared() _NOEXCEPT override;126};127 128class _LIBCPP_EXPORTED_FROM_ABI locale::id {129  once_flag __flag_;130  int32_t __id_;131 132  static int32_t __next_id;133 134public:135  _LIBCPP_HIDE_FROM_ABI id() : __id_(0) {}136  void operator=(const id&) = delete;137  id(const id&)             = delete;138 139public: // only needed for tests140  long __get();141 142  friend class locale;143  friend class locale::__imp;144};145 146template <class _Facet>147inline _LIBCPP_HIDE_FROM_ABI locale::locale(const locale& __other, _Facet* __f) {148  __install_ctor(__other, __f, __f ? __f->id.__get() : 0);149}150 151template <class _Facet>152locale locale::combine(const locale& __other) const {153  if (!std::has_facet<_Facet>(__other))154    __throw_runtime_error("locale::combine: locale missing facet");155 156  return locale(*this, &const_cast<_Facet&>(std::use_facet<_Facet>(__other)));157}158 159template <class _Facet>160inline _LIBCPP_HIDE_FROM_ABI bool has_facet(const locale& __l) _NOEXCEPT {161  return __l.has_facet(_Facet::id);162}163 164template <class _Facet>165inline _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale& __l) {166  return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));167}168 169// template <class _CharT> class collate;170 171template <class _CharT>172class _LIBCPP_TEMPLATE_VIS collate : public locale::facet {173public:174  typedef _CharT char_type;175  typedef basic_string<char_type> string_type;176 177  _LIBCPP_HIDE_FROM_ABI explicit collate(size_t __refs = 0) : locale::facet(__refs) {}178 179  _LIBCPP_HIDE_FROM_ABI int180  compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const {181    return do_compare(__lo1, __hi1, __lo2, __hi2);182  }183 184  // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work185  // around a dllimport bug that expects an external instantiation.186  _LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE string_type187  transform(const char_type* __lo, const char_type* __hi) const {188    return do_transform(__lo, __hi);189  }190 191  _LIBCPP_HIDE_FROM_ABI long hash(const char_type* __lo, const char_type* __hi) const { return do_hash(__lo, __hi); }192 193  static locale::id id;194 195protected:196  ~collate() override;197  virtual int198  do_compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const;199  virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const {200    return string_type(__lo, __hi);201  }202  virtual long do_hash(const char_type* __lo, const char_type* __hi) const;203};204 205template <class _CharT>206locale::id collate<_CharT>::id;207 208template <class _CharT>209collate<_CharT>::~collate() {}210 211template <class _CharT>212int collate<_CharT>::do_compare(213    const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const {214  for (; __lo2 != __hi2; ++__lo1, ++__lo2) {215    if (__lo1 == __hi1 || *__lo1 < *__lo2)216      return -1;217    if (*__lo2 < *__lo1)218      return 1;219  }220  return __lo1 != __hi1;221}222 223template <class _CharT>224long collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const {225  size_t __h          = 0;226  const size_t __sr   = __CHAR_BIT__ * sizeof(size_t) - 8;227  const size_t __mask = size_t(0xF) << (__sr + 4);228  for (const char_type* __p = __lo; __p != __hi; ++__p) {229    __h        = (__h << 4) + static_cast<size_t>(*__p);230    size_t __g = __h & __mask;231    __h ^= __g | (__g >> __sr);232  }233  return static_cast<long>(__h);234}235 236extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>;237#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS238extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>;239#endif240 241// template <class CharT> class collate_byname;242 243template <class _CharT>244class _LIBCPP_TEMPLATE_VIS collate_byname;245 246template <>247class _LIBCPP_EXPORTED_FROM_ABI collate_byname<char> : public collate<char> {248  locale_t __l_;249 250public:251  typedef char char_type;252  typedef basic_string<char_type> string_type;253 254  explicit collate_byname(const char* __n, size_t __refs = 0);255  explicit collate_byname(const string& __n, size_t __refs = 0);256 257protected:258  ~collate_byname() override;259  int do_compare(260      const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const override;261  string_type do_transform(const char_type* __lo, const char_type* __hi) const override;262};263 264#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS265template <>266class _LIBCPP_EXPORTED_FROM_ABI collate_byname<wchar_t> : public collate<wchar_t> {267  locale_t __l_;268 269public:270  typedef wchar_t char_type;271  typedef basic_string<char_type> string_type;272 273  explicit collate_byname(const char* __n, size_t __refs = 0);274  explicit collate_byname(const string& __n, size_t __refs = 0);275 276protected:277  ~collate_byname() override;278 279  int do_compare(280      const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const override;281  string_type do_transform(const char_type* __lo, const char_type* __hi) const override;282};283#endif284 285template <class _CharT, class _Traits, class _Allocator>286bool locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,287                        const basic_string<_CharT, _Traits, _Allocator>& __y) const {288  return std::use_facet<std::collate<_CharT> >(*this).compare(289             __x.data(), __x.data() + __x.size(), __y.data(), __y.data() + __y.size()) < 0;290}291 292// template <class charT> class ctype293 294class _LIBCPP_EXPORTED_FROM_ABI ctype_base {295public:296#if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE)297  typedef unsigned long mask;298  static const mask space  = 1 << 0;299  static const mask print  = 1 << 1;300  static const mask cntrl  = 1 << 2;301  static const mask upper  = 1 << 3;302  static const mask lower  = 1 << 4;303  static const mask alpha  = 1 << 5;304  static const mask digit  = 1 << 6;305  static const mask punct  = 1 << 7;306  static const mask xdigit = 1 << 8;307  static const mask blank  = 1 << 9;308#  if defined(__BIONIC__)309  // Historically this was a part of regex_traits rather than ctype_base. The310  // historical value of the constant is preserved for ABI compatibility.311  static const mask __regex_word = 0x8000;312#  else313  static const mask __regex_word = 1 << 10;314#  endif // defined(__BIONIC__)315#elif defined(__GLIBC__)316  typedef unsigned short mask;317  static const mask space  = _ISspace;318  static const mask print  = _ISprint;319  static const mask cntrl  = _IScntrl;320  static const mask upper  = _ISupper;321  static const mask lower  = _ISlower;322  static const mask alpha  = _ISalpha;323  static const mask digit  = _ISdigit;324  static const mask punct  = _ISpunct;325  static const mask xdigit = _ISxdigit;326  static const mask blank  = _ISblank;327#  if defined(__mips__) || (BYTE_ORDER == BIG_ENDIAN)328  static const mask __regex_word = static_cast<mask>(_ISbit(15));329#  else330  static const mask __regex_word = 0x80;331#  endif332#elif defined(_LIBCPP_MSVCRT_LIKE)333  typedef unsigned short mask;334  static const mask space        = _SPACE;335  static const mask print        = _BLANK | _PUNCT | _ALPHA | _DIGIT;336  static const mask cntrl        = _CONTROL;337  static const mask upper        = _UPPER;338  static const mask lower        = _LOWER;339  static const mask alpha        = _ALPHA;340  static const mask digit        = _DIGIT;341  static const mask punct        = _PUNCT;342  static const mask xdigit       = _HEX;343  static const mask blank        = _BLANK;344  static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used345#  define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT346#  define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA347#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)348#  ifdef __APPLE__349  typedef __uint32_t mask;350#  elif defined(__FreeBSD__)351  typedef unsigned long mask;352#  elif defined(__NetBSD__)353  typedef unsigned short mask;354#  endif355  static const mask space  = _CTYPE_S;356  static const mask print  = _CTYPE_R;357  static const mask cntrl  = _CTYPE_C;358  static const mask upper  = _CTYPE_U;359  static const mask lower  = _CTYPE_L;360  static const mask alpha  = _CTYPE_A;361  static const mask digit  = _CTYPE_D;362  static const mask punct  = _CTYPE_P;363  static const mask xdigit = _CTYPE_X;364 365#  if defined(__NetBSD__)366  static const mask blank = _CTYPE_BL;367  // NetBSD defines classes up to 0x2000368  // see sys/ctype_bits.h, _CTYPE_Q369  static const mask __regex_word = 0x8000;370#  else371  static const mask blank        = _CTYPE_B;372  static const mask __regex_word = 0x80;373#  endif374#elif defined(_AIX)375  typedef unsigned int mask;376  static const mask space        = _ISSPACE;377  static const mask print        = _ISPRINT;378  static const mask cntrl        = _ISCNTRL;379  static const mask upper        = _ISUPPER;380  static const mask lower        = _ISLOWER;381  static const mask alpha        = _ISALPHA;382  static const mask digit        = _ISDIGIT;383  static const mask punct        = _ISPUNCT;384  static const mask xdigit       = _ISXDIGIT;385  static const mask blank        = _ISBLANK;386  static const mask __regex_word = 0x8000;387#elif _LIBCPP_LIBC_NEWLIB388  // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.389  typedef char mask;390  // In case char is signed, static_cast is needed to avoid warning on391  // positive value becomming negative.392  static const mask space  = static_cast<mask>(_S);393  static const mask print  = static_cast<mask>(_P | _U | _L | _N | _B);394  static const mask cntrl  = static_cast<mask>(_C);395  static const mask upper  = static_cast<mask>(_U);396  static const mask lower  = static_cast<mask>(_L);397  static const mask alpha  = static_cast<mask>(_U | _L);398  static const mask digit  = static_cast<mask>(_N);399  static const mask punct  = static_cast<mask>(_P);400  static const mask xdigit = static_cast<mask>(_X | _N);401  static const mask blank  = static_cast<mask>(_B);402  // mask is already fully saturated, use a different type in regex_type_traits.403  static const unsigned short __regex_word = 0x100;404#  define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT405#  define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA406#  define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT407#elif defined(__MVS__)408#  if defined(__NATIVE_ASCII_F)409  typedef unsigned int mask;410  static const mask space  = _ISSPACE_A;411  static const mask print  = _ISPRINT_A;412  static const mask cntrl  = _ISCNTRL_A;413  static const mask upper  = _ISUPPER_A;414  static const mask lower  = _ISLOWER_A;415  static const mask alpha  = _ISALPHA_A;416  static const mask digit  = _ISDIGIT_A;417  static const mask punct  = _ISPUNCT_A;418  static const mask xdigit = _ISXDIGIT_A;419  static const mask blank  = _ISBLANK_A;420#  else421  typedef unsigned short mask;422  static const mask space  = __ISSPACE;423  static const mask print  = __ISPRINT;424  static const mask cntrl  = __ISCNTRL;425  static const mask upper  = __ISUPPER;426  static const mask lower  = __ISLOWER;427  static const mask alpha  = __ISALPHA;428  static const mask digit  = __ISDIGIT;429  static const mask punct  = __ISPUNCT;430  static const mask xdigit = __ISXDIGIT;431  static const mask blank  = __ISBLANK;432#  endif433  static const mask __regex_word = 0x8000;434#else435#  error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?436#endif437  static const mask alnum = alpha | digit;438  static const mask graph = alnum | punct;439 440  _LIBCPP_HIDE_FROM_ABI ctype_base() {}441 442  static_assert((__regex_word & ~(std::make_unsigned<mask>::type)(space | print | cntrl | upper | lower | alpha |443                                                                  digit | punct | xdigit | blank)) == __regex_word,444                "__regex_word can't overlap other bits");445};446 447template <class _CharT>448class _LIBCPP_TEMPLATE_VIS ctype;449 450#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS451template <>452class _LIBCPP_EXPORTED_FROM_ABI ctype<wchar_t> : public locale::facet, public ctype_base {453public:454  typedef wchar_t char_type;455 456  _LIBCPP_HIDE_FROM_ABI explicit ctype(size_t __refs = 0) : locale::facet(__refs) {}457 458  _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const { return do_is(__m, __c); }459 460  _LIBCPP_HIDE_FROM_ABI const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const {461    return do_is(__low, __high, __vec);462  }463 464  _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const {465    return do_scan_is(__m, __low, __high);466  }467 468  _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const {469    return do_scan_not(__m, __low, __high);470  }471 472  _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); }473 474  _LIBCPP_HIDE_FROM_ABI const char_type* toupper(char_type* __low, const char_type* __high) const {475    return do_toupper(__low, __high);476  }477 478  _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); }479 480  _LIBCPP_HIDE_FROM_ABI const char_type* tolower(char_type* __low, const char_type* __high) const {481    return do_tolower(__low, __high);482  }483 484  _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); }485 486  _LIBCPP_HIDE_FROM_ABI const char* widen(const char* __low, const char* __high, char_type* __to) const {487    return do_widen(__low, __high, __to);488  }489 490  _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); }491 492  _LIBCPP_HIDE_FROM_ABI const char_type*493  narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const {494    return do_narrow(__low, __high, __dfault, __to);495  }496 497  static locale::id id;498 499protected:500  ~ctype() override;501  virtual bool do_is(mask __m, char_type __c) const;502  virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;503  virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;504  virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;505  virtual char_type do_toupper(char_type) const;506  virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;507  virtual char_type do_tolower(char_type) const;508  virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;509  virtual char_type do_widen(char) const;510  virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;511  virtual char do_narrow(char_type, char __dfault) const;512  virtual const char_type*513  do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;514};515#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS516 517template <>518class _LIBCPP_EXPORTED_FROM_ABI ctype<char> : public locale::facet, public ctype_base {519  const mask* __tab_;520  bool __del_;521 522public:523  typedef char char_type;524 525  explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0);526 527  _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const {528    return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) != 0 : false;529  }530 531  _LIBCPP_HIDE_FROM_ABI const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const {532    for (; __low != __high; ++__low, ++__vec)533      *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;534    return __low;535  }536 537  _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const {538    for (; __low != __high; ++__low)539      if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))540        break;541    return __low;542  }543 544  _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const {545    for (; __low != __high; ++__low)546      if (!isascii(*__low) || !(__tab_[static_cast<int>(*__low)] & __m))547        break;548    return __low;549  }550 551  _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); }552 553  _LIBCPP_HIDE_FROM_ABI const char_type* toupper(char_type* __low, const char_type* __high) const {554    return do_toupper(__low, __high);555  }556 557  _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); }558 559  _LIBCPP_HIDE_FROM_ABI const char_type* tolower(char_type* __low, const char_type* __high) const {560    return do_tolower(__low, __high);561  }562 563  _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); }564 565  _LIBCPP_HIDE_FROM_ABI const char* widen(const char* __low, const char* __high, char_type* __to) const {566    return do_widen(__low, __high, __to);567  }568 569  _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); }570 571  _LIBCPP_HIDE_FROM_ABI const char*572  narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const {573    return do_narrow(__low, __high, __dfault, __to);574  }575 576  static locale::id id;577 578#ifdef _CACHED_RUNES579  static const size_t table_size = _CACHED_RUNES;580#else581  static const size_t table_size = 256;582#endif583  _LIBCPP_HIDE_FROM_ABI const mask* table() const _NOEXCEPT { return __tab_; }584  static const mask* classic_table() _NOEXCEPT;585 586protected:587  ~ctype() override;588  virtual char_type do_toupper(char_type __c) const;589  virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;590  virtual char_type do_tolower(char_type __c) const;591  virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;592  virtual char_type do_widen(char __c) const;593  virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;594  virtual char do_narrow(char_type __c, char __dfault) const;595  virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;596};597 598// template <class CharT> class ctype_byname;599 600template <class _CharT>601class _LIBCPP_TEMPLATE_VIS ctype_byname;602 603template <>604class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<char> : public ctype<char> {605  locale_t __l_;606 607public:608  explicit ctype_byname(const char*, size_t = 0);609  explicit ctype_byname(const string&, size_t = 0);610 611protected:612  ~ctype_byname() override;613  char_type do_toupper(char_type) const override;614  const char_type* do_toupper(char_type* __low, const char_type* __high) const override;615  char_type do_tolower(char_type) const override;616  const char_type* do_tolower(char_type* __low, const char_type* __high) const override;617};618 619#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS620template <>621class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<wchar_t> : public ctype<wchar_t> {622  locale_t __l_;623 624public:625  explicit ctype_byname(const char*, size_t = 0);626  explicit ctype_byname(const string&, size_t = 0);627 628protected:629  ~ctype_byname() override;630  bool do_is(mask __m, char_type __c) const override;631  const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const override;632  const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const override;633  const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const override;634  char_type do_toupper(char_type) const override;635  const char_type* do_toupper(char_type* __low, const char_type* __high) const override;636  char_type do_tolower(char_type) const override;637  const char_type* do_tolower(char_type* __low, const char_type* __high) const override;638  char_type do_widen(char) const override;639  const char* do_widen(const char* __low, const char* __high, char_type* __dest) const override;640  char do_narrow(char_type, char __dfault) const override;641  const char_type*642  do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const override;643};644#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS645 646template <class _CharT>647inline _LIBCPP_HIDE_FROM_ABI bool isspace(_CharT __c, const locale& __loc) {648  return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);649}650 651template <class _CharT>652inline _LIBCPP_HIDE_FROM_ABI bool isprint(_CharT __c, const locale& __loc) {653  return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);654}655 656template <class _CharT>657inline _LIBCPP_HIDE_FROM_ABI bool iscntrl(_CharT __c, const locale& __loc) {658  return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);659}660 661template <class _CharT>662inline _LIBCPP_HIDE_FROM_ABI bool isupper(_CharT __c, const locale& __loc) {663  return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);664}665 666template <class _CharT>667inline _LIBCPP_HIDE_FROM_ABI bool islower(_CharT __c, const locale& __loc) {668  return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);669}670 671template <class _CharT>672inline _LIBCPP_HIDE_FROM_ABI bool isalpha(_CharT __c, const locale& __loc) {673  return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);674}675 676template <class _CharT>677inline _LIBCPP_HIDE_FROM_ABI bool isdigit(_CharT __c, const locale& __loc) {678  return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);679}680 681template <class _CharT>682inline _LIBCPP_HIDE_FROM_ABI bool ispunct(_CharT __c, const locale& __loc) {683  return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);684}685 686template <class _CharT>687inline _LIBCPP_HIDE_FROM_ABI bool isxdigit(_CharT __c, const locale& __loc) {688  return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);689}690 691template <class _CharT>692inline _LIBCPP_HIDE_FROM_ABI bool isalnum(_CharT __c, const locale& __loc) {693  return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);694}695 696template <class _CharT>697inline _LIBCPP_HIDE_FROM_ABI bool isgraph(_CharT __c, const locale& __loc) {698  return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);699}700 701template <class _CharT>702_LIBCPP_HIDE_FROM_ABI bool isblank(_CharT __c, const locale& __loc) {703  return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::blank, __c);704}705 706template <class _CharT>707inline _LIBCPP_HIDE_FROM_ABI _CharT toupper(_CharT __c, const locale& __loc) {708  return std::use_facet<ctype<_CharT> >(__loc).toupper(__c);709}710 711template <class _CharT>712inline _LIBCPP_HIDE_FROM_ABI _CharT tolower(_CharT __c, const locale& __loc) {713  return std::use_facet<ctype<_CharT> >(__loc).tolower(__c);714}715 716// codecvt_base717 718class _LIBCPP_EXPORTED_FROM_ABI codecvt_base {719public:720  _LIBCPP_HIDE_FROM_ABI codecvt_base() {}721  enum result { ok, partial, error, noconv };722};723 724// template <class internT, class externT, class stateT> class codecvt;725 726template <class _InternT, class _ExternT, class _StateT>727class _LIBCPP_TEMPLATE_VIS codecvt;728 729// template <> class codecvt<char, char, mbstate_t>730 731template <>732class _LIBCPP_EXPORTED_FROM_ABI codecvt<char, char, mbstate_t> : public locale::facet, public codecvt_base {733public:734  typedef char intern_type;735  typedef char extern_type;736  typedef mbstate_t state_type;737 738  _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}739 740  _LIBCPP_HIDE_FROM_ABI result741  out(state_type& __st,742      const intern_type* __frm,743      const intern_type* __frm_end,744      const intern_type*& __frm_nxt,745      extern_type* __to,746      extern_type* __to_end,747      extern_type*& __to_nxt) const {748    return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);749  }750 751  _LIBCPP_HIDE_FROM_ABI result752  unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {753    return do_unshift(__st, __to, __to_end, __to_nxt);754  }755 756  _LIBCPP_HIDE_FROM_ABI result757  in(state_type& __st,758     const extern_type* __frm,759     const extern_type* __frm_end,760     const extern_type*& __frm_nxt,761     intern_type* __to,762     intern_type* __to_end,763     intern_type*& __to_nxt) const {764    return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);765  }766 767  _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }768 769  _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }770 771  _LIBCPP_HIDE_FROM_ABI int772  length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {773    return do_length(__st, __frm, __end, __mx);774  }775 776  _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }777 778  static locale::id id;779 780protected:781  _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}782 783  ~codecvt() override;784 785  virtual result786  do_out(state_type& __st,787         const intern_type* __frm,788         const intern_type* __frm_end,789         const intern_type*& __frm_nxt,790         extern_type* __to,791         extern_type* __to_end,792         extern_type*& __to_nxt) const;793  virtual result794  do_in(state_type& __st,795        const extern_type* __frm,796        const extern_type* __frm_end,797        const extern_type*& __frm_nxt,798        intern_type* __to,799        intern_type* __to_end,800        intern_type*& __to_nxt) const;801  virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;802  virtual int do_encoding() const _NOEXCEPT;803  virtual bool do_always_noconv() const _NOEXCEPT;804  virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;805  virtual int do_max_length() const _NOEXCEPT;806};807 808// template <> class codecvt<wchar_t, char, mbstate_t>809 810#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS811template <>812class _LIBCPP_EXPORTED_FROM_ABI codecvt<wchar_t, char, mbstate_t> : public locale::facet, public codecvt_base {813  locale_t __l_;814 815public:816  typedef wchar_t intern_type;817  typedef char extern_type;818  typedef mbstate_t state_type;819 820  explicit codecvt(size_t __refs = 0);821 822  _LIBCPP_HIDE_FROM_ABI result823  out(state_type& __st,824      const intern_type* __frm,825      const intern_type* __frm_end,826      const intern_type*& __frm_nxt,827      extern_type* __to,828      extern_type* __to_end,829      extern_type*& __to_nxt) const {830    return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);831  }832 833  _LIBCPP_HIDE_FROM_ABI result834  unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {835    return do_unshift(__st, __to, __to_end, __to_nxt);836  }837 838  _LIBCPP_HIDE_FROM_ABI result839  in(state_type& __st,840     const extern_type* __frm,841     const extern_type* __frm_end,842     const extern_type*& __frm_nxt,843     intern_type* __to,844     intern_type* __to_end,845     intern_type*& __to_nxt) const {846    return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);847  }848 849  _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }850 851  _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }852 853  _LIBCPP_HIDE_FROM_ABI int854  length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {855    return do_length(__st, __frm, __end, __mx);856  }857 858  _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }859 860  static locale::id id;861 862protected:863  explicit codecvt(const char*, size_t __refs = 0);864 865  ~codecvt() override;866 867  virtual result868  do_out(state_type& __st,869         const intern_type* __frm,870         const intern_type* __frm_end,871         const intern_type*& __frm_nxt,872         extern_type* __to,873         extern_type* __to_end,874         extern_type*& __to_nxt) const;875  virtual result876  do_in(state_type& __st,877        const extern_type* __frm,878        const extern_type* __frm_end,879        const extern_type*& __frm_nxt,880        intern_type* __to,881        intern_type* __to_end,882        intern_type*& __to_nxt) const;883  virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;884  virtual int do_encoding() const _NOEXCEPT;885  virtual bool do_always_noconv() const _NOEXCEPT;886  virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;887  virtual int do_max_length() const _NOEXCEPT;888};889#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS890 891// template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20892 893template <>894class _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char, mbstate_t> : public locale::facet, public codecvt_base {895public:896  typedef char16_t intern_type;897  typedef char extern_type;898  typedef mbstate_t state_type;899 900  _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}901 902  _LIBCPP_HIDE_FROM_ABI result903  out(state_type& __st,904      const intern_type* __frm,905      const intern_type* __frm_end,906      const intern_type*& __frm_nxt,907      extern_type* __to,908      extern_type* __to_end,909      extern_type*& __to_nxt) const {910    return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);911  }912 913  _LIBCPP_HIDE_FROM_ABI result914  unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {915    return do_unshift(__st, __to, __to_end, __to_nxt);916  }917 918  _LIBCPP_HIDE_FROM_ABI result919  in(state_type& __st,920     const extern_type* __frm,921     const extern_type* __frm_end,922     const extern_type*& __frm_nxt,923     intern_type* __to,924     intern_type* __to_end,925     intern_type*& __to_nxt) const {926    return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);927  }928 929  _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }930 931  _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }932 933  _LIBCPP_HIDE_FROM_ABI int934  length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {935    return do_length(__st, __frm, __end, __mx);936  }937 938  _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }939 940  static locale::id id;941 942protected:943  _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}944 945  ~codecvt() override;946 947  virtual result948  do_out(state_type& __st,949         const intern_type* __frm,950         const intern_type* __frm_end,951         const intern_type*& __frm_nxt,952         extern_type* __to,953         extern_type* __to_end,954         extern_type*& __to_nxt) const;955  virtual result956  do_in(state_type& __st,957        const extern_type* __frm,958        const extern_type* __frm_end,959        const extern_type*& __frm_nxt,960        intern_type* __to,961        intern_type* __to_end,962        intern_type*& __to_nxt) const;963  virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;964  virtual int do_encoding() const _NOEXCEPT;965  virtual bool do_always_noconv() const _NOEXCEPT;966  virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;967  virtual int do_max_length() const _NOEXCEPT;968};969 970#ifndef _LIBCPP_HAS_NO_CHAR8_T971 972// template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20973 974template <>975class _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char8_t, mbstate_t> : public locale::facet, public codecvt_base {976public:977  typedef char16_t intern_type;978  typedef char8_t extern_type;979  typedef mbstate_t state_type;980 981  _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}982 983  _LIBCPP_HIDE_FROM_ABI result984  out(state_type& __st,985      const intern_type* __frm,986      const intern_type* __frm_end,987      const intern_type*& __frm_nxt,988      extern_type* __to,989      extern_type* __to_end,990      extern_type*& __to_nxt) const {991    return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);992  }993 994  _LIBCPP_HIDE_FROM_ABI result995  unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {996    return do_unshift(__st, __to, __to_end, __to_nxt);997  }998 999  _LIBCPP_HIDE_FROM_ABI result1000  in(state_type& __st,1001     const extern_type* __frm,1002     const extern_type* __frm_end,1003     const extern_type*& __frm_nxt,1004     intern_type* __to,1005     intern_type* __to_end,1006     intern_type*& __to_nxt) const {1007    return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);1008  }1009 1010  _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }1011 1012  _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }1013 1014  _LIBCPP_HIDE_FROM_ABI int1015  length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {1016    return do_length(__st, __frm, __end, __mx);1017  }1018 1019  _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }1020 1021  static locale::id id;1022 1023protected:1024  _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}1025 1026  ~codecvt() override;1027 1028  virtual result1029  do_out(state_type& __st,1030         const intern_type* __frm,1031         const intern_type* __frm_end,1032         const intern_type*& __frm_nxt,1033         extern_type* __to,1034         extern_type* __to_end,1035         extern_type*& __to_nxt) const;1036  virtual result1037  do_in(state_type& __st,1038        const extern_type* __frm,1039        const extern_type* __frm_end,1040        const extern_type*& __frm_nxt,1041        intern_type* __to,1042        intern_type* __to_end,1043        intern_type*& __to_nxt) const;1044  virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;1045  virtual int do_encoding() const _NOEXCEPT;1046  virtual bool do_always_noconv() const _NOEXCEPT;1047  virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;1048  virtual int do_max_length() const _NOEXCEPT;1049};1050 1051#endif1052 1053// template <> class codecvt<char32_t, char, mbstate_t> // deprecated in C++201054 1055template <>1056class _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char, mbstate_t> : public locale::facet, public codecvt_base {1057public:1058  typedef char32_t intern_type;1059  typedef char extern_type;1060  typedef mbstate_t state_type;1061 1062  _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}1063 1064  _LIBCPP_HIDE_FROM_ABI result1065  out(state_type& __st,1066      const intern_type* __frm,1067      const intern_type* __frm_end,1068      const intern_type*& __frm_nxt,1069      extern_type* __to,1070      extern_type* __to_end,1071      extern_type*& __to_nxt) const {1072    return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);1073  }1074 1075  _LIBCPP_HIDE_FROM_ABI result1076  unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {1077    return do_unshift(__st, __to, __to_end, __to_nxt);1078  }1079 1080  _LIBCPP_HIDE_FROM_ABI result1081  in(state_type& __st,1082     const extern_type* __frm,1083     const extern_type* __frm_end,1084     const extern_type*& __frm_nxt,1085     intern_type* __to,1086     intern_type* __to_end,1087     intern_type*& __to_nxt) const {1088    return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);1089  }1090 1091  _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }1092 1093  _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }1094 1095  _LIBCPP_HIDE_FROM_ABI int1096  length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {1097    return do_length(__st, __frm, __end, __mx);1098  }1099 1100  _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }1101 1102  static locale::id id;1103 1104protected:1105  _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}1106 1107  ~codecvt() override;1108 1109  virtual result1110  do_out(state_type& __st,1111         const intern_type* __frm,1112         const intern_type* __frm_end,1113         const intern_type*& __frm_nxt,1114         extern_type* __to,1115         extern_type* __to_end,1116         extern_type*& __to_nxt) const;1117  virtual result1118  do_in(state_type& __st,1119        const extern_type* __frm,1120        const extern_type* __frm_end,1121        const extern_type*& __frm_nxt,1122        intern_type* __to,1123        intern_type* __to_end,1124        intern_type*& __to_nxt) const;1125  virtual result do_unshift(state_type& __st, 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 1132#ifndef _LIBCPP_HAS_NO_CHAR8_T1133 1134// template <> class codecvt<char32_t, char8_t, mbstate_t> // C++201135 1136template <>1137class _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char8_t, mbstate_t> : public locale::facet, public codecvt_base {1138public:1139  typedef char32_t intern_type;1140  typedef char8_t extern_type;1141  typedef mbstate_t state_type;1142 1143  _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}1144 1145  _LIBCPP_HIDE_FROM_ABI result1146  out(state_type& __st,1147      const intern_type* __frm,1148      const intern_type* __frm_end,1149      const intern_type*& __frm_nxt,1150      extern_type* __to,1151      extern_type* __to_end,1152      extern_type*& __to_nxt) const {1153    return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);1154  }1155 1156  _LIBCPP_HIDE_FROM_ABI result1157  unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {1158    return do_unshift(__st, __to, __to_end, __to_nxt);1159  }1160 1161  _LIBCPP_HIDE_FROM_ABI result1162  in(state_type& __st,1163     const extern_type* __frm,1164     const extern_type* __frm_end,1165     const extern_type*& __frm_nxt,1166     intern_type* __to,1167     intern_type* __to_end,1168     intern_type*& __to_nxt) const {1169    return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);1170  }1171 1172  _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }1173 1174  _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }1175 1176  _LIBCPP_HIDE_FROM_ABI int1177  length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {1178    return do_length(__st, __frm, __end, __mx);1179  }1180 1181  _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }1182 1183  static locale::id id;1184 1185protected:1186  _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}1187 1188  ~codecvt() override;1189 1190  virtual result1191  do_out(state_type& __st,1192         const intern_type* __frm,1193         const intern_type* __frm_end,1194         const intern_type*& __frm_nxt,1195         extern_type* __to,1196         extern_type* __to_end,1197         extern_type*& __to_nxt) const;1198  virtual result1199  do_in(state_type& __st,1200        const extern_type* __frm,1201        const extern_type* __frm_end,1202        const extern_type*& __frm_nxt,1203        intern_type* __to,1204        intern_type* __to_end,1205        intern_type*& __to_nxt) const;1206  virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;1207  virtual int do_encoding() const _NOEXCEPT;1208  virtual bool do_always_noconv() const _NOEXCEPT;1209  virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;1210  virtual int do_max_length() const _NOEXCEPT;1211};1212 1213#endif1214 1215// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname1216 1217template <class _InternT, class _ExternT, class _StateT>1218class _LIBCPP_TEMPLATE_VIS codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> {1219public:1220  _LIBCPP_HIDE_FROM_ABI explicit codecvt_byname(const char* __nm, size_t __refs = 0)1221      : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}1222  _LIBCPP_HIDE_FROM_ABI explicit codecvt_byname(const string& __nm, size_t __refs = 0)1223      : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}1224 1225protected:1226  ~codecvt_byname() override;1227};1228 1229_LIBCPP_SUPPRESS_DEPRECATED_PUSH1230template <class _InternT, class _ExternT, class _StateT>1231codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() {}1232_LIBCPP_SUPPRESS_DEPRECATED_POP1233 1234extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>;1235#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS1236extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>;1237#endif1238extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>; // deprecated in C++201239extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>; // deprecated in C++201240#ifndef _LIBCPP_HAS_NO_CHAR8_T1241extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>; // C++201242extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>; // C++201243#endif1244 1245template <size_t _Np>1246struct __narrow_to_utf8 {1247  template <class _OutputIterator, class _CharT>1248  _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;1249};1250 1251template <>1252struct __narrow_to_utf8<8> {1253  template <class _OutputIterator, class _CharT>1254  _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const {1255    for (; __wb < __we; ++__wb, ++__s)1256      *__s = *__wb;1257    return __s;1258  }1259};1260 1261_LIBCPP_SUPPRESS_DEPRECATED_PUSH1262template <>1263struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<16> : public codecvt<char16_t, char, mbstate_t> {1264  _LIBCPP_HIDE_FROM_ABI __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}1265  _LIBCPP_SUPPRESS_DEPRECATED_POP1266 1267  ~__narrow_to_utf8() override;1268 1269  template <class _OutputIterator, class _CharT>1270  _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const {1271    result __r = ok;1272    mbstate_t __mb;1273    while (__wb < __we && __r != error) {1274      const int __sz = 32;1275      char __buf[__sz];1276      char* __bn;1277      const char16_t* __wn = (const char16_t*)__wb;1278      __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn, __buf, __buf + __sz, __bn);1279      if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)1280        __throw_runtime_error("locale not supported");1281      for (const char* __p = __buf; __p < __bn; ++__p, ++__s)1282        *__s = *__p;1283      __wb = (const _CharT*)__wn;1284    }1285    return __s;1286  }1287};1288 1289_LIBCPP_SUPPRESS_DEPRECATED_PUSH1290template <>1291struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<32> : public codecvt<char32_t, char, mbstate_t> {1292  _LIBCPP_HIDE_FROM_ABI __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}1293  _LIBCPP_SUPPRESS_DEPRECATED_POP1294 1295  ~__narrow_to_utf8() override;1296 1297  template <class _OutputIterator, class _CharT>1298  _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const {1299    result __r = ok;1300    mbstate_t __mb;1301    while (__wb < __we && __r != error) {1302      const int __sz = 32;1303      char __buf[__sz];1304      char* __bn;1305      const char32_t* __wn = (const char32_t*)__wb;1306      __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn, __buf, __buf + __sz, __bn);1307      if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)1308        __throw_runtime_error("locale not supported");1309      for (const char* __p = __buf; __p < __bn; ++__p, ++__s)1310        *__s = *__p;1311      __wb = (const _CharT*)__wn;1312    }1313    return __s;1314  }1315};1316 1317template <size_t _Np>1318struct __widen_from_utf8 {1319  template <class _OutputIterator>1320  _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;1321};1322 1323template <>1324struct __widen_from_utf8<8> {1325  template <class _OutputIterator>1326  _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const {1327    for (; __nb < __ne; ++__nb, ++__s)1328      *__s = *__nb;1329    return __s;1330  }1331};1332 1333_LIBCPP_SUPPRESS_DEPRECATED_PUSH1334template <>1335struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<16> : public codecvt<char16_t, char, mbstate_t> {1336  _LIBCPP_HIDE_FROM_ABI __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}1337  _LIBCPP_SUPPRESS_DEPRECATED_POP1338 1339  ~__widen_from_utf8() override;1340 1341  template <class _OutputIterator>1342  _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const {1343    result __r = ok;1344    mbstate_t __mb;1345    while (__nb < __ne && __r != error) {1346      const int __sz = 32;1347      char16_t __buf[__sz];1348      char16_t* __bn;1349      const char* __nn = __nb;1350      __r              = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn);1351      if (__r == codecvt_base::error || __nn == __nb)1352        __throw_runtime_error("locale not supported");1353      for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)1354        *__s = *__p;1355      __nb = __nn;1356    }1357    return __s;1358  }1359};1360 1361_LIBCPP_SUPPRESS_DEPRECATED_PUSH1362template <>1363struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<32> : public codecvt<char32_t, char, mbstate_t> {1364  _LIBCPP_HIDE_FROM_ABI __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}1365  _LIBCPP_SUPPRESS_DEPRECATED_POP1366 1367  ~__widen_from_utf8() override;1368 1369  template <class _OutputIterator>1370  _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const {1371    result __r = ok;1372    mbstate_t __mb;1373    while (__nb < __ne && __r != error) {1374      const int __sz = 32;1375      char32_t __buf[__sz];1376      char32_t* __bn;1377      const char* __nn = __nb;1378      __r              = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn);1379      if (__r == codecvt_base::error || __nn == __nb)1380        __throw_runtime_error("locale not supported");1381      for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)1382        *__s = *__p;1383      __nb = __nn;1384    }1385    return __s;1386  }1387};1388 1389// template <class charT> class numpunct1390 1391template <class _CharT>1392class _LIBCPP_TEMPLATE_VIS numpunct;1393 1394template <>1395class _LIBCPP_EXPORTED_FROM_ABI numpunct<char> : public locale::facet {1396public:1397  typedef char char_type;1398  typedef basic_string<char_type> string_type;1399 1400  explicit numpunct(size_t __refs = 0);1401 1402  _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); }1403  _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); }1404  _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); }1405  _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); }1406  _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); }1407 1408  static locale::id id;1409 1410protected:1411  ~numpunct() override;1412  virtual char_type do_decimal_point() const;1413  virtual char_type do_thousands_sep() const;1414  virtual string do_grouping() const;1415  virtual string_type do_truename() const;1416  virtual string_type do_falsename() const;1417 1418  char_type __decimal_point_;1419  char_type __thousands_sep_;1420  string __grouping_;1421};1422 1423#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS1424template <>1425class _LIBCPP_EXPORTED_FROM_ABI numpunct<wchar_t> : public locale::facet {1426public:1427  typedef wchar_t char_type;1428  typedef basic_string<char_type> string_type;1429 1430  explicit numpunct(size_t __refs = 0);1431 1432  _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); }1433  _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); }1434  _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); }1435  _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); }1436  _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); }1437 1438  static locale::id id;1439 1440protected:1441  ~numpunct() override;1442  virtual char_type do_decimal_point() const;1443  virtual char_type do_thousands_sep() const;1444  virtual string do_grouping() const;1445  virtual string_type do_truename() const;1446  virtual string_type do_falsename() const;1447 1448  char_type __decimal_point_;1449  char_type __thousands_sep_;1450  string __grouping_;1451};1452#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS1453 1454// template <class charT> class numpunct_byname1455 1456template <class _CharT>1457class _LIBCPP_TEMPLATE_VIS numpunct_byname;1458 1459template <>1460class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<char> : public numpunct<char> {1461public:1462  typedef char char_type;1463  typedef basic_string<char_type> string_type;1464 1465  explicit numpunct_byname(const char* __nm, size_t __refs = 0);1466  explicit numpunct_byname(const string& __nm, size_t __refs = 0);1467 1468protected:1469  ~numpunct_byname() override;1470 1471private:1472  void __init(const char*);1473};1474 1475#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS1476template <>1477class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<wchar_t> : public numpunct<wchar_t> {1478public:1479  typedef wchar_t char_type;1480  typedef basic_string<char_type> string_type;1481 1482  explicit numpunct_byname(const char* __nm, size_t __refs = 0);1483  explicit numpunct_byname(const string& __nm, size_t __refs = 0);1484 1485protected:1486  ~numpunct_byname() override;1487 1488private:1489  void __init(const char*);1490};1491#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS1492 1493_LIBCPP_END_NAMESPACE_STD1494 1495#endif // _LIBCPP___CXX03___LOCALE1496