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>
18 #include <__utility/no_destroy.h>
25 // Some platforms require more includes than others. Keep the includes on all plaforms for now.
29 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
32 # include <__std_mbstate_t.h>
35 #if defined(_LIBCPP_MSVCRT_LIKE)
36 # include <__support/win32/locale_win32.h>
37 #elif defined(_AIX) || defined(__MVS__)
38 # include <__support/ibm/xlocale.h>
39 #elif defined(__ANDROID__)
40 # include <__support/android/locale_bionic.h>
41 #elif defined(_NEWLIB_VERSION)
42 # include <__support/newlib/xlocale.h>
43 #elif defined(__OpenBSD__)
44 # include <__support/openbsd/xlocale.h>
45 #elif (defined(__APPLE__) || defined(__FreeBSD__))
47 #elif defined(__Fuchsia__)
48 # include <__support/fuchsia/xlocale.h>
49 #elif defined(__wasi__)
50 // WASI libc uses musl's locales support.
51 # include <__support/musl/xlocale.h>
52 #elif defined(_LIBCPP_HAS_MUSL_LIBC)
53 # include <__support/musl/xlocale.h>
56 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
57 # pragma GCC system_header
60 _LIBCPP_BEGIN_NAMESPACE_STD
62 class _LIBCPP_EXPORTED_FROM_ABI locale;
64 template <class _Facet>
65 _LIBCPP_HIDE_FROM_ABI bool has_facet(const locale&) _NOEXCEPT;
67 template <class _Facet>
68 _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale&);
70 class _LIBCPP_EXPORTED_FROM_ABI locale {
73 class _LIBCPP_EXPORTED_FROM_ABI facet;
74 class _LIBCPP_EXPORTED_FROM_ABI id;
78 static const category // values assigned here are for exposition only
80 collate = LC_COLLATE_MASK, ctype = LC_CTYPE_MASK, monetary = LC_MONETARY_MASK, numeric = LC_NUMERIC_MASK,
81 time = LC_TIME_MASK, messages = LC_MESSAGES_MASK, all = collate | ctype | monetary | numeric | time | messages;
83 // construct/copy/destroy:
85 locale(const locale&) _NOEXCEPT;
86 explicit locale(const char*);
87 explicit locale(const string&);
88 locale(const locale&, const char*, category);
89 locale(const locale&, const string&, category);
90 template <class _Facet>
91 _LIBCPP_HIDE_FROM_ABI locale(const locale&, _Facet*);
92 locale(const locale&, const locale&, category);
96 const locale& operator=(const locale&) _NOEXCEPT;
98 template <class _Facet>
99 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS locale combine(const locale&) const;
101 // locale operations:
103 bool operator==(const locale&) const;
104 #if _LIBCPP_STD_VER <= 17
105 _LIBCPP_HIDE_FROM_ABI bool operator!=(const locale& __y) const { return !(*this == __y); }
107 template <class _CharT, class _Traits, class _Allocator>
108 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool
109 operator()(const basic_string<_CharT, _Traits, _Allocator>&, const basic_string<_CharT, _Traits, _Allocator>&) const;
111 // global locale objects:
112 static locale global(const locale&);
113 static const locale& classic();
120 friend struct __no_destroy;
121 struct __private_tag {};
122 _LIBCPP_HIDE_FROM_ABI explicit locale(__private_tag, __imp* __loc) : __locale_(__loc) {}
124 void __install_ctor(const locale&, facet*, long);
125 static locale& __global();
126 bool has_facet(id&) const;
127 const facet* use_facet(id&) const;
129 template <class _Facet>
130 friend bool has_facet(const locale&) _NOEXCEPT;
131 template <class _Facet>
132 friend const _Facet& use_facet(const locale&);
135 class _LIBCPP_EXPORTED_FROM_ABI locale::facet : public __shared_count {
137 _LIBCPP_HIDE_FROM_ABI explicit facet(size_t __refs = 0) : __shared_count(static_cast<long>(__refs) - 1) {}
141 // facet(const facet&) = delete; // effectively done in __shared_count
142 // void operator=(const facet&) = delete;
145 void __on_zero_shared() _NOEXCEPT override;
148 class _LIBCPP_EXPORTED_FROM_ABI locale::id {
152 static int32_t __next_id;
155 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR id() : __id_(0) {}
156 void operator=(const id&) = delete;
157 id(const id&) = delete;
159 public: // only needed for tests
163 friend class locale::__imp;
166 template <class _Facet>
167 inline _LIBCPP_HIDE_FROM_ABI locale::locale(const locale& __other, _Facet* __f) {
168 __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
171 template <class _Facet>
172 locale locale::combine(const locale& __other) const {
173 if (!std::has_facet<_Facet>(__other))
174 __throw_runtime_error("locale::combine: locale missing facet");
176 return locale(*this, &const_cast<_Facet&>(std::use_facet<_Facet>(__other)));
179 template <class _Facet>
180 inline _LIBCPP_HIDE_FROM_ABI bool has_facet(const locale& __l) _NOEXCEPT {
181 return __l.has_facet(_Facet::id);
184 template <class _Facet>
185 inline _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale& __l) {
186 return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
189 // template <class _CharT> class collate;
191 template <class _CharT>
192 class _LIBCPP_TEMPLATE_VIS collate : public locale::facet {
194 typedef _CharT char_type;
195 typedef basic_string<char_type> string_type;
197 _LIBCPP_HIDE_FROM_ABI explicit collate(size_t __refs = 0) : locale::facet(__refs) {}
199 _LIBCPP_HIDE_FROM_ABI int
200 compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const {
201 return do_compare(__lo1, __hi1, __lo2, __hi2);
204 // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work
205 // around a dllimport bug that expects an external instantiation.
206 _LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE string_type
207 transform(const char_type* __lo, const char_type* __hi) const {
208 return do_transform(__lo, __hi);
211 _LIBCPP_HIDE_FROM_ABI long hash(const char_type* __lo, const char_type* __hi) const { return do_hash(__lo, __hi); }
213 static locale::id id;
218 do_compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const;
219 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const {
220 return string_type(__lo, __hi);
222 virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
225 template <class _CharT>
226 locale::id collate<_CharT>::id;
228 template <class _CharT>
229 collate<_CharT>::~collate() {}
231 template <class _CharT>
232 int collate<_CharT>::do_compare(
233 const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const {
234 for (; __lo2 != __hi2; ++__lo1, ++__lo2) {
235 if (__lo1 == __hi1 || *__lo1 < *__lo2)
240 return __lo1 != __hi1;
243 template <class _CharT>
244 long collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const {
246 const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
247 const size_t __mask = size_t(0xF) << (__sr + 4);
248 for (const char_type* __p = __lo; __p != __hi; ++__p) {
249 __h = (__h << 4) + static_cast<size_t>(*__p);
250 size_t __g = __h & __mask;
251 __h ^= __g | (__g >> __sr);
253 return static_cast<long>(__h);
256 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>;
257 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
258 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>;
261 // template <class CharT> class collate_byname;
263 template <class _CharT>
264 class _LIBCPP_TEMPLATE_VIS collate_byname;
267 class _LIBCPP_EXPORTED_FROM_ABI collate_byname<char> : public collate<char> {
271 typedef char char_type;
272 typedef basic_string<char_type> string_type;
274 explicit collate_byname(const char* __n, size_t __refs = 0);
275 explicit collate_byname(const string& __n, size_t __refs = 0);
278 ~collate_byname() override;
280 const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const override;
281 string_type do_transform(const char_type* __lo, const char_type* __hi) const override;
284 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
286 class _LIBCPP_EXPORTED_FROM_ABI collate_byname<wchar_t> : public collate<wchar_t> {
290 typedef wchar_t char_type;
291 typedef basic_string<char_type> string_type;
293 explicit collate_byname(const char* __n, size_t __refs = 0);
294 explicit collate_byname(const string& __n, size_t __refs = 0);
297 ~collate_byname() override;
300 const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const override;
301 string_type do_transform(const char_type* __lo, const char_type* __hi) const override;
305 template <class _CharT, class _Traits, class _Allocator>
306 bool locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
307 const basic_string<_CharT, _Traits, _Allocator>& __y) const {
308 return std::use_facet<std::collate<_CharT> >(*this).compare(
309 __x.data(), __x.data() + __x.size(), __y.data(), __y.data() + __y.size()) < 0;
312 // template <class charT> class ctype
314 class _LIBCPP_EXPORTED_FROM_ABI ctype_base {
316 #if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE)
317 typedef unsigned long mask;
318 static const mask space = 1 << 0;
319 static const mask print = 1 << 1;
320 static const mask cntrl = 1 << 2;
321 static const mask upper = 1 << 3;
322 static const mask lower = 1 << 4;
323 static const mask alpha = 1 << 5;
324 static const mask digit = 1 << 6;
325 static const mask punct = 1 << 7;
326 static const mask xdigit = 1 << 8;
327 static const mask blank = 1 << 9;
328 # if defined(__BIONIC__)
329 // Historically this was a part of regex_traits rather than ctype_base. The
330 // historical value of the constant is preserved for ABI compatibility.
331 static const mask __regex_word = 0x8000;
333 static const mask __regex_word = 1 << 10;
334 # endif // defined(__BIONIC__)
335 #elif defined(__GLIBC__)
336 typedef unsigned short mask;
337 static const mask space = _ISspace;
338 static const mask print = _ISprint;
339 static const mask cntrl = _IScntrl;
340 static const mask upper = _ISupper;
341 static const mask lower = _ISlower;
342 static const mask alpha = _ISalpha;
343 static const mask digit = _ISdigit;
344 static const mask punct = _ISpunct;
345 static const mask xdigit = _ISxdigit;
346 static const mask blank = _ISblank;
347 # if defined(__mips__) || (BYTE_ORDER == BIG_ENDIAN)
348 static const mask __regex_word = static_cast<mask>(_ISbit(15));
350 static const mask __regex_word = 0x80;
352 #elif defined(_LIBCPP_MSVCRT_LIKE)
353 typedef unsigned short mask;
354 static const mask space = _SPACE;
355 static const mask print = _BLANK | _PUNCT | _ALPHA | _DIGIT;
356 static const mask cntrl = _CONTROL;
357 static const mask upper = _UPPER;
358 static const mask lower = _LOWER;
359 static const mask alpha = _ALPHA;
360 static const mask digit = _DIGIT;
361 static const mask punct = _PUNCT;
362 static const mask xdigit = _HEX;
363 static const mask blank = _BLANK;
364 static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used
365 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
366 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
367 #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
369 typedef __uint32_t mask;
370 # elif defined(__FreeBSD__)
371 typedef unsigned long mask;
372 # elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
373 typedef unsigned short mask;
375 static const mask space = _CTYPE_S;
376 static const mask print = _CTYPE_R;
377 static const mask cntrl = _CTYPE_C;
378 static const mask upper = _CTYPE_U;
379 static const mask lower = _CTYPE_L;
380 static const mask alpha = _CTYPE_A;
381 static const mask digit = _CTYPE_D;
382 static const mask punct = _CTYPE_P;
383 static const mask xdigit = _CTYPE_X;
385 # if defined(__NetBSD__)
386 static const mask blank = _CTYPE_BL;
387 // NetBSD defines classes up to 0x2000
388 // see sys/ctype_bits.h, _CTYPE_Q
389 static const mask __regex_word = 0x8000;
391 static const mask blank = _CTYPE_B;
392 static const mask __regex_word = 0x80;
395 typedef unsigned int mask;
396 static const mask space = _ISSPACE;
397 static const mask print = _ISPRINT;
398 static const mask cntrl = _ISCNTRL;
399 static const mask upper = _ISUPPER;
400 static const mask lower = _ISLOWER;
401 static const mask alpha = _ISALPHA;
402 static const mask digit = _ISDIGIT;
403 static const mask punct = _ISPUNCT;
404 static const mask xdigit = _ISXDIGIT;
405 static const mask blank = _ISBLANK;
406 static const mask __regex_word = 0x8000;
407 #elif defined(_NEWLIB_VERSION)
408 // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
410 // In case char is signed, static_cast is needed to avoid warning on
411 // positive value becomming negative.
412 static const mask space = static_cast<mask>(_S);
413 static const mask print = static_cast<mask>(_P | _U | _L | _N | _B);
414 static const mask cntrl = static_cast<mask>(_C);
415 static const mask upper = static_cast<mask>(_U);
416 static const mask lower = static_cast<mask>(_L);
417 static const mask alpha = static_cast<mask>(_U | _L);
418 static const mask digit = static_cast<mask>(_N);
419 static const mask punct = static_cast<mask>(_P);
420 static const mask xdigit = static_cast<mask>(_X | _N);
421 static const mask blank = static_cast<mask>(_B);
422 // mask is already fully saturated, use a different type in regex_type_traits.
423 static const unsigned short __regex_word = 0x100;
424 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
425 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
426 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
427 #elif defined(__MVS__)
428 # if defined(__NATIVE_ASCII_F)
429 typedef unsigned int mask;
430 static const mask space = _ISSPACE_A;
431 static const mask print = _ISPRINT_A;
432 static const mask cntrl = _ISCNTRL_A;
433 static const mask upper = _ISUPPER_A;
434 static const mask lower = _ISLOWER_A;
435 static const mask alpha = _ISALPHA_A;
436 static const mask digit = _ISDIGIT_A;
437 static const mask punct = _ISPUNCT_A;
438 static const mask xdigit = _ISXDIGIT_A;
439 static const mask blank = _ISBLANK_A;
441 typedef unsigned short mask;
442 static const mask space = __ISSPACE;
443 static const mask print = __ISPRINT;
444 static const mask cntrl = __ISCNTRL;
445 static const mask upper = __ISUPPER;
446 static const mask lower = __ISLOWER;
447 static const mask alpha = __ISALPHA;
448 static const mask digit = __ISDIGIT;
449 static const mask punct = __ISPUNCT;
450 static const mask xdigit = __ISXDIGIT;
451 static const mask blank = __ISBLANK;
453 static const mask __regex_word = 0x8000;
455 # error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?
457 static const mask alnum = alpha | digit;
458 static const mask graph = alnum | punct;
460 _LIBCPP_HIDE_FROM_ABI ctype_base() {}
462 static_assert((__regex_word & ~(std::make_unsigned<mask>::type)(space | print | cntrl | upper | lower | alpha |
463 digit | punct | xdigit | blank)) == __regex_word,
464 "__regex_word can't overlap other bits");
467 template <class _CharT>
468 class _LIBCPP_TEMPLATE_VIS ctype;
470 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
472 class _LIBCPP_EXPORTED_FROM_ABI ctype<wchar_t> : public locale::facet, public ctype_base {
474 typedef wchar_t char_type;
476 _LIBCPP_HIDE_FROM_ABI explicit ctype(size_t __refs = 0) : locale::facet(__refs) {}
478 _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const { return do_is(__m, __c); }
480 _LIBCPP_HIDE_FROM_ABI const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const {
481 return do_is(__low, __high, __vec);
484 _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const {
485 return do_scan_is(__m, __low, __high);
488 _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const {
489 return do_scan_not(__m, __low, __high);
492 _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); }
494 _LIBCPP_HIDE_FROM_ABI const char_type* toupper(char_type* __low, const char_type* __high) const {
495 return do_toupper(__low, __high);
498 _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); }
500 _LIBCPP_HIDE_FROM_ABI const char_type* tolower(char_type* __low, const char_type* __high) const {
501 return do_tolower(__low, __high);
504 _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); }
506 _LIBCPP_HIDE_FROM_ABI const char* widen(const char* __low, const char* __high, char_type* __to) const {
507 return do_widen(__low, __high, __to);
510 _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); }
512 _LIBCPP_HIDE_FROM_ABI const char_type*
513 narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const {
514 return do_narrow(__low, __high, __dfault, __to);
517 static locale::id id;
521 virtual bool do_is(mask __m, char_type __c) const;
522 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
523 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
524 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
525 virtual char_type do_toupper(char_type) const;
526 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
527 virtual char_type do_tolower(char_type) const;
528 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
529 virtual char_type do_widen(char) const;
530 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
531 virtual char do_narrow(char_type, char __dfault) const;
532 virtual const char_type*
533 do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
535 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
538 class _LIBCPP_EXPORTED_FROM_ABI ctype<char> : public locale::facet, public ctype_base {
543 typedef char char_type;
545 explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0);
547 _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const {
548 return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) != 0 : false;
551 _LIBCPP_HIDE_FROM_ABI const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const {
552 for (; __low != __high; ++__low, ++__vec)
553 *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
557 _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const {
558 for (; __low != __high; ++__low)
559 if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
564 _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const {
565 for (; __low != __high; ++__low)
566 if (!isascii(*__low) || !(__tab_[static_cast<int>(*__low)] & __m))
571 _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); }
573 _LIBCPP_HIDE_FROM_ABI const char_type* toupper(char_type* __low, const char_type* __high) const {
574 return do_toupper(__low, __high);
577 _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); }
579 _LIBCPP_HIDE_FROM_ABI const char_type* tolower(char_type* __low, const char_type* __high) const {
580 return do_tolower(__low, __high);
583 _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); }
585 _LIBCPP_HIDE_FROM_ABI const char* widen(const char* __low, const char* __high, char_type* __to) const {
586 return do_widen(__low, __high, __to);
589 _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); }
591 _LIBCPP_HIDE_FROM_ABI const char*
592 narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const {
593 return do_narrow(__low, __high, __dfault, __to);
596 static locale::id id;
599 static const size_t table_size = _CACHED_RUNES;
601 static const size_t table_size = 256; // FIXME: Don't hardcode this.
603 _LIBCPP_HIDE_FROM_ABI const mask* table() const _NOEXCEPT { return __tab_; }
604 static const mask* classic_table() _NOEXCEPT;
605 #if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
606 static const int* __classic_upper_table() _NOEXCEPT;
607 static const int* __classic_lower_table() _NOEXCEPT;
609 #if defined(__NetBSD__)
610 static const short* __classic_upper_table() _NOEXCEPT;
611 static const short* __classic_lower_table() _NOEXCEPT;
614 static const unsigned short* __classic_upper_table() _NOEXCEPT;
615 static const unsigned short* __classic_lower_table() _NOEXCEPT;
620 virtual char_type do_toupper(char_type __c) const;
621 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
622 virtual char_type do_tolower(char_type __c) const;
623 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
624 virtual char_type do_widen(char __c) const;
625 virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
626 virtual char do_narrow(char_type __c, char __dfault) const;
627 virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
630 // template <class CharT> class ctype_byname;
632 template <class _CharT>
633 class _LIBCPP_TEMPLATE_VIS ctype_byname;
636 class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<char> : public ctype<char> {
640 explicit ctype_byname(const char*, size_t = 0);
641 explicit ctype_byname(const string&, size_t = 0);
644 ~ctype_byname() override;
645 char_type do_toupper(char_type) const override;
646 const char_type* do_toupper(char_type* __low, const char_type* __high) const override;
647 char_type do_tolower(char_type) const override;
648 const char_type* do_tolower(char_type* __low, const char_type* __high) const override;
651 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
653 class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<wchar_t> : public ctype<wchar_t> {
657 explicit ctype_byname(const char*, size_t = 0);
658 explicit ctype_byname(const string&, size_t = 0);
661 ~ctype_byname() override;
662 bool do_is(mask __m, char_type __c) const override;
663 const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const override;
664 const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const override;
665 const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const override;
666 char_type do_toupper(char_type) const override;
667 const char_type* do_toupper(char_type* __low, const char_type* __high) const override;
668 char_type do_tolower(char_type) const override;
669 const char_type* do_tolower(char_type* __low, const char_type* __high) const override;
670 char_type do_widen(char) const override;
671 const char* do_widen(const char* __low, const char* __high, char_type* __dest) const override;
672 char do_narrow(char_type, char __dfault) const override;
674 do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const override;
676 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
678 template <class _CharT>
679 inline _LIBCPP_HIDE_FROM_ABI bool isspace(_CharT __c, const locale& __loc) {
680 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
683 template <class _CharT>
684 inline _LIBCPP_HIDE_FROM_ABI bool isprint(_CharT __c, const locale& __loc) {
685 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
688 template <class _CharT>
689 inline _LIBCPP_HIDE_FROM_ABI bool iscntrl(_CharT __c, const locale& __loc) {
690 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
693 template <class _CharT>
694 inline _LIBCPP_HIDE_FROM_ABI bool isupper(_CharT __c, const locale& __loc) {
695 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
698 template <class _CharT>
699 inline _LIBCPP_HIDE_FROM_ABI bool islower(_CharT __c, const locale& __loc) {
700 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
703 template <class _CharT>
704 inline _LIBCPP_HIDE_FROM_ABI bool isalpha(_CharT __c, const locale& __loc) {
705 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
708 template <class _CharT>
709 inline _LIBCPP_HIDE_FROM_ABI bool isdigit(_CharT __c, const locale& __loc) {
710 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
713 template <class _CharT>
714 inline _LIBCPP_HIDE_FROM_ABI bool ispunct(_CharT __c, const locale& __loc) {
715 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
718 template <class _CharT>
719 inline _LIBCPP_HIDE_FROM_ABI bool isxdigit(_CharT __c, const locale& __loc) {
720 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
723 template <class _CharT>
724 inline _LIBCPP_HIDE_FROM_ABI bool isalnum(_CharT __c, const locale& __loc) {
725 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
728 template <class _CharT>
729 inline _LIBCPP_HIDE_FROM_ABI bool isgraph(_CharT __c, const locale& __loc) {
730 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
733 template <class _CharT>
734 _LIBCPP_HIDE_FROM_ABI bool isblank(_CharT __c, const locale& __loc) {
735 return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::blank, __c);
738 template <class _CharT>
739 inline _LIBCPP_HIDE_FROM_ABI _CharT toupper(_CharT __c, const locale& __loc) {
740 return std::use_facet<ctype<_CharT> >(__loc).toupper(__c);
743 template <class _CharT>
744 inline _LIBCPP_HIDE_FROM_ABI _CharT tolower(_CharT __c, const locale& __loc) {
745 return std::use_facet<ctype<_CharT> >(__loc).tolower(__c);
750 class _LIBCPP_EXPORTED_FROM_ABI codecvt_base {
752 _LIBCPP_HIDE_FROM_ABI codecvt_base() {}
753 enum result { ok, partial, error, noconv };
756 // template <class internT, class externT, class stateT> class codecvt;
758 template <class _InternT, class _ExternT, class _StateT>
759 class _LIBCPP_TEMPLATE_VIS codecvt;
761 // template <> class codecvt<char, char, mbstate_t>
764 class _LIBCPP_EXPORTED_FROM_ABI codecvt<char, char, mbstate_t> : public locale::facet, public codecvt_base {
766 typedef char intern_type;
767 typedef char extern_type;
768 typedef mbstate_t state_type;
770 _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
772 _LIBCPP_HIDE_FROM_ABI result
773 out(state_type& __st,
774 const intern_type* __frm,
775 const intern_type* __frm_end,
776 const intern_type*& __frm_nxt,
778 extern_type* __to_end,
779 extern_type*& __to_nxt) const {
780 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
783 _LIBCPP_HIDE_FROM_ABI result
784 unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {
785 return do_unshift(__st, __to, __to_end, __to_nxt);
788 _LIBCPP_HIDE_FROM_ABI result
790 const extern_type* __frm,
791 const extern_type* __frm_end,
792 const extern_type*& __frm_nxt,
794 intern_type* __to_end,
795 intern_type*& __to_nxt) const {
796 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
799 _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }
801 _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }
803 _LIBCPP_HIDE_FROM_ABI int
804 length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {
805 return do_length(__st, __frm, __end, __mx);
808 _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }
810 static locale::id id;
813 _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}
818 do_out(state_type& __st,
819 const intern_type* __frm,
820 const intern_type* __frm_end,
821 const intern_type*& __frm_nxt,
823 extern_type* __to_end,
824 extern_type*& __to_nxt) const;
826 do_in(state_type& __st,
827 const extern_type* __frm,
828 const extern_type* __frm_end,
829 const extern_type*& __frm_nxt,
831 intern_type* __to_end,
832 intern_type*& __to_nxt) const;
833 virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
834 virtual int do_encoding() const _NOEXCEPT;
835 virtual bool do_always_noconv() const _NOEXCEPT;
836 virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
837 virtual int do_max_length() const _NOEXCEPT;
840 // template <> class codecvt<wchar_t, char, mbstate_t>
842 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
844 class _LIBCPP_EXPORTED_FROM_ABI codecvt<wchar_t, char, mbstate_t> : public locale::facet, public codecvt_base {
848 typedef wchar_t intern_type;
849 typedef char extern_type;
850 typedef mbstate_t state_type;
852 explicit codecvt(size_t __refs = 0);
854 _LIBCPP_HIDE_FROM_ABI result
855 out(state_type& __st,
856 const intern_type* __frm,
857 const intern_type* __frm_end,
858 const intern_type*& __frm_nxt,
860 extern_type* __to_end,
861 extern_type*& __to_nxt) const {
862 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
865 _LIBCPP_HIDE_FROM_ABI result
866 unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {
867 return do_unshift(__st, __to, __to_end, __to_nxt);
870 _LIBCPP_HIDE_FROM_ABI result
872 const extern_type* __frm,
873 const extern_type* __frm_end,
874 const extern_type*& __frm_nxt,
876 intern_type* __to_end,
877 intern_type*& __to_nxt) const {
878 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
881 _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }
883 _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }
885 _LIBCPP_HIDE_FROM_ABI int
886 length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {
887 return do_length(__st, __frm, __end, __mx);
890 _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }
892 static locale::id id;
895 explicit codecvt(const char*, size_t __refs = 0);
900 do_out(state_type& __st,
901 const intern_type* __frm,
902 const intern_type* __frm_end,
903 const intern_type*& __frm_nxt,
905 extern_type* __to_end,
906 extern_type*& __to_nxt) const;
908 do_in(state_type& __st,
909 const extern_type* __frm,
910 const extern_type* __frm_end,
911 const extern_type*& __frm_nxt,
913 intern_type* __to_end,
914 intern_type*& __to_nxt) const;
915 virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
916 virtual int do_encoding() const _NOEXCEPT;
917 virtual bool do_always_noconv() const _NOEXCEPT;
918 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
919 virtual int do_max_length() const _NOEXCEPT;
921 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
923 // template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20
926 class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char, mbstate_t>
927 : public locale::facet, public codecvt_base {
929 typedef char16_t intern_type;
930 typedef char extern_type;
931 typedef mbstate_t state_type;
933 _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
935 _LIBCPP_HIDE_FROM_ABI result
936 out(state_type& __st,
937 const intern_type* __frm,
938 const intern_type* __frm_end,
939 const intern_type*& __frm_nxt,
941 extern_type* __to_end,
942 extern_type*& __to_nxt) const {
943 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
946 _LIBCPP_HIDE_FROM_ABI result
947 unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {
948 return do_unshift(__st, __to, __to_end, __to_nxt);
951 _LIBCPP_HIDE_FROM_ABI result
953 const extern_type* __frm,
954 const extern_type* __frm_end,
955 const extern_type*& __frm_nxt,
957 intern_type* __to_end,
958 intern_type*& __to_nxt) const {
959 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
962 _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }
964 _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }
966 _LIBCPP_HIDE_FROM_ABI int
967 length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {
968 return do_length(__st, __frm, __end, __mx);
971 _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }
973 static locale::id id;
976 _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}
981 do_out(state_type& __st,
982 const intern_type* __frm,
983 const intern_type* __frm_end,
984 const intern_type*& __frm_nxt,
986 extern_type* __to_end,
987 extern_type*& __to_nxt) const;
989 do_in(state_type& __st,
990 const extern_type* __frm,
991 const extern_type* __frm_end,
992 const extern_type*& __frm_nxt,
994 intern_type* __to_end,
995 intern_type*& __to_nxt) const;
996 virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
997 virtual int do_encoding() const _NOEXCEPT;
998 virtual bool do_always_noconv() const _NOEXCEPT;
999 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1000 virtual int do_max_length() const _NOEXCEPT;
1003 #ifndef _LIBCPP_HAS_NO_CHAR8_T
1005 // template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20
1008 class _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char8_t, mbstate_t> : public locale::facet, public codecvt_base {
1010 typedef char16_t intern_type;
1011 typedef char8_t extern_type;
1012 typedef mbstate_t state_type;
1014 _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
1016 _LIBCPP_HIDE_FROM_ABI result
1017 out(state_type& __st,
1018 const intern_type* __frm,
1019 const intern_type* __frm_end,
1020 const intern_type*& __frm_nxt,
1022 extern_type* __to_end,
1023 extern_type*& __to_nxt) const {
1024 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1027 _LIBCPP_HIDE_FROM_ABI result
1028 unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {
1029 return do_unshift(__st, __to, __to_end, __to_nxt);
1032 _LIBCPP_HIDE_FROM_ABI result
1033 in(state_type& __st,
1034 const extern_type* __frm,
1035 const extern_type* __frm_end,
1036 const extern_type*& __frm_nxt,
1038 intern_type* __to_end,
1039 intern_type*& __to_nxt) const {
1040 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1043 _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }
1045 _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }
1047 _LIBCPP_HIDE_FROM_ABI int
1048 length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {
1049 return do_length(__st, __frm, __end, __mx);
1052 _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }
1054 static locale::id id;
1057 _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}
1059 ~codecvt() override;
1062 do_out(state_type& __st,
1063 const intern_type* __frm,
1064 const intern_type* __frm_end,
1065 const intern_type*& __frm_nxt,
1067 extern_type* __to_end,
1068 extern_type*& __to_nxt) const;
1070 do_in(state_type& __st,
1071 const extern_type* __frm,
1072 const extern_type* __frm_end,
1073 const extern_type*& __frm_nxt,
1075 intern_type* __to_end,
1076 intern_type*& __to_nxt) const;
1077 virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1078 virtual int do_encoding() const _NOEXCEPT;
1079 virtual bool do_always_noconv() const _NOEXCEPT;
1080 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1081 virtual int do_max_length() const _NOEXCEPT;
1086 // template <> class codecvt<char32_t, char, mbstate_t> // deprecated in C++20
1089 class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char, mbstate_t>
1090 : public locale::facet, public codecvt_base {
1092 typedef char32_t intern_type;
1093 typedef char extern_type;
1094 typedef mbstate_t state_type;
1096 _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
1098 _LIBCPP_HIDE_FROM_ABI result
1099 out(state_type& __st,
1100 const intern_type* __frm,
1101 const intern_type* __frm_end,
1102 const intern_type*& __frm_nxt,
1104 extern_type* __to_end,
1105 extern_type*& __to_nxt) const {
1106 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1109 _LIBCPP_HIDE_FROM_ABI result
1110 unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {
1111 return do_unshift(__st, __to, __to_end, __to_nxt);
1114 _LIBCPP_HIDE_FROM_ABI result
1115 in(state_type& __st,
1116 const extern_type* __frm,
1117 const extern_type* __frm_end,
1118 const extern_type*& __frm_nxt,
1120 intern_type* __to_end,
1121 intern_type*& __to_nxt) const {
1122 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1125 _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }
1127 _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }
1129 _LIBCPP_HIDE_FROM_ABI int
1130 length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {
1131 return do_length(__st, __frm, __end, __mx);
1134 _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }
1136 static locale::id id;
1139 _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}
1141 ~codecvt() override;
1144 do_out(state_type& __st,
1145 const intern_type* __frm,
1146 const intern_type* __frm_end,
1147 const intern_type*& __frm_nxt,
1149 extern_type* __to_end,
1150 extern_type*& __to_nxt) const;
1152 do_in(state_type& __st,
1153 const extern_type* __frm,
1154 const extern_type* __frm_end,
1155 const extern_type*& __frm_nxt,
1157 intern_type* __to_end,
1158 intern_type*& __to_nxt) const;
1159 virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1160 virtual int do_encoding() const _NOEXCEPT;
1161 virtual bool do_always_noconv() const _NOEXCEPT;
1162 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1163 virtual int do_max_length() const _NOEXCEPT;
1166 #ifndef _LIBCPP_HAS_NO_CHAR8_T
1168 // template <> class codecvt<char32_t, char8_t, mbstate_t> // C++20
1171 class _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char8_t, mbstate_t> : public locale::facet, public codecvt_base {
1173 typedef char32_t intern_type;
1174 typedef char8_t extern_type;
1175 typedef mbstate_t state_type;
1177 _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
1179 _LIBCPP_HIDE_FROM_ABI result
1180 out(state_type& __st,
1181 const intern_type* __frm,
1182 const intern_type* __frm_end,
1183 const intern_type*& __frm_nxt,
1185 extern_type* __to_end,
1186 extern_type*& __to_nxt) const {
1187 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1190 _LIBCPP_HIDE_FROM_ABI result
1191 unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const {
1192 return do_unshift(__st, __to, __to_end, __to_nxt);
1195 _LIBCPP_HIDE_FROM_ABI result
1196 in(state_type& __st,
1197 const extern_type* __frm,
1198 const extern_type* __frm_end,
1199 const extern_type*& __frm_nxt,
1201 intern_type* __to_end,
1202 intern_type*& __to_nxt) const {
1203 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1206 _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); }
1208 _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); }
1210 _LIBCPP_HIDE_FROM_ABI int
1211 length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const {
1212 return do_length(__st, __frm, __end, __mx);
1215 _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); }
1217 static locale::id id;
1220 _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {}
1222 ~codecvt() override;
1225 do_out(state_type& __st,
1226 const intern_type* __frm,
1227 const intern_type* __frm_end,
1228 const intern_type*& __frm_nxt,
1230 extern_type* __to_end,
1231 extern_type*& __to_nxt) const;
1233 do_in(state_type& __st,
1234 const extern_type* __frm,
1235 const extern_type* __frm_end,
1236 const extern_type*& __frm_nxt,
1238 intern_type* __to_end,
1239 intern_type*& __to_nxt) const;
1240 virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1241 virtual int do_encoding() const _NOEXCEPT;
1242 virtual bool do_always_noconv() const _NOEXCEPT;
1243 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1244 virtual int do_max_length() const _NOEXCEPT;
1249 // template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
1251 template <class _InternT, class _ExternT, class _StateT>
1252 class _LIBCPP_TEMPLATE_VIS codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> {
1254 _LIBCPP_HIDE_FROM_ABI explicit codecvt_byname(const char* __nm, size_t __refs = 0)
1255 : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
1256 _LIBCPP_HIDE_FROM_ABI explicit codecvt_byname(const string& __nm, size_t __refs = 0)
1257 : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
1260 ~codecvt_byname() override;
1263 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1264 template <class _InternT, class _ExternT, class _StateT>
1265 codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() {}
1266 _LIBCPP_SUPPRESS_DEPRECATED_POP
1268 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>;
1269 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1270 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>;
1272 extern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
1273 codecvt_byname<char16_t, char, mbstate_t>; // deprecated in C++20
1274 extern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
1275 codecvt_byname<char32_t, char, mbstate_t>; // deprecated in C++20
1276 #ifndef _LIBCPP_HAS_NO_CHAR8_T
1277 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>; // C++20
1278 extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>; // C++20
1281 template <size_t _Np>
1282 struct __narrow_to_utf8 {
1283 template <class _OutputIterator, class _CharT>
1284 _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
1288 struct __narrow_to_utf8<8> {
1289 template <class _OutputIterator, class _CharT>
1290 _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const {
1291 for (; __wb < __we; ++__wb, ++__s)
1297 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1299 struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<16> : public codecvt<char16_t, char, mbstate_t> {
1300 _LIBCPP_HIDE_FROM_ABI __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1301 _LIBCPP_SUPPRESS_DEPRECATED_POP
1303 ~__narrow_to_utf8() override;
1305 template <class _OutputIterator, class _CharT>
1306 _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const {
1309 while (__wb < __we && __r != error) {
1310 const int __sz = 32;
1313 const char16_t* __wn = (const char16_t*)__wb;
1314 __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn, __buf, __buf + __sz, __bn);
1315 if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
1316 __throw_runtime_error("locale not supported");
1317 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1319 __wb = (const _CharT*)__wn;
1325 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1327 struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<32> : public codecvt<char32_t, char, mbstate_t> {
1328 _LIBCPP_HIDE_FROM_ABI __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1329 _LIBCPP_SUPPRESS_DEPRECATED_POP
1331 ~__narrow_to_utf8() override;
1333 template <class _OutputIterator, class _CharT>
1334 _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const {
1337 while (__wb < __we && __r != error) {
1338 const int __sz = 32;
1341 const char32_t* __wn = (const char32_t*)__wb;
1342 __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn, __buf, __buf + __sz, __bn);
1343 if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
1344 __throw_runtime_error("locale not supported");
1345 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1347 __wb = (const _CharT*)__wn;
1353 template <size_t _Np>
1354 struct __widen_from_utf8 {
1355 template <class _OutputIterator>
1356 _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
1360 struct __widen_from_utf8<8> {
1361 template <class _OutputIterator>
1362 _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const {
1363 for (; __nb < __ne; ++__nb, ++__s)
1369 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1371 struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<16> : public codecvt<char16_t, char, mbstate_t> {
1372 _LIBCPP_HIDE_FROM_ABI __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1373 _LIBCPP_SUPPRESS_DEPRECATED_POP
1375 ~__widen_from_utf8() override;
1377 template <class _OutputIterator>
1378 _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const {
1381 while (__nb < __ne && __r != error) {
1382 const int __sz = 32;
1383 char16_t __buf[__sz];
1385 const char* __nn = __nb;
1386 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn);
1387 if (__r == codecvt_base::error || __nn == __nb)
1388 __throw_runtime_error("locale not supported");
1389 for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
1397 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
1399 struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<32> : public codecvt<char32_t, char, mbstate_t> {
1400 _LIBCPP_HIDE_FROM_ABI __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1401 _LIBCPP_SUPPRESS_DEPRECATED_POP
1403 ~__widen_from_utf8() override;
1405 template <class _OutputIterator>
1406 _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const {
1409 while (__nb < __ne && __r != error) {
1410 const int __sz = 32;
1411 char32_t __buf[__sz];
1413 const char* __nn = __nb;
1414 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn);
1415 if (__r == codecvt_base::error || __nn == __nb)
1416 __throw_runtime_error("locale not supported");
1417 for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
1425 // template <class charT> class numpunct
1427 template <class _CharT>
1428 class _LIBCPP_TEMPLATE_VIS numpunct;
1431 class _LIBCPP_EXPORTED_FROM_ABI numpunct<char> : public locale::facet {
1433 typedef char char_type;
1434 typedef basic_string<char_type> string_type;
1436 explicit numpunct(size_t __refs = 0);
1438 _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); }
1439 _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); }
1440 _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); }
1441 _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); }
1442 _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); }
1444 static locale::id id;
1447 ~numpunct() override;
1448 virtual char_type do_decimal_point() const;
1449 virtual char_type do_thousands_sep() const;
1450 virtual string do_grouping() const;
1451 virtual string_type do_truename() const;
1452 virtual string_type do_falsename() const;
1454 char_type __decimal_point_;
1455 char_type __thousands_sep_;
1459 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1461 class _LIBCPP_EXPORTED_FROM_ABI numpunct<wchar_t> : public locale::facet {
1463 typedef wchar_t char_type;
1464 typedef basic_string<char_type> string_type;
1466 explicit numpunct(size_t __refs = 0);
1468 _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); }
1469 _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); }
1470 _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); }
1471 _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); }
1472 _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); }
1474 static locale::id id;
1477 ~numpunct() override;
1478 virtual char_type do_decimal_point() const;
1479 virtual char_type do_thousands_sep() const;
1480 virtual string do_grouping() const;
1481 virtual string_type do_truename() const;
1482 virtual string_type do_falsename() const;
1484 char_type __decimal_point_;
1485 char_type __thousands_sep_;
1488 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1490 // template <class charT> class numpunct_byname
1492 template <class _CharT>
1493 class _LIBCPP_TEMPLATE_VIS numpunct_byname;
1496 class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<char> : public numpunct<char> {
1498 typedef char char_type;
1499 typedef basic_string<char_type> string_type;
1501 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1502 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1505 ~numpunct_byname() override;
1508 void __init(const char*);
1511 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1513 class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<wchar_t> : public numpunct<wchar_t> {
1515 typedef wchar_t char_type;
1516 typedef basic_string<char_type> string_type;
1518 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1519 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1522 ~numpunct_byname() override;
1525 void __init(const char*);
1527 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1529 _LIBCPP_END_NAMESPACE_STD
1531 #endif // _LIBCPP___LOCALE