10b57cec5SDimitry Andric// -*- C++ -*- 20b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP___LOCALE 110b57cec5SDimitry Andric#define _LIBCPP___LOCALE 120b57cec5SDimitry Andric 13fe6060f1SDimitry Andric#include <__config> 14*0fca6ea1SDimitry Andric#include <__locale_dir/locale_base_api.h> 1506c3fb27SDimitry Andric#include <__memory/shared_ptr.h> // __shared_count 165f757f3fSDimitry Andric#include <__mutex/once_flag.h> 1706c3fb27SDimitry Andric#include <__type_traits/make_unsigned.h> 185f757f3fSDimitry Andric#include <__utility/no_destroy.h> 19*0fca6ea1SDimitry Andric#include <__utility/private_constructor_tag.h> 200b57cec5SDimitry Andric#include <cctype> 2106c3fb27SDimitry Andric#include <clocale> 2204eeddc0SDimitry Andric#include <cstdint> 2306c3fb27SDimitry Andric#include <cstdlib> 2404eeddc0SDimitry Andric#include <string> 2504eeddc0SDimitry Andric 26bdd1243dSDimitry Andric// Some platforms require more includes than others. Keep the includes on all plaforms for now. 27bdd1243dSDimitry Andric#include <cstddef> 28bdd1243dSDimitry Andric#include <cstring> 29bdd1243dSDimitry Andric 3006c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 3106c3fb27SDimitry Andric# include <cwchar> 3206c3fb27SDimitry Andric#else 3306c3fb27SDimitry Andric# include <__std_mbstate_t.h> 3406c3fb27SDimitry Andric#endif 3506c3fb27SDimitry Andric 360b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 370b57cec5SDimitry Andric# pragma GCC system_header 380b57cec5SDimitry Andric#endif 390b57cec5SDimitry Andric 400b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 410b57cec5SDimitry Andric 4206c3fb27SDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI locale; 430b57cec5SDimitry Andric 440b57cec5SDimitry Andrictemplate <class _Facet> 45cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool has_facet(const locale&) _NOEXCEPT; 460b57cec5SDimitry Andric 470b57cec5SDimitry Andrictemplate <class _Facet> 48cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale&); 490b57cec5SDimitry Andric 50cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI locale { 510b57cec5SDimitry Andricpublic: 52*0fca6ea1SDimitry Andric // locale is essentially a shared_ptr that doesn't support weak_ptrs and never got a move constructor. 53*0fca6ea1SDimitry Andric using __trivially_relocatable = locale; 54*0fca6ea1SDimitry Andric 550b57cec5SDimitry Andric // types: 5606c3fb27SDimitry Andric class _LIBCPP_EXPORTED_FROM_ABI facet; 5706c3fb27SDimitry Andric class _LIBCPP_EXPORTED_FROM_ABI id; 580b57cec5SDimitry Andric 590b57cec5SDimitry Andric typedef int category; 605f757f3fSDimitry Andric 610b57cec5SDimitry Andric static const category // values assigned here are for exposition only 620b57cec5SDimitry Andric none = 0, 63cb14a3feSDimitry Andric collate = LC_COLLATE_MASK, ctype = LC_CTYPE_MASK, monetary = LC_MONETARY_MASK, numeric = LC_NUMERIC_MASK, 64cb14a3feSDimitry Andric time = LC_TIME_MASK, messages = LC_MESSAGES_MASK, all = collate | ctype | monetary | numeric | time | messages; 650b57cec5SDimitry Andric 660b57cec5SDimitry Andric // construct/copy/destroy: 670b57cec5SDimitry Andric locale() _NOEXCEPT; 680b57cec5SDimitry Andric locale(const locale&) _NOEXCEPT; 690b57cec5SDimitry Andric explicit locale(const char*); 700b57cec5SDimitry Andric explicit locale(const string&); 710b57cec5SDimitry Andric locale(const locale&, const char*, category); 720b57cec5SDimitry Andric locale(const locale&, const string&, category); 730b57cec5SDimitry Andric template <class _Facet> 745f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI locale(const locale&, _Facet*); 750b57cec5SDimitry Andric locale(const locale&, const locale&, category); 760b57cec5SDimitry Andric 770b57cec5SDimitry Andric ~locale(); 780b57cec5SDimitry Andric 790b57cec5SDimitry Andric const locale& operator=(const locale&) _NOEXCEPT; 800b57cec5SDimitry Andric 810b57cec5SDimitry Andric template <class _Facet> 82cb14a3feSDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS locale combine(const locale&) const; 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric // locale operations: 850b57cec5SDimitry Andric string name() const; 860b57cec5SDimitry Andric bool operator==(const locale&) const; 8706c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17 8806c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI bool operator!=(const locale& __y) const { return !(*this == __y); } 8906c3fb27SDimitry Andric#endif 900b57cec5SDimitry Andric template <class _CharT, class _Traits, class _Allocator> 91cb14a3feSDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool 92cb14a3feSDimitry Andric operator()(const basic_string<_CharT, _Traits, _Allocator>&, const basic_string<_CharT, _Traits, _Allocator>&) const; 930b57cec5SDimitry Andric 940b57cec5SDimitry Andric // global locale objects: 950b57cec5SDimitry Andric static locale global(const locale&); 960b57cec5SDimitry Andric static const locale& classic(); 970b57cec5SDimitry Andric 980b57cec5SDimitry Andricprivate: 990b57cec5SDimitry Andric class __imp; 1000b57cec5SDimitry Andric __imp* __locale_; 1010b57cec5SDimitry Andric 102cb14a3feSDimitry Andric template <class> 103cb14a3feSDimitry Andric friend struct __no_destroy; 104*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit locale(__private_constructor_tag, __imp* __loc) : __locale_(__loc) {} 1055f757f3fSDimitry Andric 1060b57cec5SDimitry Andric void __install_ctor(const locale&, facet*, long); 1070b57cec5SDimitry Andric static locale& __global(); 1080b57cec5SDimitry Andric bool has_facet(id&) const; 1090b57cec5SDimitry Andric const facet* use_facet(id&) const; 1100b57cec5SDimitry Andric 111cb14a3feSDimitry Andric template <class _Facet> 112cb14a3feSDimitry Andric friend bool has_facet(const locale&) _NOEXCEPT; 113cb14a3feSDimitry Andric template <class _Facet> 114cb14a3feSDimitry Andric friend const _Facet& use_facet(const locale&); 1150b57cec5SDimitry Andric}; 1160b57cec5SDimitry Andric 117cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI locale::facet : public __shared_count { 1180b57cec5SDimitry Andricprotected: 119cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit facet(size_t __refs = 0) : __shared_count(static_cast<long>(__refs) - 1) {} 1200b57cec5SDimitry Andric 121bdd1243dSDimitry Andric ~facet() override; 1220b57cec5SDimitry Andric 1230b57cec5SDimitry Andric // facet(const facet&) = delete; // effectively done in __shared_count 1240b57cec5SDimitry Andric // void operator=(const facet&) = delete; 125cb14a3feSDimitry Andric 1260b57cec5SDimitry Andricprivate: 127bdd1243dSDimitry Andric void __on_zero_shared() _NOEXCEPT override; 1280b57cec5SDimitry Andric}; 1290b57cec5SDimitry Andric 130cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI locale::id { 1310b57cec5SDimitry Andric once_flag __flag_; 1320b57cec5SDimitry Andric int32_t __id_; 1330b57cec5SDimitry Andric 1340b57cec5SDimitry Andric static int32_t __next_id; 135cb14a3feSDimitry Andric 1360b57cec5SDimitry Andricpublic: 1375f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR id() : __id_(0) {} 1380eae32dcSDimitry Andric void operator=(const id&) = delete; 1390eae32dcSDimitry Andric id(const id&) = delete; 1400eae32dcSDimitry Andric 1410b57cec5SDimitry Andricpublic: // only needed for tests 1420b57cec5SDimitry Andric long __get(); 1430b57cec5SDimitry Andric 1440b57cec5SDimitry Andric friend class locale; 1450b57cec5SDimitry Andric friend class locale::__imp; 1460b57cec5SDimitry Andric}; 1470b57cec5SDimitry Andric 1480b57cec5SDimitry Andrictemplate <class _Facet> 149cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI locale::locale(const locale& __other, _Facet* __f) { 1500b57cec5SDimitry Andric __install_ctor(__other, __f, __f ? __f->id.__get() : 0); 1510b57cec5SDimitry Andric} 1520b57cec5SDimitry Andric 1530b57cec5SDimitry Andrictemplate <class _Facet> 154cb14a3feSDimitry Andriclocale locale::combine(const locale& __other) const { 1555f757f3fSDimitry Andric if (!std::has_facet<_Facet>(__other)) 1560b57cec5SDimitry Andric __throw_runtime_error("locale::combine: locale missing facet"); 1570b57cec5SDimitry Andric 1585f757f3fSDimitry Andric return locale(*this, &const_cast<_Facet&>(std::use_facet<_Facet>(__other))); 1590b57cec5SDimitry Andric} 1600b57cec5SDimitry Andric 1610b57cec5SDimitry Andrictemplate <class _Facet> 162cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool has_facet(const locale& __l) _NOEXCEPT { 1630b57cec5SDimitry Andric return __l.has_facet(_Facet::id); 1640b57cec5SDimitry Andric} 1650b57cec5SDimitry Andric 1660b57cec5SDimitry Andrictemplate <class _Facet> 167cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI const _Facet& use_facet(const locale& __l) { 1680b57cec5SDimitry Andric return static_cast<const _Facet&>(*__l.use_facet(_Facet::id)); 1690b57cec5SDimitry Andric} 1700b57cec5SDimitry Andric 1710b57cec5SDimitry Andric// template <class _CharT> class collate; 1720b57cec5SDimitry Andric 1730b57cec5SDimitry Andrictemplate <class _CharT> 174cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS collate : public locale::facet { 1750b57cec5SDimitry Andricpublic: 1760b57cec5SDimitry Andric typedef _CharT char_type; 1770b57cec5SDimitry Andric typedef basic_string<char_type> string_type; 1780b57cec5SDimitry Andric 179cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit collate(size_t __refs = 0) : locale::facet(__refs) {} 1800b57cec5SDimitry Andric 181cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int 182cb14a3feSDimitry Andric compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const { 1830b57cec5SDimitry Andric return do_compare(__lo1, __hi1, __lo2, __hi2); 1840b57cec5SDimitry Andric } 1850b57cec5SDimitry Andric 1860b57cec5SDimitry Andric // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work 1870b57cec5SDimitry Andric // around a dllimport bug that expects an external instantiation. 188cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE string_type 189cb14a3feSDimitry Andric transform(const char_type* __lo, const char_type* __hi) const { 1900b57cec5SDimitry Andric return do_transform(__lo, __hi); 1910b57cec5SDimitry Andric } 1920b57cec5SDimitry Andric 193cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI long hash(const char_type* __lo, const char_type* __hi) const { return do_hash(__lo, __hi); } 1940b57cec5SDimitry Andric 1950b57cec5SDimitry Andric static locale::id id; 1960b57cec5SDimitry Andric 1970b57cec5SDimitry Andricprotected: 198bdd1243dSDimitry Andric ~collate() override; 199cb14a3feSDimitry Andric virtual int 200cb14a3feSDimitry Andric do_compare(const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const; 201cb14a3feSDimitry Andric virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const { 202cb14a3feSDimitry Andric return string_type(__lo, __hi); 203cb14a3feSDimitry Andric } 2040b57cec5SDimitry Andric virtual long do_hash(const char_type* __lo, const char_type* __hi) const; 2050b57cec5SDimitry Andric}; 2060b57cec5SDimitry Andric 207cb14a3feSDimitry Andrictemplate <class _CharT> 208cb14a3feSDimitry Andriclocale::id collate<_CharT>::id; 2090b57cec5SDimitry Andric 2100b57cec5SDimitry Andrictemplate <class _CharT> 211cb14a3feSDimitry Andriccollate<_CharT>::~collate() {} 2120b57cec5SDimitry Andric 2130b57cec5SDimitry Andrictemplate <class _CharT> 214cb14a3feSDimitry Andricint collate<_CharT>::do_compare( 215cb14a3feSDimitry Andric const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const { 216cb14a3feSDimitry Andric for (; __lo2 != __hi2; ++__lo1, ++__lo2) { 2170b57cec5SDimitry Andric if (__lo1 == __hi1 || *__lo1 < *__lo2) 2180b57cec5SDimitry Andric return -1; 2190b57cec5SDimitry Andric if (*__lo2 < *__lo1) 2200b57cec5SDimitry Andric return 1; 2210b57cec5SDimitry Andric } 2220b57cec5SDimitry Andric return __lo1 != __hi1; 2230b57cec5SDimitry Andric} 2240b57cec5SDimitry Andric 2250b57cec5SDimitry Andrictemplate <class _CharT> 226cb14a3feSDimitry Andriclong collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const { 2270b57cec5SDimitry Andric size_t __h = 0; 2280b57cec5SDimitry Andric const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8; 2290b57cec5SDimitry Andric const size_t __mask = size_t(0xF) << (__sr + 4); 230cb14a3feSDimitry Andric for (const char_type* __p = __lo; __p != __hi; ++__p) { 2310b57cec5SDimitry Andric __h = (__h << 4) + static_cast<size_t>(*__p); 2320b57cec5SDimitry Andric size_t __g = __h & __mask; 2330b57cec5SDimitry Andric __h ^= __g | (__g >> __sr); 2340b57cec5SDimitry Andric } 2350b57cec5SDimitry Andric return static_cast<long>(__h); 2360b57cec5SDimitry Andric} 2370b57cec5SDimitry Andric 23881ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>; 239349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 24081ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>; 241349cc55cSDimitry Andric#endif 2420b57cec5SDimitry Andric 2430b57cec5SDimitry Andric// template <class CharT> class collate_byname; 2440b57cec5SDimitry Andric 245cb14a3feSDimitry Andrictemplate <class _CharT> 246cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS collate_byname; 2470b57cec5SDimitry Andric 2480b57cec5SDimitry Andrictemplate <> 249cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI collate_byname<char> : public collate<char> { 250bdd1243dSDimitry Andric locale_t __l_; 251cb14a3feSDimitry Andric 2520b57cec5SDimitry Andricpublic: 2530b57cec5SDimitry Andric typedef char char_type; 2540b57cec5SDimitry Andric typedef basic_string<char_type> string_type; 2550b57cec5SDimitry Andric 2560b57cec5SDimitry Andric explicit collate_byname(const char* __n, size_t __refs = 0); 2570b57cec5SDimitry Andric explicit collate_byname(const string& __n, size_t __refs = 0); 2580b57cec5SDimitry Andric 2590b57cec5SDimitry Andricprotected: 260bdd1243dSDimitry Andric ~collate_byname() override; 261cb14a3feSDimitry Andric int do_compare( 262cb14a3feSDimitry Andric const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const override; 263bdd1243dSDimitry Andric string_type do_transform(const char_type* __lo, const char_type* __hi) const override; 2640b57cec5SDimitry Andric}; 2650b57cec5SDimitry Andric 266349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 2670b57cec5SDimitry Andrictemplate <> 268cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI collate_byname<wchar_t> : public collate<wchar_t> { 269bdd1243dSDimitry Andric locale_t __l_; 270cb14a3feSDimitry Andric 2710b57cec5SDimitry Andricpublic: 2720b57cec5SDimitry Andric typedef wchar_t char_type; 2730b57cec5SDimitry Andric typedef basic_string<char_type> string_type; 2740b57cec5SDimitry Andric 2750b57cec5SDimitry Andric explicit collate_byname(const char* __n, size_t __refs = 0); 2760b57cec5SDimitry Andric explicit collate_byname(const string& __n, size_t __refs = 0); 2770b57cec5SDimitry Andric 2780b57cec5SDimitry Andricprotected: 279bdd1243dSDimitry Andric ~collate_byname() override; 2800b57cec5SDimitry Andric 281cb14a3feSDimitry Andric int do_compare( 282cb14a3feSDimitry Andric const char_type* __lo1, const char_type* __hi1, const char_type* __lo2, const char_type* __hi2) const override; 283bdd1243dSDimitry Andric string_type do_transform(const char_type* __lo, const char_type* __hi) const override; 2840b57cec5SDimitry Andric}; 285349cc55cSDimitry Andric#endif 2860b57cec5SDimitry Andric 2870b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 288cb14a3feSDimitry Andricbool locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x, 289cb14a3feSDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __y) const { 2905f757f3fSDimitry Andric return std::use_facet<std::collate<_CharT> >(*this).compare( 291cb14a3feSDimitry Andric __x.data(), __x.data() + __x.size(), __y.data(), __y.data() + __y.size()) < 0; 2920b57cec5SDimitry Andric} 2930b57cec5SDimitry Andric 2940b57cec5SDimitry Andric// template <class charT> class ctype 2950b57cec5SDimitry Andric 296cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI ctype_base { 2970b57cec5SDimitry Andricpublic: 298e8d8bef9SDimitry Andric#if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE) 299e8d8bef9SDimitry Andric typedef unsigned long mask; 300e8d8bef9SDimitry Andric static const mask space = 1 << 0; 301e8d8bef9SDimitry Andric static const mask print = 1 << 1; 302e8d8bef9SDimitry Andric static const mask cntrl = 1 << 2; 303e8d8bef9SDimitry Andric static const mask upper = 1 << 3; 304e8d8bef9SDimitry Andric static const mask lower = 1 << 4; 305e8d8bef9SDimitry Andric static const mask alpha = 1 << 5; 306e8d8bef9SDimitry Andric static const mask digit = 1 << 6; 307e8d8bef9SDimitry Andric static const mask punct = 1 << 7; 308e8d8bef9SDimitry Andric static const mask xdigit = 1 << 8; 309e8d8bef9SDimitry Andric static const mask blank = 1 << 9; 310e8d8bef9SDimitry Andric# if defined(__BIONIC__) 311e8d8bef9SDimitry Andric // Historically this was a part of regex_traits rather than ctype_base. The 312e8d8bef9SDimitry Andric // historical value of the constant is preserved for ABI compatibility. 313e8d8bef9SDimitry Andric static const mask __regex_word = 0x8000; 314e8d8bef9SDimitry Andric# else 315e8d8bef9SDimitry Andric static const mask __regex_word = 1 << 10; 316e8d8bef9SDimitry Andric# endif // defined(__BIONIC__) 317e8d8bef9SDimitry Andric#elif defined(__GLIBC__) 3180b57cec5SDimitry Andric typedef unsigned short mask; 3190b57cec5SDimitry Andric static const mask space = _ISspace; 3200b57cec5SDimitry Andric static const mask print = _ISprint; 3210b57cec5SDimitry Andric static const mask cntrl = _IScntrl; 3220b57cec5SDimitry Andric static const mask upper = _ISupper; 3230b57cec5SDimitry Andric static const mask lower = _ISlower; 3240b57cec5SDimitry Andric static const mask alpha = _ISalpha; 3250b57cec5SDimitry Andric static const mask digit = _ISdigit; 3260b57cec5SDimitry Andric static const mask punct = _ISpunct; 3270b57cec5SDimitry Andric static const mask xdigit = _ISxdigit; 3280b57cec5SDimitry Andric static const mask blank = _ISblank; 3295f757f3fSDimitry Andric# if defined(__mips__) || (BYTE_ORDER == BIG_ENDIAN) 3300b57cec5SDimitry Andric static const mask __regex_word = static_cast<mask>(_ISbit(15)); 3310b57cec5SDimitry Andric# else 3320b57cec5SDimitry Andric static const mask __regex_word = 0x80; 3330b57cec5SDimitry Andric# endif 3340b57cec5SDimitry Andric#elif defined(_LIBCPP_MSVCRT_LIKE) 3350b57cec5SDimitry Andric typedef unsigned short mask; 3360b57cec5SDimitry Andric static const mask space = _SPACE; 3370b57cec5SDimitry Andric static const mask print = _BLANK | _PUNCT | _ALPHA | _DIGIT; 3380b57cec5SDimitry Andric static const mask cntrl = _CONTROL; 3390b57cec5SDimitry Andric static const mask upper = _UPPER; 3400b57cec5SDimitry Andric static const mask lower = _LOWER; 3410b57cec5SDimitry Andric static const mask alpha = _ALPHA; 3420b57cec5SDimitry Andric static const mask digit = _DIGIT; 3430b57cec5SDimitry Andric static const mask punct = _PUNCT; 3440b57cec5SDimitry Andric static const mask xdigit = _HEX; 3450b57cec5SDimitry Andric static const mask blank = _BLANK; 3461fd87a68SDimitry Andric static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used 3470b57cec5SDimitry Andric# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT 34881ad6265SDimitry Andric# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA 349*0fca6ea1SDimitry Andric#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) 3500b57cec5SDimitry Andric# ifdef __APPLE__ 3510b57cec5SDimitry Andric typedef __uint32_t mask; 3520b57cec5SDimitry Andric# elif defined(__FreeBSD__) 3530b57cec5SDimitry Andric typedef unsigned long mask; 354*0fca6ea1SDimitry Andric# elif defined(__NetBSD__) 3550b57cec5SDimitry Andric typedef unsigned short mask; 3560b57cec5SDimitry Andric# endif 3570b57cec5SDimitry Andric static const mask space = _CTYPE_S; 3580b57cec5SDimitry Andric static const mask print = _CTYPE_R; 3590b57cec5SDimitry Andric static const mask cntrl = _CTYPE_C; 3600b57cec5SDimitry Andric static const mask upper = _CTYPE_U; 3610b57cec5SDimitry Andric static const mask lower = _CTYPE_L; 3620b57cec5SDimitry Andric static const mask alpha = _CTYPE_A; 3630b57cec5SDimitry Andric static const mask digit = _CTYPE_D; 3640b57cec5SDimitry Andric static const mask punct = _CTYPE_P; 3650b57cec5SDimitry Andric static const mask xdigit = _CTYPE_X; 3660b57cec5SDimitry Andric 3670b57cec5SDimitry Andric# if defined(__NetBSD__) 3680b57cec5SDimitry Andric static const mask blank = _CTYPE_BL; 3690b57cec5SDimitry Andric // NetBSD defines classes up to 0x2000 3700b57cec5SDimitry Andric // see sys/ctype_bits.h, _CTYPE_Q 3710b57cec5SDimitry Andric static const mask __regex_word = 0x8000; 3720b57cec5SDimitry Andric# else 3730b57cec5SDimitry Andric static const mask blank = _CTYPE_B; 3740b57cec5SDimitry Andric static const mask __regex_word = 0x80; 3750b57cec5SDimitry Andric# endif 37606c3fb27SDimitry Andric#elif defined(_AIX) 3770b57cec5SDimitry Andric typedef unsigned int mask; 3780b57cec5SDimitry Andric static const mask space = _ISSPACE; 3790b57cec5SDimitry Andric static const mask print = _ISPRINT; 3800b57cec5SDimitry Andric static const mask cntrl = _ISCNTRL; 3810b57cec5SDimitry Andric static const mask upper = _ISUPPER; 3820b57cec5SDimitry Andric static const mask lower = _ISLOWER; 3830b57cec5SDimitry Andric static const mask alpha = _ISALPHA; 3840b57cec5SDimitry Andric static const mask digit = _ISDIGIT; 3850b57cec5SDimitry Andric static const mask punct = _ISPUNCT; 3860b57cec5SDimitry Andric static const mask xdigit = _ISXDIGIT; 3870b57cec5SDimitry Andric static const mask blank = _ISBLANK; 388fcaf7f86SDimitry Andric static const mask __regex_word = 0x8000; 3890b57cec5SDimitry Andric#elif defined(_NEWLIB_VERSION) 3900b57cec5SDimitry Andric // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h. 3910b57cec5SDimitry Andric typedef char mask; 3925f757f3fSDimitry Andric // In case char is signed, static_cast is needed to avoid warning on 3935f757f3fSDimitry Andric // positive value becomming negative. 3945f757f3fSDimitry Andric static const mask space = static_cast<mask>(_S); 3955f757f3fSDimitry Andric static const mask print = static_cast<mask>(_P | _U | _L | _N | _B); 3965f757f3fSDimitry Andric static const mask cntrl = static_cast<mask>(_C); 3975f757f3fSDimitry Andric static const mask upper = static_cast<mask>(_U); 3985f757f3fSDimitry Andric static const mask lower = static_cast<mask>(_L); 3995f757f3fSDimitry Andric static const mask alpha = static_cast<mask>(_U | _L); 4005f757f3fSDimitry Andric static const mask digit = static_cast<mask>(_N); 4015f757f3fSDimitry Andric static const mask punct = static_cast<mask>(_P); 4025f757f3fSDimitry Andric static const mask xdigit = static_cast<mask>(_X | _N); 4035f757f3fSDimitry Andric static const mask blank = static_cast<mask>(_B); 404bdd1243dSDimitry Andric // mask is already fully saturated, use a different type in regex_type_traits. 405bdd1243dSDimitry Andric static const unsigned short __regex_word = 0x100; 4060b57cec5SDimitry Andric# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT 4070b57cec5SDimitry Andric# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA 4080b57cec5SDimitry Andric# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT 40904eeddc0SDimitry Andric#elif defined(__MVS__) 41004eeddc0SDimitry Andric# if defined(__NATIVE_ASCII_F) 41104eeddc0SDimitry Andric typedef unsigned int mask; 41204eeddc0SDimitry Andric static const mask space = _ISSPACE_A; 41304eeddc0SDimitry Andric static const mask print = _ISPRINT_A; 41404eeddc0SDimitry Andric static const mask cntrl = _ISCNTRL_A; 41504eeddc0SDimitry Andric static const mask upper = _ISUPPER_A; 41604eeddc0SDimitry Andric static const mask lower = _ISLOWER_A; 41704eeddc0SDimitry Andric static const mask alpha = _ISALPHA_A; 41804eeddc0SDimitry Andric static const mask digit = _ISDIGIT_A; 41904eeddc0SDimitry Andric static const mask punct = _ISPUNCT_A; 42004eeddc0SDimitry Andric static const mask xdigit = _ISXDIGIT_A; 42104eeddc0SDimitry Andric static const mask blank = _ISBLANK_A; 42204eeddc0SDimitry Andric# else 42304eeddc0SDimitry Andric typedef unsigned short mask; 42404eeddc0SDimitry Andric static const mask space = __ISSPACE; 42504eeddc0SDimitry Andric static const mask print = __ISPRINT; 42604eeddc0SDimitry Andric static const mask cntrl = __ISCNTRL; 42704eeddc0SDimitry Andric static const mask upper = __ISUPPER; 42804eeddc0SDimitry Andric static const mask lower = __ISLOWER; 42904eeddc0SDimitry Andric static const mask alpha = __ISALPHA; 43004eeddc0SDimitry Andric static const mask digit = __ISDIGIT; 43104eeddc0SDimitry Andric static const mask punct = __ISPUNCT; 43204eeddc0SDimitry Andric static const mask xdigit = __ISXDIGIT; 43304eeddc0SDimitry Andric static const mask blank = __ISBLANK; 43404eeddc0SDimitry Andric# endif 43504eeddc0SDimitry Andric static const mask __regex_word = 0x8000; 4360b57cec5SDimitry Andric#else 437e8d8bef9SDimitry Andric# error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE? 4380b57cec5SDimitry Andric#endif 4390b57cec5SDimitry Andric static const mask alnum = alpha | digit; 4400b57cec5SDimitry Andric static const mask graph = alnum | punct; 4410b57cec5SDimitry Andric 4425f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI ctype_base() {} 4431fd87a68SDimitry Andric 444bdd1243dSDimitry Andric static_assert((__regex_word & ~(std::make_unsigned<mask>::type)(space | print | cntrl | upper | lower | alpha | 445bdd1243dSDimitry Andric digit | punct | xdigit | blank)) == __regex_word, 4461fd87a68SDimitry Andric "__regex_word can't overlap other bits"); 4470b57cec5SDimitry Andric}; 4480b57cec5SDimitry Andric 449cb14a3feSDimitry Andrictemplate <class _CharT> 450cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS ctype; 4510b57cec5SDimitry Andric 452349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 4530b57cec5SDimitry Andrictemplate <> 454cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI ctype<wchar_t> : public locale::facet, public ctype_base { 4550b57cec5SDimitry Andricpublic: 4560b57cec5SDimitry Andric typedef wchar_t char_type; 4570b57cec5SDimitry Andric 458cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit ctype(size_t __refs = 0) : locale::facet(__refs) {} 4590b57cec5SDimitry Andric 460cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const { return do_is(__m, __c); } 4610b57cec5SDimitry Andric 462cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const { 4630b57cec5SDimitry Andric return do_is(__low, __high, __vec); 4640b57cec5SDimitry Andric } 4650b57cec5SDimitry Andric 466cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const { 4670b57cec5SDimitry Andric return do_scan_is(__m, __low, __high); 4680b57cec5SDimitry Andric } 4690b57cec5SDimitry Andric 470cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const { 4710b57cec5SDimitry Andric return do_scan_not(__m, __low, __high); 4720b57cec5SDimitry Andric } 4730b57cec5SDimitry Andric 474cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); } 4750b57cec5SDimitry Andric 476cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI const char_type* toupper(char_type* __low, const char_type* __high) const { 4770b57cec5SDimitry Andric return do_toupper(__low, __high); 4780b57cec5SDimitry Andric } 4790b57cec5SDimitry Andric 480cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); } 4810b57cec5SDimitry Andric 482cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI const char_type* tolower(char_type* __low, const char_type* __high) const { 4830b57cec5SDimitry Andric return do_tolower(__low, __high); 4840b57cec5SDimitry Andric } 4850b57cec5SDimitry Andric 486cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); } 4870b57cec5SDimitry Andric 488cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI const char* widen(const char* __low, const char* __high, char_type* __to) const { 4890b57cec5SDimitry Andric return do_widen(__low, __high, __to); 4900b57cec5SDimitry Andric } 4910b57cec5SDimitry Andric 492cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); } 4930b57cec5SDimitry Andric 494cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI const char_type* 495cb14a3feSDimitry Andric narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const { 4960b57cec5SDimitry Andric return do_narrow(__low, __high, __dfault, __to); 4970b57cec5SDimitry Andric } 4980b57cec5SDimitry Andric 4990b57cec5SDimitry Andric static locale::id id; 5000b57cec5SDimitry Andric 5010b57cec5SDimitry Andricprotected: 502bdd1243dSDimitry Andric ~ctype() override; 5030b57cec5SDimitry Andric virtual bool do_is(mask __m, char_type __c) const; 5040b57cec5SDimitry Andric virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const; 5050b57cec5SDimitry Andric virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const; 5060b57cec5SDimitry Andric virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const; 5070b57cec5SDimitry Andric virtual char_type do_toupper(char_type) const; 5080b57cec5SDimitry Andric virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; 5090b57cec5SDimitry Andric virtual char_type do_tolower(char_type) const; 5100b57cec5SDimitry Andric virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; 5110b57cec5SDimitry Andric virtual char_type do_widen(char) const; 5120b57cec5SDimitry Andric virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const; 5130b57cec5SDimitry Andric virtual char do_narrow(char_type, char __dfault) const; 514cb14a3feSDimitry Andric virtual const char_type* 515cb14a3feSDimitry Andric do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const; 5160b57cec5SDimitry Andric}; 517349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS 5180b57cec5SDimitry Andric 5190b57cec5SDimitry Andrictemplate <> 520cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI ctype<char> : public locale::facet, public ctype_base { 5210b57cec5SDimitry Andric const mask* __tab_; 5220b57cec5SDimitry Andric bool __del_; 523cb14a3feSDimitry Andric 5240b57cec5SDimitry Andricpublic: 5250b57cec5SDimitry Andric typedef char char_type; 5260b57cec5SDimitry Andric 527e8d8bef9SDimitry Andric explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0); 5280b57cec5SDimitry Andric 529cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI bool is(mask __m, char_type __c) const { 5300b57cec5SDimitry Andric return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) != 0 : false; 5310b57cec5SDimitry Andric } 5320b57cec5SDimitry Andric 533cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const { 5340b57cec5SDimitry Andric for (; __low != __high; ++__low, ++__vec) 5350b57cec5SDimitry Andric *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0; 5360b57cec5SDimitry Andric return __low; 5370b57cec5SDimitry Andric } 5380b57cec5SDimitry Andric 539cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const { 5400b57cec5SDimitry Andric for (; __low != __high; ++__low) 5410b57cec5SDimitry Andric if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)) 5420b57cec5SDimitry Andric break; 5430b57cec5SDimitry Andric return __low; 5440b57cec5SDimitry Andric } 5450b57cec5SDimitry Andric 546cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const { 5470b57cec5SDimitry Andric for (; __low != __high; ++__low) 548bdd1243dSDimitry Andric if (!isascii(*__low) || !(__tab_[static_cast<int>(*__low)] & __m)) 5490b57cec5SDimitry Andric break; 5500b57cec5SDimitry Andric return __low; 5510b57cec5SDimitry Andric } 5520b57cec5SDimitry Andric 553cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type toupper(char_type __c) const { return do_toupper(__c); } 5540b57cec5SDimitry Andric 555cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI const char_type* toupper(char_type* __low, const char_type* __high) const { 5560b57cec5SDimitry Andric return do_toupper(__low, __high); 5570b57cec5SDimitry Andric } 5580b57cec5SDimitry Andric 559cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type tolower(char_type __c) const { return do_tolower(__c); } 5600b57cec5SDimitry Andric 561cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI const char_type* tolower(char_type* __low, const char_type* __high) const { 5620b57cec5SDimitry Andric return do_tolower(__low, __high); 5630b57cec5SDimitry Andric } 5640b57cec5SDimitry Andric 565cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const { return do_widen(__c); } 5660b57cec5SDimitry Andric 567cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI const char* widen(const char* __low, const char* __high, char_type* __to) const { 5680b57cec5SDimitry Andric return do_widen(__low, __high, __to); 5690b57cec5SDimitry Andric } 5700b57cec5SDimitry Andric 571cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const { return do_narrow(__c, __dfault); } 5720b57cec5SDimitry Andric 573cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI const char* 574cb14a3feSDimitry Andric narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const { 5750b57cec5SDimitry Andric return do_narrow(__low, __high, __dfault, __to); 5760b57cec5SDimitry Andric } 5770b57cec5SDimitry Andric 5780b57cec5SDimitry Andric static locale::id id; 5790b57cec5SDimitry Andric 5800b57cec5SDimitry Andric#ifdef _CACHED_RUNES 5810b57cec5SDimitry Andric static const size_t table_size = _CACHED_RUNES; 5820b57cec5SDimitry Andric#else 5830b57cec5SDimitry Andric static const size_t table_size = 256; // FIXME: Don't hardcode this. 5840b57cec5SDimitry Andric#endif 5855f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI const mask* table() const _NOEXCEPT { return __tab_; } 5860b57cec5SDimitry Andric static const mask* classic_table() _NOEXCEPT; 5870b57cec5SDimitry Andric#if defined(__GLIBC__) || defined(__EMSCRIPTEN__) 5880b57cec5SDimitry Andric static const int* __classic_upper_table() _NOEXCEPT; 5890b57cec5SDimitry Andric static const int* __classic_lower_table() _NOEXCEPT; 5900b57cec5SDimitry Andric#endif 5910b57cec5SDimitry Andric#if defined(__NetBSD__) 5920b57cec5SDimitry Andric static const short* __classic_upper_table() _NOEXCEPT; 5930b57cec5SDimitry Andric static const short* __classic_lower_table() _NOEXCEPT; 5940b57cec5SDimitry Andric#endif 59504eeddc0SDimitry Andric#if defined(__MVS__) 59604eeddc0SDimitry Andric static const unsigned short* __classic_upper_table() _NOEXCEPT; 59704eeddc0SDimitry Andric static const unsigned short* __classic_lower_table() _NOEXCEPT; 59804eeddc0SDimitry Andric#endif 5990b57cec5SDimitry Andric 6000b57cec5SDimitry Andricprotected: 601bdd1243dSDimitry Andric ~ctype() override; 6020b57cec5SDimitry Andric virtual char_type do_toupper(char_type __c) const; 6030b57cec5SDimitry Andric virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const; 6040b57cec5SDimitry Andric virtual char_type do_tolower(char_type __c) const; 6050b57cec5SDimitry Andric virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const; 6060b57cec5SDimitry Andric virtual char_type do_widen(char __c) const; 6070b57cec5SDimitry Andric virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const; 6080b57cec5SDimitry Andric virtual char do_narrow(char_type __c, char __dfault) const; 6090b57cec5SDimitry Andric virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const; 6100b57cec5SDimitry Andric}; 6110b57cec5SDimitry Andric 6120b57cec5SDimitry Andric// template <class CharT> class ctype_byname; 6130b57cec5SDimitry Andric 614cb14a3feSDimitry Andrictemplate <class _CharT> 615cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS ctype_byname; 6160b57cec5SDimitry Andric 6170b57cec5SDimitry Andrictemplate <> 618cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI ctype_byname<char> : public ctype<char> { 619bdd1243dSDimitry Andric locale_t __l_; 6200b57cec5SDimitry Andric 6210b57cec5SDimitry Andricpublic: 6220b57cec5SDimitry Andric explicit ctype_byname(const char*, size_t = 0); 6230b57cec5SDimitry Andric explicit ctype_byname(const string&, size_t = 0); 6240b57cec5SDimitry Andric 6250b57cec5SDimitry Andricprotected: 626bdd1243dSDimitry Andric ~ctype_byname() override; 627bdd1243dSDimitry Andric char_type do_toupper(char_type) const override; 628bdd1243dSDimitry Andric const char_type* do_toupper(char_type* __low, const char_type* __high) const override; 629bdd1243dSDimitry Andric char_type do_tolower(char_type) const override; 630bdd1243dSDimitry Andric const char_type* do_tolower(char_type* __low, const char_type* __high) const override; 6310b57cec5SDimitry Andric}; 6320b57cec5SDimitry Andric 633349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 6340b57cec5SDimitry Andrictemplate <> 635cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI ctype_byname<wchar_t> : public ctype<wchar_t> { 636bdd1243dSDimitry Andric locale_t __l_; 6370b57cec5SDimitry Andric 6380b57cec5SDimitry Andricpublic: 6390b57cec5SDimitry Andric explicit ctype_byname(const char*, size_t = 0); 6400b57cec5SDimitry Andric explicit ctype_byname(const string&, size_t = 0); 6410b57cec5SDimitry Andric 6420b57cec5SDimitry Andricprotected: 643bdd1243dSDimitry Andric ~ctype_byname() override; 644bdd1243dSDimitry Andric bool do_is(mask __m, char_type __c) const override; 645bdd1243dSDimitry Andric const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const override; 646bdd1243dSDimitry Andric const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const override; 647bdd1243dSDimitry Andric const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const override; 648bdd1243dSDimitry Andric char_type do_toupper(char_type) const override; 649bdd1243dSDimitry Andric const char_type* do_toupper(char_type* __low, const char_type* __high) const override; 650bdd1243dSDimitry Andric char_type do_tolower(char_type) const override; 651bdd1243dSDimitry Andric const char_type* do_tolower(char_type* __low, const char_type* __high) const override; 652bdd1243dSDimitry Andric char_type do_widen(char) const override; 653bdd1243dSDimitry Andric const char* do_widen(const char* __low, const char* __high, char_type* __dest) const override; 654bdd1243dSDimitry Andric char do_narrow(char_type, char __dfault) const override; 655cb14a3feSDimitry Andric const char_type* 656cb14a3feSDimitry Andric do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const override; 6570b57cec5SDimitry Andric}; 658349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS 6590b57cec5SDimitry Andric 6600b57cec5SDimitry Andrictemplate <class _CharT> 661cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool isspace(_CharT __c, const locale& __loc) { 662bdd1243dSDimitry Andric return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); 6630b57cec5SDimitry Andric} 6640b57cec5SDimitry Andric 6650b57cec5SDimitry Andrictemplate <class _CharT> 666cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool isprint(_CharT __c, const locale& __loc) { 667bdd1243dSDimitry Andric return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); 6680b57cec5SDimitry Andric} 6690b57cec5SDimitry Andric 6700b57cec5SDimitry Andrictemplate <class _CharT> 671cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool iscntrl(_CharT __c, const locale& __loc) { 672bdd1243dSDimitry Andric return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); 6730b57cec5SDimitry Andric} 6740b57cec5SDimitry Andric 6750b57cec5SDimitry Andrictemplate <class _CharT> 676cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool isupper(_CharT __c, const locale& __loc) { 677bdd1243dSDimitry Andric return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); 6780b57cec5SDimitry Andric} 6790b57cec5SDimitry Andric 6800b57cec5SDimitry Andrictemplate <class _CharT> 681cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool islower(_CharT __c, const locale& __loc) { 682bdd1243dSDimitry Andric return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); 6830b57cec5SDimitry Andric} 6840b57cec5SDimitry Andric 6850b57cec5SDimitry Andrictemplate <class _CharT> 686cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool isalpha(_CharT __c, const locale& __loc) { 687bdd1243dSDimitry Andric return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); 6880b57cec5SDimitry Andric} 6890b57cec5SDimitry Andric 6900b57cec5SDimitry Andrictemplate <class _CharT> 691cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool isdigit(_CharT __c, const locale& __loc) { 692bdd1243dSDimitry Andric return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); 6930b57cec5SDimitry Andric} 6940b57cec5SDimitry Andric 6950b57cec5SDimitry Andrictemplate <class _CharT> 696cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool ispunct(_CharT __c, const locale& __loc) { 697bdd1243dSDimitry Andric return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); 6980b57cec5SDimitry Andric} 6990b57cec5SDimitry Andric 7000b57cec5SDimitry Andrictemplate <class _CharT> 701cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool isxdigit(_CharT __c, const locale& __loc) { 702bdd1243dSDimitry Andric return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); 7030b57cec5SDimitry Andric} 7040b57cec5SDimitry Andric 7050b57cec5SDimitry Andrictemplate <class _CharT> 706cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool isalnum(_CharT __c, const locale& __loc) { 707bdd1243dSDimitry Andric return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); 7080b57cec5SDimitry Andric} 7090b57cec5SDimitry Andric 7100b57cec5SDimitry Andrictemplate <class _CharT> 711cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool isgraph(_CharT __c, const locale& __loc) { 712bdd1243dSDimitry Andric return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); 7130b57cec5SDimitry Andric} 7140b57cec5SDimitry Andric 7150b57cec5SDimitry Andrictemplate <class _CharT> 71606c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI bool isblank(_CharT __c, const locale& __loc) { 71706c3fb27SDimitry Andric return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::blank, __c); 71806c3fb27SDimitry Andric} 71906c3fb27SDimitry Andric 72006c3fb27SDimitry Andrictemplate <class _CharT> 721cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _CharT toupper(_CharT __c, const locale& __loc) { 722bdd1243dSDimitry Andric return std::use_facet<ctype<_CharT> >(__loc).toupper(__c); 7230b57cec5SDimitry Andric} 7240b57cec5SDimitry Andric 7250b57cec5SDimitry Andrictemplate <class _CharT> 726cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _CharT tolower(_CharT __c, const locale& __loc) { 727bdd1243dSDimitry Andric return std::use_facet<ctype<_CharT> >(__loc).tolower(__c); 7280b57cec5SDimitry Andric} 7290b57cec5SDimitry Andric 7300b57cec5SDimitry Andric// codecvt_base 7310b57cec5SDimitry Andric 732cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI codecvt_base { 7330b57cec5SDimitry Andricpublic: 7345f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI codecvt_base() {} 7350b57cec5SDimitry Andric enum result { ok, partial, error, noconv }; 7360b57cec5SDimitry Andric}; 7370b57cec5SDimitry Andric 7380b57cec5SDimitry Andric// template <class internT, class externT, class stateT> class codecvt; 7390b57cec5SDimitry Andric 740cb14a3feSDimitry Andrictemplate <class _InternT, class _ExternT, class _StateT> 741cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS codecvt; 7420b57cec5SDimitry Andric 7430b57cec5SDimitry Andric// template <> class codecvt<char, char, mbstate_t> 7440b57cec5SDimitry Andric 7450b57cec5SDimitry Andrictemplate <> 746cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI codecvt<char, char, mbstate_t> : public locale::facet, public codecvt_base { 7470b57cec5SDimitry Andricpublic: 7480b57cec5SDimitry Andric typedef char intern_type; 7490b57cec5SDimitry Andric typedef char extern_type; 7500b57cec5SDimitry Andric typedef mbstate_t state_type; 7510b57cec5SDimitry Andric 752cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} 7530b57cec5SDimitry Andric 754cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 755cb14a3feSDimitry Andric out(state_type& __st, 756cb14a3feSDimitry Andric const intern_type* __frm, 757cb14a3feSDimitry Andric const intern_type* __frm_end, 758cb14a3feSDimitry Andric const intern_type*& __frm_nxt, 759cb14a3feSDimitry Andric extern_type* __to, 760cb14a3feSDimitry Andric extern_type* __to_end, 761cb14a3feSDimitry Andric extern_type*& __to_nxt) const { 7620b57cec5SDimitry Andric return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); 7630b57cec5SDimitry Andric } 7640b57cec5SDimitry Andric 765cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 766cb14a3feSDimitry Andric unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { 7670b57cec5SDimitry Andric return do_unshift(__st, __to, __to_end, __to_nxt); 7680b57cec5SDimitry Andric } 7690b57cec5SDimitry Andric 770cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 771cb14a3feSDimitry Andric in(state_type& __st, 772cb14a3feSDimitry Andric const extern_type* __frm, 773cb14a3feSDimitry Andric const extern_type* __frm_end, 774cb14a3feSDimitry Andric const extern_type*& __frm_nxt, 775cb14a3feSDimitry Andric intern_type* __to, 776cb14a3feSDimitry Andric intern_type* __to_end, 777cb14a3feSDimitry Andric intern_type*& __to_nxt) const { 7780b57cec5SDimitry Andric return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); 7790b57cec5SDimitry Andric } 7800b57cec5SDimitry Andric 781cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } 7820b57cec5SDimitry Andric 783cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } 7840b57cec5SDimitry Andric 785cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int 786cb14a3feSDimitry Andric length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { 7870b57cec5SDimitry Andric return do_length(__st, __frm, __end, __mx); 7880b57cec5SDimitry Andric } 7890b57cec5SDimitry Andric 790cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } 7910b57cec5SDimitry Andric 7920b57cec5SDimitry Andric static locale::id id; 7930b57cec5SDimitry Andric 7940b57cec5SDimitry Andricprotected: 795cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {} 7960b57cec5SDimitry Andric 797bdd1243dSDimitry Andric ~codecvt() override; 7980b57cec5SDimitry Andric 799cb14a3feSDimitry Andric virtual result 800cb14a3feSDimitry Andric do_out(state_type& __st, 801cb14a3feSDimitry Andric const intern_type* __frm, 802cb14a3feSDimitry Andric const intern_type* __frm_end, 803cb14a3feSDimitry Andric const intern_type*& __frm_nxt, 804cb14a3feSDimitry Andric extern_type* __to, 805cb14a3feSDimitry Andric extern_type* __to_end, 806cb14a3feSDimitry Andric extern_type*& __to_nxt) const; 807cb14a3feSDimitry Andric virtual result 808cb14a3feSDimitry Andric do_in(state_type& __st, 809cb14a3feSDimitry Andric const extern_type* __frm, 810cb14a3feSDimitry Andric const extern_type* __frm_end, 811cb14a3feSDimitry Andric const extern_type*& __frm_nxt, 812cb14a3feSDimitry Andric intern_type* __to, 813cb14a3feSDimitry Andric intern_type* __to_end, 814cb14a3feSDimitry Andric intern_type*& __to_nxt) const; 815cb14a3feSDimitry Andric virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; 8160b57cec5SDimitry Andric virtual int do_encoding() const _NOEXCEPT; 8170b57cec5SDimitry Andric virtual bool do_always_noconv() const _NOEXCEPT; 8180b57cec5SDimitry Andric virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const; 8190b57cec5SDimitry Andric virtual int do_max_length() const _NOEXCEPT; 8200b57cec5SDimitry Andric}; 8210b57cec5SDimitry Andric 8220b57cec5SDimitry Andric// template <> class codecvt<wchar_t, char, mbstate_t> 8230b57cec5SDimitry Andric 824349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 8250b57cec5SDimitry Andrictemplate <> 826cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI codecvt<wchar_t, char, mbstate_t> : public locale::facet, public codecvt_base { 827bdd1243dSDimitry Andric locale_t __l_; 828cb14a3feSDimitry Andric 8290b57cec5SDimitry Andricpublic: 8300b57cec5SDimitry Andric typedef wchar_t intern_type; 8310b57cec5SDimitry Andric typedef char extern_type; 8320b57cec5SDimitry Andric typedef mbstate_t state_type; 8330b57cec5SDimitry Andric 8340b57cec5SDimitry Andric explicit codecvt(size_t __refs = 0); 8350b57cec5SDimitry Andric 836cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 837cb14a3feSDimitry Andric out(state_type& __st, 838cb14a3feSDimitry Andric const intern_type* __frm, 839cb14a3feSDimitry Andric const intern_type* __frm_end, 840cb14a3feSDimitry Andric const intern_type*& __frm_nxt, 841cb14a3feSDimitry Andric extern_type* __to, 842cb14a3feSDimitry Andric extern_type* __to_end, 843cb14a3feSDimitry Andric extern_type*& __to_nxt) const { 8440b57cec5SDimitry Andric return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); 8450b57cec5SDimitry Andric } 8460b57cec5SDimitry Andric 847cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 848cb14a3feSDimitry Andric unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { 8490b57cec5SDimitry Andric return do_unshift(__st, __to, __to_end, __to_nxt); 8500b57cec5SDimitry Andric } 8510b57cec5SDimitry Andric 852cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 853cb14a3feSDimitry Andric in(state_type& __st, 854cb14a3feSDimitry Andric const extern_type* __frm, 855cb14a3feSDimitry Andric const extern_type* __frm_end, 856cb14a3feSDimitry Andric const extern_type*& __frm_nxt, 857cb14a3feSDimitry Andric intern_type* __to, 858cb14a3feSDimitry Andric intern_type* __to_end, 859cb14a3feSDimitry Andric intern_type*& __to_nxt) const { 8600b57cec5SDimitry Andric return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); 8610b57cec5SDimitry Andric } 8620b57cec5SDimitry Andric 863cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } 8640b57cec5SDimitry Andric 865cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } 8660b57cec5SDimitry Andric 867cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int 868cb14a3feSDimitry Andric length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { 8690b57cec5SDimitry Andric return do_length(__st, __frm, __end, __mx); 8700b57cec5SDimitry Andric } 8710b57cec5SDimitry Andric 872cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } 8730b57cec5SDimitry Andric 8740b57cec5SDimitry Andric static locale::id id; 8750b57cec5SDimitry Andric 8760b57cec5SDimitry Andricprotected: 8770b57cec5SDimitry Andric explicit codecvt(const char*, size_t __refs = 0); 8780b57cec5SDimitry Andric 879bdd1243dSDimitry Andric ~codecvt() override; 8800b57cec5SDimitry Andric 881cb14a3feSDimitry Andric virtual result 882cb14a3feSDimitry Andric do_out(state_type& __st, 883cb14a3feSDimitry Andric const intern_type* __frm, 884cb14a3feSDimitry Andric const intern_type* __frm_end, 885cb14a3feSDimitry Andric const intern_type*& __frm_nxt, 886cb14a3feSDimitry Andric extern_type* __to, 887cb14a3feSDimitry Andric extern_type* __to_end, 888cb14a3feSDimitry Andric extern_type*& __to_nxt) const; 889cb14a3feSDimitry Andric virtual result 890cb14a3feSDimitry Andric do_in(state_type& __st, 891cb14a3feSDimitry Andric const extern_type* __frm, 892cb14a3feSDimitry Andric const extern_type* __frm_end, 893cb14a3feSDimitry Andric const extern_type*& __frm_nxt, 894cb14a3feSDimitry Andric intern_type* __to, 895cb14a3feSDimitry Andric intern_type* __to_end, 896cb14a3feSDimitry Andric intern_type*& __to_nxt) const; 897cb14a3feSDimitry Andric virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; 8980b57cec5SDimitry Andric virtual int do_encoding() const _NOEXCEPT; 8990b57cec5SDimitry Andric virtual bool do_always_noconv() const _NOEXCEPT; 9000b57cec5SDimitry Andric virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; 9010b57cec5SDimitry Andric virtual int do_max_length() const _NOEXCEPT; 9020b57cec5SDimitry Andric}; 903349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS 9040b57cec5SDimitry Andric 905e8d8bef9SDimitry Andric// template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20 9060b57cec5SDimitry Andric 9070b57cec5SDimitry Andrictemplate <> 90806c3fb27SDimitry Andricclass _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char, mbstate_t> 909cb14a3feSDimitry Andric : public locale::facet, public codecvt_base { 9100b57cec5SDimitry Andricpublic: 9110b57cec5SDimitry Andric typedef char16_t intern_type; 9120b57cec5SDimitry Andric typedef char extern_type; 9130b57cec5SDimitry Andric typedef mbstate_t state_type; 9140b57cec5SDimitry Andric 915cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} 9160b57cec5SDimitry Andric 917cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 918cb14a3feSDimitry Andric out(state_type& __st, 919cb14a3feSDimitry Andric const intern_type* __frm, 920cb14a3feSDimitry Andric const intern_type* __frm_end, 921cb14a3feSDimitry Andric const intern_type*& __frm_nxt, 922cb14a3feSDimitry Andric extern_type* __to, 923cb14a3feSDimitry Andric extern_type* __to_end, 924cb14a3feSDimitry Andric extern_type*& __to_nxt) const { 9250b57cec5SDimitry Andric return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); 9260b57cec5SDimitry Andric } 9270b57cec5SDimitry Andric 928cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 929cb14a3feSDimitry Andric unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { 9300b57cec5SDimitry Andric return do_unshift(__st, __to, __to_end, __to_nxt); 9310b57cec5SDimitry Andric } 9320b57cec5SDimitry Andric 933cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 934cb14a3feSDimitry Andric in(state_type& __st, 935cb14a3feSDimitry Andric const extern_type* __frm, 936cb14a3feSDimitry Andric const extern_type* __frm_end, 937cb14a3feSDimitry Andric const extern_type*& __frm_nxt, 938cb14a3feSDimitry Andric intern_type* __to, 939cb14a3feSDimitry Andric intern_type* __to_end, 940cb14a3feSDimitry Andric intern_type*& __to_nxt) const { 9410b57cec5SDimitry Andric return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); 9420b57cec5SDimitry Andric } 9430b57cec5SDimitry Andric 944cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } 9450b57cec5SDimitry Andric 946cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } 9470b57cec5SDimitry Andric 948cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int 949cb14a3feSDimitry Andric length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { 9500b57cec5SDimitry Andric return do_length(__st, __frm, __end, __mx); 9510b57cec5SDimitry Andric } 9520b57cec5SDimitry Andric 953cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } 9540b57cec5SDimitry Andric 9550b57cec5SDimitry Andric static locale::id id; 9560b57cec5SDimitry Andric 9570b57cec5SDimitry Andricprotected: 958cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {} 9590b57cec5SDimitry Andric 960bdd1243dSDimitry Andric ~codecvt() override; 9610b57cec5SDimitry Andric 962cb14a3feSDimitry Andric virtual result 963cb14a3feSDimitry Andric do_out(state_type& __st, 964cb14a3feSDimitry Andric const intern_type* __frm, 965cb14a3feSDimitry Andric const intern_type* __frm_end, 966cb14a3feSDimitry Andric const intern_type*& __frm_nxt, 967cb14a3feSDimitry Andric extern_type* __to, 968cb14a3feSDimitry Andric extern_type* __to_end, 969cb14a3feSDimitry Andric extern_type*& __to_nxt) const; 970cb14a3feSDimitry Andric virtual result 971cb14a3feSDimitry Andric do_in(state_type& __st, 972cb14a3feSDimitry Andric const extern_type* __frm, 973cb14a3feSDimitry Andric const extern_type* __frm_end, 974cb14a3feSDimitry Andric const extern_type*& __frm_nxt, 975cb14a3feSDimitry Andric intern_type* __to, 976cb14a3feSDimitry Andric intern_type* __to_end, 977cb14a3feSDimitry Andric intern_type*& __to_nxt) const; 978cb14a3feSDimitry Andric virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; 9790b57cec5SDimitry Andric virtual int do_encoding() const _NOEXCEPT; 9800b57cec5SDimitry Andric virtual bool do_always_noconv() const _NOEXCEPT; 9810b57cec5SDimitry Andric virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; 9820b57cec5SDimitry Andric virtual int do_max_length() const _NOEXCEPT; 9830b57cec5SDimitry Andric}; 9840b57cec5SDimitry Andric 985fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T 986e8d8bef9SDimitry Andric 987e8d8bef9SDimitry Andric// template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20 9880b57cec5SDimitry Andric 9890b57cec5SDimitry Andrictemplate <> 990cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char8_t, mbstate_t> : public locale::facet, public codecvt_base { 991e8d8bef9SDimitry Andricpublic: 992e8d8bef9SDimitry Andric typedef char16_t intern_type; 993e8d8bef9SDimitry Andric typedef char8_t extern_type; 994e8d8bef9SDimitry Andric typedef mbstate_t state_type; 995e8d8bef9SDimitry Andric 996cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} 997e8d8bef9SDimitry Andric 998cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 999cb14a3feSDimitry Andric out(state_type& __st, 1000cb14a3feSDimitry Andric const intern_type* __frm, 1001cb14a3feSDimitry Andric const intern_type* __frm_end, 1002cb14a3feSDimitry Andric const intern_type*& __frm_nxt, 1003cb14a3feSDimitry Andric extern_type* __to, 1004cb14a3feSDimitry Andric extern_type* __to_end, 1005cb14a3feSDimitry Andric extern_type*& __to_nxt) const { 1006e8d8bef9SDimitry Andric return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); 1007e8d8bef9SDimitry Andric } 1008e8d8bef9SDimitry Andric 1009cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 1010cb14a3feSDimitry Andric unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { 1011e8d8bef9SDimitry Andric return do_unshift(__st, __to, __to_end, __to_nxt); 1012e8d8bef9SDimitry Andric } 1013e8d8bef9SDimitry Andric 1014cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 1015cb14a3feSDimitry Andric in(state_type& __st, 1016cb14a3feSDimitry Andric const extern_type* __frm, 1017cb14a3feSDimitry Andric const extern_type* __frm_end, 1018cb14a3feSDimitry Andric const extern_type*& __frm_nxt, 1019cb14a3feSDimitry Andric intern_type* __to, 1020cb14a3feSDimitry Andric intern_type* __to_end, 1021cb14a3feSDimitry Andric intern_type*& __to_nxt) const { 1022e8d8bef9SDimitry Andric return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); 1023e8d8bef9SDimitry Andric } 1024e8d8bef9SDimitry Andric 1025cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } 1026e8d8bef9SDimitry Andric 1027cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } 1028e8d8bef9SDimitry Andric 1029cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int 1030cb14a3feSDimitry Andric length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { 1031e8d8bef9SDimitry Andric return do_length(__st, __frm, __end, __mx); 1032e8d8bef9SDimitry Andric } 1033e8d8bef9SDimitry Andric 1034cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } 1035e8d8bef9SDimitry Andric 1036e8d8bef9SDimitry Andric static locale::id id; 1037e8d8bef9SDimitry Andric 1038e8d8bef9SDimitry Andricprotected: 1039cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {} 1040e8d8bef9SDimitry Andric 1041bdd1243dSDimitry Andric ~codecvt() override; 1042e8d8bef9SDimitry Andric 1043cb14a3feSDimitry Andric virtual result 1044cb14a3feSDimitry Andric do_out(state_type& __st, 1045cb14a3feSDimitry Andric const intern_type* __frm, 1046cb14a3feSDimitry Andric const intern_type* __frm_end, 1047cb14a3feSDimitry Andric const intern_type*& __frm_nxt, 1048cb14a3feSDimitry Andric extern_type* __to, 1049cb14a3feSDimitry Andric extern_type* __to_end, 1050cb14a3feSDimitry Andric extern_type*& __to_nxt) const; 1051cb14a3feSDimitry Andric virtual result 1052cb14a3feSDimitry Andric do_in(state_type& __st, 1053cb14a3feSDimitry Andric const extern_type* __frm, 1054cb14a3feSDimitry Andric const extern_type* __frm_end, 1055cb14a3feSDimitry Andric const extern_type*& __frm_nxt, 1056cb14a3feSDimitry Andric intern_type* __to, 1057cb14a3feSDimitry Andric intern_type* __to_end, 1058cb14a3feSDimitry Andric intern_type*& __to_nxt) const; 1059cb14a3feSDimitry Andric virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; 1060e8d8bef9SDimitry Andric virtual int do_encoding() const _NOEXCEPT; 1061e8d8bef9SDimitry Andric virtual bool do_always_noconv() const _NOEXCEPT; 1062e8d8bef9SDimitry Andric virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; 1063e8d8bef9SDimitry Andric virtual int do_max_length() const _NOEXCEPT; 1064e8d8bef9SDimitry Andric}; 1065e8d8bef9SDimitry Andric 1066e8d8bef9SDimitry Andric#endif 1067e8d8bef9SDimitry Andric 1068e8d8bef9SDimitry Andric// template <> class codecvt<char32_t, char, mbstate_t> // deprecated in C++20 1069e8d8bef9SDimitry Andric 1070e8d8bef9SDimitry Andrictemplate <> 107106c3fb27SDimitry Andricclass _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char, mbstate_t> 1072cb14a3feSDimitry Andric : public locale::facet, public codecvt_base { 10730b57cec5SDimitry Andricpublic: 10740b57cec5SDimitry Andric typedef char32_t intern_type; 10750b57cec5SDimitry Andric typedef char extern_type; 10760b57cec5SDimitry Andric typedef mbstate_t state_type; 10770b57cec5SDimitry Andric 1078cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} 10790b57cec5SDimitry Andric 1080cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 1081cb14a3feSDimitry Andric out(state_type& __st, 1082cb14a3feSDimitry Andric const intern_type* __frm, 1083cb14a3feSDimitry Andric const intern_type* __frm_end, 1084cb14a3feSDimitry Andric const intern_type*& __frm_nxt, 1085cb14a3feSDimitry Andric extern_type* __to, 1086cb14a3feSDimitry Andric extern_type* __to_end, 1087cb14a3feSDimitry Andric extern_type*& __to_nxt) const { 10880b57cec5SDimitry Andric return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); 10890b57cec5SDimitry Andric } 10900b57cec5SDimitry Andric 1091cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 1092cb14a3feSDimitry Andric unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { 10930b57cec5SDimitry Andric return do_unshift(__st, __to, __to_end, __to_nxt); 10940b57cec5SDimitry Andric } 10950b57cec5SDimitry Andric 1096cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 1097cb14a3feSDimitry Andric in(state_type& __st, 1098cb14a3feSDimitry Andric const extern_type* __frm, 1099cb14a3feSDimitry Andric const extern_type* __frm_end, 1100cb14a3feSDimitry Andric const extern_type*& __frm_nxt, 1101cb14a3feSDimitry Andric intern_type* __to, 1102cb14a3feSDimitry Andric intern_type* __to_end, 1103cb14a3feSDimitry Andric intern_type*& __to_nxt) const { 11040b57cec5SDimitry Andric return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); 11050b57cec5SDimitry Andric } 11060b57cec5SDimitry Andric 1107cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } 11080b57cec5SDimitry Andric 1109cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } 11100b57cec5SDimitry Andric 1111cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int 1112cb14a3feSDimitry Andric length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { 11130b57cec5SDimitry Andric return do_length(__st, __frm, __end, __mx); 11140b57cec5SDimitry Andric } 11150b57cec5SDimitry Andric 1116cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } 11170b57cec5SDimitry Andric 11180b57cec5SDimitry Andric static locale::id id; 11190b57cec5SDimitry Andric 11200b57cec5SDimitry Andricprotected: 1121cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {} 11220b57cec5SDimitry Andric 1123bdd1243dSDimitry Andric ~codecvt() override; 11240b57cec5SDimitry Andric 1125cb14a3feSDimitry Andric virtual result 1126cb14a3feSDimitry Andric do_out(state_type& __st, 1127cb14a3feSDimitry Andric const intern_type* __frm, 1128cb14a3feSDimitry Andric const intern_type* __frm_end, 1129cb14a3feSDimitry Andric const intern_type*& __frm_nxt, 1130cb14a3feSDimitry Andric extern_type* __to, 1131cb14a3feSDimitry Andric extern_type* __to_end, 1132cb14a3feSDimitry Andric extern_type*& __to_nxt) const; 1133cb14a3feSDimitry Andric virtual result 1134cb14a3feSDimitry Andric do_in(state_type& __st, 1135cb14a3feSDimitry Andric const extern_type* __frm, 1136cb14a3feSDimitry Andric const extern_type* __frm_end, 1137cb14a3feSDimitry Andric const extern_type*& __frm_nxt, 1138cb14a3feSDimitry Andric intern_type* __to, 1139cb14a3feSDimitry Andric intern_type* __to_end, 1140cb14a3feSDimitry Andric intern_type*& __to_nxt) const; 1141cb14a3feSDimitry Andric virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; 11420b57cec5SDimitry Andric virtual int do_encoding() const _NOEXCEPT; 11430b57cec5SDimitry Andric virtual bool do_always_noconv() const _NOEXCEPT; 11440b57cec5SDimitry Andric virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; 11450b57cec5SDimitry Andric virtual int do_max_length() const _NOEXCEPT; 11460b57cec5SDimitry Andric}; 11470b57cec5SDimitry Andric 1148fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T 1149e8d8bef9SDimitry Andric 1150e8d8bef9SDimitry Andric// template <> class codecvt<char32_t, char8_t, mbstate_t> // C++20 1151e8d8bef9SDimitry Andric 1152e8d8bef9SDimitry Andrictemplate <> 1153cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char8_t, mbstate_t> : public locale::facet, public codecvt_base { 1154e8d8bef9SDimitry Andricpublic: 1155e8d8bef9SDimitry Andric typedef char32_t intern_type; 1156e8d8bef9SDimitry Andric typedef char8_t extern_type; 1157e8d8bef9SDimitry Andric typedef mbstate_t state_type; 1158e8d8bef9SDimitry Andric 1159cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {} 1160e8d8bef9SDimitry Andric 1161cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 1162cb14a3feSDimitry Andric out(state_type& __st, 1163cb14a3feSDimitry Andric const intern_type* __frm, 1164cb14a3feSDimitry Andric const intern_type* __frm_end, 1165cb14a3feSDimitry Andric const intern_type*& __frm_nxt, 1166cb14a3feSDimitry Andric extern_type* __to, 1167cb14a3feSDimitry Andric extern_type* __to_end, 1168cb14a3feSDimitry Andric extern_type*& __to_nxt) const { 1169e8d8bef9SDimitry Andric return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); 1170e8d8bef9SDimitry Andric } 1171e8d8bef9SDimitry Andric 1172cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 1173cb14a3feSDimitry Andric unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const { 1174e8d8bef9SDimitry Andric return do_unshift(__st, __to, __to_end, __to_nxt); 1175e8d8bef9SDimitry Andric } 1176e8d8bef9SDimitry Andric 1177cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI result 1178cb14a3feSDimitry Andric in(state_type& __st, 1179cb14a3feSDimitry Andric const extern_type* __frm, 1180cb14a3feSDimitry Andric const extern_type* __frm_end, 1181cb14a3feSDimitry Andric const extern_type*& __frm_nxt, 1182cb14a3feSDimitry Andric intern_type* __to, 1183cb14a3feSDimitry Andric intern_type* __to_end, 1184cb14a3feSDimitry Andric intern_type*& __to_nxt) const { 1185e8d8bef9SDimitry Andric return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt); 1186e8d8bef9SDimitry Andric } 1187e8d8bef9SDimitry Andric 1188cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int encoding() const _NOEXCEPT { return do_encoding(); } 1189e8d8bef9SDimitry Andric 1190cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI bool always_noconv() const _NOEXCEPT { return do_always_noconv(); } 1191e8d8bef9SDimitry Andric 1192cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int 1193cb14a3feSDimitry Andric length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const { 1194e8d8bef9SDimitry Andric return do_length(__st, __frm, __end, __mx); 1195e8d8bef9SDimitry Andric } 1196e8d8bef9SDimitry Andric 1197cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI int max_length() const _NOEXCEPT { return do_max_length(); } 1198e8d8bef9SDimitry Andric 1199e8d8bef9SDimitry Andric static locale::id id; 1200e8d8bef9SDimitry Andric 1201e8d8bef9SDimitry Andricprotected: 1202cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit codecvt(const char*, size_t __refs = 0) : locale::facet(__refs) {} 1203e8d8bef9SDimitry Andric 1204bdd1243dSDimitry Andric ~codecvt() override; 1205e8d8bef9SDimitry Andric 1206cb14a3feSDimitry Andric virtual result 1207cb14a3feSDimitry Andric do_out(state_type& __st, 1208cb14a3feSDimitry Andric const intern_type* __frm, 1209cb14a3feSDimitry Andric const intern_type* __frm_end, 1210cb14a3feSDimitry Andric const intern_type*& __frm_nxt, 1211cb14a3feSDimitry Andric extern_type* __to, 1212cb14a3feSDimitry Andric extern_type* __to_end, 1213cb14a3feSDimitry Andric extern_type*& __to_nxt) const; 1214cb14a3feSDimitry Andric virtual result 1215cb14a3feSDimitry Andric do_in(state_type& __st, 1216cb14a3feSDimitry Andric const extern_type* __frm, 1217cb14a3feSDimitry Andric const extern_type* __frm_end, 1218cb14a3feSDimitry Andric const extern_type*& __frm_nxt, 1219cb14a3feSDimitry Andric intern_type* __to, 1220cb14a3feSDimitry Andric intern_type* __to_end, 1221cb14a3feSDimitry Andric intern_type*& __to_nxt) const; 1222cb14a3feSDimitry Andric virtual result do_unshift(state_type& __st, extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const; 1223e8d8bef9SDimitry Andric virtual int do_encoding() const _NOEXCEPT; 1224e8d8bef9SDimitry Andric virtual bool do_always_noconv() const _NOEXCEPT; 1225e8d8bef9SDimitry Andric virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const; 1226e8d8bef9SDimitry Andric virtual int do_max_length() const _NOEXCEPT; 1227e8d8bef9SDimitry Andric}; 1228e8d8bef9SDimitry Andric 1229e8d8bef9SDimitry Andric#endif 1230e8d8bef9SDimitry Andric 12310b57cec5SDimitry Andric// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname 12320b57cec5SDimitry Andric 12330b57cec5SDimitry Andrictemplate <class _InternT, class _ExternT, class _StateT> 1234cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> { 12350b57cec5SDimitry Andricpublic: 1236cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit codecvt_byname(const char* __nm, size_t __refs = 0) 12370b57cec5SDimitry Andric : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {} 1238cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI explicit codecvt_byname(const string& __nm, size_t __refs = 0) 12390b57cec5SDimitry Andric : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {} 1240cb14a3feSDimitry Andric 12410b57cec5SDimitry Andricprotected: 1242bdd1243dSDimitry Andric ~codecvt_byname() override; 12430b57cec5SDimitry Andric}; 12440b57cec5SDimitry Andric 1245e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_PUSH 12460b57cec5SDimitry Andrictemplate <class _InternT, class _ExternT, class _StateT> 1247cb14a3feSDimitry Andriccodecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname() {} 1248e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_POP 12490b57cec5SDimitry Andric 125081ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>; 1251349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 125281ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>; 1253349cc55cSDimitry Andric#endif 1254*0fca6ea1SDimitry Andricextern template class _LIBCPP_DEPRECATED_IN_CXX20 1255*0fca6ea1SDimitry Andric_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>; // deprecated in C++20 1256*0fca6ea1SDimitry Andricextern template class _LIBCPP_DEPRECATED_IN_CXX20 1257*0fca6ea1SDimitry Andric_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>; // deprecated in C++20 1258fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T 125981ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>; // C++20 126081ad6265SDimitry Andricextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>; // C++20 1261e8d8bef9SDimitry Andric#endif 12620b57cec5SDimitry Andric 12630b57cec5SDimitry Andrictemplate <size_t _Np> 1264cb14a3feSDimitry Andricstruct __narrow_to_utf8 { 12650b57cec5SDimitry Andric template <class _OutputIterator, class _CharT> 1266cb14a3feSDimitry Andric _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const; 12670b57cec5SDimitry Andric}; 12680b57cec5SDimitry Andric 12690b57cec5SDimitry Andrictemplate <> 1270cb14a3feSDimitry Andricstruct __narrow_to_utf8<8> { 12710b57cec5SDimitry Andric template <class _OutputIterator, class _CharT> 1272cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const { 12730b57cec5SDimitry Andric for (; __wb < __we; ++__wb, ++__s) 12740b57cec5SDimitry Andric *__s = *__wb; 12750b57cec5SDimitry Andric return __s; 12760b57cec5SDimitry Andric } 12770b57cec5SDimitry Andric}; 12780b57cec5SDimitry Andric 1279e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_PUSH 12800b57cec5SDimitry Andrictemplate <> 1281cb14a3feSDimitry Andricstruct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<16> : public codecvt<char16_t, char, mbstate_t> { 1282cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {} 1283e8d8bef9SDimitry Andric _LIBCPP_SUPPRESS_DEPRECATED_POP 12840b57cec5SDimitry Andric 1285bdd1243dSDimitry Andric ~__narrow_to_utf8() override; 12860b57cec5SDimitry Andric 12870b57cec5SDimitry Andric template <class _OutputIterator, class _CharT> 1288cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const { 12890b57cec5SDimitry Andric result __r = ok; 12900b57cec5SDimitry Andric mbstate_t __mb; 1291cb14a3feSDimitry Andric while (__wb < __we && __r != error) { 12920b57cec5SDimitry Andric const int __sz = 32; 12930b57cec5SDimitry Andric char __buf[__sz]; 12940b57cec5SDimitry Andric char* __bn; 12950b57cec5SDimitry Andric const char16_t* __wn = (const char16_t*)__wb; 1296cb14a3feSDimitry Andric __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn, __buf, __buf + __sz, __bn); 12970b57cec5SDimitry Andric if (__r == codecvt_base::error || __wn == (const char16_t*)__wb) 12980b57cec5SDimitry Andric __throw_runtime_error("locale not supported"); 12990b57cec5SDimitry Andric for (const char* __p = __buf; __p < __bn; ++__p, ++__s) 13000b57cec5SDimitry Andric *__s = *__p; 13010b57cec5SDimitry Andric __wb = (const _CharT*)__wn; 13020b57cec5SDimitry Andric } 13030b57cec5SDimitry Andric return __s; 13040b57cec5SDimitry Andric } 13050b57cec5SDimitry Andric}; 13060b57cec5SDimitry Andric 1307e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_PUSH 13080b57cec5SDimitry Andrictemplate <> 1309cb14a3feSDimitry Andricstruct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<32> : public codecvt<char32_t, char, mbstate_t> { 1310cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {} 1311e8d8bef9SDimitry Andric _LIBCPP_SUPPRESS_DEPRECATED_POP 13120b57cec5SDimitry Andric 1313bdd1243dSDimitry Andric ~__narrow_to_utf8() override; 13140b57cec5SDimitry Andric 13150b57cec5SDimitry Andric template <class _OutputIterator, class _CharT> 1316cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const { 13170b57cec5SDimitry Andric result __r = ok; 13180b57cec5SDimitry Andric mbstate_t __mb; 1319cb14a3feSDimitry Andric while (__wb < __we && __r != error) { 13200b57cec5SDimitry Andric const int __sz = 32; 13210b57cec5SDimitry Andric char __buf[__sz]; 13220b57cec5SDimitry Andric char* __bn; 13230b57cec5SDimitry Andric const char32_t* __wn = (const char32_t*)__wb; 1324cb14a3feSDimitry Andric __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn, __buf, __buf + __sz, __bn); 13250b57cec5SDimitry Andric if (__r == codecvt_base::error || __wn == (const char32_t*)__wb) 13260b57cec5SDimitry Andric __throw_runtime_error("locale not supported"); 13270b57cec5SDimitry Andric for (const char* __p = __buf; __p < __bn; ++__p, ++__s) 13280b57cec5SDimitry Andric *__s = *__p; 13290b57cec5SDimitry Andric __wb = (const _CharT*)__wn; 13300b57cec5SDimitry Andric } 13310b57cec5SDimitry Andric return __s; 13320b57cec5SDimitry Andric } 13330b57cec5SDimitry Andric}; 13340b57cec5SDimitry Andric 13350b57cec5SDimitry Andrictemplate <size_t _Np> 1336cb14a3feSDimitry Andricstruct __widen_from_utf8 { 13370b57cec5SDimitry Andric template <class _OutputIterator> 1338cb14a3feSDimitry Andric _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const; 13390b57cec5SDimitry Andric}; 13400b57cec5SDimitry Andric 13410b57cec5SDimitry Andrictemplate <> 1342cb14a3feSDimitry Andricstruct __widen_from_utf8<8> { 13430b57cec5SDimitry Andric template <class _OutputIterator> 1344cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const { 13450b57cec5SDimitry Andric for (; __nb < __ne; ++__nb, ++__s) 13460b57cec5SDimitry Andric *__s = *__nb; 13470b57cec5SDimitry Andric return __s; 13480b57cec5SDimitry Andric } 13490b57cec5SDimitry Andric}; 13500b57cec5SDimitry Andric 1351e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_PUSH 13520b57cec5SDimitry Andrictemplate <> 1353cb14a3feSDimitry Andricstruct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<16> : public codecvt<char16_t, char, mbstate_t> { 1354cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {} 1355e8d8bef9SDimitry Andric _LIBCPP_SUPPRESS_DEPRECATED_POP 13560b57cec5SDimitry Andric 1357bdd1243dSDimitry Andric ~__widen_from_utf8() override; 13580b57cec5SDimitry Andric 13590b57cec5SDimitry Andric template <class _OutputIterator> 1360cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const { 13610b57cec5SDimitry Andric result __r = ok; 13620b57cec5SDimitry Andric mbstate_t __mb; 1363cb14a3feSDimitry Andric while (__nb < __ne && __r != error) { 13640b57cec5SDimitry Andric const int __sz = 32; 13650b57cec5SDimitry Andric char16_t __buf[__sz]; 13660b57cec5SDimitry Andric char16_t* __bn; 13670b57cec5SDimitry Andric const char* __nn = __nb; 1368cb14a3feSDimitry Andric __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn); 13690b57cec5SDimitry Andric if (__r == codecvt_base::error || __nn == __nb) 13700b57cec5SDimitry Andric __throw_runtime_error("locale not supported"); 13710b57cec5SDimitry Andric for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s) 1372e8d8bef9SDimitry Andric *__s = *__p; 13730b57cec5SDimitry Andric __nb = __nn; 13740b57cec5SDimitry Andric } 13750b57cec5SDimitry Andric return __s; 13760b57cec5SDimitry Andric } 13770b57cec5SDimitry Andric}; 13780b57cec5SDimitry Andric 1379e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_PUSH 13800b57cec5SDimitry Andrictemplate <> 1381cb14a3feSDimitry Andricstruct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<32> : public codecvt<char32_t, char, mbstate_t> { 1382cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {} 1383e8d8bef9SDimitry Andric _LIBCPP_SUPPRESS_DEPRECATED_POP 13840b57cec5SDimitry Andric 1385bdd1243dSDimitry Andric ~__widen_from_utf8() override; 13860b57cec5SDimitry Andric 13870b57cec5SDimitry Andric template <class _OutputIterator> 1388cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _OutputIterator operator()(_OutputIterator __s, const char* __nb, const char* __ne) const { 13890b57cec5SDimitry Andric result __r = ok; 13900b57cec5SDimitry Andric mbstate_t __mb; 1391cb14a3feSDimitry Andric while (__nb < __ne && __r != error) { 13920b57cec5SDimitry Andric const int __sz = 32; 13930b57cec5SDimitry Andric char32_t __buf[__sz]; 13940b57cec5SDimitry Andric char32_t* __bn; 13950b57cec5SDimitry Andric const char* __nn = __nb; 1396cb14a3feSDimitry Andric __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb + __sz : __ne, __nn, __buf, __buf + __sz, __bn); 13970b57cec5SDimitry Andric if (__r == codecvt_base::error || __nn == __nb) 13980b57cec5SDimitry Andric __throw_runtime_error("locale not supported"); 13990b57cec5SDimitry Andric for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s) 1400e8d8bef9SDimitry Andric *__s = *__p; 14010b57cec5SDimitry Andric __nb = __nn; 14020b57cec5SDimitry Andric } 14030b57cec5SDimitry Andric return __s; 14040b57cec5SDimitry Andric } 14050b57cec5SDimitry Andric}; 14060b57cec5SDimitry Andric 14070b57cec5SDimitry Andric// template <class charT> class numpunct 14080b57cec5SDimitry Andric 1409cb14a3feSDimitry Andrictemplate <class _CharT> 1410cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS numpunct; 14110b57cec5SDimitry Andric 14120b57cec5SDimitry Andrictemplate <> 1413cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI numpunct<char> : public locale::facet { 14140b57cec5SDimitry Andricpublic: 14150b57cec5SDimitry Andric typedef char char_type; 14160b57cec5SDimitry Andric typedef basic_string<char_type> string_type; 14170b57cec5SDimitry Andric 14180b57cec5SDimitry Andric explicit numpunct(size_t __refs = 0); 14190b57cec5SDimitry Andric 14205f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); } 14215f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); } 14225f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); } 14235f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); } 14245f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); } 14250b57cec5SDimitry Andric 14260b57cec5SDimitry Andric static locale::id id; 14270b57cec5SDimitry Andric 14280b57cec5SDimitry Andricprotected: 1429bdd1243dSDimitry Andric ~numpunct() override; 14300b57cec5SDimitry Andric virtual char_type do_decimal_point() const; 14310b57cec5SDimitry Andric virtual char_type do_thousands_sep() const; 14320b57cec5SDimitry Andric virtual string do_grouping() const; 14330b57cec5SDimitry Andric virtual string_type do_truename() const; 14340b57cec5SDimitry Andric virtual string_type do_falsename() const; 14350b57cec5SDimitry Andric 14360b57cec5SDimitry Andric char_type __decimal_point_; 14370b57cec5SDimitry Andric char_type __thousands_sep_; 14380b57cec5SDimitry Andric string __grouping_; 14390b57cec5SDimitry Andric}; 14400b57cec5SDimitry Andric 1441349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 14420b57cec5SDimitry Andrictemplate <> 1443cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI numpunct<wchar_t> : public locale::facet { 14440b57cec5SDimitry Andricpublic: 14450b57cec5SDimitry Andric typedef wchar_t char_type; 14460b57cec5SDimitry Andric typedef basic_string<char_type> string_type; 14470b57cec5SDimitry Andric 14480b57cec5SDimitry Andric explicit numpunct(size_t __refs = 0); 14490b57cec5SDimitry Andric 14505f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type decimal_point() const { return do_decimal_point(); } 14515f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI char_type thousands_sep() const { return do_thousands_sep(); } 14525f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI string grouping() const { return do_grouping(); } 14535f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type truename() const { return do_truename(); } 14545f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI string_type falsename() const { return do_falsename(); } 14550b57cec5SDimitry Andric 14560b57cec5SDimitry Andric static locale::id id; 14570b57cec5SDimitry Andric 14580b57cec5SDimitry Andricprotected: 1459bdd1243dSDimitry Andric ~numpunct() override; 14600b57cec5SDimitry Andric virtual char_type do_decimal_point() const; 14610b57cec5SDimitry Andric virtual char_type do_thousands_sep() const; 14620b57cec5SDimitry Andric virtual string do_grouping() const; 14630b57cec5SDimitry Andric virtual string_type do_truename() const; 14640b57cec5SDimitry Andric virtual string_type do_falsename() const; 14650b57cec5SDimitry Andric 14660b57cec5SDimitry Andric char_type __decimal_point_; 14670b57cec5SDimitry Andric char_type __thousands_sep_; 14680b57cec5SDimitry Andric string __grouping_; 14690b57cec5SDimitry Andric}; 1470349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS 14710b57cec5SDimitry Andric 14720b57cec5SDimitry Andric// template <class charT> class numpunct_byname 14730b57cec5SDimitry Andric 1474cb14a3feSDimitry Andrictemplate <class _CharT> 1475cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS numpunct_byname; 14760b57cec5SDimitry Andric 14770b57cec5SDimitry Andrictemplate <> 1478cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<char> : public numpunct<char> { 14790b57cec5SDimitry Andricpublic: 14800b57cec5SDimitry Andric typedef char char_type; 14810b57cec5SDimitry Andric typedef basic_string<char_type> string_type; 14820b57cec5SDimitry Andric 14830b57cec5SDimitry Andric explicit numpunct_byname(const char* __nm, size_t __refs = 0); 14840b57cec5SDimitry Andric explicit numpunct_byname(const string& __nm, size_t __refs = 0); 14850b57cec5SDimitry Andric 14860b57cec5SDimitry Andricprotected: 1487bdd1243dSDimitry Andric ~numpunct_byname() override; 14880b57cec5SDimitry Andric 14890b57cec5SDimitry Andricprivate: 14900b57cec5SDimitry Andric void __init(const char*); 14910b57cec5SDimitry Andric}; 14920b57cec5SDimitry Andric 1493349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 14940b57cec5SDimitry Andrictemplate <> 1495cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<wchar_t> : public numpunct<wchar_t> { 14960b57cec5SDimitry Andricpublic: 14970b57cec5SDimitry Andric typedef wchar_t char_type; 14980b57cec5SDimitry Andric typedef basic_string<char_type> string_type; 14990b57cec5SDimitry Andric 15000b57cec5SDimitry Andric explicit numpunct_byname(const char* __nm, size_t __refs = 0); 15010b57cec5SDimitry Andric explicit numpunct_byname(const string& __nm, size_t __refs = 0); 15020b57cec5SDimitry Andric 15030b57cec5SDimitry Andricprotected: 1504bdd1243dSDimitry Andric ~numpunct_byname() override; 15050b57cec5SDimitry Andric 15060b57cec5SDimitry Andricprivate: 15070b57cec5SDimitry Andric void __init(const char*); 15080b57cec5SDimitry Andric}; 1509349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS 15100b57cec5SDimitry Andric 15110b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 15120b57cec5SDimitry Andric 15130b57cec5SDimitry Andric#endif // _LIBCPP___LOCALE 1514