1508 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___LOCALE11#define _LIBCPP___LOCALE12 13#include <__config>14 15#if _LIBCPP_HAS_LOCALIZATION16 17# include <__locale_dir/locale_base_api.h>18# include <__memory/addressof.h>19# include <__memory/shared_count.h>20# include <__mutex/once_flag.h>21# include <__type_traits/make_unsigned.h>22# include <__utility/no_destroy.h>23# include <__utility/private_constructor_tag.h>24# include <cctype>25# include <clocale>26# include <cstdint>27# include <cstdlib>28# include <string>29 30// Some platforms require more includes than others. Keep the includes on all plaforms for now.31# include <cstddef>32# include <cstring>33 34# if _LIBCPP_HAS_WIDE_CHARACTERS35# include <cwchar>36# else37# include <__std_mbstate_t.h>38# endif39 40# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)41# pragma GCC system_header42# endif43 44_LIBCPP_BEGIN_NAMESPACE_STD45 46class _LIBCPP_EXPORTED_FROM_ABI locale;47 48template <class _CharT>49class collate;50 51template <class _Facet>52_LIBCPP_HIDE_FROM_ABI bool has_facet(const locale&) _NOEXCEPT;53 54template <class _Facet>55_LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale&);56 57class _LIBCPP_EXPORTED_FROM_ABI locale {58public:59 // locale is essentially a shared_ptr that doesn't support weak_ptrs and never got a move constructor,60 // so it is trivially relocatable.61 using __trivially_relocatable _LIBCPP_NODEBUG = locale;62 63 // types:64 class _LIBCPP_EXPORTED_FROM_ABI facet;65 class _LIBCPP_EXPORTED_FROM_ABI id;66 67 typedef int category;68 69 static const category // values assigned here are for exposition only70 none = 0,71 collate = _LIBCPP_COLLATE_MASK, ctype = _LIBCPP_CTYPE_MASK, monetary = _LIBCPP_MONETARY_MASK,72 numeric = _LIBCPP_NUMERIC_MASK, time = _LIBCPP_TIME_MASK, messages = _LIBCPP_MESSAGES_MASK,73 all = collate | ctype | monetary | numeric | time | messages;74 75 // construct/copy/destroy:76 locale() _NOEXCEPT;77 locale(const locale&) _NOEXCEPT;78 explicit locale(const char*);79 explicit locale(const string&);80 locale(const locale&, const char*, category);81 locale(const locale&, const string&, category);82 template <class _Facet>83 _LIBCPP_HIDE_FROM_ABI locale(const locale&, _Facet*);84 locale(const locale&, const locale&, category);85 86 ~locale();87 88 const locale& operator=(const locale&) _NOEXCEPT;89 90 template <class _Facet>91 _LIBCPP_HIDE_FROM_ABI locale combine(const locale& __other) const {92 if (!std::has_facet<_Facet>(__other))93 __throw_runtime_error("locale::combine: locale missing facet");94 95 return locale(*this, std::addressof(const_cast<_Facet&>(std::use_facet<_Facet>(__other))));96 }97 98 // locale operations:99 string name() const;100 bool operator==(const locale&) const;101# if _LIBCPP_STD_VER <= 17102 _LIBCPP_HIDE_FROM_ABI bool operator!=(const locale& __y) const { return !(*this == __y); }103# endif104 template <class _CharT, class _Traits, class _Allocator>105 _LIBCPP_HIDE_FROM_ABI bool operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,106 const basic_string<_CharT, _Traits, _Allocator>& __y) const {107 return std::use_facet<std::collate<_CharT> >(*this).compare(108 __x.data(), __x.data() + __x.size(), __y.data(), __y.data() + __y.size()) < 0;109 }110 111 // global locale objects:112 static locale global(const locale&);113 static const locale& classic();114 115private:116 class __imp;117 __imp* __locale_;118 119 template <class>120 friend struct __no_destroy;121 _LIBCPP_HIDE_FROM_ABI explicit locale(__private_constructor_tag, __imp* __loc) : __locale_(__loc) {}122 123 void __install_ctor(const locale&, facet*, long);124 static locale& __global();125 bool has_facet(id&) const;126 const facet* use_facet(id&) const;127 128 template <class _Facet>129 friend bool has_facet(const locale&) _NOEXCEPT;130 template <class _Facet>131 friend const _Facet& use_facet(const locale&);132};133 134class _LIBCPP_EXPORTED_FROM_ABI locale::facet : public __shared_count {135protected:136 _LIBCPP_HIDE_FROM_ABI explicit facet(size_t __refs = 0) : __shared_count(static_cast<long>(__refs) - 1) {}137 138 ~facet() override;139 140 // facet(const facet&) = delete; // effectively done in __shared_count141 // void operator=(const facet&) = delete;142 143private:144 void __on_zero_shared() _NOEXCEPT override;145};146 147class _LIBCPP_EXPORTED_FROM_ABI locale::id {148 once_flag __flag_;149 int32_t __id_;150 151 static int32_t __next_id;152 153public:154 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR id() : __id_(0) {}155 void operator=(const id&) = delete;156 id(const id&) = delete;157 158public: // only needed for tests159 long __get();160 161 friend class locale;162 friend class locale::__imp;163};164 165template <class _Facet>166inline _LIBCPP_HIDE_FROM_ABI locale::locale(const locale& __other, _Facet* __f) {167 __install_ctor(__other, __f, __f ? __f->id.__get() : 0);168}169 170template <class _Facet>171inline _LIBCPP_HIDE_FROM_ABI bool has_facet(const locale& __l) _NOEXCEPT {172 return __l.has_facet(_Facet::id);173}174 175template <class _Facet>176inline _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale& __l) {177 return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));178}179 180// template <class _CharT> class collate;181 182template <class _CharT>183class collate : public locale::facet {184public:185 typedef _CharT char_type;186 typedef basic_string<char_type> string_type;187 188 _LIBCPP_HIDE_FROM_ABI explicit collate(size_t __refs = 0) : locale::facet(__refs) {}189 190 _LIBCPP_HIDE_FROM_ABI int191 compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const {192 return do_compare(__lo1, __hi1, __lo2, __hi2);193 }194 195 // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work196 // around a dllimport bug that expects an external instantiation.197 _LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE string_type198 transform(const char_type* __lo, const char_type* __hi) const {199 return do_transform(__lo, __hi);200 }201 202 _LIBCPP_HIDE_FROM_ABI long hash(const char_type* __lo, const char_type* __hi) const { return do_hash(__lo, __hi); }203 204 static locale::id id;205 206protected:207 ~collate() override;208 virtual int209 do_compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const;210 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const {211 return string_type(__lo, __hi);212 }213 virtual long do_hash(const char_type* __lo, const char_type* __hi) const;214};215 216template <class _CharT>217locale::id collate<_CharT>::id;218 219template <class _CharT>220collate<_CharT>::~collate() {}221 222template <class _CharT>223int collate<_CharT>::do_compare(224 const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const {225 for (; __lo2 != __hi2; ++__lo1, ++__lo2) {226 if (__lo1 == __hi1 || *__lo1 < *__lo2)227 return -1;228 if (*__lo2 < *__lo1)229 return 1;230 }231 return __lo1 != __hi1;232}233 234template <class _CharT>235long collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const {236 size_t __h = 0;237 const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;238 const size_t __mask = size_t(0xF) << (__sr + 4);239 for (const char_type* __p = __lo; __p != __hi; ++__p) {240 __h = (__h << 4) + static_cast<size_t>(*__p);241 size_t __g = __h & __mask;242 __h ^= __g | (__g >> __sr);243 }244 return static_cast<long>(__h);245}246 247extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>;248# if _LIBCPP_HAS_WIDE_CHARACTERS249extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>;250# endif251 252// template <class CharT> class collate_byname;253 254template <class _CharT>255class collate_byname;256 257template <>258class _LIBCPP_EXPORTED_FROM_ABI collate_byname<char> : public collate<char> {259 __locale::__locale_t __l_;260 261public:262 typedef char char_type;263 typedef basic_string<char_type> string_type;264 265 explicit collate_byname(const char* __n, size_t __refs = 0);266 explicit collate_byname(const string& __n, size_t __refs = 0);267 268protected:269 ~collate_byname() override;270 int do_compare(271 const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const override;272 string_type do_transform(const char_type* __lo, const char_type* __hi) const override;273};274 275# if _LIBCPP_HAS_WIDE_CHARACTERS276template <>277class _LIBCPP_EXPORTED_FROM_ABI collate_byname<wchar_t> : public collate<wchar_t> {278 __locale::__locale_t __l_;279 280public:281 typedef wchar_t char_type;282 typedef basic_string<char_type> string_type;283 284 explicit collate_byname(const char* __n, size_t __refs = 0);285 explicit collate_byname(const string& __n, size_t __refs = 0);286 287protected:288 ~collate_byname() override;289 290 int do_compare(291 const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const override;292 string_type do_transform(const char_type* __lo, const char_type* __hi) const override;293};294# endif295 296// template <class charT> class ctype297 298class _LIBCPP_EXPORTED_FROM_ABI ctype_base {299public:300# if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE)301 typedef unsigned long mask;302 static const mask space = 1 << 0;303 static const mask print = 1 << 1;304 static const mask cntrl = 1 << 2;305 static const mask upper = 1 << 3;306 static const mask lower = 1 << 4;307 static const mask alpha = 1 << 5;308 static const mask digit = 1 << 6;309 static const mask punct = 1 << 7;310 static const mask xdigit = 1 << 8;311 static const mask blank = 1 << 9;312# if defined(__BIONIC__)313 // Historically this was a part of regex_traits rather than ctype_base. The314 // historical value of the constant is preserved for ABI compatibility.315 static const mask __regex_word = 0x8000;316# else317 static const mask __regex_word = 1 << 10;318# endif // defined(__BIONIC__)319# elif defined(__GLIBC__)320 typedef unsigned short mask;321 static const mask space = _ISspace;322 static const mask print = _ISprint;323 static const mask cntrl = _IScntrl;324 static const mask upper = _ISupper;325 static const mask lower = _ISlower;326 static const mask alpha = _ISalpha;327 static const mask digit = _ISdigit;328 static const mask punct = _ISpunct;329 static const mask xdigit = _ISxdigit;330 static const mask blank = _ISblank;331# if defined(__mips__) || (BYTE_ORDER == BIG_ENDIAN)332 static const mask __regex_word = static_cast<mask>(_ISbit(15));333# else334 static const mask __regex_word = 0x80;335# endif336# elif defined(_LIBCPP_MSVCRT_LIKE)337 typedef unsigned short mask;338 static const mask space = _SPACE;339 static const mask print = _BLANK | _PUNCT | _ALPHA | _DIGIT;340 static const mask cntrl = _CONTROL;341 static const mask upper = _UPPER;342 static const mask lower = _LOWER;343 static const mask alpha = _ALPHA;344 static const mask digit = _DIGIT;345 static const mask punct = _PUNCT;346 static const mask xdigit = _HEX;347 static const mask blank = _BLANK;348 static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used349# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT350# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA351# elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)352# ifdef __APPLE__353 typedef uint32_t mask;354# elif defined(__FreeBSD__)355 typedef unsigned long mask;356# elif defined(__NetBSD__)357 typedef unsigned short mask;358# endif359 static const mask space = _CTYPE_S;360 static const mask print = _CTYPE_R;361 static const mask cntrl = _CTYPE_C;362 static const mask upper = _CTYPE_U;363 static const mask lower = _CTYPE_L;364 static const mask alpha = _CTYPE_A;365 static const mask digit = _CTYPE_D;366 static const mask punct = _CTYPE_P;367 static const mask xdigit = _CTYPE_X;368 369# if defined(__NetBSD__)370 static const mask blank = _CTYPE_BL;371 // NetBSD defines classes up to 0x2000372 // see sys/ctype_bits.h, _CTYPE_Q373 static const mask __regex_word = 0x8000;374# else375 static const mask blank = _CTYPE_B;376 static const mask __regex_word = 0x80;377# endif378# elif defined(_AIX)379 typedef unsigned int mask;380 static const mask space = _ISSPACE;381 static const mask print = _ISPRINT;382 static const mask cntrl = _ISCNTRL;383 static const mask upper = _ISUPPER;384 static const mask lower = _ISLOWER;385 static const mask alpha = _ISALPHA;386 static const mask digit = _ISDIGIT;387 static const mask punct = _ISPUNCT;388 static const mask xdigit = _ISXDIGIT;389 static const mask blank = _ISBLANK;390 static const mask __regex_word = 0x8000;391# elif _LIBCPP_LIBC_NEWLIB392 // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.393 typedef char mask;394 // In case char is signed, static_cast is needed to avoid warning on395 // positive value becomming negative.396 static const mask space = static_cast<mask>(_S);397 static const mask print = static_cast<mask>(_P | _U | _L | _N | _B);398 static const mask cntrl = static_cast<mask>(_C);399 static const mask upper = static_cast<mask>(_U);400 static const mask lower = static_cast<mask>(_L);401 static const mask alpha = static_cast<mask>(_U | _L);402 static const mask digit = static_cast<mask>(_N);403 static const mask punct = static_cast<mask>(_P);404 static const mask xdigit = static_cast<mask>(_X | _N);405 static const mask blank = static_cast<mask>(_B);406 // mask is already fully saturated, use a different type in regex_type_traits.407 static const unsigned short __regex_word = 0x100;408# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT409# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA410# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT411# elif defined(__MVS__)412# if defined(__NATIVE_ASCII_F)413 typedef unsigned int mask;414 static const mask space = _ISSPACE_A;415 static const mask print = _ISPRINT_A;416 static const mask cntrl = _ISCNTRL_A;417 static const mask upper = _ISUPPER_A;418 static const mask lower = _ISLOWER_A;419 static const mask alpha = _ISALPHA_A;420 static const mask digit = _ISDIGIT_A;421 static const mask punct = _ISPUNCT_A;422 static const mask xdigit = _ISXDIGIT_A;423 static const mask blank = _ISBLANK_A;424# else425 typedef unsigned short mask;426 static const mask space = __ISSPACE;427 static const mask print = __ISPRINT;428 static const mask cntrl = __ISCNTRL;429 static const mask upper = __ISUPPER;430 static const mask lower = __ISLOWER;431 static const mask alpha = __ISALPHA;432 static const mask digit = __ISDIGIT;433 static const mask punct = __ISPUNCT;434 static const mask xdigit = __ISXDIGIT;435 static const mask blank = __ISBLANK;436# endif437 static const mask __regex_word = 0x8000;438# else439# error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?440# endif441 static const mask alnum = alpha | digit;442 static const mask graph = alnum | punct;443 444 _LIBCPP_HIDE_FROM_ABI ctype_base() {}445 446 static_assert((__regex_word & ~(std::make_unsigned<mask>::type)(space | print | cntrl | upper | lower | alpha |447 digit | punct | xdigit | blank)) == __regex_word,448 "__regex_word can't overlap other bits");449};450 451template <class _CharT>452class ctype;453 454# if _LIBCPP_HAS_WIDE_CHARACTERS455template <>456class _LIBCPP_EXPORTED_FROM_ABI ctype<wchar_t> : public locale::facet, public ctype_base {457public:458 typedef wchar_t char_type;459 460 _LIBCPP_HIDE_FROM_ABI explicit ctype(size_t __refs = 0) : locale::facet(__refs) {}461 462 _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const { return do_is(__m, __c); }463 464 _LIBCPP_HIDE_FROM_ABI const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const {465 return do_is(__low, __high, __vec);466 }467 468 _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const {469 return do_scan_is(__m, __low, __high);470 }471 472 _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const {473 return do_scan_not(__m, __low, __high);474 }475 476 _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); }477 478 _LIBCPP_HIDE_FROM_ABI const char_type* toupper(char_type* __low, const char_type* __high) const {479 return do_toupper(__low, __high);480 }481 482 _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); }483 484 _LIBCPP_HIDE_FROM_ABI const char_type* tolower(char_type* __low, const char_type* __high) const {485 return do_tolower(__low, __high);486 }487 488 _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); }489 490 _LIBCPP_HIDE_FROM_ABI const char* widen(const char* __low, const char* __high, char_type* __to) const {491 return do_widen(__low, __high, __to);492 }493 494 _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); }495 496 _LIBCPP_HIDE_FROM_ABI const char_type*497 narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const {498 return do_narrow(__low, __high, __dfault, __to);499 }500 501 static locale::id id;502 503protected:504 ~ctype() override;505 virtual bool do_is(mask __m, char_type __c) const;506 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;507 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;508 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;509 virtual char_type do_toupper(char_type) const;510 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;511 virtual char_type do_tolower(char_type) const;512 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;513 virtual char_type do_widen(char) const;514 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;515 virtual char do_narrow(char_type, char __dfault) const;516 virtual const char_type*517 do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;518};519# endif // _LIBCPP_HAS_WIDE_CHARACTERS520 521inline _LIBCPP_HIDE_FROM_ABI bool __libcpp_isascii(int __c) { return (__c & ~0x7F) == 0; }522 523template <>524class _LIBCPP_EXPORTED_FROM_ABI ctype<char> : public locale::facet, public ctype_base {525 const mask* __tab_;526 bool __del_;527 528public:529 typedef char char_type;530 531 explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0);532 533 _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const {534 return std::__libcpp_isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) != 0 : false;535 }536 537 _LIBCPP_HIDE_FROM_ABI const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const {538 for (; __low != __high; ++__low, ++__vec)539 *__vec = std::__libcpp_isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;540 return __low;541 }542 543 _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const {544 for (; __low != __high; ++__low)545 if (std::__libcpp_isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))546 break;547 return __low;548 }549 550 _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const {551 for (; __low != __high; ++__low)552 if (!std::__libcpp_isascii(*__low) || !(__tab_[static_cast<int>(*__low)] & __m))553 break;554 return __low;555 }556 557 _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); }558 559 _LIBCPP_HIDE_FROM_ABI const char_type* toupper(char_type* __low, const char_type* __high) const {560 return do_toupper(__low, __high);561 }562 563 _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); }564 565 _LIBCPP_HIDE_FROM_ABI const char_type* tolower(char_type* __low, const char_type* __high) const {566 return do_tolower(__low, __high);567 }568 569 _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); }570 571 _LIBCPP_HIDE_FROM_ABI const char* widen(const char* __low, const char* __high, char_type* __to) const {572 return do_widen(__low, __high, __to);573 }574 575 _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); }576 577 _LIBCPP_HIDE_FROM_ABI const char*578 narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const {579 return do_narrow(__low, __high, __dfault, __to);580 }581 582 static locale::id id;583 584# ifdef _CACHED_RUNES585 static const size_t table_size = _CACHED_RUNES;586# else587 static const size_t table_size = 256;588# endif589 _LIBCPP_HIDE_FROM_ABI const mask* table() const _NOEXCEPT { return __tab_; }590 static const mask* classic_table() _NOEXCEPT;591 592protected:593 ~ctype() override;594 virtual char_type do_toupper(char_type __c) const;595 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;596 virtual char_type do_tolower(char_type __c) const;597 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;598 virtual char_type do_widen(char __c) const;599 virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;600 virtual char do_narrow(char_type __c, char __dfault) const;601 virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;602};603 604// template <class CharT> class ctype_byname;605 606template <class _CharT>607class ctype_byname;608 609template <>610class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<char> : public ctype<char> {611 __locale::__locale_t __l_;612 613public:614 explicit ctype_byname(const char*, size_t = 0);615 explicit ctype_byname(const string&, size_t = 0);616 617protected:618 ~ctype_byname() override;619 char_type do_toupper(char_type) const override;620 const char_type* do_toupper(char_type* __low, const char_type* __high) const override;621 char_type do_tolower(char_type) const override;622 const char_type* do_tolower(char_type* __low, const char_type* __high) const override;623};624 625# if _LIBCPP_HAS_WIDE_CHARACTERS626template <>627class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<wchar_t> : public ctype<wchar_t> {628 __locale::__locale_t __l_;629 630public:631 explicit ctype_byname(const char*, size_t = 0);632 explicit ctype_byname(const string&, size_t = 0);633 634protected:635 ~ctype_byname() override;636 bool do_is(mask __m, char_type __c) const override;637 const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const override;638 const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const override;639 const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const override;640 char_type do_toupper(char_type) const override;641 const char_type* do_toupper(char_type* __low, const char_type* __high) const override;642 char_type do_tolower(char_type) const override;643 const char_type* do_tolower(char_type* __low, const char_type* __high) const override;644 char_type do_widen(char) const override;645 const char* do_widen(const char* __low, const char* __high, char_type* __dest) const override;646 char do_narrow(char_type, char __dfault) const override;647 const char_type*648 do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const override;649};650# endif // _LIBCPP_HAS_WIDE_CHARACTERS651 652template <class _CharT>653inline _LIBCPP_HIDE_FROM_ABI bool isspace(_CharT __c, const locale& __loc) {654 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);655}656 657template <class _CharT>658inline _LIBCPP_HIDE_FROM_ABI bool isprint(_CharT __c, const locale& __loc) {659 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);660}661 662template <class _CharT>663inline _LIBCPP_HIDE_FROM_ABI bool iscntrl(_CharT __c, const locale& __loc) {664 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);665}666 667template <class _CharT>668inline _LIBCPP_HIDE_FROM_ABI bool isupper(_CharT __c, const locale& __loc) {669 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);670}671 672template <class _CharT>673inline _LIBCPP_HIDE_FROM_ABI bool islower(_CharT __c, const locale& __loc) {674 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);675}676 677template <class _CharT>678inline _LIBCPP_HIDE_FROM_ABI bool isalpha(_CharT __c, const locale& __loc) {679 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);680}681 682template <class _CharT>683inline _LIBCPP_HIDE_FROM_ABI bool isdigit(_CharT __c, const locale& __loc) {684 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);685}686 687template <class _CharT>688inline _LIBCPP_HIDE_FROM_ABI bool ispunct(_CharT __c, const locale& __loc) {689 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);690}691 692template <class _CharT>693inline _LIBCPP_HIDE_FROM_ABI bool isxdigit(_CharT __c, const locale& __loc) {694 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);695}696 697template <class _CharT>698inline _LIBCPP_HIDE_FROM_ABI bool isalnum(_CharT __c, const locale& __loc) {699 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);700}701 702template <class _CharT>703inline _LIBCPP_HIDE_FROM_ABI bool isgraph(_CharT __c, const locale& __loc) {704 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);705}706 707template <class _CharT>708_LIBCPP_HIDE_FROM_ABI bool isblank(_CharT __c, const locale& __loc) {709 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::blank, __c);710}711 712template <class _CharT>713inline _LIBCPP_HIDE_FROM_ABI _CharT toupper(_CharT __c, const locale& __loc) {714 return std::use_facet<ctype<_CharT> >(__loc).toupper(__c);715}716 717template <class _CharT>718inline _LIBCPP_HIDE_FROM_ABI _CharT tolower(_CharT __c, const locale& __loc) {719 return std::use_facet<ctype<_CharT> >(__loc).tolower(__c);720}721 722// codecvt_base723 724class _LIBCPP_EXPORTED_FROM_ABI codecvt_base {725public:726 _LIBCPP_HIDE_FROM_ABI codecvt_base() {}727 enum result { ok, partial, error, noconv };728};729 730// template <class internT, class externT, class stateT> class codecvt;731 732template <class _InternT, class _ExternT, class _StateT>733class codecvt;734 735// template <> class codecvt<char, char, mbstate_t>736 737template <>738class _LIBCPP_EXPORTED_FROM_ABI codecvt<char, char, mbstate_t> : public locale::facet, public codecvt_base {739public:740 typedef char intern_type;741 typedef char extern_type;742 typedef mbstate_t state_type;743 744 _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}745 746 _LIBCPP_HIDE_FROM_ABI result747 out(state_type& __st,748 const intern_type* __frm,749 const intern_type* __frm_end,750 const intern_type*& __frm_nxt,751 extern_type* __to,752 extern_type* __to_end,753 extern_type*& __to_nxt) const {754 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);755 }756 757 _LIBCPP_HIDE_FROM_ABI result758 unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {759 return do_unshift(__st, __to, __to_end, __to_nxt);760 }761 762 _LIBCPP_HIDE_FROM_ABI result763 in(state_type& __st,764 const extern_type* __frm,765 const extern_type* __frm_end,766 const extern_type*& __frm_nxt,767 intern_type* __to,768 intern_type* __to_end,769 intern_type*& __to_nxt) const {770 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);771 }772 773 _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }774 775 _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }776 777 _LIBCPP_HIDE_FROM_ABI int778 length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {779 return do_length(__st, __frm, __end, __mx);780 }781 782 _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }783 784 static locale::id id;785 786protected:787 _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}788 789 ~codecvt() override;790 791 virtual result792 do_out(state_type& __st,793 const intern_type* __frm,794 const intern_type* __frm_end,795 const intern_type*& __frm_nxt,796 extern_type* __to,797 extern_type* __to_end,798 extern_type*& __to_nxt) const;799 virtual result800 do_in(state_type& __st,801 const extern_type* __frm,802 const extern_type* __frm_end,803 const extern_type*& __frm_nxt,804 intern_type* __to,805 intern_type* __to_end,806 intern_type*& __to_nxt) const;807 virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;808 virtual int do_encoding() const _NOEXCEPT;809 virtual bool do_always_noconv() const _NOEXCEPT;810 virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;811 virtual int do_max_length() const _NOEXCEPT;812};813 814// template <> class codecvt<wchar_t, char, mbstate_t>815 816# if _LIBCPP_HAS_WIDE_CHARACTERS817template <>818class _LIBCPP_EXPORTED_FROM_ABI codecvt<wchar_t, char, mbstate_t> : public locale::facet, public codecvt_base {819 __locale::__locale_t __l_;820 821public:822 typedef wchar_t intern_type;823 typedef char extern_type;824 typedef mbstate_t state_type;825 826 explicit codecvt(size_t __refs = 0);827 828 _LIBCPP_HIDE_FROM_ABI result829 out(state_type& __st,830 const intern_type* __frm,831 const intern_type* __frm_end,832 const intern_type*& __frm_nxt,833 extern_type* __to,834 extern_type* __to_end,835 extern_type*& __to_nxt) const {836 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);837 }838 839 _LIBCPP_HIDE_FROM_ABI result840 unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {841 return do_unshift(__st, __to, __to_end, __to_nxt);842 }843 844 _LIBCPP_HIDE_FROM_ABI result845 in(state_type& __st,846 const extern_type* __frm,847 const extern_type* __frm_end,848 const extern_type*& __frm_nxt,849 intern_type* __to,850 intern_type* __to_end,851 intern_type*& __to_nxt) const {852 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);853 }854 855 _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }856 857 _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }858 859 _LIBCPP_HIDE_FROM_ABI int860 length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {861 return do_length(__st, __frm, __end, __mx);862 }863 864 _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }865 866 static locale::id id;867 868protected:869 explicit codecvt(const char*, size_t __refs = 0);870 871 ~codecvt() override;872 873 virtual result874 do_out(state_type& __st,875 const intern_type* __frm,876 const intern_type* __frm_end,877 const intern_type*& __frm_nxt,878 extern_type* __to,879 extern_type* __to_end,880 extern_type*& __to_nxt) const;881 virtual result882 do_in(state_type& __st,883 const extern_type* __frm,884 const extern_type* __frm_end,885 const extern_type*& __frm_nxt,886 intern_type* __to,887 intern_type* __to_end,888 intern_type*& __to_nxt) const;889 virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;890 virtual int do_encoding() const _NOEXCEPT;891 virtual bool do_always_noconv() const _NOEXCEPT;892 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;893 virtual int do_max_length() const _NOEXCEPT;894};895# endif // _LIBCPP_HAS_WIDE_CHARACTERS896 897// template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20898 899template <>900class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char, mbstate_t>901 : public locale::facet, public codecvt_base {902public:903 typedef char16_t intern_type;904 typedef char extern_type;905 typedef mbstate_t state_type;906 907 _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}908 909 _LIBCPP_HIDE_FROM_ABI result910 out(state_type& __st,911 const intern_type* __frm,912 const intern_type* __frm_end,913 const intern_type*& __frm_nxt,914 extern_type* __to,915 extern_type* __to_end,916 extern_type*& __to_nxt) const {917 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);918 }919 920 _LIBCPP_HIDE_FROM_ABI result921 unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {922 return do_unshift(__st, __to, __to_end, __to_nxt);923 }924 925 _LIBCPP_HIDE_FROM_ABI result926 in(state_type& __st,927 const extern_type* __frm,928 const extern_type* __frm_end,929 const extern_type*& __frm_nxt,930 intern_type* __to,931 intern_type* __to_end,932 intern_type*& __to_nxt) const {933 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);934 }935 936 _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }937 938 _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }939 940 _LIBCPP_HIDE_FROM_ABI int941 length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {942 return do_length(__st, __frm, __end, __mx);943 }944 945 _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }946 947 static locale::id id;948 949protected:950 _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}951 952 ~codecvt() override;953 954 virtual result955 do_out(state_type& __st,956 const intern_type* __frm,957 const intern_type* __frm_end,958 const intern_type*& __frm_nxt,959 extern_type* __to,960 extern_type* __to_end,961 extern_type*& __to_nxt) const;962 virtual result963 do_in(state_type& __st,964 const extern_type* __frm,965 const extern_type* __frm_end,966 const extern_type*& __frm_nxt,967 intern_type* __to,968 intern_type* __to_end,969 intern_type*& __to_nxt) const;970 virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;971 virtual int do_encoding() const _NOEXCEPT;972 virtual bool do_always_noconv() const _NOEXCEPT;973 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;974 virtual int do_max_length() const _NOEXCEPT;975};976 977# if _LIBCPP_HAS_CHAR8_T978 979// template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20980 981template <>982class _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char8_t, mbstate_t> : public locale::facet, public codecvt_base {983public:984 typedef char16_t intern_type;985 typedef char8_t extern_type;986 typedef mbstate_t state_type;987 988 _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}989 990 _LIBCPP_HIDE_FROM_ABI result991 out(state_type& __st,992 const intern_type* __frm,993 const intern_type* __frm_end,994 const intern_type*& __frm_nxt,995 extern_type* __to,996 extern_type* __to_end,997 extern_type*& __to_nxt) const {998 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);999 }1000 1001 _LIBCPP_HIDE_FROM_ABI result1002 unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {1003 return do_unshift(__st, __to, __to_end, __to_nxt);1004 }1005 1006 _LIBCPP_HIDE_FROM_ABI result1007 in(state_type& __st,1008 const extern_type* __frm,1009 const extern_type* __frm_end,1010 const extern_type*& __frm_nxt,1011 intern_type* __to,1012 intern_type* __to_end,1013 intern_type*& __to_nxt) const {1014 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);1015 }1016 1017 _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }1018 1019 _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }1020 1021 _LIBCPP_HIDE_FROM_ABI int1022 length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {1023 return do_length(__st, __frm, __end, __mx);1024 }1025 1026 _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }1027 1028 static locale::id id;1029 1030protected:1031 _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}1032 1033 ~codecvt() override;1034 1035 virtual result1036 do_out(state_type& __st,1037 const intern_type* __frm,1038 const intern_type* __frm_end,1039 const intern_type*& __frm_nxt,1040 extern_type* __to,1041 extern_type* __to_end,1042 extern_type*& __to_nxt) const;1043 virtual result1044 do_in(state_type& __st,1045 const extern_type* __frm,1046 const extern_type* __frm_end,1047 const extern_type*& __frm_nxt,1048 intern_type* __to,1049 intern_type* __to_end,1050 intern_type*& __to_nxt) const;1051 virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;1052 virtual int do_encoding() const _NOEXCEPT;1053 virtual bool do_always_noconv() const _NOEXCEPT;1054 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;1055 virtual int do_max_length() const _NOEXCEPT;1056};1057 1058# endif1059 1060// template <> class codecvt<char32_t, char, mbstate_t> // deprecated in C++201061 1062template <>1063class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char, mbstate_t>1064 : public locale::facet, public codecvt_base {1065public:1066 typedef char32_t intern_type;1067 typedef char extern_type;1068 typedef mbstate_t state_type;1069 1070 _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}1071 1072 _LIBCPP_HIDE_FROM_ABI result1073 out(state_type& __st,1074 const intern_type* __frm,1075 const intern_type* __frm_end,1076 const intern_type*& __frm_nxt,1077 extern_type* __to,1078 extern_type* __to_end,1079 extern_type*& __to_nxt) const {1080 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);1081 }1082 1083 _LIBCPP_HIDE_FROM_ABI result1084 unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {1085 return do_unshift(__st, __to, __to_end, __to_nxt);1086 }1087 1088 _LIBCPP_HIDE_FROM_ABI result1089 in(state_type& __st,1090 const extern_type* __frm,1091 const extern_type* __frm_end,1092 const extern_type*& __frm_nxt,1093 intern_type* __to,1094 intern_type* __to_end,1095 intern_type*& __to_nxt) const {1096 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);1097 }1098 1099 _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }1100 1101 _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }1102 1103 _LIBCPP_HIDE_FROM_ABI int1104 length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {1105 return do_length(__st, __frm, __end, __mx);1106 }1107 1108 _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }1109 1110 static locale::id id;1111 1112protected:1113 _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}1114 1115 ~codecvt() override;1116 1117 virtual result1118 do_out(state_type& __st,1119 const intern_type* __frm,1120 const intern_type* __frm_end,1121 const intern_type*& __frm_nxt,1122 extern_type* __to,1123 extern_type* __to_end,1124 extern_type*& __to_nxt) const;1125 virtual result1126 do_in(state_type& __st,1127 const extern_type* __frm,1128 const extern_type* __frm_end,1129 const extern_type*& __frm_nxt,1130 intern_type* __to,1131 intern_type* __to_end,1132 intern_type*& __to_nxt) const;1133 virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;1134 virtual int do_encoding() const _NOEXCEPT;1135 virtual bool do_always_noconv() const _NOEXCEPT;1136 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;1137 virtual int do_max_length() const _NOEXCEPT;1138};1139 1140# if _LIBCPP_HAS_CHAR8_T1141 1142// template <> class codecvt<char32_t, char8_t, mbstate_t> // C++201143 1144template <>1145class _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char8_t, mbstate_t> : public locale::facet, public codecvt_base {1146public:1147 typedef char32_t intern_type;1148 typedef char8_t extern_type;1149 typedef mbstate_t state_type;1150 1151 _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}1152 1153 _LIBCPP_HIDE_FROM_ABI result1154 out(state_type& __st,1155 const intern_type* __frm,1156 const intern_type* __frm_end,1157 const intern_type*& __frm_nxt,1158 extern_type* __to,1159 extern_type* __to_end,1160 extern_type*& __to_nxt) const {1161 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);1162 }1163 1164 _LIBCPP_HIDE_FROM_ABI result1165 unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {1166 return do_unshift(__st, __to, __to_end, __to_nxt);1167 }1168 1169 _LIBCPP_HIDE_FROM_ABI result1170 in(state_type& __st,1171 const extern_type* __frm,1172 const extern_type* __frm_end,1173 const extern_type*& __frm_nxt,1174 intern_type* __to,1175 intern_type* __to_end,1176 intern_type*& __to_nxt) const {1177 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);1178 }1179 1180 _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }1181 1182 _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }1183 1184 _LIBCPP_HIDE_FROM_ABI int1185 length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {1186 return do_length(__st, __frm, __end, __mx);1187 }1188 1189 _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }1190 1191 static locale::id id;1192 1193protected:1194 _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}1195 1196 ~codecvt() override;1197 1198 virtual result1199 do_out(state_type& __st,1200 const intern_type* __frm,1201 const intern_type* __frm_end,1202 const intern_type*& __frm_nxt,1203 extern_type* __to,1204 extern_type* __to_end,1205 extern_type*& __to_nxt) const;1206 virtual result1207 do_in(state_type& __st,1208 const extern_type* __frm,1209 const extern_type* __frm_end,1210 const extern_type*& __frm_nxt,1211 intern_type* __to,1212 intern_type* __to_end,1213 intern_type*& __to_nxt) const;1214 virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;1215 virtual int do_encoding() const _NOEXCEPT;1216 virtual bool do_always_noconv() const _NOEXCEPT;1217 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;1218 virtual int do_max_length() const _NOEXCEPT;1219};1220 1221# endif1222 1223// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname1224 1225template <class _InternT, class _ExternT, class _StateT>1226class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> {1227public:1228 _LIBCPP_HIDE_FROM_ABI explicit codecvt_byname(const char* __nm, size_t __refs = 0)1229 : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}1230 _LIBCPP_HIDE_FROM_ABI explicit codecvt_byname(const string& __nm, size_t __refs = 0)1231 : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}1232 1233protected:1234 ~codecvt_byname() override;1235};1236 1237_LIBCPP_SUPPRESS_DEPRECATED_PUSH1238template <class _InternT, class _ExternT, class _StateT>1239codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() {}1240_LIBCPP_SUPPRESS_DEPRECATED_POP1241 1242extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>;1243# if _LIBCPP_HAS_WIDE_CHARACTERS1244extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>;1245# endif1246extern template class _LIBCPP_DEPRECATED_IN_CXX201247_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>; // deprecated in C++201248extern template class _LIBCPP_DEPRECATED_IN_CXX201249_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>; // deprecated in C++201250# if _LIBCPP_HAS_CHAR8_T1251extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>; // C++201252extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>; // C++201253# endif1254 1255template <size_t _Np>1256struct __narrow_to_utf8 {1257 template <class _OutputIterator, class _CharT>1258 _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;1259};1260 1261template <>1262struct __narrow_to_utf8<8> {1263 template <class _OutputIterator, class _CharT>1264 _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const {1265 for (; __wb < __we; ++__wb, ++__s)1266 *__s = *__wb;1267 return __s;1268 }1269};1270 1271_LIBCPP_SUPPRESS_DEPRECATED_PUSH1272template <>1273struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<16> : public codecvt<char16_t, char, mbstate_t> {1274 _LIBCPP_HIDE_FROM_ABI __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}1275 _LIBCPP_SUPPRESS_DEPRECATED_POP1276 1277 ~__narrow_to_utf8() override;1278 1279 template <class _OutputIterator, class _CharT>1280 _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const {1281 result __r = ok;1282 mbstate_t __mb;1283 while (__wb < __we && __r != error) {1284 const int __sz = 32;1285 char __buf[__sz];1286 char* __bn;1287 const char16_t* __wn = (const char16_t*)__wb;1288 __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn, __buf, __buf + __sz, __bn);1289 if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)1290 std::__throw_runtime_error("locale not supported");1291 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)1292 *__s = *__p;1293 __wb = (const _CharT*)__wn;1294 }1295 return __s;1296 }1297};1298 1299_LIBCPP_SUPPRESS_DEPRECATED_PUSH1300template <>1301struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<32> : public codecvt<char32_t, char, mbstate_t> {1302 _LIBCPP_HIDE_FROM_ABI __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}1303 _LIBCPP_SUPPRESS_DEPRECATED_POP1304 1305 ~__narrow_to_utf8() override;1306 1307 template <class _OutputIterator, class _CharT>1308 _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const {1309 result __r = ok;1310 mbstate_t __mb;1311 while (__wb < __we && __r != error) {1312 const int __sz = 32;1313 char __buf[__sz];1314 char* __bn;1315 const char32_t* __wn = (const char32_t*)__wb;1316 __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn, __buf, __buf + __sz, __bn);1317 if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)1318 std::__throw_runtime_error("locale not supported");1319 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)1320 *__s = *__p;1321 __wb = (const _CharT*)__wn;1322 }1323 return __s;1324 }1325};1326 1327template <size_t _Np>1328struct __widen_from_utf8 {1329 template <class _OutputIterator>1330 _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;1331};1332 1333template <>1334struct __widen_from_utf8<8> {1335 template <class _OutputIterator>1336 _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const {1337 for (; __nb < __ne; ++__nb, ++__s)1338 *__s = *__nb;1339 return __s;1340 }1341};1342 1343_LIBCPP_SUPPRESS_DEPRECATED_PUSH1344template <>1345struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<16> : public codecvt<char16_t, char, mbstate_t> {1346 _LIBCPP_HIDE_FROM_ABI __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}1347 _LIBCPP_SUPPRESS_DEPRECATED_POP1348 1349 ~__widen_from_utf8() override;1350 1351 template <class _OutputIterator>1352 _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const {1353 result __r = ok;1354 mbstate_t __mb;1355 while (__nb < __ne && __r != error) {1356 const int __sz = 32;1357 char16_t __buf[__sz];1358 char16_t* __bn;1359 const char* __nn = __nb;1360 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn);1361 if (__r == codecvt_base::error || __nn == __nb)1362 std::__throw_runtime_error("locale not supported");1363 for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)1364 *__s = *__p;1365 __nb = __nn;1366 }1367 return __s;1368 }1369};1370 1371_LIBCPP_SUPPRESS_DEPRECATED_PUSH1372template <>1373struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<32> : public codecvt<char32_t, char, mbstate_t> {1374 _LIBCPP_HIDE_FROM_ABI __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}1375 _LIBCPP_SUPPRESS_DEPRECATED_POP1376 1377 ~__widen_from_utf8() override;1378 1379 template <class _OutputIterator>1380 _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const {1381 result __r = ok;1382 mbstate_t __mb;1383 while (__nb < __ne && __r != error) {1384 const int __sz = 32;1385 char32_t __buf[__sz];1386 char32_t* __bn;1387 const char* __nn = __nb;1388 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn);1389 if (__r == codecvt_base::error || __nn == __nb)1390 std::__throw_runtime_error("locale not supported");1391 for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)1392 *__s = *__p;1393 __nb = __nn;1394 }1395 return __s;1396 }1397};1398 1399// template <class charT> class numpunct1400 1401template <class _CharT>1402class numpunct;1403 1404template <>1405class _LIBCPP_EXPORTED_FROM_ABI numpunct<char> : public locale::facet {1406public:1407 typedef char char_type;1408 typedef basic_string<char_type> string_type;1409 1410 explicit numpunct(size_t __refs = 0);1411 1412 _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); }1413 _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); }1414 _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); }1415 _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); }1416 _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); }1417 1418 static locale::id id;1419 1420protected:1421 ~numpunct() override;1422 virtual char_type do_decimal_point() const;1423 virtual char_type do_thousands_sep() const;1424 virtual string do_grouping() const;1425 virtual string_type do_truename() const;1426 virtual string_type do_falsename() const;1427 1428 char_type __decimal_point_;1429 char_type __thousands_sep_;1430 string __grouping_;1431};1432 1433# if _LIBCPP_HAS_WIDE_CHARACTERS1434template <>1435class _LIBCPP_EXPORTED_FROM_ABI numpunct<wchar_t> : public locale::facet {1436public:1437 typedef wchar_t char_type;1438 typedef basic_string<char_type> string_type;1439 1440 explicit numpunct(size_t __refs = 0);1441 1442 _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); }1443 _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); }1444 _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); }1445 _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); }1446 _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); }1447 1448 static locale::id id;1449 1450protected:1451 ~numpunct() override;1452 virtual char_type do_decimal_point() const;1453 virtual char_type do_thousands_sep() const;1454 virtual string do_grouping() const;1455 virtual string_type do_truename() const;1456 virtual string_type do_falsename() const;1457 1458 char_type __decimal_point_;1459 char_type __thousands_sep_;1460 string __grouping_;1461};1462# endif // _LIBCPP_HAS_WIDE_CHARACTERS1463 1464// template <class charT> class numpunct_byname1465 1466template <class _CharT>1467class numpunct_byname;1468 1469template <>1470class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<char> : public numpunct<char> {1471public:1472 typedef char char_type;1473 typedef basic_string<char_type> string_type;1474 1475 explicit numpunct_byname(const char* __nm, size_t __refs = 0);1476 explicit numpunct_byname(const string& __nm, size_t __refs = 0);1477 1478protected:1479 ~numpunct_byname() override;1480 1481private:1482 void __init(const char*);1483};1484 1485# if _LIBCPP_HAS_WIDE_CHARACTERS1486template <>1487class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<wchar_t> : public numpunct<wchar_t> {1488public:1489 typedef wchar_t char_type;1490 typedef basic_string<char_type> string_type;1491 1492 explicit numpunct_byname(const char* __nm, size_t __refs = 0);1493 explicit numpunct_byname(const string& __nm, size_t __refs = 0);1494 1495protected:1496 ~numpunct_byname() override;1497 1498private:1499 void __init(const char*);1500};1501# endif // _LIBCPP_HAS_WIDE_CHARACTERS1502 1503_LIBCPP_END_NAMESPACE_STD1504 1505#endif // _LIBCPP_HAS_LOCALIZATION1506 1507#endif // _LIBCPP___LOCALE1508