2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___LOCALE
11 #define _LIBCPP___LOCALE
13 #include <__availability>
15 #include <__memory/shared_ptr.h> // __shared_count
16 #include <__mutex/once_flag.h>
17 #include <__type_traits/make_unsigned.h>
24 // Some platforms require more includes than others. Keep the includes on all plaforms for now.
28 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
31 # include <__std_mbstate_t.h>
34 #if defined(_LIBCPP_MSVCRT_LIKE)
35 # include <__support/win32/locale_win32.h>
36 #elif defined(_AIX) || defined(__MVS__)
37 # include <__support/ibm/xlocale.h>
38 #elif defined(__ANDROID__)
39 # include <__support/android/locale_bionic.h>
40 #elif defined(_NEWLIB_VERSION)
41 # include <__support/newlib/xlocale.h>
42 #elif defined(__OpenBSD__)
43 # include <__support/openbsd/xlocale.h>
44 #elif (defined(__APPLE__) || defined(__FreeBSD__))
46 #elif defined(__Fuchsia__)
47 # include <__support/fuchsia/xlocale.h>
48 #elif defined(__wasi__)
49 // WASI libc uses musl's locales support.
50 # include <__support/musl/xlocale.h>
51 #elif defined(_LIBCPP_HAS_MUSL_LIBC)
52 # include <__support/musl/xlocale.h>
55 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
56 # pragma GCC system_header
59 _LIBCPP_BEGIN_NAMESPACE_STD
61 class _LIBCPP_EXPORTED_FROM_ABI locale;
63 template <class _Facet>
64 _LIBCPP_INLINE_VISIBILITY
66 has_facet(const locale&) _NOEXCEPT;
68 template <class _Facet>
69 _LIBCPP_INLINE_VISIBILITY
71 use_facet(const locale&);
73 class _LIBCPP_EXPORTED_FROM_ABI locale
77 class _LIBCPP_EXPORTED_FROM_ABI facet;
78 class _LIBCPP_EXPORTED_FROM_ABI id;
81 _LIBCPP_AVAILABILITY_LOCALE_CATEGORY
82 static const category // values assigned here are for exposition only
84 collate = LC_COLLATE_MASK,
85 ctype = LC_CTYPE_MASK,
86 monetary = LC_MONETARY_MASK,
87 numeric = LC_NUMERIC_MASK,
89 messages = LC_MESSAGES_MASK,
90 all = collate | ctype | monetary | numeric | time | messages;
92 // construct/copy/destroy:
94 locale(const locale&) _NOEXCEPT;
95 explicit locale(const char*);
96 explicit locale(const string&);
97 locale(const locale&, const char*, category);
98 locale(const locale&, const string&, category);
99 template <class _Facet>
100 _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
101 locale(const locale&, const locale&, category);
105 const locale& operator=(const locale&) _NOEXCEPT;
107 template <class _Facet>
108 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
109 locale combine(const locale&) const;
111 // locale operations:
113 bool operator==(const locale&) const;
114 #if _LIBCPP_STD_VER <= 17
115 _LIBCPP_HIDE_FROM_ABI bool operator!=(const locale& __y) const {return !(*this == __y);}
117 template <class _CharT, class _Traits, class _Allocator>
118 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
119 bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
120 const basic_string<_CharT, _Traits, _Allocator>&) const;
122 // global locale objects:
123 static locale global(const locale&);
124 static const locale& classic();
130 void __install_ctor(const locale&, facet*, long);
131 static locale& __global();
132 bool has_facet(id&) const;
133 const facet* use_facet(id&) const;
135 template <class _Facet> friend bool has_facet(const locale&) _NOEXCEPT;
136 template <class _Facet> friend const _Facet& use_facet(const locale&);
139 class _LIBCPP_EXPORTED_FROM_ABI locale::facet
140 : public __shared_count
143 _LIBCPP_INLINE_VISIBILITY
144 explicit facet(size_t __refs = 0)
145 : __shared_count(static_cast<long>(__refs)-1) {}
149 // facet(const facet&) = delete; // effectively done in __shared_count
150 // void operator=(const facet&) = delete;
152 void __on_zero_shared() _NOEXCEPT override;
155 class _LIBCPP_EXPORTED_FROM_ABI locale::id
160 static int32_t __next_id;
162 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
163 void operator=(const id&) = delete;
164 id(const id&) = delete;
166 public: // only needed for tests
170 friend class locale::__imp;
173 template <class _Facet>
174 inline _LIBCPP_INLINE_VISIBILITY
175 locale::locale(const locale& __other, _Facet* __f)
177 __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
180 template <class _Facet>
182 locale::combine(const locale& __other) const
184 if (!_VSTD::has_facet<_Facet>(__other))
185 __throw_runtime_error("locale::combine: locale missing facet");
187 return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
190 template <class _Facet>
191 inline _LIBCPP_INLINE_VISIBILITY
193 has_facet(const locale& __l) _NOEXCEPT
195 return __l.has_facet(_Facet::id);
198 template <class _Facet>
199 inline _LIBCPP_INLINE_VISIBILITY
201 use_facet(const locale& __l)
203 return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
206 // template <class _CharT> class collate;
208 template <class _CharT>
209 class _LIBCPP_TEMPLATE_VIS collate
210 : public locale::facet
213 typedef _CharT char_type;
214 typedef basic_string<char_type> string_type;
216 _LIBCPP_INLINE_VISIBILITY
217 explicit collate(size_t __refs = 0)
218 : locale::facet(__refs) {}
220 _LIBCPP_INLINE_VISIBILITY
221 int compare(const char_type* __lo1, const char_type* __hi1,
222 const char_type* __lo2, const char_type* __hi2) const
224 return do_compare(__lo1, __hi1, __lo2, __hi2);
227 // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work
228 // around a dllimport bug that expects an external instantiation.
229 _LIBCPP_INLINE_VISIBILITY
230 _LIBCPP_ALWAYS_INLINE
231 string_type transform(const char_type* __lo, const char_type* __hi) const
233 return do_transform(__lo, __hi);
236 _LIBCPP_INLINE_VISIBILITY
237 long hash(const char_type* __lo, const char_type* __hi) const
239 return do_hash(__lo, __hi);
242 static locale::id id;
246 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
247 const char_type* __lo2, const char_type* __hi2) const;
248 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
249 {return string_type(__lo, __hi);}
250 virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
253 template <class _CharT> locale::id collate<_CharT>::id;
255 template <class _CharT>
256 collate<_CharT>::~collate()
260 template <class _CharT>
262 collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
263 const char_type* __lo2, const char_type* __hi2) const
265 for (; __lo2 != __hi2; ++__lo1, ++__lo2)
267 if (__lo1 == __hi1 || *__lo1 < *__lo2)
272 return __lo1 != __hi1;
275 template <class _CharT>
277 collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
280 const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
281 const size_t __mask = size_t(0xF) << (__sr + 4);
282 for(const char_type* __p = __lo; __p != __hi; ++__p)
284 __h = (__h << 4) + static_cast<size_t>(*__p);
285 size_t __g = __h & __mask;
286 __h ^= __g | (__g >> __sr);
288 return static_cast<long>(__h);
291 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>;
292 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
293 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>;
296 // template <class CharT> class collate_byname;
298 template <class _CharT> class _LIBCPP_TEMPLATE_VIS collate_byname;
301 class _LIBCPP_EXPORTED_FROM_ABI collate_byname<char>
302 : public collate<char>
306 typedef char char_type;
307 typedef basic_string<char_type> string_type;
309 explicit collate_byname(const char* __n, size_t __refs = 0);
310 explicit collate_byname(const string& __n, size_t __refs = 0);
313 ~collate_byname() override;
314 int do_compare(const char_type* __lo1, const char_type* __hi1,
315 const char_type* __lo2, const char_type* __hi2) const override;
316 string_type do_transform(const char_type* __lo, const char_type* __hi) const override;
319 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
321 class _LIBCPP_EXPORTED_FROM_ABI collate_byname<wchar_t>
322 : public collate<wchar_t>
326 typedef wchar_t char_type;
327 typedef basic_string<char_type> string_type;
329 explicit collate_byname(const char* __n, size_t __refs = 0);
330 explicit collate_byname(const string& __n, size_t __refs = 0);
333 ~collate_byname() override;
335 int do_compare(const char_type* __lo1, const char_type* __hi1,
336 const char_type* __lo2, const char_type* __hi2) const override;
337 string_type do_transform(const char_type* __lo, const char_type* __hi) const override;
341 template <class _CharT, class _Traits, class _Allocator>
343 locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
344 const basic_string<_CharT, _Traits, _Allocator>& __y) const
346 return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
347 __x.data(), __x.data() + __x.size(),
348 __y.data(), __y.data() + __y.size()) < 0;
351 // template <class charT> class ctype
353 class _LIBCPP_EXPORTED_FROM_ABI ctype_base
356 #if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE)
357 typedef unsigned long mask;
358 static const mask space = 1<<0;
359 static const mask print = 1<<1;
360 static const mask cntrl = 1<<2;
361 static const mask upper = 1<<3;
362 static const mask lower = 1<<4;
363 static const mask alpha = 1<<5;
364 static const mask digit = 1<<6;
365 static const mask punct = 1<<7;
366 static const mask xdigit = 1<<8;
367 static const mask blank = 1<<9;
368 #if defined(__BIONIC__)
369 // Historically this was a part of regex_traits rather than ctype_base. The
370 // historical value of the constant is preserved for ABI compatibility.
371 static const mask __regex_word = 0x8000;
373 static const mask __regex_word = 1<<10;
374 #endif // defined(__BIONIC__)
375 #elif defined(__GLIBC__)
376 typedef unsigned short mask;
377 static const mask space = _ISspace;
378 static const mask print = _ISprint;
379 static const mask cntrl = _IScntrl;
380 static const mask upper = _ISupper;
381 static const mask lower = _ISlower;
382 static const mask alpha = _ISalpha;
383 static const mask digit = _ISdigit;
384 static const mask punct = _ISpunct;
385 static const mask xdigit = _ISxdigit;
386 static const mask blank = _ISblank;
387 #if defined(__mips__)
388 static const mask __regex_word = static_cast<mask>(_ISbit(15));
390 static const mask __regex_word = 0x80;
392 #elif defined(_LIBCPP_MSVCRT_LIKE)
393 typedef unsigned short mask;
394 static const mask space = _SPACE;
395 static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT;
396 static const mask cntrl = _CONTROL;
397 static const mask upper = _UPPER;
398 static const mask lower = _LOWER;
399 static const mask alpha = _ALPHA;
400 static const mask digit = _DIGIT;
401 static const mask punct = _PUNCT;
402 static const mask xdigit = _HEX;
403 static const mask blank = _BLANK;
404 static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used
405 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
406 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
407 #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
409 typedef __uint32_t mask;
410 # elif defined(__FreeBSD__)
411 typedef unsigned long mask;
412 # elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
413 typedef unsigned short mask;
415 static const mask space = _CTYPE_S;
416 static const mask print = _CTYPE_R;
417 static const mask cntrl = _CTYPE_C;
418 static const mask upper = _CTYPE_U;
419 static const mask lower = _CTYPE_L;
420 static const mask alpha = _CTYPE_A;
421 static const mask digit = _CTYPE_D;
422 static const mask punct = _CTYPE_P;
423 static const mask xdigit = _CTYPE_X;
425 # if defined(__NetBSD__)
426 static const mask blank = _CTYPE_BL;
427 // NetBSD defines classes up to 0x2000
428 // see sys/ctype_bits.h, _CTYPE_Q
429 static const mask __regex_word = 0x8000;
431 static const mask blank = _CTYPE_B;
432 static const mask __regex_word = 0x80;
435 typedef unsigned int mask;
436 static const mask space = _ISSPACE;
437 static const mask print = _ISPRINT;
438 static const mask cntrl = _ISCNTRL;
439 static const mask upper = _ISUPPER;
440 static const mask lower = _ISLOWER;
441 static const mask alpha = _ISALPHA;
442 static const mask digit = _ISDIGIT;
443 static const mask punct = _ISPUNCT;
444 static const mask xdigit = _ISXDIGIT;
445 static const mask blank = _ISBLANK;
446 static const mask __regex_word = 0x8000;
447 #elif defined(_NEWLIB_VERSION)
448 // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
450 static const mask space = _S;
451 static const mask print = _P | _U | _L | _N | _B;
452 static const mask cntrl = _C;
453 static const mask upper = _U;
454 static const mask lower = _L;
455 static const mask alpha = _U | _L;
456 static const mask digit = _N;
457 static const mask punct = _P;
458 static const mask xdigit = _X | _N;
459 static const mask blank = _B;
460 // mask is already fully saturated, use a different type in regex_type_traits.
461 static const unsigned short __regex_word = 0x100;
462 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
463 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
464 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
465 #elif defined(__MVS__)
466 # if defined(__NATIVE_ASCII_F)
467 typedef unsigned int mask;
468 static const mask space = _ISSPACE_A;
469 static const mask print = _ISPRINT_A;
470 static const mask cntrl = _ISCNTRL_A;
471 static const mask upper = _ISUPPER_A;
472 static const mask lower = _ISLOWER_A;
473 static const mask alpha = _ISALPHA_A;
474 static const mask digit = _ISDIGIT_A;
475 static const mask punct = _ISPUNCT_A;
476 static const mask xdigit = _ISXDIGIT_A;
477 static const mask blank = _ISBLANK_A;
479 typedef unsigned short mask;
480 static const mask space = __ISSPACE;
481 static const mask print = __ISPRINT;
482 static const mask cntrl = __ISCNTRL;
483 static const mask upper = __ISUPPER;
484 static const mask lower = __ISLOWER;
485 static const mask alpha = __ISALPHA;
486 static const mask digit = __ISDIGIT;
487 static const mask punct = __ISPUNCT;
488 static const mask xdigit = __ISXDIGIT;
489 static const mask blank = __ISBLANK;
491 static const mask __regex_word = 0x8000;
493 # error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?
495 static const mask alnum = alpha | digit;
496 static const mask graph = alnum | punct;
498 _LIBCPP_INLINE_VISIBILITY ctype_base() {}
500 static_assert((__regex_word & ~(std::make_unsigned<mask>::type)(space | print | cntrl | upper | lower | alpha |
501 digit | punct | xdigit | blank)) == __regex_word,
502 "__regex_word can't overlap other bits");
505 template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
507 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
509 class _LIBCPP_EXPORTED_FROM_ABI ctype<wchar_t>
510 : public locale::facet,
514 typedef wchar_t char_type;
516 _LIBCPP_INLINE_VISIBILITY
517 explicit ctype(size_t __refs = 0)
518 : locale::facet(__refs) {}
520 _LIBCPP_INLINE_VISIBILITY
521 bool is(mask __m, char_type __c) const
523 return do_is(__m, __c);
526 _LIBCPP_INLINE_VISIBILITY
527 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
529 return do_is(__low, __high, __vec);
532 _LIBCPP_INLINE_VISIBILITY
533 const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
535 return do_scan_is(__m, __low, __high);
538 _LIBCPP_INLINE_VISIBILITY
539 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
541 return do_scan_not(__m, __low, __high);
544 _LIBCPP_INLINE_VISIBILITY
545 char_type toupper(char_type __c) const
547 return do_toupper(__c);
550 _LIBCPP_INLINE_VISIBILITY
551 const char_type* toupper(char_type* __low, const char_type* __high) const
553 return do_toupper(__low, __high);
556 _LIBCPP_INLINE_VISIBILITY
557 char_type tolower(char_type __c) const
559 return do_tolower(__c);
562 _LIBCPP_INLINE_VISIBILITY
563 const char_type* tolower(char_type* __low, const char_type* __high) const
565 return do_tolower(__low, __high);
568 _LIBCPP_INLINE_VISIBILITY
569 char_type widen(char __c) const
571 return do_widen(__c);
574 _LIBCPP_INLINE_VISIBILITY
575 const char* widen(const char* __low, const char* __high, char_type* __to) const
577 return do_widen(__low, __high, __to);
580 _LIBCPP_INLINE_VISIBILITY
581 char narrow(char_type __c, char __dfault) const
583 return do_narrow(__c, __dfault);
586 _LIBCPP_INLINE_VISIBILITY
587 const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
589 return do_narrow(__low, __high, __dfault, __to);
592 static locale::id id;
596 virtual bool do_is(mask __m, char_type __c) const;
597 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
598 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
599 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
600 virtual char_type do_toupper(char_type) const;
601 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
602 virtual char_type do_tolower(char_type) const;
603 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
604 virtual char_type do_widen(char) const;
605 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
606 virtual char do_narrow(char_type, char __dfault) const;
607 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
609 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
612 class _LIBCPP_EXPORTED_FROM_ABI ctype<char>
613 : public locale::facet, public ctype_base
618 typedef char char_type;
620 explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0);
622 _LIBCPP_INLINE_VISIBILITY
623 bool is(mask __m, char_type __c) const
625 return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false;
628 _LIBCPP_INLINE_VISIBILITY
629 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
631 for (; __low != __high; ++__low, ++__vec)
632 *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
636 _LIBCPP_INLINE_VISIBILITY
637 const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
639 for (; __low != __high; ++__low)
640 if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
645 _LIBCPP_INLINE_VISIBILITY
646 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
648 for (; __low != __high; ++__low)
649 if (!isascii(*__low) || !(__tab_[static_cast<int>(*__low)] & __m))
654 _LIBCPP_INLINE_VISIBILITY
655 char_type toupper(char_type __c) const
657 return do_toupper(__c);
660 _LIBCPP_INLINE_VISIBILITY
661 const char_type* toupper(char_type* __low, const char_type* __high) const
663 return do_toupper(__low, __high);
666 _LIBCPP_INLINE_VISIBILITY
667 char_type tolower(char_type __c) const
669 return do_tolower(__c);
672 _LIBCPP_INLINE_VISIBILITY
673 const char_type* tolower(char_type* __low, const char_type* __high) const
675 return do_tolower(__low, __high);
678 _LIBCPP_INLINE_VISIBILITY
679 char_type widen(char __c) const
681 return do_widen(__c);
684 _LIBCPP_INLINE_VISIBILITY
685 const char* widen(const char* __low, const char* __high, char_type* __to) const
687 return do_widen(__low, __high, __to);
690 _LIBCPP_INLINE_VISIBILITY
691 char narrow(char_type __c, char __dfault) const
693 return do_narrow(__c, __dfault);
696 _LIBCPP_INLINE_VISIBILITY
697 const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
699 return do_narrow(__low, __high, __dfault, __to);
702 static locale::id id;
705 static const size_t table_size = _CACHED_RUNES;
707 static const size_t table_size = 256; // FIXME: Don't hardcode this.
709 _LIBCPP_INLINE_VISIBILITY const mask* table() const _NOEXCEPT {return __tab_;}
710 static const mask* classic_table() _NOEXCEPT;
711 #if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
712 static const int* __classic_upper_table() _NOEXCEPT;
713 static const int* __classic_lower_table() _NOEXCEPT;
715 #if defined(__NetBSD__)
716 static const short* __classic_upper_table() _NOEXCEPT;
717 static const short* __classic_lower_table() _NOEXCEPT;
720 static const unsigned short* __classic_upper_table() _NOEXCEPT;
721 static const unsigned short* __classic_lower_table() _NOEXCEPT;
726 virtual char_type do_toupper(char_type __c) const;
727 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
728 virtual char_type do_tolower(char_type __c) const;
729 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
730 virtual char_type do_widen(char __c) const;
731 virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
732 virtual char do_narrow(char_type __c, char __dfault) const;
733 virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
736 // template <class CharT> class ctype_byname;
738 template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype_byname;
741 class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<char>
747 explicit ctype_byname(const char*, size_t = 0);
748 explicit ctype_byname(const string&, size_t = 0);
751 ~ctype_byname() override;
752 char_type do_toupper(char_type) const override;
753 const char_type* do_toupper(char_type* __low, const char_type* __high) const override;
754 char_type do_tolower(char_type) const override;
755 const char_type* do_tolower(char_type* __low, const char_type* __high) const override;
758 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
760 class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<wchar_t>
761 : public ctype<wchar_t>
766 explicit ctype_byname(const char*, size_t = 0);
767 explicit ctype_byname(const string&, size_t = 0);
770 ~ctype_byname() override;
771 bool do_is(mask __m, char_type __c) const override;
772 const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const override;
773 const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const override;
774 const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const override;
775 char_type do_toupper(char_type) const override;
776 const char_type* do_toupper(char_type* __low, const char_type* __high) const override;
777 char_type do_tolower(char_type) const override;
778 const char_type* do_tolower(char_type* __low, const char_type* __high) const override;
779 char_type do_widen(char) const override;
780 const char* do_widen(const char* __low, const char* __high, char_type* __dest) const override;
781 char do_narrow(char_type, char __dfault) const override;
782 const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const override;
784 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
786 template <class _CharT>
787 inline _LIBCPP_INLINE_VISIBILITY
789 isspace(_CharT __c, const locale& __loc)
791 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
794 template <class _CharT>
795 inline _LIBCPP_INLINE_VISIBILITY
797 isprint(_CharT __c, const locale& __loc)
799 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
802 template <class _CharT>
803 inline _LIBCPP_INLINE_VISIBILITY
805 iscntrl(_CharT __c, const locale& __loc)
807 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
810 template <class _CharT>
811 inline _LIBCPP_INLINE_VISIBILITY
813 isupper(_CharT __c, const locale& __loc)
815 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
818 template <class _CharT>
819 inline _LIBCPP_INLINE_VISIBILITY
821 islower(_CharT __c, const locale& __loc)
823 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
826 template <class _CharT>
827 inline _LIBCPP_INLINE_VISIBILITY
829 isalpha(_CharT __c, const locale& __loc)
831 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
834 template <class _CharT>
835 inline _LIBCPP_INLINE_VISIBILITY
837 isdigit(_CharT __c, const locale& __loc)
839 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
842 template <class _CharT>
843 inline _LIBCPP_INLINE_VISIBILITY
845 ispunct(_CharT __c, const locale& __loc)
847 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
850 template <class _CharT>
851 inline _LIBCPP_INLINE_VISIBILITY
853 isxdigit(_CharT __c, const locale& __loc)
855 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
858 template <class _CharT>
859 inline _LIBCPP_INLINE_VISIBILITY
861 isalnum(_CharT __c, const locale& __loc)
863 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
866 template <class _CharT>
867 inline _LIBCPP_INLINE_VISIBILITY
869 isgraph(_CharT __c, const locale& __loc)
871 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
874 template <class _CharT>
875 _LIBCPP_HIDE_FROM_ABI bool isblank(_CharT __c, const locale& __loc) {
876 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::blank, __c);
879 template <class _CharT>
880 inline _LIBCPP_INLINE_VISIBILITY
882 toupper(_CharT __c, const locale& __loc)
884 return std::use_facet<ctype<_CharT> >(__loc).toupper(__c);
887 template <class _CharT>
888 inline _LIBCPP_INLINE_VISIBILITY
890 tolower(_CharT __c, const locale& __loc)
892 return std::use_facet<ctype<_CharT> >(__loc).tolower(__c);
897 class _LIBCPP_EXPORTED_FROM_ABI codecvt_base
900 _LIBCPP_INLINE_VISIBILITY codecvt_base() {}
901 enum result {ok, partial, error, noconv};
904 // template <class internT, class externT, class stateT> class codecvt;
906 template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TEMPLATE_VIS codecvt;
908 // template <> class codecvt<char, char, mbstate_t>
911 class _LIBCPP_EXPORTED_FROM_ABI codecvt<char, char, mbstate_t>
912 : public locale::facet,
916 typedef char intern_type;
917 typedef char extern_type;
918 typedef mbstate_t state_type;
920 _LIBCPP_INLINE_VISIBILITY
921 explicit codecvt(size_t __refs = 0)
922 : locale::facet(__refs) {}
924 _LIBCPP_INLINE_VISIBILITY
925 result out(state_type& __st,
926 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
927 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
929 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
932 _LIBCPP_INLINE_VISIBILITY
933 result unshift(state_type& __st,
934 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
936 return do_unshift(__st, __to, __to_end, __to_nxt);
939 _LIBCPP_INLINE_VISIBILITY
940 result in(state_type& __st,
941 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
942 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
944 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
947 _LIBCPP_INLINE_VISIBILITY
948 int encoding() const _NOEXCEPT
950 return do_encoding();
953 _LIBCPP_INLINE_VISIBILITY
954 bool always_noconv() const _NOEXCEPT
956 return do_always_noconv();
959 _LIBCPP_INLINE_VISIBILITY
960 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
962 return do_length(__st, __frm, __end, __mx);
965 _LIBCPP_INLINE_VISIBILITY
966 int max_length() const _NOEXCEPT
968 return do_max_length();
971 static locale::id id;
974 _LIBCPP_INLINE_VISIBILITY
975 explicit codecvt(const char*, size_t __refs = 0)
976 : locale::facet(__refs) {}
980 virtual result do_out(state_type& __st,
981 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
982 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
983 virtual result do_in(state_type& __st,
984 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
985 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
986 virtual result do_unshift(state_type& __st,
987 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
988 virtual int do_encoding() const _NOEXCEPT;
989 virtual bool do_always_noconv() const _NOEXCEPT;
990 virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
991 virtual int do_max_length() const _NOEXCEPT;
994 // template <> class codecvt<wchar_t, char, mbstate_t>
996 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
998 class _LIBCPP_EXPORTED_FROM_ABI codecvt<wchar_t, char, mbstate_t>
999 : public locale::facet,
1004 typedef wchar_t intern_type;
1005 typedef char extern_type;
1006 typedef mbstate_t state_type;
1008 explicit codecvt(size_t __refs = 0);
1010 _LIBCPP_INLINE_VISIBILITY
1011 result out(state_type& __st,
1012 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1013 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1015 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1018 _LIBCPP_INLINE_VISIBILITY
1019 result unshift(state_type& __st,
1020 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1022 return do_unshift(__st, __to, __to_end, __to_nxt);
1025 _LIBCPP_INLINE_VISIBILITY
1026 result in(state_type& __st,
1027 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1028 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1030 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1033 _LIBCPP_INLINE_VISIBILITY
1034 int encoding() const _NOEXCEPT
1036 return do_encoding();
1039 _LIBCPP_INLINE_VISIBILITY
1040 bool always_noconv() const _NOEXCEPT
1042 return do_always_noconv();
1045 _LIBCPP_INLINE_VISIBILITY
1046 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1048 return do_length(__st, __frm, __end, __mx);
1051 _LIBCPP_INLINE_VISIBILITY
1052 int max_length() const _NOEXCEPT
1054 return do_max_length();
1057 static locale::id id;
1060 explicit codecvt(const char*, size_t __refs = 0);
1062 ~codecvt() override;
1064 virtual result do_out(state_type& __st,
1065 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1066 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1067 virtual result do_in(state_type& __st,
1068 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1069 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1070 virtual result do_unshift(state_type& __st,
1071 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1072 virtual int do_encoding() const _NOEXCEPT;
1073 virtual bool do_always_noconv() const _NOEXCEPT;
1074 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1075 virtual int do_max_length() const _NOEXCEPT;
1077 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1079 // template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20
1082 class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char, mbstate_t>
1083 : public locale::facet,
1087 typedef char16_t intern_type;
1088 typedef char extern_type;
1089 typedef mbstate_t state_type;
1091 _LIBCPP_INLINE_VISIBILITY
1092 explicit codecvt(size_t __refs = 0)
1093 : locale::facet(__refs) {}
1095 _LIBCPP_INLINE_VISIBILITY
1096 result out(state_type& __st,
1097 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1098 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1100 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1103 _LIBCPP_INLINE_VISIBILITY
1104 result unshift(state_type& __st,
1105 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1107 return do_unshift(__st, __to, __to_end, __to_nxt);
1110 _LIBCPP_INLINE_VISIBILITY
1111 result in(state_type& __st,
1112 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1113 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1115 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1118 _LIBCPP_INLINE_VISIBILITY
1119 int encoding() const _NOEXCEPT
1121 return do_encoding();
1124 _LIBCPP_INLINE_VISIBILITY
1125 bool always_noconv() const _NOEXCEPT
1127 return do_always_noconv();
1130 _LIBCPP_INLINE_VISIBILITY
1131 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1133 return do_length(__st, __frm, __end, __mx);
1136 _LIBCPP_INLINE_VISIBILITY
1137 int max_length() const _NOEXCEPT
1139 return do_max_length();
1142 static locale::id id;
1145 _LIBCPP_INLINE_VISIBILITY
1146 explicit codecvt(const char*, size_t __refs = 0)
1147 : locale::facet(__refs) {}
1149 ~codecvt() override;
1151 virtual result do_out(state_type& __st,
1152 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1153 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1154 virtual result do_in(state_type& __st,
1155 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1156 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1157 virtual result do_unshift(state_type& __st,
1158 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1159 virtual int do_encoding() const _NOEXCEPT;
1160 virtual bool do_always_noconv() const _NOEXCEPT;
1161 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1162 virtual int do_max_length() const _NOEXCEPT;
1165 #ifndef _LIBCPP_HAS_NO_CHAR8_T
1167 // template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20
1170 class _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char8_t, mbstate_t>
1171 : public locale::facet,
1175 typedef char16_t intern_type;
1176 typedef char8_t extern_type;
1177 typedef mbstate_t state_type;
1179 _LIBCPP_INLINE_VISIBILITY
1180 explicit codecvt(size_t __refs = 0)
1181 : locale::facet(__refs) {}
1183 _LIBCPP_INLINE_VISIBILITY
1184 result out(state_type& __st,
1185 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1186 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1188 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1191 _LIBCPP_INLINE_VISIBILITY
1192 result unshift(state_type& __st,
1193 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1195 return do_unshift(__st, __to, __to_end, __to_nxt);
1198 _LIBCPP_INLINE_VISIBILITY
1199 result in(state_type& __st,
1200 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1201 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1203 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1206 _LIBCPP_INLINE_VISIBILITY
1207 int encoding() const _NOEXCEPT
1209 return do_encoding();
1212 _LIBCPP_INLINE_VISIBILITY
1213 bool always_noconv() const _NOEXCEPT
1215 return do_always_noconv();
1218 _LIBCPP_INLINE_VISIBILITY
1219 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1221 return do_length(__st, __frm, __end, __mx);
1224 _LIBCPP_INLINE_VISIBILITY
1225 int max_length() const _NOEXCEPT
1227 return do_max_length();
1230 static locale::id id;
1233 _LIBCPP_INLINE_VISIBILITY
1234 explicit codecvt(const char*, size_t __refs = 0)
1235 : locale::facet(__refs) {}
1237 ~codecvt() override;
1239 virtual result do_out(state_type& __st,
1240 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1241 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1242 virtual result do_in(state_type& __st,
1243 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1244 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1245 virtual result do_unshift(state_type& __st,
1246 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1247 virtual int do_encoding() const _NOEXCEPT;
1248 virtual bool do_always_noconv() const _NOEXCEPT;
1249 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1250 virtual int do_max_length() const _NOEXCEPT;
1255 // template <> class codecvt<char32_t, char, mbstate_t> // deprecated in C++20
1258 class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char, mbstate_t>
1259 : public locale::facet,
1263 typedef char32_t intern_type;
1264 typedef char extern_type;
1265 typedef mbstate_t state_type;
1267 _LIBCPP_INLINE_VISIBILITY
1268 explicit codecvt(size_t __refs = 0)
1269 : locale::facet(__refs) {}
1271 _LIBCPP_INLINE_VISIBILITY
1272 result out(state_type& __st,
1273 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1274 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1276 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1279 _LIBCPP_INLINE_VISIBILITY
1280 result unshift(state_type& __st,
1281 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1283 return do_unshift(__st, __to, __to_end, __to_nxt);
1286 _LIBCPP_INLINE_VISIBILITY
1287 result in(state_type& __st,
1288 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1289 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1291 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1294 _LIBCPP_INLINE_VISIBILITY
1295 int encoding() const _NOEXCEPT
1297 return do_encoding();
1300 _LIBCPP_INLINE_VISIBILITY
1301 bool always_noconv() const _NOEXCEPT
1303 return do_always_noconv();
1306 _LIBCPP_INLINE_VISIBILITY
1307 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1309 return do_length(__st, __frm, __end, __mx);
1312 _LIBCPP_INLINE_VISIBILITY
1313 int max_length() const _NOEXCEPT
1315 return do_max_length();
1318 static locale::id id;
1321 _LIBCPP_INLINE_VISIBILITY
1322 explicit codecvt(const char*, size_t __refs = 0)
1323 : locale::facet(__refs) {}
1325 ~codecvt() override;
1327 virtual result do_out(state_type& __st,
1328 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1329 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1330 virtual result do_in(state_type& __st,
1331 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1332 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1333 virtual result do_unshift(state_type& __st,
1334 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1335 virtual int do_encoding() const _NOEXCEPT;
1336 virtual bool do_always_noconv() const _NOEXCEPT;
1337 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1338 virtual int do_max_length() const _NOEXCEPT;
1341 #ifndef _LIBCPP_HAS_NO_CHAR8_T
1343 // template <> class codecvt<char32_t, char8_t, mbstate_t> // C++20
1346 class _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char8_t, mbstate_t>
1347 : public locale::facet,
1351 typedef char32_t intern_type;
1352 typedef char8_t extern_type;
1353 typedef mbstate_t state_type;
1355 _LIBCPP_INLINE_VISIBILITY
1356 explicit codecvt(size_t __refs = 0)
1357 : locale::facet(__refs) {}
1359 _LIBCPP_INLINE_VISIBILITY
1360 result out(state_type& __st,
1361 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1362 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1364 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1367 _LIBCPP_INLINE_VISIBILITY
1368 result unshift(state_type& __st,
1369 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1371 return do_unshift(__st, __to, __to_end, __to_nxt);
1374 _LIBCPP_INLINE_VISIBILITY
1375 result in(state_type& __st,
1376 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1377 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1379 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1382 _LIBCPP_INLINE_VISIBILITY
1383 int encoding() const _NOEXCEPT
1385 return do_encoding();
1388 _LIBCPP_INLINE_VISIBILITY
1389 bool always_noconv() const _NOEXCEPT
1391 return do_always_noconv();
1394 _LIBCPP_INLINE_VISIBILITY
1395 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1397 return do_length(__st, __frm, __end, __mx);
1400 _LIBCPP_INLINE_VISIBILITY
1401 int max_length() const _NOEXCEPT
1403 return do_max_length();
1406 static locale::id id;
1409 _LIBCPP_INLINE_VISIBILITY
1410 explicit codecvt(const char*, size_t __refs = 0)
1411 : locale::facet(__refs) {}
1413 ~codecvt() override;
1415 virtual result do_out(state_type& __st,
1416 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1417 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1418 virtual result do_in(state_type& __st,
1419 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1420 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1421 virtual result do_unshift(state_type& __st,
1422 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1423 virtual int do_encoding() const _NOEXCEPT;
1424 virtual bool do_always_noconv() const _NOEXCEPT;
1425 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1426 virtual int do_max_length() const _NOEXCEPT;
1431 // template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
1433 template <class _InternT, class _ExternT, class _StateT>
1434 class _LIBCPP_TEMPLATE_VIS codecvt_byname
1435 : public codecvt<_InternT, _ExternT, _StateT>
1438 _LIBCPP_INLINE_VISIBILITY
1439 explicit codecvt_byname(const char* __nm, size_t __refs = 0)
1440 : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
1441 _LIBCPP_INLINE_VISIBILITY
1442 explicit codecvt_byname(const string& __nm, size_t __refs = 0)
1443 : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
1445 ~codecvt_byname() override;
1448 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1449 template <class _InternT, class _ExternT, class _StateT>
1450 codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
1453 _LIBCPP_SUPPRESS_DEPRECATED_POP
1455 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>;
1456 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1457 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>;
1459 extern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>; // deprecated in C++20
1460 extern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>; // deprecated in C++20
1461 #ifndef _LIBCPP_HAS_NO_CHAR8_T
1462 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>; // C++20
1463 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>; // C++20
1466 template <size_t _Np>
1467 struct __narrow_to_utf8
1469 template <class _OutputIterator, class _CharT>
1471 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
1475 struct __narrow_to_utf8<8>
1477 template <class _OutputIterator, class _CharT>
1478 _LIBCPP_INLINE_VISIBILITY
1480 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1482 for (; __wb < __we; ++__wb, ++__s)
1488 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1490 struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<16>
1491 : public codecvt<char16_t, char, mbstate_t>
1493 _LIBCPP_INLINE_VISIBILITY
1494 __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1495 _LIBCPP_SUPPRESS_DEPRECATED_POP
1497 ~__narrow_to_utf8() override;
1499 template <class _OutputIterator, class _CharT>
1500 _LIBCPP_INLINE_VISIBILITY
1502 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1506 while (__wb < __we && __r != error)
1508 const int __sz = 32;
1511 const char16_t* __wn = (const char16_t*)__wb;
1512 __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
1513 __buf, __buf+__sz, __bn);
1514 if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
1515 __throw_runtime_error("locale not supported");
1516 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1518 __wb = (const _CharT*)__wn;
1524 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1526 struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<32>
1527 : public codecvt<char32_t, char, mbstate_t>
1529 _LIBCPP_INLINE_VISIBILITY
1530 __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1531 _LIBCPP_SUPPRESS_DEPRECATED_POP
1533 ~__narrow_to_utf8() override;
1535 template <class _OutputIterator, class _CharT>
1536 _LIBCPP_INLINE_VISIBILITY
1538 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1542 while (__wb < __we && __r != error)
1544 const int __sz = 32;
1547 const char32_t* __wn = (const char32_t*)__wb;
1548 __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
1549 __buf, __buf+__sz, __bn);
1550 if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
1551 __throw_runtime_error("locale not supported");
1552 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1554 __wb = (const _CharT*)__wn;
1560 template <size_t _Np>
1561 struct __widen_from_utf8
1563 template <class _OutputIterator>
1565 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
1569 struct __widen_from_utf8<8>
1571 template <class _OutputIterator>
1572 _LIBCPP_INLINE_VISIBILITY
1574 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1576 for (; __nb < __ne; ++__nb, ++__s)
1582 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1584 struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<16>
1585 : public codecvt<char16_t, char, mbstate_t>
1587 _LIBCPP_INLINE_VISIBILITY
1588 __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1589 _LIBCPP_SUPPRESS_DEPRECATED_POP
1591 ~__widen_from_utf8() override;
1593 template <class _OutputIterator>
1594 _LIBCPP_INLINE_VISIBILITY
1596 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1600 while (__nb < __ne && __r != error)
1602 const int __sz = 32;
1603 char16_t __buf[__sz];
1605 const char* __nn = __nb;
1606 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1607 __buf, __buf+__sz, __bn);
1608 if (__r == codecvt_base::error || __nn == __nb)
1609 __throw_runtime_error("locale not supported");
1610 for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
1618 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1620 struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<32>
1621 : public codecvt<char32_t, char, mbstate_t>
1623 _LIBCPP_INLINE_VISIBILITY
1624 __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1625 _LIBCPP_SUPPRESS_DEPRECATED_POP
1627 ~__widen_from_utf8() override;
1629 template <class _OutputIterator>
1630 _LIBCPP_INLINE_VISIBILITY
1632 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1636 while (__nb < __ne && __r != error)
1638 const int __sz = 32;
1639 char32_t __buf[__sz];
1641 const char* __nn = __nb;
1642 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1643 __buf, __buf+__sz, __bn);
1644 if (__r == codecvt_base::error || __nn == __nb)
1645 __throw_runtime_error("locale not supported");
1646 for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
1654 // template <class charT> class numpunct
1656 template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct;
1659 class _LIBCPP_EXPORTED_FROM_ABI numpunct<char>
1660 : public locale::facet
1663 typedef char char_type;
1664 typedef basic_string<char_type> string_type;
1666 explicit numpunct(size_t __refs = 0);
1668 _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
1669 _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
1670 _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();}
1671 _LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();}
1672 _LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();}
1674 static locale::id id;
1677 ~numpunct() override;
1678 virtual char_type do_decimal_point() const;
1679 virtual char_type do_thousands_sep() const;
1680 virtual string do_grouping() const;
1681 virtual string_type do_truename() const;
1682 virtual string_type do_falsename() const;
1684 char_type __decimal_point_;
1685 char_type __thousands_sep_;
1689 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1691 class _LIBCPP_EXPORTED_FROM_ABI numpunct<wchar_t>
1692 : public locale::facet
1695 typedef wchar_t char_type;
1696 typedef basic_string<char_type> string_type;
1698 explicit numpunct(size_t __refs = 0);
1700 _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
1701 _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
1702 _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();}
1703 _LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();}
1704 _LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();}
1706 static locale::id id;
1709 ~numpunct() override;
1710 virtual char_type do_decimal_point() const;
1711 virtual char_type do_thousands_sep() const;
1712 virtual string do_grouping() const;
1713 virtual string_type do_truename() const;
1714 virtual string_type do_falsename() const;
1716 char_type __decimal_point_;
1717 char_type __thousands_sep_;
1720 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1722 // template <class charT> class numpunct_byname
1724 template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct_byname;
1727 class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<char>
1728 : public numpunct<char>
1731 typedef char char_type;
1732 typedef basic_string<char_type> string_type;
1734 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1735 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1738 ~numpunct_byname() override;
1741 void __init(const char*);
1744 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1746 class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<wchar_t>
1747 : public numpunct<wchar_t>
1750 typedef wchar_t char_type;
1751 typedef basic_string<char_type> string_type;
1753 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1754 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1757 ~numpunct_byname() override;
1760 void __init(const char*);
1762 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1764 _LIBCPP_END_NAMESPACE_STD
1766 #endif // _LIBCPP___LOCALE