xref: /openbsd-src/gnu/llvm/libcxx/include/__locale (revision dc37c87a60a1e3d67c2ac5d5c5b9fc1e4af89632)
146035553Spatrick// -*- C++ -*-
246035553Spatrick//===----------------------------------------------------------------------===//
346035553Spatrick//
446035553Spatrick// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
546035553Spatrick// See https://llvm.org/LICENSE.txt for license information.
646035553Spatrick// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
746035553Spatrick//
846035553Spatrick//===----------------------------------------------------------------------===//
946035553Spatrick
1046035553Spatrick#ifndef _LIBCPP___LOCALE
1146035553Spatrick#define _LIBCPP___LOCALE
1246035553Spatrick
13a0747c9fSpatrick#include <__availability>
1446035553Spatrick#include <__config>
1546035553Spatrick#include <cctype>
16*dc37c87aSrobert#include <cstdint>
1746035553Spatrick#include <locale.h>
18*dc37c87aSrobert#include <mutex>
19*dc37c87aSrobert#include <string>
20*dc37c87aSrobert
21*dc37c87aSrobert// Some platforms require more includes than others. Keep the includes on all plaforms for now.
22*dc37c87aSrobert#include <cstddef>
2346035553Spatrick#include <cstring>
24*dc37c87aSrobert
25*dc37c87aSrobert#if defined(_LIBCPP_MSVCRT_LIKE)
26a0747c9fSpatrick# include <__support/win32/locale_win32.h>
27a0747c9fSpatrick#elif defined(_AIX) || defined(__MVS__)
28a0747c9fSpatrick# include <__support/ibm/xlocale.h>
2946035553Spatrick#elif defined(__ANDROID__)
30a0747c9fSpatrick# include <__support/android/locale_bionic.h>
3146035553Spatrick#elif defined(__sun__)
32a0747c9fSpatrick# include <__support/solaris/xlocale.h>
33*dc37c87aSrobert# include <xlocale.h>
34a0747c9fSpatrick#elif defined(_NEWLIB_VERSION)
35a0747c9fSpatrick# include <__support/newlib/xlocale.h>
36a0747c9fSpatrick#elif defined(__OpenBSD__)
37a0747c9fSpatrick# include <__support/openbsd/xlocale.h>
38*dc37c87aSrobert#elif (defined(__APPLE__) || defined(__FreeBSD__))
3946035553Spatrick# include <xlocale.h>
4046035553Spatrick#elif defined(__Fuchsia__)
41a0747c9fSpatrick# include <__support/fuchsia/xlocale.h>
4246035553Spatrick#elif defined(__wasi__)
4346035553Spatrick// WASI libc uses musl's locales support.
44a0747c9fSpatrick# include <__support/musl/xlocale.h>
4546035553Spatrick#elif defined(_LIBCPP_HAS_MUSL_LIBC)
46a0747c9fSpatrick# include <__support/musl/xlocale.h>
4746035553Spatrick#endif
4846035553Spatrick
4946035553Spatrick#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5046035553Spatrick#  pragma GCC system_header
5146035553Spatrick#endif
5246035553Spatrick
5346035553Spatrick_LIBCPP_BEGIN_NAMESPACE_STD
5446035553Spatrick
5546035553Spatrick#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
5646035553Spatrickstruct __libcpp_locale_guard {
5746035553Spatrick  _LIBCPP_INLINE_VISIBILITY
5846035553Spatrick  __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
5946035553Spatrick
6046035553Spatrick  _LIBCPP_INLINE_VISIBILITY
6146035553Spatrick  ~__libcpp_locale_guard() {
6246035553Spatrick    if (__old_loc_)
6346035553Spatrick      uselocale(__old_loc_);
6446035553Spatrick  }
6546035553Spatrick
6646035553Spatrick  locale_t __old_loc_;
6746035553Spatrickprivate:
6846035553Spatrick  __libcpp_locale_guard(__libcpp_locale_guard const&);
6946035553Spatrick  __libcpp_locale_guard& operator=(__libcpp_locale_guard const&);
7046035553Spatrick};
7146035553Spatrick#elif defined(_LIBCPP_MSVCRT_LIKE)
7246035553Spatrickstruct __libcpp_locale_guard {
7346035553Spatrick    __libcpp_locale_guard(locale_t __l) :
7446035553Spatrick        __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) {
7546035553Spatrick      // Setting the locale can be expensive even when the locale given is
7646035553Spatrick      // already the current locale, so do an explicit check to see if the
7746035553Spatrick      // current locale is already the one we want.
7846035553Spatrick      const char* __lc = __setlocale(nullptr);
7946035553Spatrick      // If every category is the same, the locale string will simply be the
8046035553Spatrick      // locale name, otherwise it will be a semicolon-separated string listing
8146035553Spatrick      // each category.  In the second case, we know at least one category won't
8246035553Spatrick      // be what we want, so we only have to check the first case.
83a0747c9fSpatrick      if (_VSTD::strcmp(__l.__get_locale(), __lc) != 0) {
8446035553Spatrick        __locale_all = _strdup(__lc);
8546035553Spatrick        if (__locale_all == nullptr)
8646035553Spatrick          __throw_bad_alloc();
8746035553Spatrick        __setlocale(__l.__get_locale());
8846035553Spatrick      }
8946035553Spatrick    }
9046035553Spatrick    ~__libcpp_locale_guard() {
9146035553Spatrick      // The CRT documentation doesn't explicitly say, but setlocale() does the
9246035553Spatrick      // right thing when given a semicolon-separated list of locale settings
9346035553Spatrick      // for the different categories in the same format as returned by
9446035553Spatrick      // setlocale(LC_ALL, nullptr).
9546035553Spatrick      if (__locale_all != nullptr) {
9646035553Spatrick        __setlocale(__locale_all);
9746035553Spatrick        free(__locale_all);
9846035553Spatrick      }
9946035553Spatrick      _configthreadlocale(__status);
10046035553Spatrick    }
10146035553Spatrick    static const char* __setlocale(const char* __locale) {
10246035553Spatrick      const char* __new_locale = setlocale(LC_ALL, __locale);
10346035553Spatrick      if (__new_locale == nullptr)
10446035553Spatrick        __throw_bad_alloc();
10546035553Spatrick      return __new_locale;
10646035553Spatrick    }
10746035553Spatrick    int __status;
10846035553Spatrick    char* __locale_all = nullptr;
10946035553Spatrick};
11046035553Spatrick#endif
11146035553Spatrick
11246035553Spatrickclass _LIBCPP_TYPE_VIS locale;
11346035553Spatrick
11446035553Spatricktemplate <class _Facet>
11546035553Spatrick_LIBCPP_INLINE_VISIBILITY
11646035553Spatrickbool
11746035553Spatrickhas_facet(const locale&) _NOEXCEPT;
11846035553Spatrick
11946035553Spatricktemplate <class _Facet>
12046035553Spatrick_LIBCPP_INLINE_VISIBILITY
12146035553Spatrickconst _Facet&
12246035553Spatrickuse_facet(const locale&);
12346035553Spatrick
12446035553Spatrickclass _LIBCPP_TYPE_VIS locale
12546035553Spatrick{
12646035553Spatrickpublic:
12746035553Spatrick    // types:
12846035553Spatrick    class _LIBCPP_TYPE_VIS facet;
12946035553Spatrick    class _LIBCPP_TYPE_VIS id;
13046035553Spatrick
13146035553Spatrick    typedef int category;
13246035553Spatrick    _LIBCPP_AVAILABILITY_LOCALE_CATEGORY
13346035553Spatrick    static const category // values assigned here are for exposition only
13446035553Spatrick        none     = 0,
13546035553Spatrick        collate  = LC_COLLATE_MASK,
13646035553Spatrick        ctype    = LC_CTYPE_MASK,
13746035553Spatrick        monetary = LC_MONETARY_MASK,
13846035553Spatrick        numeric  = LC_NUMERIC_MASK,
13946035553Spatrick        time     = LC_TIME_MASK,
14046035553Spatrick        messages = LC_MESSAGES_MASK,
14146035553Spatrick        all = collate | ctype | monetary | numeric | time | messages;
14246035553Spatrick
14346035553Spatrick    // construct/copy/destroy:
14446035553Spatrick    locale()  _NOEXCEPT;
14546035553Spatrick    locale(const locale&)  _NOEXCEPT;
14646035553Spatrick    explicit locale(const char*);
14746035553Spatrick    explicit locale(const string&);
14846035553Spatrick    locale(const locale&, const char*, category);
14946035553Spatrick    locale(const locale&, const string&, category);
15046035553Spatrick    template <class _Facet>
15146035553Spatrick        _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
15246035553Spatrick    locale(const locale&, const locale&, category);
15346035553Spatrick
15446035553Spatrick    ~locale();
15546035553Spatrick
15646035553Spatrick    const locale& operator=(const locale&)  _NOEXCEPT;
15746035553Spatrick
15846035553Spatrick    template <class _Facet>
15946035553Spatrick      _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
16046035553Spatrick      locale combine(const locale&) const;
16146035553Spatrick
16246035553Spatrick    // locale operations:
16346035553Spatrick    string name() const;
16446035553Spatrick    bool operator==(const locale&) const;
16546035553Spatrick    bool operator!=(const locale& __y) const {return !(*this == __y);}
16646035553Spatrick    template <class _CharT, class _Traits, class _Allocator>
16746035553Spatrick      _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
16846035553Spatrick      bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
16946035553Spatrick                      const basic_string<_CharT, _Traits, _Allocator>&) const;
17046035553Spatrick
17146035553Spatrick    // global locale objects:
17246035553Spatrick    static locale global(const locale&);
17346035553Spatrick    static const locale& classic();
17446035553Spatrick
17546035553Spatrickprivate:
17646035553Spatrick    class __imp;
17746035553Spatrick    __imp* __locale_;
17846035553Spatrick
17946035553Spatrick    void __install_ctor(const locale&, facet*, long);
18046035553Spatrick    static locale& __global();
18146035553Spatrick    bool has_facet(id&) const;
18246035553Spatrick    const facet* use_facet(id&) const;
18346035553Spatrick
18446035553Spatrick    template <class _Facet> friend bool has_facet(const locale&)  _NOEXCEPT;
18546035553Spatrick    template <class _Facet> friend const _Facet& use_facet(const locale&);
18646035553Spatrick};
18746035553Spatrick
18846035553Spatrickclass _LIBCPP_TYPE_VIS locale::facet
18946035553Spatrick    : public __shared_count
19046035553Spatrick{
19146035553Spatrickprotected:
19246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
19346035553Spatrick    explicit facet(size_t __refs = 0)
19446035553Spatrick        : __shared_count(static_cast<long>(__refs)-1) {}
19546035553Spatrick
196*dc37c87aSrobert    ~facet() override;
19746035553Spatrick
19846035553Spatrick//    facet(const facet&) = delete;     // effectively done in __shared_count
19946035553Spatrick//    void operator=(const facet&) = delete;
20046035553Spatrickprivate:
201*dc37c87aSrobert    void __on_zero_shared() _NOEXCEPT override;
20246035553Spatrick};
20346035553Spatrick
20446035553Spatrickclass _LIBCPP_TYPE_VIS locale::id
20546035553Spatrick{
20646035553Spatrick    once_flag      __flag_;
20746035553Spatrick    int32_t        __id_;
20846035553Spatrick
20946035553Spatrick    static int32_t __next_id;
21046035553Spatrickpublic:
21146035553Spatrick    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
212*dc37c87aSrobert    void operator=(const id&) = delete;
213*dc37c87aSrobert    id(const id&) = delete;
214*dc37c87aSrobert
21546035553Spatrickprivate:
21646035553Spatrick    void __init();
21746035553Spatrickpublic:  // only needed for tests
21846035553Spatrick    long __get();
21946035553Spatrick
22046035553Spatrick    friend class locale;
22146035553Spatrick    friend class locale::__imp;
22246035553Spatrick};
22346035553Spatrick
22446035553Spatricktemplate <class _Facet>
22546035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
22646035553Spatricklocale::locale(const locale& __other, _Facet* __f)
22746035553Spatrick{
22846035553Spatrick    __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
22946035553Spatrick}
23046035553Spatrick
23146035553Spatricktemplate <class _Facet>
23246035553Spatricklocale
23346035553Spatricklocale::combine(const locale& __other) const
23446035553Spatrick{
23546035553Spatrick    if (!_VSTD::has_facet<_Facet>(__other))
23646035553Spatrick        __throw_runtime_error("locale::combine: locale missing facet");
23746035553Spatrick
23846035553Spatrick    return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
23946035553Spatrick}
24046035553Spatrick
24146035553Spatricktemplate <class _Facet>
24246035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
24346035553Spatrickbool
24446035553Spatrickhas_facet(const locale& __l)  _NOEXCEPT
24546035553Spatrick{
24646035553Spatrick    return __l.has_facet(_Facet::id);
24746035553Spatrick}
24846035553Spatrick
24946035553Spatricktemplate <class _Facet>
25046035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
25146035553Spatrickconst _Facet&
25246035553Spatrickuse_facet(const locale& __l)
25346035553Spatrick{
25446035553Spatrick    return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
25546035553Spatrick}
25646035553Spatrick
25746035553Spatrick// template <class _CharT> class collate;
25846035553Spatrick
25946035553Spatricktemplate <class _CharT>
26046035553Spatrickclass _LIBCPP_TEMPLATE_VIS collate
26146035553Spatrick    : public locale::facet
26246035553Spatrick{
26346035553Spatrickpublic:
26446035553Spatrick    typedef _CharT char_type;
26546035553Spatrick    typedef basic_string<char_type> string_type;
26646035553Spatrick
26746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
26846035553Spatrick    explicit collate(size_t __refs = 0)
26946035553Spatrick        : locale::facet(__refs) {}
27046035553Spatrick
27146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
27246035553Spatrick    int compare(const char_type* __lo1, const char_type* __hi1,
27346035553Spatrick                const char_type* __lo2, const char_type* __hi2) const
27446035553Spatrick    {
27546035553Spatrick        return do_compare(__lo1, __hi1, __lo2, __hi2);
27646035553Spatrick    }
27746035553Spatrick
27846035553Spatrick    // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work
27946035553Spatrick    // around a dllimport bug that expects an external instantiation.
28046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
28146035553Spatrick    _LIBCPP_ALWAYS_INLINE
28246035553Spatrick    string_type transform(const char_type* __lo, const char_type* __hi) const
28346035553Spatrick    {
28446035553Spatrick        return do_transform(__lo, __hi);
28546035553Spatrick    }
28646035553Spatrick
28746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
28846035553Spatrick    long hash(const char_type* __lo, const char_type* __hi) const
28946035553Spatrick    {
29046035553Spatrick        return do_hash(__lo, __hi);
29146035553Spatrick    }
29246035553Spatrick
29346035553Spatrick    static locale::id id;
29446035553Spatrick
29546035553Spatrickprotected:
296*dc37c87aSrobert    ~collate() override;
29746035553Spatrick    virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
29846035553Spatrick                           const char_type* __lo2, const char_type* __hi2) const;
29946035553Spatrick    virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
30046035553Spatrick        {return string_type(__lo, __hi);}
30146035553Spatrick    virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
30246035553Spatrick};
30346035553Spatrick
30446035553Spatricktemplate <class _CharT> locale::id collate<_CharT>::id;
30546035553Spatrick
30646035553Spatricktemplate <class _CharT>
30746035553Spatrickcollate<_CharT>::~collate()
30846035553Spatrick{
30946035553Spatrick}
31046035553Spatrick
31146035553Spatricktemplate <class _CharT>
31246035553Spatrickint
31346035553Spatrickcollate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
31446035553Spatrick                            const char_type* __lo2, const char_type* __hi2) const
31546035553Spatrick{
31646035553Spatrick    for (; __lo2 != __hi2; ++__lo1, ++__lo2)
31746035553Spatrick    {
31846035553Spatrick        if (__lo1 == __hi1 || *__lo1 < *__lo2)
31946035553Spatrick            return -1;
32046035553Spatrick        if (*__lo2 < *__lo1)
32146035553Spatrick            return 1;
32246035553Spatrick    }
32346035553Spatrick    return __lo1 != __hi1;
32446035553Spatrick}
32546035553Spatrick
32646035553Spatricktemplate <class _CharT>
32746035553Spatricklong
32846035553Spatrickcollate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
32946035553Spatrick{
33046035553Spatrick    size_t __h = 0;
33146035553Spatrick    const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
33246035553Spatrick    const size_t __mask = size_t(0xF) << (__sr + 4);
33346035553Spatrick    for(const char_type* __p = __lo; __p != __hi; ++__p)
33446035553Spatrick    {
33546035553Spatrick        __h = (__h << 4) + static_cast<size_t>(*__p);
33646035553Spatrick        size_t __g = __h & __mask;
33746035553Spatrick        __h ^= __g | (__g >> __sr);
33846035553Spatrick    }
33946035553Spatrick    return static_cast<long>(__h);
34046035553Spatrick}
34146035553Spatrick
342*dc37c87aSrobertextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>;
343*dc37c87aSrobert#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
344*dc37c87aSrobertextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>;
345*dc37c87aSrobert#endif
34646035553Spatrick
34746035553Spatrick// template <class CharT> class collate_byname;
34846035553Spatrick
34946035553Spatricktemplate <class _CharT> class _LIBCPP_TEMPLATE_VIS collate_byname;
35046035553Spatrick
35146035553Spatricktemplate <>
35246035553Spatrickclass _LIBCPP_TYPE_VIS collate_byname<char>
35346035553Spatrick    : public collate<char>
35446035553Spatrick{
355*dc37c87aSrobert    locale_t __l_;
35646035553Spatrickpublic:
35746035553Spatrick    typedef char char_type;
35846035553Spatrick    typedef basic_string<char_type> string_type;
35946035553Spatrick
36046035553Spatrick    explicit collate_byname(const char* __n, size_t __refs = 0);
36146035553Spatrick    explicit collate_byname(const string& __n, size_t __refs = 0);
36246035553Spatrick
36346035553Spatrickprotected:
364*dc37c87aSrobert    ~collate_byname() override;
365*dc37c87aSrobert    int do_compare(const char_type* __lo1, const char_type* __hi1,
366*dc37c87aSrobert                   const char_type* __lo2, const char_type* __hi2) const override;
367*dc37c87aSrobert    string_type do_transform(const char_type* __lo, const char_type* __hi) const override;
36846035553Spatrick};
36946035553Spatrick
370*dc37c87aSrobert#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
37146035553Spatricktemplate <>
37246035553Spatrickclass _LIBCPP_TYPE_VIS collate_byname<wchar_t>
37346035553Spatrick    : public collate<wchar_t>
37446035553Spatrick{
375*dc37c87aSrobert    locale_t __l_;
37646035553Spatrickpublic:
37746035553Spatrick    typedef wchar_t char_type;
37846035553Spatrick    typedef basic_string<char_type> string_type;
37946035553Spatrick
38046035553Spatrick    explicit collate_byname(const char* __n, size_t __refs = 0);
38146035553Spatrick    explicit collate_byname(const string& __n, size_t __refs = 0);
38246035553Spatrick
38346035553Spatrickprotected:
384*dc37c87aSrobert    ~collate_byname() override;
38546035553Spatrick
386*dc37c87aSrobert    int do_compare(const char_type* __lo1, const char_type* __hi1,
387*dc37c87aSrobert                   const char_type* __lo2, const char_type* __hi2) const override;
388*dc37c87aSrobert    string_type do_transform(const char_type* __lo, const char_type* __hi) const override;
38946035553Spatrick};
390*dc37c87aSrobert#endif
39146035553Spatrick
39246035553Spatricktemplate <class _CharT, class _Traits, class _Allocator>
39346035553Spatrickbool
39446035553Spatricklocale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
39546035553Spatrick                   const basic_string<_CharT, _Traits, _Allocator>& __y) const
39646035553Spatrick{
39746035553Spatrick    return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
39846035553Spatrick                                       __x.data(), __x.data() + __x.size(),
39946035553Spatrick                                       __y.data(), __y.data() + __y.size()) < 0;
40046035553Spatrick}
40146035553Spatrick
40246035553Spatrick// template <class charT> class ctype
40346035553Spatrick
40446035553Spatrickclass _LIBCPP_TYPE_VIS ctype_base
40546035553Spatrick{
40646035553Spatrickpublic:
407a0747c9fSpatrick#if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE)
408a0747c9fSpatrick    typedef unsigned long mask;
409a0747c9fSpatrick    static const mask space  = 1<<0;
410a0747c9fSpatrick    static const mask print  = 1<<1;
411a0747c9fSpatrick    static const mask cntrl  = 1<<2;
412a0747c9fSpatrick    static const mask upper  = 1<<3;
413a0747c9fSpatrick    static const mask lower  = 1<<4;
414a0747c9fSpatrick    static const mask alpha  = 1<<5;
415a0747c9fSpatrick    static const mask digit  = 1<<6;
416a0747c9fSpatrick    static const mask punct  = 1<<7;
417a0747c9fSpatrick    static const mask xdigit = 1<<8;
418a0747c9fSpatrick    static const mask blank  = 1<<9;
419a0747c9fSpatrick#if defined(__BIONIC__)
420a0747c9fSpatrick    // Historically this was a part of regex_traits rather than ctype_base. The
421a0747c9fSpatrick    // historical value of the constant is preserved for ABI compatibility.
422a0747c9fSpatrick    static const mask __regex_word = 0x8000;
423a0747c9fSpatrick#else
424a0747c9fSpatrick    static const mask __regex_word = 1<<10;
425a0747c9fSpatrick#endif // defined(__BIONIC__)
426a0747c9fSpatrick#elif defined(__GLIBC__)
42746035553Spatrick    typedef unsigned short mask;
42846035553Spatrick    static const mask space  = _ISspace;
42946035553Spatrick    static const mask print  = _ISprint;
43046035553Spatrick    static const mask cntrl  = _IScntrl;
43146035553Spatrick    static const mask upper  = _ISupper;
43246035553Spatrick    static const mask lower  = _ISlower;
43346035553Spatrick    static const mask alpha  = _ISalpha;
43446035553Spatrick    static const mask digit  = _ISdigit;
43546035553Spatrick    static const mask punct  = _ISpunct;
43646035553Spatrick    static const mask xdigit = _ISxdigit;
43746035553Spatrick    static const mask blank  = _ISblank;
43846035553Spatrick#if defined(__mips__)
43946035553Spatrick    static const mask __regex_word = static_cast<mask>(_ISbit(15));
44046035553Spatrick#else
44146035553Spatrick    static const mask __regex_word = 0x80;
44246035553Spatrick#endif
44346035553Spatrick#elif defined(_LIBCPP_MSVCRT_LIKE)
44446035553Spatrick    typedef unsigned short mask;
44546035553Spatrick    static const mask space  = _SPACE;
44646035553Spatrick    static const mask print  = _BLANK|_PUNCT|_ALPHA|_DIGIT;
44746035553Spatrick    static const mask cntrl  = _CONTROL;
44846035553Spatrick    static const mask upper  = _UPPER;
44946035553Spatrick    static const mask lower  = _LOWER;
45046035553Spatrick    static const mask alpha  = _ALPHA;
45146035553Spatrick    static const mask digit  = _DIGIT;
45246035553Spatrick    static const mask punct  = _PUNCT;
45346035553Spatrick    static const mask xdigit = _HEX;
45446035553Spatrick    static const mask blank  = _BLANK;
455*dc37c87aSrobert    static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used
45646035553Spatrick# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
457*dc37c87aSrobert# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
45846035553Spatrick#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
45946035553Spatrick# ifdef __APPLE__
46046035553Spatrick    typedef __uint32_t mask;
46146035553Spatrick# elif defined(__FreeBSD__)
46246035553Spatrick    typedef unsigned long mask;
46346035553Spatrick# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
46446035553Spatrick    typedef unsigned short mask;
46546035553Spatrick# endif
46646035553Spatrick    static const mask space  = _CTYPE_S;
46746035553Spatrick    static const mask print  = _CTYPE_R;
46846035553Spatrick    static const mask cntrl  = _CTYPE_C;
46946035553Spatrick    static const mask upper  = _CTYPE_U;
47046035553Spatrick    static const mask lower  = _CTYPE_L;
47146035553Spatrick    static const mask alpha  = _CTYPE_A;
47246035553Spatrick    static const mask digit  = _CTYPE_D;
47346035553Spatrick    static const mask punct  = _CTYPE_P;
47446035553Spatrick    static const mask xdigit = _CTYPE_X;
47546035553Spatrick
47646035553Spatrick# if defined(__NetBSD__)
47746035553Spatrick    static const mask blank  = _CTYPE_BL;
47846035553Spatrick    // NetBSD defines classes up to 0x2000
47946035553Spatrick    // see sys/ctype_bits.h, _CTYPE_Q
48046035553Spatrick    static const mask __regex_word = 0x8000;
48146035553Spatrick# else
48246035553Spatrick    static const mask blank  = _CTYPE_B;
48346035553Spatrick    static const mask __regex_word = 0x80;
48446035553Spatrick# endif
48546035553Spatrick#elif defined(__sun__) || defined(_AIX)
48646035553Spatrick    typedef unsigned int mask;
48746035553Spatrick    static const mask space  = _ISSPACE;
48846035553Spatrick    static const mask print  = _ISPRINT;
48946035553Spatrick    static const mask cntrl  = _ISCNTRL;
49046035553Spatrick    static const mask upper  = _ISUPPER;
49146035553Spatrick    static const mask lower  = _ISLOWER;
49246035553Spatrick    static const mask alpha  = _ISALPHA;
49346035553Spatrick    static const mask digit  = _ISDIGIT;
49446035553Spatrick    static const mask punct  = _ISPUNCT;
49546035553Spatrick    static const mask xdigit = _ISXDIGIT;
49646035553Spatrick    static const mask blank  = _ISBLANK;
497*dc37c87aSrobert# if defined(_AIX)
498*dc37c87aSrobert    static const mask __regex_word = 0x8000;
499*dc37c87aSrobert# else
50046035553Spatrick    static const mask __regex_word = 0x80;
501*dc37c87aSrobert# endif
50246035553Spatrick#elif defined(_NEWLIB_VERSION)
50346035553Spatrick    // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
50446035553Spatrick    typedef char mask;
50546035553Spatrick    static const mask space  = _S;
50646035553Spatrick    static const mask print  = _P | _U | _L | _N | _B;
50746035553Spatrick    static const mask cntrl  = _C;
50846035553Spatrick    static const mask upper  = _U;
50946035553Spatrick    static const mask lower  = _L;
51046035553Spatrick    static const mask alpha  = _U | _L;
51146035553Spatrick    static const mask digit  = _N;
51246035553Spatrick    static const mask punct  = _P;
51346035553Spatrick    static const mask xdigit = _X | _N;
51446035553Spatrick    static const mask blank  = _B;
515*dc37c87aSrobert    // mask is already fully saturated, use a different type in regex_type_traits.
516*dc37c87aSrobert    static const unsigned short __regex_word = 0x100;
51746035553Spatrick# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
51846035553Spatrick# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
51946035553Spatrick# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
520*dc37c87aSrobert#elif defined(__MVS__)
521*dc37c87aSrobert# if defined(__NATIVE_ASCII_F)
522*dc37c87aSrobert    typedef unsigned int mask;
523*dc37c87aSrobert    static const mask space  = _ISSPACE_A;
524*dc37c87aSrobert    static const mask print  = _ISPRINT_A;
525*dc37c87aSrobert    static const mask cntrl  = _ISCNTRL_A;
526*dc37c87aSrobert    static const mask upper  = _ISUPPER_A;
527*dc37c87aSrobert    static const mask lower  = _ISLOWER_A;
528*dc37c87aSrobert    static const mask alpha  = _ISALPHA_A;
529*dc37c87aSrobert    static const mask digit  = _ISDIGIT_A;
530*dc37c87aSrobert    static const mask punct  = _ISPUNCT_A;
531*dc37c87aSrobert    static const mask xdigit = _ISXDIGIT_A;
532*dc37c87aSrobert    static const mask blank  = _ISBLANK_A;
533*dc37c87aSrobert# else
534*dc37c87aSrobert    typedef unsigned short mask;
535*dc37c87aSrobert    static const mask space  = __ISSPACE;
536*dc37c87aSrobert    static const mask print  = __ISPRINT;
537*dc37c87aSrobert    static const mask cntrl  = __ISCNTRL;
538*dc37c87aSrobert    static const mask upper  = __ISUPPER;
539*dc37c87aSrobert    static const mask lower  = __ISLOWER;
540*dc37c87aSrobert    static const mask alpha  = __ISALPHA;
541*dc37c87aSrobert    static const mask digit  = __ISDIGIT;
542*dc37c87aSrobert    static const mask punct  = __ISPUNCT;
543*dc37c87aSrobert    static const mask xdigit = __ISXDIGIT;
544*dc37c87aSrobert    static const mask blank  = __ISBLANK;
545*dc37c87aSrobert# endif
546*dc37c87aSrobert    static const mask __regex_word = 0x8000;
54746035553Spatrick#else
548a0747c9fSpatrick# error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?
54946035553Spatrick#endif
55046035553Spatrick    static const mask alnum  = alpha | digit;
55146035553Spatrick    static const mask graph  = alnum | punct;
55246035553Spatrick
55346035553Spatrick    _LIBCPP_INLINE_VISIBILITY ctype_base() {}
554*dc37c87aSrobert
555*dc37c87aSrobert    static_assert((__regex_word & ~(std::make_unsigned<mask>::type)(space | print | cntrl | upper | lower | alpha |
556*dc37c87aSrobert                                                                    digit | punct | xdigit | blank)) == __regex_word,
557*dc37c87aSrobert                  "__regex_word can't overlap other bits");
55846035553Spatrick};
55946035553Spatrick
56046035553Spatricktemplate <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
56146035553Spatrick
562*dc37c87aSrobert#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
56346035553Spatricktemplate <>
56446035553Spatrickclass _LIBCPP_TYPE_VIS ctype<wchar_t>
56546035553Spatrick    : public locale::facet,
56646035553Spatrick      public ctype_base
56746035553Spatrick{
56846035553Spatrickpublic:
56946035553Spatrick    typedef wchar_t char_type;
57046035553Spatrick
57146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
57246035553Spatrick    explicit ctype(size_t __refs = 0)
57346035553Spatrick        : locale::facet(__refs) {}
57446035553Spatrick
57546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
57646035553Spatrick    bool is(mask __m, char_type __c) const
57746035553Spatrick    {
57846035553Spatrick        return do_is(__m, __c);
57946035553Spatrick    }
58046035553Spatrick
58146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
58246035553Spatrick    const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
58346035553Spatrick    {
58446035553Spatrick        return do_is(__low, __high, __vec);
58546035553Spatrick    }
58646035553Spatrick
58746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
58846035553Spatrick    const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
58946035553Spatrick    {
59046035553Spatrick        return do_scan_is(__m, __low, __high);
59146035553Spatrick    }
59246035553Spatrick
59346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
59446035553Spatrick    const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
59546035553Spatrick    {
59646035553Spatrick        return do_scan_not(__m, __low, __high);
59746035553Spatrick    }
59846035553Spatrick
59946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
60046035553Spatrick    char_type toupper(char_type __c) const
60146035553Spatrick    {
60246035553Spatrick        return do_toupper(__c);
60346035553Spatrick    }
60446035553Spatrick
60546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
60646035553Spatrick    const char_type* toupper(char_type* __low, const char_type* __high) const
60746035553Spatrick    {
60846035553Spatrick        return do_toupper(__low, __high);
60946035553Spatrick    }
61046035553Spatrick
61146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
61246035553Spatrick    char_type tolower(char_type __c) const
61346035553Spatrick    {
61446035553Spatrick        return do_tolower(__c);
61546035553Spatrick    }
61646035553Spatrick
61746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
61846035553Spatrick    const char_type* tolower(char_type* __low, const char_type* __high) const
61946035553Spatrick    {
62046035553Spatrick        return do_tolower(__low, __high);
62146035553Spatrick    }
62246035553Spatrick
62346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
62446035553Spatrick    char_type widen(char __c) const
62546035553Spatrick    {
62646035553Spatrick        return do_widen(__c);
62746035553Spatrick    }
62846035553Spatrick
62946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
63046035553Spatrick    const char* widen(const char* __low, const char* __high, char_type* __to) const
63146035553Spatrick    {
63246035553Spatrick        return do_widen(__low, __high, __to);
63346035553Spatrick    }
63446035553Spatrick
63546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
63646035553Spatrick    char narrow(char_type __c, char __dfault) const
63746035553Spatrick    {
63846035553Spatrick        return do_narrow(__c, __dfault);
63946035553Spatrick    }
64046035553Spatrick
64146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
64246035553Spatrick    const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
64346035553Spatrick    {
64446035553Spatrick        return do_narrow(__low, __high, __dfault, __to);
64546035553Spatrick    }
64646035553Spatrick
64746035553Spatrick    static locale::id id;
64846035553Spatrick
64946035553Spatrickprotected:
650*dc37c87aSrobert    ~ctype() override;
65146035553Spatrick    virtual bool do_is(mask __m, char_type __c) const;
65246035553Spatrick    virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
65346035553Spatrick    virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
65446035553Spatrick    virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
65546035553Spatrick    virtual char_type do_toupper(char_type) const;
65646035553Spatrick    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
65746035553Spatrick    virtual char_type do_tolower(char_type) const;
65846035553Spatrick    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
65946035553Spatrick    virtual char_type do_widen(char) const;
66046035553Spatrick    virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
66146035553Spatrick    virtual char do_narrow(char_type, char __dfault) const;
66246035553Spatrick    virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
66346035553Spatrick};
664*dc37c87aSrobert#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
66546035553Spatrick
66646035553Spatricktemplate <>
66746035553Spatrickclass _LIBCPP_TYPE_VIS ctype<char>
66846035553Spatrick    : public locale::facet, public ctype_base
66946035553Spatrick{
67046035553Spatrick    const mask* __tab_;
67146035553Spatrick    bool        __del_;
67246035553Spatrickpublic:
67346035553Spatrick    typedef char char_type;
67446035553Spatrick
675a0747c9fSpatrick    explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0);
67646035553Spatrick
67746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
67846035553Spatrick    bool is(mask __m, char_type __c) const
67946035553Spatrick    {
68046035553Spatrick        return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false;
68146035553Spatrick    }
68246035553Spatrick
68346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
68446035553Spatrick    const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
68546035553Spatrick    {
68646035553Spatrick        for (; __low != __high; ++__low, ++__vec)
68746035553Spatrick            *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
68846035553Spatrick        return __low;
68946035553Spatrick    }
69046035553Spatrick
69146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
69246035553Spatrick    const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
69346035553Spatrick    {
69446035553Spatrick        for (; __low != __high; ++__low)
69546035553Spatrick            if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
69646035553Spatrick                break;
69746035553Spatrick        return __low;
69846035553Spatrick    }
69946035553Spatrick
70046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
70146035553Spatrick    const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
70246035553Spatrick    {
70346035553Spatrick        for (; __low != __high; ++__low)
704*dc37c87aSrobert            if (!isascii(*__low) || !(__tab_[static_cast<int>(*__low)] & __m))
70546035553Spatrick                break;
70646035553Spatrick        return __low;
70746035553Spatrick    }
70846035553Spatrick
70946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
71046035553Spatrick    char_type toupper(char_type __c) const
71146035553Spatrick    {
71246035553Spatrick        return do_toupper(__c);
71346035553Spatrick    }
71446035553Spatrick
71546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
71646035553Spatrick    const char_type* toupper(char_type* __low, const char_type* __high) const
71746035553Spatrick    {
71846035553Spatrick        return do_toupper(__low, __high);
71946035553Spatrick    }
72046035553Spatrick
72146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
72246035553Spatrick    char_type tolower(char_type __c) const
72346035553Spatrick    {
72446035553Spatrick        return do_tolower(__c);
72546035553Spatrick    }
72646035553Spatrick
72746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
72846035553Spatrick    const char_type* tolower(char_type* __low, const char_type* __high) const
72946035553Spatrick    {
73046035553Spatrick        return do_tolower(__low, __high);
73146035553Spatrick    }
73246035553Spatrick
73346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
73446035553Spatrick    char_type widen(char __c) const
73546035553Spatrick    {
73646035553Spatrick        return do_widen(__c);
73746035553Spatrick    }
73846035553Spatrick
73946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
74046035553Spatrick    const char* widen(const char* __low, const char* __high, char_type* __to) const
74146035553Spatrick    {
74246035553Spatrick        return do_widen(__low, __high, __to);
74346035553Spatrick    }
74446035553Spatrick
74546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
74646035553Spatrick    char narrow(char_type __c, char __dfault) const
74746035553Spatrick    {
74846035553Spatrick        return do_narrow(__c, __dfault);
74946035553Spatrick    }
75046035553Spatrick
75146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
75246035553Spatrick    const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
75346035553Spatrick    {
75446035553Spatrick        return do_narrow(__low, __high, __dfault, __to);
75546035553Spatrick    }
75646035553Spatrick
75746035553Spatrick    static locale::id id;
75846035553Spatrick
75946035553Spatrick#ifdef _CACHED_RUNES
76046035553Spatrick    static const size_t table_size = _CACHED_RUNES;
76146035553Spatrick#else
76246035553Spatrick    static const size_t table_size = 256;  // FIXME: Don't hardcode this.
76346035553Spatrick#endif
76446035553Spatrick    _LIBCPP_INLINE_VISIBILITY const mask* table() const  _NOEXCEPT {return __tab_;}
76546035553Spatrick    static const mask* classic_table()  _NOEXCEPT;
76646035553Spatrick#if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
76746035553Spatrick    static const int* __classic_upper_table() _NOEXCEPT;
76846035553Spatrick    static const int* __classic_lower_table() _NOEXCEPT;
76946035553Spatrick#endif
77046035553Spatrick#if defined(__NetBSD__)
77146035553Spatrick    static const short* __classic_upper_table() _NOEXCEPT;
77246035553Spatrick    static const short* __classic_lower_table() _NOEXCEPT;
77346035553Spatrick#endif
774*dc37c87aSrobert#if defined(__MVS__)
775*dc37c87aSrobert    static const unsigned short* __classic_upper_table() _NOEXCEPT;
776*dc37c87aSrobert    static const unsigned short* __classic_lower_table() _NOEXCEPT;
777*dc37c87aSrobert#endif
77846035553Spatrick
77946035553Spatrickprotected:
780*dc37c87aSrobert    ~ctype() override;
78146035553Spatrick    virtual char_type do_toupper(char_type __c) const;
78246035553Spatrick    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
78346035553Spatrick    virtual char_type do_tolower(char_type __c) const;
78446035553Spatrick    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
78546035553Spatrick    virtual char_type do_widen(char __c) const;
78646035553Spatrick    virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
78746035553Spatrick    virtual char do_narrow(char_type __c, char __dfault) const;
78846035553Spatrick    virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
78946035553Spatrick};
79046035553Spatrick
79146035553Spatrick// template <class CharT> class ctype_byname;
79246035553Spatrick
79346035553Spatricktemplate <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype_byname;
79446035553Spatrick
79546035553Spatricktemplate <>
79646035553Spatrickclass _LIBCPP_TYPE_VIS ctype_byname<char>
79746035553Spatrick    : public ctype<char>
79846035553Spatrick{
799*dc37c87aSrobert    locale_t __l_;
80046035553Spatrick
80146035553Spatrickpublic:
80246035553Spatrick    explicit ctype_byname(const char*, size_t = 0);
80346035553Spatrick    explicit ctype_byname(const string&, size_t = 0);
80446035553Spatrick
80546035553Spatrickprotected:
806*dc37c87aSrobert    ~ctype_byname() override;
807*dc37c87aSrobert    char_type do_toupper(char_type) const override;
808*dc37c87aSrobert    const char_type* do_toupper(char_type* __low, const char_type* __high) const override;
809*dc37c87aSrobert    char_type do_tolower(char_type) const override;
810*dc37c87aSrobert    const char_type* do_tolower(char_type* __low, const char_type* __high) const override;
81146035553Spatrick};
81246035553Spatrick
813*dc37c87aSrobert#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
81446035553Spatricktemplate <>
81546035553Spatrickclass _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
81646035553Spatrick    : public ctype<wchar_t>
81746035553Spatrick{
818*dc37c87aSrobert    locale_t __l_;
81946035553Spatrick
82046035553Spatrickpublic:
82146035553Spatrick    explicit ctype_byname(const char*, size_t = 0);
82246035553Spatrick    explicit ctype_byname(const string&, size_t = 0);
82346035553Spatrick
82446035553Spatrickprotected:
825*dc37c87aSrobert    ~ctype_byname() override;
826*dc37c87aSrobert    bool do_is(mask __m, char_type __c) const override;
827*dc37c87aSrobert    const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const override;
828*dc37c87aSrobert    const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const override;
829*dc37c87aSrobert    const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const override;
830*dc37c87aSrobert    char_type do_toupper(char_type) const override;
831*dc37c87aSrobert    const char_type* do_toupper(char_type* __low, const char_type* __high) const override;
832*dc37c87aSrobert    char_type do_tolower(char_type) const override;
833*dc37c87aSrobert    const char_type* do_tolower(char_type* __low, const char_type* __high) const override;
834*dc37c87aSrobert    char_type do_widen(char) const override;
835*dc37c87aSrobert    const char* do_widen(const char* __low, const char* __high, char_type* __dest) const override;
836*dc37c87aSrobert    char do_narrow(char_type, char __dfault) const override;
837*dc37c87aSrobert    const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const override;
83846035553Spatrick};
839*dc37c87aSrobert#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
84046035553Spatrick
84146035553Spatricktemplate <class _CharT>
84246035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
84346035553Spatrickbool
84446035553Spatrickisspace(_CharT __c, const locale& __loc)
84546035553Spatrick{
846*dc37c87aSrobert    return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
84746035553Spatrick}
84846035553Spatrick
84946035553Spatricktemplate <class _CharT>
85046035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
85146035553Spatrickbool
85246035553Spatrickisprint(_CharT __c, const locale& __loc)
85346035553Spatrick{
854*dc37c87aSrobert    return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
85546035553Spatrick}
85646035553Spatrick
85746035553Spatricktemplate <class _CharT>
85846035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
85946035553Spatrickbool
86046035553Spatrickiscntrl(_CharT __c, const locale& __loc)
86146035553Spatrick{
862*dc37c87aSrobert    return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
86346035553Spatrick}
86446035553Spatrick
86546035553Spatricktemplate <class _CharT>
86646035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
86746035553Spatrickbool
86846035553Spatrickisupper(_CharT __c, const locale& __loc)
86946035553Spatrick{
870*dc37c87aSrobert    return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
87146035553Spatrick}
87246035553Spatrick
87346035553Spatricktemplate <class _CharT>
87446035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
87546035553Spatrickbool
87646035553Spatrickislower(_CharT __c, const locale& __loc)
87746035553Spatrick{
878*dc37c87aSrobert    return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
87946035553Spatrick}
88046035553Spatrick
88146035553Spatricktemplate <class _CharT>
88246035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
88346035553Spatrickbool
88446035553Spatrickisalpha(_CharT __c, const locale& __loc)
88546035553Spatrick{
886*dc37c87aSrobert    return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
88746035553Spatrick}
88846035553Spatrick
88946035553Spatricktemplate <class _CharT>
89046035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
89146035553Spatrickbool
89246035553Spatrickisdigit(_CharT __c, const locale& __loc)
89346035553Spatrick{
894*dc37c87aSrobert    return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
89546035553Spatrick}
89646035553Spatrick
89746035553Spatricktemplate <class _CharT>
89846035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
89946035553Spatrickbool
90046035553Spatrickispunct(_CharT __c, const locale& __loc)
90146035553Spatrick{
902*dc37c87aSrobert    return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
90346035553Spatrick}
90446035553Spatrick
90546035553Spatricktemplate <class _CharT>
90646035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
90746035553Spatrickbool
90846035553Spatrickisxdigit(_CharT __c, const locale& __loc)
90946035553Spatrick{
910*dc37c87aSrobert    return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
91146035553Spatrick}
91246035553Spatrick
91346035553Spatricktemplate <class _CharT>
91446035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
91546035553Spatrickbool
91646035553Spatrickisalnum(_CharT __c, const locale& __loc)
91746035553Spatrick{
918*dc37c87aSrobert    return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
91946035553Spatrick}
92046035553Spatrick
92146035553Spatricktemplate <class _CharT>
92246035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
92346035553Spatrickbool
92446035553Spatrickisgraph(_CharT __c, const locale& __loc)
92546035553Spatrick{
926*dc37c87aSrobert    return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
92746035553Spatrick}
92846035553Spatrick
92946035553Spatricktemplate <class _CharT>
93046035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
93146035553Spatrick_CharT
93246035553Spatricktoupper(_CharT __c, const locale& __loc)
93346035553Spatrick{
934*dc37c87aSrobert    return std::use_facet<ctype<_CharT> >(__loc).toupper(__c);
93546035553Spatrick}
93646035553Spatrick
93746035553Spatricktemplate <class _CharT>
93846035553Spatrickinline _LIBCPP_INLINE_VISIBILITY
93946035553Spatrick_CharT
94046035553Spatricktolower(_CharT __c, const locale& __loc)
94146035553Spatrick{
942*dc37c87aSrobert    return std::use_facet<ctype<_CharT> >(__loc).tolower(__c);
94346035553Spatrick}
94446035553Spatrick
94546035553Spatrick// codecvt_base
94646035553Spatrick
94746035553Spatrickclass _LIBCPP_TYPE_VIS codecvt_base
94846035553Spatrick{
94946035553Spatrickpublic:
95046035553Spatrick    _LIBCPP_INLINE_VISIBILITY codecvt_base() {}
95146035553Spatrick    enum result {ok, partial, error, noconv};
95246035553Spatrick};
95346035553Spatrick
95446035553Spatrick// template <class internT, class externT, class stateT> class codecvt;
95546035553Spatrick
95646035553Spatricktemplate <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TEMPLATE_VIS codecvt;
95746035553Spatrick
95846035553Spatrick// template <> class codecvt<char, char, mbstate_t>
95946035553Spatrick
96046035553Spatricktemplate <>
96146035553Spatrickclass _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
96246035553Spatrick    : public locale::facet,
96346035553Spatrick      public codecvt_base
96446035553Spatrick{
96546035553Spatrickpublic:
96646035553Spatrick    typedef char      intern_type;
96746035553Spatrick    typedef char      extern_type;
96846035553Spatrick    typedef mbstate_t state_type;
96946035553Spatrick
97046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
97146035553Spatrick    explicit codecvt(size_t __refs = 0)
97246035553Spatrick        : locale::facet(__refs) {}
97346035553Spatrick
97446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
97546035553Spatrick    result out(state_type& __st,
97646035553Spatrick               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
97746035553Spatrick               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
97846035553Spatrick    {
97946035553Spatrick        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
98046035553Spatrick    }
98146035553Spatrick
98246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
98346035553Spatrick    result unshift(state_type& __st,
98446035553Spatrick                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
98546035553Spatrick    {
98646035553Spatrick        return do_unshift(__st, __to, __to_end, __to_nxt);
98746035553Spatrick    }
98846035553Spatrick
98946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
99046035553Spatrick    result in(state_type& __st,
99146035553Spatrick              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
99246035553Spatrick              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
99346035553Spatrick    {
99446035553Spatrick        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
99546035553Spatrick    }
99646035553Spatrick
99746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
99846035553Spatrick    int encoding() const  _NOEXCEPT
99946035553Spatrick    {
100046035553Spatrick        return do_encoding();
100146035553Spatrick    }
100246035553Spatrick
100346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
100446035553Spatrick    bool always_noconv() const  _NOEXCEPT
100546035553Spatrick    {
100646035553Spatrick        return do_always_noconv();
100746035553Spatrick    }
100846035553Spatrick
100946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
101046035553Spatrick    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
101146035553Spatrick    {
101246035553Spatrick        return do_length(__st, __frm, __end, __mx);
101346035553Spatrick    }
101446035553Spatrick
101546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
101646035553Spatrick    int max_length() const  _NOEXCEPT
101746035553Spatrick    {
101846035553Spatrick        return do_max_length();
101946035553Spatrick    }
102046035553Spatrick
102146035553Spatrick    static locale::id id;
102246035553Spatrick
102346035553Spatrickprotected:
102446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
102546035553Spatrick    explicit codecvt(const char*, size_t __refs = 0)
102646035553Spatrick        : locale::facet(__refs) {}
102746035553Spatrick
1028*dc37c87aSrobert    ~codecvt() override;
102946035553Spatrick
103046035553Spatrick    virtual result do_out(state_type& __st,
103146035553Spatrick                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
103246035553Spatrick                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
103346035553Spatrick    virtual result do_in(state_type& __st,
103446035553Spatrick                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
103546035553Spatrick                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
103646035553Spatrick    virtual result do_unshift(state_type& __st,
103746035553Spatrick                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
103846035553Spatrick    virtual int do_encoding() const  _NOEXCEPT;
103946035553Spatrick    virtual bool do_always_noconv() const  _NOEXCEPT;
104046035553Spatrick    virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
104146035553Spatrick    virtual int do_max_length() const  _NOEXCEPT;
104246035553Spatrick};
104346035553Spatrick
104446035553Spatrick// template <> class codecvt<wchar_t, char, mbstate_t>
104546035553Spatrick
1046*dc37c87aSrobert#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
104746035553Spatricktemplate <>
104846035553Spatrickclass _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
104946035553Spatrick    : public locale::facet,
105046035553Spatrick      public codecvt_base
105146035553Spatrick{
1052*dc37c87aSrobert    locale_t __l_;
105346035553Spatrickpublic:
105446035553Spatrick    typedef wchar_t   intern_type;
105546035553Spatrick    typedef char      extern_type;
105646035553Spatrick    typedef mbstate_t state_type;
105746035553Spatrick
105846035553Spatrick    explicit codecvt(size_t __refs = 0);
105946035553Spatrick
106046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
106146035553Spatrick    result out(state_type& __st,
106246035553Spatrick               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
106346035553Spatrick               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
106446035553Spatrick    {
106546035553Spatrick        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
106646035553Spatrick    }
106746035553Spatrick
106846035553Spatrick    _LIBCPP_INLINE_VISIBILITY
106946035553Spatrick    result unshift(state_type& __st,
107046035553Spatrick                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
107146035553Spatrick    {
107246035553Spatrick        return do_unshift(__st, __to, __to_end, __to_nxt);
107346035553Spatrick    }
107446035553Spatrick
107546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
107646035553Spatrick    result in(state_type& __st,
107746035553Spatrick              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
107846035553Spatrick              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
107946035553Spatrick    {
108046035553Spatrick        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
108146035553Spatrick    }
108246035553Spatrick
108346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
108446035553Spatrick    int encoding() const  _NOEXCEPT
108546035553Spatrick    {
108646035553Spatrick        return do_encoding();
108746035553Spatrick    }
108846035553Spatrick
108946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
109046035553Spatrick    bool always_noconv() const  _NOEXCEPT
109146035553Spatrick    {
109246035553Spatrick        return do_always_noconv();
109346035553Spatrick    }
109446035553Spatrick
109546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
109646035553Spatrick    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
109746035553Spatrick    {
109846035553Spatrick        return do_length(__st, __frm, __end, __mx);
109946035553Spatrick    }
110046035553Spatrick
110146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
110246035553Spatrick    int max_length() const  _NOEXCEPT
110346035553Spatrick    {
110446035553Spatrick        return do_max_length();
110546035553Spatrick    }
110646035553Spatrick
110746035553Spatrick    static locale::id id;
110846035553Spatrick
110946035553Spatrickprotected:
111046035553Spatrick    explicit codecvt(const char*, size_t __refs = 0);
111146035553Spatrick
1112*dc37c87aSrobert    ~codecvt() override;
111346035553Spatrick
111446035553Spatrick    virtual result do_out(state_type& __st,
111546035553Spatrick                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
111646035553Spatrick                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
111746035553Spatrick    virtual result do_in(state_type& __st,
111846035553Spatrick                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
111946035553Spatrick                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
112046035553Spatrick    virtual result do_unshift(state_type& __st,
112146035553Spatrick                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
112246035553Spatrick    virtual int do_encoding() const  _NOEXCEPT;
112346035553Spatrick    virtual bool do_always_noconv() const  _NOEXCEPT;
112446035553Spatrick    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
112546035553Spatrick    virtual int do_max_length() const  _NOEXCEPT;
112646035553Spatrick};
1127*dc37c87aSrobert#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
112846035553Spatrick
1129a0747c9fSpatrick// template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20
113046035553Spatrick
113146035553Spatricktemplate <>
1132a0747c9fSpatrickclass _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
113346035553Spatrick    : public locale::facet,
113446035553Spatrick      public codecvt_base
113546035553Spatrick{
113646035553Spatrickpublic:
113746035553Spatrick    typedef char16_t  intern_type;
113846035553Spatrick    typedef char      extern_type;
113946035553Spatrick    typedef mbstate_t state_type;
114046035553Spatrick
114146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
114246035553Spatrick    explicit codecvt(size_t __refs = 0)
114346035553Spatrick        : locale::facet(__refs) {}
114446035553Spatrick
114546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
114646035553Spatrick    result out(state_type& __st,
114746035553Spatrick               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
114846035553Spatrick               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
114946035553Spatrick    {
115046035553Spatrick        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
115146035553Spatrick    }
115246035553Spatrick
115346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
115446035553Spatrick    result unshift(state_type& __st,
115546035553Spatrick                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
115646035553Spatrick    {
115746035553Spatrick        return do_unshift(__st, __to, __to_end, __to_nxt);
115846035553Spatrick    }
115946035553Spatrick
116046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
116146035553Spatrick    result in(state_type& __st,
116246035553Spatrick              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
116346035553Spatrick              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
116446035553Spatrick    {
116546035553Spatrick        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
116646035553Spatrick    }
116746035553Spatrick
116846035553Spatrick    _LIBCPP_INLINE_VISIBILITY
116946035553Spatrick    int encoding() const  _NOEXCEPT
117046035553Spatrick    {
117146035553Spatrick        return do_encoding();
117246035553Spatrick    }
117346035553Spatrick
117446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
117546035553Spatrick    bool always_noconv() const  _NOEXCEPT
117646035553Spatrick    {
117746035553Spatrick        return do_always_noconv();
117846035553Spatrick    }
117946035553Spatrick
118046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
118146035553Spatrick    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
118246035553Spatrick    {
118346035553Spatrick        return do_length(__st, __frm, __end, __mx);
118446035553Spatrick    }
118546035553Spatrick
118646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
118746035553Spatrick    int max_length() const  _NOEXCEPT
118846035553Spatrick    {
118946035553Spatrick        return do_max_length();
119046035553Spatrick    }
119146035553Spatrick
119246035553Spatrick    static locale::id id;
119346035553Spatrick
119446035553Spatrickprotected:
119546035553Spatrick    _LIBCPP_INLINE_VISIBILITY
119646035553Spatrick    explicit codecvt(const char*, size_t __refs = 0)
119746035553Spatrick        : locale::facet(__refs) {}
119846035553Spatrick
1199*dc37c87aSrobert    ~codecvt() override;
120046035553Spatrick
120146035553Spatrick    virtual result do_out(state_type& __st,
120246035553Spatrick                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
120346035553Spatrick                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
120446035553Spatrick    virtual result do_in(state_type& __st,
120546035553Spatrick                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
120646035553Spatrick                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
120746035553Spatrick    virtual result do_unshift(state_type& __st,
120846035553Spatrick                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
120946035553Spatrick    virtual int do_encoding() const  _NOEXCEPT;
121046035553Spatrick    virtual bool do_always_noconv() const  _NOEXCEPT;
121146035553Spatrick    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
121246035553Spatrick    virtual int do_max_length() const  _NOEXCEPT;
121346035553Spatrick};
121446035553Spatrick
1215a0747c9fSpatrick#ifndef _LIBCPP_HAS_NO_CHAR8_T
1216a0747c9fSpatrick
1217a0747c9fSpatrick// template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20
121846035553Spatrick
121946035553Spatricktemplate <>
1220a0747c9fSpatrickclass _LIBCPP_TYPE_VIS codecvt<char16_t, char8_t, mbstate_t>
1221a0747c9fSpatrick    : public locale::facet,
1222a0747c9fSpatrick      public codecvt_base
1223a0747c9fSpatrick{
1224a0747c9fSpatrickpublic:
1225a0747c9fSpatrick    typedef char16_t  intern_type;
1226a0747c9fSpatrick    typedef char8_t   extern_type;
1227a0747c9fSpatrick    typedef mbstate_t state_type;
1228a0747c9fSpatrick
1229a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1230a0747c9fSpatrick    explicit codecvt(size_t __refs = 0)
1231a0747c9fSpatrick        : locale::facet(__refs) {}
1232a0747c9fSpatrick
1233a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1234a0747c9fSpatrick    result out(state_type& __st,
1235a0747c9fSpatrick               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1236a0747c9fSpatrick               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1237a0747c9fSpatrick    {
1238a0747c9fSpatrick        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1239a0747c9fSpatrick    }
1240a0747c9fSpatrick
1241a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1242a0747c9fSpatrick    result unshift(state_type& __st,
1243a0747c9fSpatrick                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1244a0747c9fSpatrick    {
1245a0747c9fSpatrick        return do_unshift(__st, __to, __to_end, __to_nxt);
1246a0747c9fSpatrick    }
1247a0747c9fSpatrick
1248a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1249a0747c9fSpatrick    result in(state_type& __st,
1250a0747c9fSpatrick              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1251a0747c9fSpatrick              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1252a0747c9fSpatrick    {
1253a0747c9fSpatrick        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1254a0747c9fSpatrick    }
1255a0747c9fSpatrick
1256a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1257a0747c9fSpatrick    int encoding() const  _NOEXCEPT
1258a0747c9fSpatrick    {
1259a0747c9fSpatrick        return do_encoding();
1260a0747c9fSpatrick    }
1261a0747c9fSpatrick
1262a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1263a0747c9fSpatrick    bool always_noconv() const  _NOEXCEPT
1264a0747c9fSpatrick    {
1265a0747c9fSpatrick        return do_always_noconv();
1266a0747c9fSpatrick    }
1267a0747c9fSpatrick
1268a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1269a0747c9fSpatrick    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1270a0747c9fSpatrick    {
1271a0747c9fSpatrick        return do_length(__st, __frm, __end, __mx);
1272a0747c9fSpatrick    }
1273a0747c9fSpatrick
1274a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1275a0747c9fSpatrick    int max_length() const  _NOEXCEPT
1276a0747c9fSpatrick    {
1277a0747c9fSpatrick        return do_max_length();
1278a0747c9fSpatrick    }
1279a0747c9fSpatrick
1280a0747c9fSpatrick    static locale::id id;
1281a0747c9fSpatrick
1282a0747c9fSpatrickprotected:
1283a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1284a0747c9fSpatrick    explicit codecvt(const char*, size_t __refs = 0)
1285a0747c9fSpatrick        : locale::facet(__refs) {}
1286a0747c9fSpatrick
1287*dc37c87aSrobert    ~codecvt() override;
1288a0747c9fSpatrick
1289a0747c9fSpatrick    virtual result do_out(state_type& __st,
1290a0747c9fSpatrick                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1291a0747c9fSpatrick                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1292a0747c9fSpatrick    virtual result do_in(state_type& __st,
1293a0747c9fSpatrick                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1294a0747c9fSpatrick                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1295a0747c9fSpatrick    virtual result do_unshift(state_type& __st,
1296a0747c9fSpatrick                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1297a0747c9fSpatrick    virtual int do_encoding() const  _NOEXCEPT;
1298a0747c9fSpatrick    virtual bool do_always_noconv() const  _NOEXCEPT;
1299a0747c9fSpatrick    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1300a0747c9fSpatrick    virtual int do_max_length() const  _NOEXCEPT;
1301a0747c9fSpatrick};
1302a0747c9fSpatrick
1303a0747c9fSpatrick#endif
1304a0747c9fSpatrick
1305a0747c9fSpatrick// template <> class codecvt<char32_t, char, mbstate_t> // deprecated in C++20
1306a0747c9fSpatrick
1307a0747c9fSpatricktemplate <>
1308a0747c9fSpatrickclass _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
130946035553Spatrick    : public locale::facet,
131046035553Spatrick      public codecvt_base
131146035553Spatrick{
131246035553Spatrickpublic:
131346035553Spatrick    typedef char32_t  intern_type;
131446035553Spatrick    typedef char      extern_type;
131546035553Spatrick    typedef mbstate_t state_type;
131646035553Spatrick
131746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
131846035553Spatrick    explicit codecvt(size_t __refs = 0)
131946035553Spatrick        : locale::facet(__refs) {}
132046035553Spatrick
132146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
132246035553Spatrick    result out(state_type& __st,
132346035553Spatrick               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
132446035553Spatrick               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
132546035553Spatrick    {
132646035553Spatrick        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
132746035553Spatrick    }
132846035553Spatrick
132946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
133046035553Spatrick    result unshift(state_type& __st,
133146035553Spatrick                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
133246035553Spatrick    {
133346035553Spatrick        return do_unshift(__st, __to, __to_end, __to_nxt);
133446035553Spatrick    }
133546035553Spatrick
133646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
133746035553Spatrick    result in(state_type& __st,
133846035553Spatrick              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
133946035553Spatrick              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
134046035553Spatrick    {
134146035553Spatrick        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
134246035553Spatrick    }
134346035553Spatrick
134446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
134546035553Spatrick    int encoding() const  _NOEXCEPT
134646035553Spatrick    {
134746035553Spatrick        return do_encoding();
134846035553Spatrick    }
134946035553Spatrick
135046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
135146035553Spatrick    bool always_noconv() const  _NOEXCEPT
135246035553Spatrick    {
135346035553Spatrick        return do_always_noconv();
135446035553Spatrick    }
135546035553Spatrick
135646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
135746035553Spatrick    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
135846035553Spatrick    {
135946035553Spatrick        return do_length(__st, __frm, __end, __mx);
136046035553Spatrick    }
136146035553Spatrick
136246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
136346035553Spatrick    int max_length() const  _NOEXCEPT
136446035553Spatrick    {
136546035553Spatrick        return do_max_length();
136646035553Spatrick    }
136746035553Spatrick
136846035553Spatrick    static locale::id id;
136946035553Spatrick
137046035553Spatrickprotected:
137146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
137246035553Spatrick    explicit codecvt(const char*, size_t __refs = 0)
137346035553Spatrick        : locale::facet(__refs) {}
137446035553Spatrick
1375*dc37c87aSrobert    ~codecvt() override;
137646035553Spatrick
137746035553Spatrick    virtual result do_out(state_type& __st,
137846035553Spatrick                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
137946035553Spatrick                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
138046035553Spatrick    virtual result do_in(state_type& __st,
138146035553Spatrick                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
138246035553Spatrick                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
138346035553Spatrick    virtual result do_unshift(state_type& __st,
138446035553Spatrick                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
138546035553Spatrick    virtual int do_encoding() const  _NOEXCEPT;
138646035553Spatrick    virtual bool do_always_noconv() const  _NOEXCEPT;
138746035553Spatrick    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
138846035553Spatrick    virtual int do_max_length() const  _NOEXCEPT;
138946035553Spatrick};
139046035553Spatrick
1391a0747c9fSpatrick#ifndef _LIBCPP_HAS_NO_CHAR8_T
1392a0747c9fSpatrick
1393a0747c9fSpatrick// template <> class codecvt<char32_t, char8_t, mbstate_t> // C++20
1394a0747c9fSpatrick
1395a0747c9fSpatricktemplate <>
1396a0747c9fSpatrickclass _LIBCPP_TYPE_VIS codecvt<char32_t, char8_t, mbstate_t>
1397a0747c9fSpatrick    : public locale::facet,
1398a0747c9fSpatrick      public codecvt_base
1399a0747c9fSpatrick{
1400a0747c9fSpatrickpublic:
1401a0747c9fSpatrick    typedef char32_t  intern_type;
1402a0747c9fSpatrick    typedef char8_t   extern_type;
1403a0747c9fSpatrick    typedef mbstate_t state_type;
1404a0747c9fSpatrick
1405a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1406a0747c9fSpatrick    explicit codecvt(size_t __refs = 0)
1407a0747c9fSpatrick        : locale::facet(__refs) {}
1408a0747c9fSpatrick
1409a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1410a0747c9fSpatrick    result out(state_type& __st,
1411a0747c9fSpatrick               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1412a0747c9fSpatrick               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1413a0747c9fSpatrick    {
1414a0747c9fSpatrick        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1415a0747c9fSpatrick    }
1416a0747c9fSpatrick
1417a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1418a0747c9fSpatrick    result unshift(state_type& __st,
1419a0747c9fSpatrick                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1420a0747c9fSpatrick    {
1421a0747c9fSpatrick        return do_unshift(__st, __to, __to_end, __to_nxt);
1422a0747c9fSpatrick    }
1423a0747c9fSpatrick
1424a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1425a0747c9fSpatrick    result in(state_type& __st,
1426a0747c9fSpatrick              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1427a0747c9fSpatrick              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1428a0747c9fSpatrick    {
1429a0747c9fSpatrick        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1430a0747c9fSpatrick    }
1431a0747c9fSpatrick
1432a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1433a0747c9fSpatrick    int encoding() const  _NOEXCEPT
1434a0747c9fSpatrick    {
1435a0747c9fSpatrick        return do_encoding();
1436a0747c9fSpatrick    }
1437a0747c9fSpatrick
1438a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1439a0747c9fSpatrick    bool always_noconv() const  _NOEXCEPT
1440a0747c9fSpatrick    {
1441a0747c9fSpatrick        return do_always_noconv();
1442a0747c9fSpatrick    }
1443a0747c9fSpatrick
1444a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1445a0747c9fSpatrick    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1446a0747c9fSpatrick    {
1447a0747c9fSpatrick        return do_length(__st, __frm, __end, __mx);
1448a0747c9fSpatrick    }
1449a0747c9fSpatrick
1450a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1451a0747c9fSpatrick    int max_length() const  _NOEXCEPT
1452a0747c9fSpatrick    {
1453a0747c9fSpatrick        return do_max_length();
1454a0747c9fSpatrick    }
1455a0747c9fSpatrick
1456a0747c9fSpatrick    static locale::id id;
1457a0747c9fSpatrick
1458a0747c9fSpatrickprotected:
1459a0747c9fSpatrick    _LIBCPP_INLINE_VISIBILITY
1460a0747c9fSpatrick    explicit codecvt(const char*, size_t __refs = 0)
1461a0747c9fSpatrick        : locale::facet(__refs) {}
1462a0747c9fSpatrick
1463*dc37c87aSrobert    ~codecvt() override;
1464a0747c9fSpatrick
1465a0747c9fSpatrick    virtual result do_out(state_type& __st,
1466a0747c9fSpatrick                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1467a0747c9fSpatrick                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1468a0747c9fSpatrick    virtual result do_in(state_type& __st,
1469a0747c9fSpatrick                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1470a0747c9fSpatrick                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1471a0747c9fSpatrick    virtual result do_unshift(state_type& __st,
1472a0747c9fSpatrick                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1473a0747c9fSpatrick    virtual int do_encoding() const  _NOEXCEPT;
1474a0747c9fSpatrick    virtual bool do_always_noconv() const  _NOEXCEPT;
1475a0747c9fSpatrick    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1476a0747c9fSpatrick    virtual int do_max_length() const  _NOEXCEPT;
1477a0747c9fSpatrick};
1478a0747c9fSpatrick
1479a0747c9fSpatrick#endif
1480a0747c9fSpatrick
148146035553Spatrick// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
148246035553Spatrick
148346035553Spatricktemplate <class _InternT, class _ExternT, class _StateT>
148446035553Spatrickclass _LIBCPP_TEMPLATE_VIS codecvt_byname
148546035553Spatrick    : public codecvt<_InternT, _ExternT, _StateT>
148646035553Spatrick{
148746035553Spatrickpublic:
148846035553Spatrick    _LIBCPP_INLINE_VISIBILITY
148946035553Spatrick    explicit codecvt_byname(const char* __nm, size_t __refs = 0)
149046035553Spatrick        : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
149146035553Spatrick    _LIBCPP_INLINE_VISIBILITY
149246035553Spatrick    explicit codecvt_byname(const string& __nm, size_t __refs = 0)
149346035553Spatrick        : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
149446035553Spatrickprotected:
1495*dc37c87aSrobert    ~codecvt_byname() override;
149646035553Spatrick};
149746035553Spatrick
1498a0747c9fSpatrick_LIBCPP_SUPPRESS_DEPRECATED_PUSH
149946035553Spatricktemplate <class _InternT, class _ExternT, class _StateT>
150046035553Spatrickcodecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
150146035553Spatrick{
150246035553Spatrick}
1503a0747c9fSpatrick_LIBCPP_SUPPRESS_DEPRECATED_POP
150446035553Spatrick
1505*dc37c87aSrobertextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>;
1506*dc37c87aSrobert#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1507*dc37c87aSrobertextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>;
1508*dc37c87aSrobert#endif
1509*dc37c87aSrobertextern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>; // deprecated in C++20
1510*dc37c87aSrobertextern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>; // deprecated in C++20
1511a0747c9fSpatrick#ifndef _LIBCPP_HAS_NO_CHAR8_T
1512*dc37c87aSrobertextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>; // C++20
1513*dc37c87aSrobertextern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>; // C++20
1514a0747c9fSpatrick#endif
151546035553Spatrick
151646035553Spatricktemplate <size_t _Np>
151746035553Spatrickstruct __narrow_to_utf8
151846035553Spatrick{
151946035553Spatrick    template <class _OutputIterator, class _CharT>
152046035553Spatrick    _OutputIterator
152146035553Spatrick    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
152246035553Spatrick};
152346035553Spatrick
152446035553Spatricktemplate <>
152546035553Spatrickstruct __narrow_to_utf8<8>
152646035553Spatrick{
152746035553Spatrick    template <class _OutputIterator, class _CharT>
152846035553Spatrick    _LIBCPP_INLINE_VISIBILITY
152946035553Spatrick    _OutputIterator
153046035553Spatrick    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
153146035553Spatrick    {
153246035553Spatrick        for (; __wb < __we; ++__wb, ++__s)
153346035553Spatrick            *__s = *__wb;
153446035553Spatrick        return __s;
153546035553Spatrick    }
153646035553Spatrick};
153746035553Spatrick
1538a0747c9fSpatrick_LIBCPP_SUPPRESS_DEPRECATED_PUSH
153946035553Spatricktemplate <>
1540a0747c9fSpatrickstruct _LIBCPP_TYPE_VIS __narrow_to_utf8<16>
154146035553Spatrick    : public codecvt<char16_t, char, mbstate_t>
154246035553Spatrick{
154346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
154446035553Spatrick    __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1545a0747c9fSpatrick_LIBCPP_SUPPRESS_DEPRECATED_POP
154646035553Spatrick
1547*dc37c87aSrobert    ~__narrow_to_utf8() override;
154846035553Spatrick
154946035553Spatrick    template <class _OutputIterator, class _CharT>
155046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
155146035553Spatrick    _OutputIterator
155246035553Spatrick    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
155346035553Spatrick    {
155446035553Spatrick        result __r = ok;
155546035553Spatrick        mbstate_t __mb;
155646035553Spatrick        while (__wb < __we && __r != error)
155746035553Spatrick        {
155846035553Spatrick            const int __sz = 32;
155946035553Spatrick            char __buf[__sz];
156046035553Spatrick            char* __bn;
156146035553Spatrick            const char16_t* __wn = (const char16_t*)__wb;
156246035553Spatrick            __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
156346035553Spatrick                         __buf, __buf+__sz, __bn);
156446035553Spatrick            if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
156546035553Spatrick                __throw_runtime_error("locale not supported");
156646035553Spatrick            for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
156746035553Spatrick                *__s = *__p;
156846035553Spatrick            __wb = (const _CharT*)__wn;
156946035553Spatrick        }
157046035553Spatrick        return __s;
157146035553Spatrick    }
157246035553Spatrick};
157346035553Spatrick
1574a0747c9fSpatrick_LIBCPP_SUPPRESS_DEPRECATED_PUSH
157546035553Spatricktemplate <>
1576a0747c9fSpatrickstruct _LIBCPP_TYPE_VIS __narrow_to_utf8<32>
157746035553Spatrick    : public codecvt<char32_t, char, mbstate_t>
157846035553Spatrick{
157946035553Spatrick    _LIBCPP_INLINE_VISIBILITY
158046035553Spatrick    __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1581a0747c9fSpatrick_LIBCPP_SUPPRESS_DEPRECATED_POP
158246035553Spatrick
1583*dc37c87aSrobert    ~__narrow_to_utf8() override;
158446035553Spatrick
158546035553Spatrick    template <class _OutputIterator, class _CharT>
158646035553Spatrick    _LIBCPP_INLINE_VISIBILITY
158746035553Spatrick    _OutputIterator
158846035553Spatrick    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
158946035553Spatrick    {
159046035553Spatrick        result __r = ok;
159146035553Spatrick        mbstate_t __mb;
159246035553Spatrick        while (__wb < __we && __r != error)
159346035553Spatrick        {
159446035553Spatrick            const int __sz = 32;
159546035553Spatrick            char __buf[__sz];
159646035553Spatrick            char* __bn;
159746035553Spatrick            const char32_t* __wn = (const char32_t*)__wb;
159846035553Spatrick            __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
159946035553Spatrick                         __buf, __buf+__sz, __bn);
160046035553Spatrick            if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
160146035553Spatrick                __throw_runtime_error("locale not supported");
160246035553Spatrick            for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
160346035553Spatrick                *__s = *__p;
160446035553Spatrick            __wb = (const _CharT*)__wn;
160546035553Spatrick        }
160646035553Spatrick        return __s;
160746035553Spatrick    }
160846035553Spatrick};
160946035553Spatrick
161046035553Spatricktemplate <size_t _Np>
161146035553Spatrickstruct __widen_from_utf8
161246035553Spatrick{
161346035553Spatrick    template <class _OutputIterator>
161446035553Spatrick    _OutputIterator
161546035553Spatrick    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
161646035553Spatrick};
161746035553Spatrick
161846035553Spatricktemplate <>
161946035553Spatrickstruct __widen_from_utf8<8>
162046035553Spatrick{
162146035553Spatrick    template <class _OutputIterator>
162246035553Spatrick    _LIBCPP_INLINE_VISIBILITY
162346035553Spatrick    _OutputIterator
162446035553Spatrick    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
162546035553Spatrick    {
162646035553Spatrick        for (; __nb < __ne; ++__nb, ++__s)
162746035553Spatrick            *__s = *__nb;
162846035553Spatrick        return __s;
162946035553Spatrick    }
163046035553Spatrick};
163146035553Spatrick
1632a0747c9fSpatrick_LIBCPP_SUPPRESS_DEPRECATED_PUSH
163346035553Spatricktemplate <>
1634a0747c9fSpatrickstruct _LIBCPP_TYPE_VIS __widen_from_utf8<16>
163546035553Spatrick    : public codecvt<char16_t, char, mbstate_t>
163646035553Spatrick{
163746035553Spatrick    _LIBCPP_INLINE_VISIBILITY
163846035553Spatrick    __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1639a0747c9fSpatrick_LIBCPP_SUPPRESS_DEPRECATED_POP
164046035553Spatrick
1641*dc37c87aSrobert    ~__widen_from_utf8() override;
164246035553Spatrick
164346035553Spatrick    template <class _OutputIterator>
164446035553Spatrick    _LIBCPP_INLINE_VISIBILITY
164546035553Spatrick    _OutputIterator
164646035553Spatrick    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
164746035553Spatrick    {
164846035553Spatrick        result __r = ok;
164946035553Spatrick        mbstate_t __mb;
165046035553Spatrick        while (__nb < __ne && __r != error)
165146035553Spatrick        {
165246035553Spatrick            const int __sz = 32;
165346035553Spatrick            char16_t __buf[__sz];
165446035553Spatrick            char16_t* __bn;
165546035553Spatrick            const char* __nn = __nb;
165646035553Spatrick            __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
165746035553Spatrick                        __buf, __buf+__sz, __bn);
165846035553Spatrick            if (__r == codecvt_base::error || __nn == __nb)
165946035553Spatrick                __throw_runtime_error("locale not supported");
166046035553Spatrick            for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
1661a0747c9fSpatrick                *__s = *__p;
166246035553Spatrick            __nb = __nn;
166346035553Spatrick        }
166446035553Spatrick        return __s;
166546035553Spatrick    }
166646035553Spatrick};
166746035553Spatrick
1668a0747c9fSpatrick_LIBCPP_SUPPRESS_DEPRECATED_PUSH
166946035553Spatricktemplate <>
1670a0747c9fSpatrickstruct _LIBCPP_TYPE_VIS __widen_from_utf8<32>
167146035553Spatrick    : public codecvt<char32_t, char, mbstate_t>
167246035553Spatrick{
167346035553Spatrick    _LIBCPP_INLINE_VISIBILITY
167446035553Spatrick    __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1675a0747c9fSpatrick_LIBCPP_SUPPRESS_DEPRECATED_POP
167646035553Spatrick
1677*dc37c87aSrobert    ~__widen_from_utf8() override;
167846035553Spatrick
167946035553Spatrick    template <class _OutputIterator>
168046035553Spatrick    _LIBCPP_INLINE_VISIBILITY
168146035553Spatrick    _OutputIterator
168246035553Spatrick    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
168346035553Spatrick    {
168446035553Spatrick        result __r = ok;
168546035553Spatrick        mbstate_t __mb;
168646035553Spatrick        while (__nb < __ne && __r != error)
168746035553Spatrick        {
168846035553Spatrick            const int __sz = 32;
168946035553Spatrick            char32_t __buf[__sz];
169046035553Spatrick            char32_t* __bn;
169146035553Spatrick            const char* __nn = __nb;
169246035553Spatrick            __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
169346035553Spatrick                        __buf, __buf+__sz, __bn);
169446035553Spatrick            if (__r == codecvt_base::error || __nn == __nb)
169546035553Spatrick                __throw_runtime_error("locale not supported");
169646035553Spatrick            for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
1697a0747c9fSpatrick                *__s = *__p;
169846035553Spatrick            __nb = __nn;
169946035553Spatrick        }
170046035553Spatrick        return __s;
170146035553Spatrick    }
170246035553Spatrick};
170346035553Spatrick
170446035553Spatrick// template <class charT> class numpunct
170546035553Spatrick
170646035553Spatricktemplate <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct;
170746035553Spatrick
170846035553Spatricktemplate <>
170946035553Spatrickclass _LIBCPP_TYPE_VIS numpunct<char>
171046035553Spatrick    : public locale::facet
171146035553Spatrick{
171246035553Spatrickpublic:
171346035553Spatrick    typedef char char_type;
171446035553Spatrick    typedef basic_string<char_type> string_type;
171546035553Spatrick
171646035553Spatrick    explicit numpunct(size_t __refs = 0);
171746035553Spatrick
171846035553Spatrick    _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
171946035553Spatrick    _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
172046035553Spatrick    _LIBCPP_INLINE_VISIBILITY string grouping() const         {return do_grouping();}
172146035553Spatrick    _LIBCPP_INLINE_VISIBILITY string_type truename() const    {return do_truename();}
172246035553Spatrick    _LIBCPP_INLINE_VISIBILITY string_type falsename() const   {return do_falsename();}
172346035553Spatrick
172446035553Spatrick    static locale::id id;
172546035553Spatrick
172646035553Spatrickprotected:
1727*dc37c87aSrobert    ~numpunct() override;
172846035553Spatrick    virtual char_type do_decimal_point() const;
172946035553Spatrick    virtual char_type do_thousands_sep() const;
173046035553Spatrick    virtual string do_grouping() const;
173146035553Spatrick    virtual string_type do_truename() const;
173246035553Spatrick    virtual string_type do_falsename() const;
173346035553Spatrick
173446035553Spatrick    char_type __decimal_point_;
173546035553Spatrick    char_type __thousands_sep_;
173646035553Spatrick    string __grouping_;
173746035553Spatrick};
173846035553Spatrick
1739*dc37c87aSrobert#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
174046035553Spatricktemplate <>
174146035553Spatrickclass _LIBCPP_TYPE_VIS numpunct<wchar_t>
174246035553Spatrick    : public locale::facet
174346035553Spatrick{
174446035553Spatrickpublic:
174546035553Spatrick    typedef wchar_t char_type;
174646035553Spatrick    typedef basic_string<char_type> string_type;
174746035553Spatrick
174846035553Spatrick    explicit numpunct(size_t __refs = 0);
174946035553Spatrick
175046035553Spatrick    _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
175146035553Spatrick    _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
175246035553Spatrick    _LIBCPP_INLINE_VISIBILITY string grouping() const         {return do_grouping();}
175346035553Spatrick    _LIBCPP_INLINE_VISIBILITY string_type truename() const    {return do_truename();}
175446035553Spatrick    _LIBCPP_INLINE_VISIBILITY string_type falsename() const   {return do_falsename();}
175546035553Spatrick
175646035553Spatrick    static locale::id id;
175746035553Spatrick
175846035553Spatrickprotected:
1759*dc37c87aSrobert    ~numpunct() override;
176046035553Spatrick    virtual char_type do_decimal_point() const;
176146035553Spatrick    virtual char_type do_thousands_sep() const;
176246035553Spatrick    virtual string do_grouping() const;
176346035553Spatrick    virtual string_type do_truename() const;
176446035553Spatrick    virtual string_type do_falsename() const;
176546035553Spatrick
176646035553Spatrick    char_type __decimal_point_;
176746035553Spatrick    char_type __thousands_sep_;
176846035553Spatrick    string __grouping_;
176946035553Spatrick};
1770*dc37c87aSrobert#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
177146035553Spatrick
177246035553Spatrick// template <class charT> class numpunct_byname
177346035553Spatrick
177446035553Spatricktemplate <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct_byname;
177546035553Spatrick
177646035553Spatricktemplate <>
177746035553Spatrickclass _LIBCPP_TYPE_VIS numpunct_byname<char>
177846035553Spatrick: public numpunct<char>
177946035553Spatrick{
178046035553Spatrickpublic:
178146035553Spatrick    typedef char char_type;
178246035553Spatrick    typedef basic_string<char_type> string_type;
178346035553Spatrick
178446035553Spatrick    explicit numpunct_byname(const char* __nm, size_t __refs = 0);
178546035553Spatrick    explicit numpunct_byname(const string& __nm, size_t __refs = 0);
178646035553Spatrick
178746035553Spatrickprotected:
1788*dc37c87aSrobert    ~numpunct_byname() override;
178946035553Spatrick
179046035553Spatrickprivate:
179146035553Spatrick    void __init(const char*);
179246035553Spatrick};
179346035553Spatrick
1794*dc37c87aSrobert#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
179546035553Spatricktemplate <>
179646035553Spatrickclass _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
179746035553Spatrick: public numpunct<wchar_t>
179846035553Spatrick{
179946035553Spatrickpublic:
180046035553Spatrick    typedef wchar_t char_type;
180146035553Spatrick    typedef basic_string<char_type> string_type;
180246035553Spatrick
180346035553Spatrick    explicit numpunct_byname(const char* __nm, size_t __refs = 0);
180446035553Spatrick    explicit numpunct_byname(const string& __nm, size_t __refs = 0);
180546035553Spatrick
180646035553Spatrickprotected:
1807*dc37c87aSrobert    ~numpunct_byname() override;
180846035553Spatrick
180946035553Spatrickprivate:
181046035553Spatrick    void __init(const char*);
181146035553Spatrick};
1812*dc37c87aSrobert#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
181346035553Spatrick
181446035553Spatrick_LIBCPP_END_NAMESPACE_STD
181546035553Spatrick
181646035553Spatrick#endif // _LIBCPP___LOCALE
1817