xref: /freebsd/contrib/llvm-project/libcxx/include/__locale (revision 1fd87a682ad7442327078e1eeb63edc4258f9815)
10b57cec5SDimitry Andric// -*- C++ -*-
20b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP___LOCALE
110b57cec5SDimitry Andric#define _LIBCPP___LOCALE
120b57cec5SDimitry Andric
13e8d8bef9SDimitry Andric#include <__availability>
14fe6060f1SDimitry Andric#include <__config>
150b57cec5SDimitry Andric#include <cctype>
1604eeddc0SDimitry Andric#include <cstdint>
170b57cec5SDimitry Andric#include <locale.h>
1804eeddc0SDimitry Andric#include <memory>
1904eeddc0SDimitry Andric#include <mutex>
2004eeddc0SDimitry Andric#include <string>
2104eeddc0SDimitry Andric#include <utility>
2204eeddc0SDimitry Andric
230b57cec5SDimitry Andric#if defined(_LIBCPP_MSVCRT_LIKE)
240b57cec5SDimitry Andric# include <cstring>
25d409305fSDimitry Andric# include <__support/win32/locale_win32.h>
26e8d8bef9SDimitry Andric#elif defined(_AIX) || defined(__MVS__)
27d409305fSDimitry Andric# include <__support/ibm/xlocale.h>
280b57cec5SDimitry Andric#elif defined(__ANDROID__)
29d409305fSDimitry Andric# include <__support/android/locale_bionic.h>
300b57cec5SDimitry Andric#elif defined(__sun__)
310b57cec5SDimitry Andric# include <xlocale.h>
32d409305fSDimitry Andric# include <__support/solaris/xlocale.h>
330b57cec5SDimitry Andric#elif defined(_NEWLIB_VERSION)
34d409305fSDimitry Andric# include <__support/newlib/xlocale.h>
35e8d8bef9SDimitry Andric#elif defined(__OpenBSD__)
36d409305fSDimitry Andric# include <__support/openbsd/xlocale.h>
370b57cec5SDimitry Andric#elif (defined(__APPLE__)      || defined(__FreeBSD__) \
380b57cec5SDimitry Andric    || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
390b57cec5SDimitry Andric# include <xlocale.h>
400b57cec5SDimitry Andric#elif defined(__Fuchsia__)
41d409305fSDimitry Andric# include <__support/fuchsia/xlocale.h>
420b57cec5SDimitry Andric#elif defined(__wasi__)
430b57cec5SDimitry Andric// WASI libc uses musl's locales support.
44d409305fSDimitry Andric# include <__support/musl/xlocale.h>
450b57cec5SDimitry Andric#elif defined(_LIBCPP_HAS_MUSL_LIBC)
46d409305fSDimitry Andric# include <__support/musl/xlocale.h>
470b57cec5SDimitry Andric#endif
480b57cec5SDimitry Andric
490b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
500b57cec5SDimitry Andric#pragma GCC system_header
510b57cec5SDimitry Andric#endif
520b57cec5SDimitry Andric
530b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
540b57cec5SDimitry Andric
550b57cec5SDimitry Andric#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
560b57cec5SDimitry Andricstruct __libcpp_locale_guard {
570b57cec5SDimitry Andric  _LIBCPP_INLINE_VISIBILITY
580b57cec5SDimitry Andric  __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
590b57cec5SDimitry Andric
600b57cec5SDimitry Andric  _LIBCPP_INLINE_VISIBILITY
610b57cec5SDimitry Andric  ~__libcpp_locale_guard() {
620b57cec5SDimitry Andric    if (__old_loc_)
630b57cec5SDimitry Andric      uselocale(__old_loc_);
640b57cec5SDimitry Andric  }
650b57cec5SDimitry Andric
660b57cec5SDimitry Andric  locale_t __old_loc_;
670b57cec5SDimitry Andricprivate:
680b57cec5SDimitry Andric  __libcpp_locale_guard(__libcpp_locale_guard const&);
690b57cec5SDimitry Andric  __libcpp_locale_guard& operator=(__libcpp_locale_guard const&);
700b57cec5SDimitry Andric};
710b57cec5SDimitry Andric#elif defined(_LIBCPP_MSVCRT_LIKE)
720b57cec5SDimitry Andricstruct __libcpp_locale_guard {
730b57cec5SDimitry Andric    __libcpp_locale_guard(locale_t __l) :
740b57cec5SDimitry Andric        __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) {
750b57cec5SDimitry Andric      // Setting the locale can be expensive even when the locale given is
760b57cec5SDimitry Andric      // already the current locale, so do an explicit check to see if the
770b57cec5SDimitry Andric      // current locale is already the one we want.
780b57cec5SDimitry Andric      const char* __lc = __setlocale(nullptr);
790b57cec5SDimitry Andric      // If every category is the same, the locale string will simply be the
800b57cec5SDimitry Andric      // locale name, otherwise it will be a semicolon-separated string listing
810b57cec5SDimitry Andric      // each category.  In the second case, we know at least one category won't
820b57cec5SDimitry Andric      // be what we want, so we only have to check the first case.
83e8d8bef9SDimitry Andric      if (_VSTD::strcmp(__l.__get_locale(), __lc) != 0) {
840b57cec5SDimitry Andric        __locale_all = _strdup(__lc);
850b57cec5SDimitry Andric        if (__locale_all == nullptr)
860b57cec5SDimitry Andric          __throw_bad_alloc();
870b57cec5SDimitry Andric        __setlocale(__l.__get_locale());
880b57cec5SDimitry Andric      }
890b57cec5SDimitry Andric    }
900b57cec5SDimitry Andric    ~__libcpp_locale_guard() {
910b57cec5SDimitry Andric      // The CRT documentation doesn't explicitly say, but setlocale() does the
920b57cec5SDimitry Andric      // right thing when given a semicolon-separated list of locale settings
930b57cec5SDimitry Andric      // for the different categories in the same format as returned by
940b57cec5SDimitry Andric      // setlocale(LC_ALL, nullptr).
950b57cec5SDimitry Andric      if (__locale_all != nullptr) {
960b57cec5SDimitry Andric        __setlocale(__locale_all);
970b57cec5SDimitry Andric        free(__locale_all);
980b57cec5SDimitry Andric      }
990b57cec5SDimitry Andric      _configthreadlocale(__status);
1000b57cec5SDimitry Andric    }
1010b57cec5SDimitry Andric    static const char* __setlocale(const char* __locale) {
1020b57cec5SDimitry Andric      const char* __new_locale = setlocale(LC_ALL, __locale);
1030b57cec5SDimitry Andric      if (__new_locale == nullptr)
1040b57cec5SDimitry Andric        __throw_bad_alloc();
1050b57cec5SDimitry Andric      return __new_locale;
1060b57cec5SDimitry Andric    }
1070b57cec5SDimitry Andric    int __status;
1080b57cec5SDimitry Andric    char* __locale_all = nullptr;
1090b57cec5SDimitry Andric};
1100b57cec5SDimitry Andric#endif
1110b57cec5SDimitry Andric
1120b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS locale;
1130b57cec5SDimitry Andric
1140b57cec5SDimitry Andrictemplate <class _Facet>
1150b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
1160b57cec5SDimitry Andricbool
1170b57cec5SDimitry Andrichas_facet(const locale&) _NOEXCEPT;
1180b57cec5SDimitry Andric
1190b57cec5SDimitry Andrictemplate <class _Facet>
1200b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY
1210b57cec5SDimitry Andricconst _Facet&
1220b57cec5SDimitry Andricuse_facet(const locale&);
1230b57cec5SDimitry Andric
1240b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS locale
1250b57cec5SDimitry Andric{
1260b57cec5SDimitry Andricpublic:
1270b57cec5SDimitry Andric    // types:
1280b57cec5SDimitry Andric    class _LIBCPP_TYPE_VIS facet;
1290b57cec5SDimitry Andric    class _LIBCPP_TYPE_VIS id;
1300b57cec5SDimitry Andric
1310b57cec5SDimitry Andric    typedef int category;
1320b57cec5SDimitry Andric    _LIBCPP_AVAILABILITY_LOCALE_CATEGORY
1330b57cec5SDimitry Andric    static const category // values assigned here are for exposition only
1340b57cec5SDimitry Andric        none     = 0,
1350b57cec5SDimitry Andric        collate  = LC_COLLATE_MASK,
1360b57cec5SDimitry Andric        ctype    = LC_CTYPE_MASK,
1370b57cec5SDimitry Andric        monetary = LC_MONETARY_MASK,
1380b57cec5SDimitry Andric        numeric  = LC_NUMERIC_MASK,
1390b57cec5SDimitry Andric        time     = LC_TIME_MASK,
1400b57cec5SDimitry Andric        messages = LC_MESSAGES_MASK,
1410b57cec5SDimitry Andric        all = collate | ctype | monetary | numeric | time | messages;
1420b57cec5SDimitry Andric
1430b57cec5SDimitry Andric    // construct/copy/destroy:
1440b57cec5SDimitry Andric    locale()  _NOEXCEPT;
1450b57cec5SDimitry Andric    locale(const locale&)  _NOEXCEPT;
1460b57cec5SDimitry Andric    explicit locale(const char*);
1470b57cec5SDimitry Andric    explicit locale(const string&);
1480b57cec5SDimitry Andric    locale(const locale&, const char*, category);
1490b57cec5SDimitry Andric    locale(const locale&, const string&, category);
1500b57cec5SDimitry Andric    template <class _Facet>
1510b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
1520b57cec5SDimitry Andric    locale(const locale&, const locale&, category);
1530b57cec5SDimitry Andric
1540b57cec5SDimitry Andric    ~locale();
1550b57cec5SDimitry Andric
1560b57cec5SDimitry Andric    const locale& operator=(const locale&)  _NOEXCEPT;
1570b57cec5SDimitry Andric
1580b57cec5SDimitry Andric    template <class _Facet>
1590b57cec5SDimitry Andric      _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1600b57cec5SDimitry Andric      locale combine(const locale&) const;
1610b57cec5SDimitry Andric
1620b57cec5SDimitry Andric    // locale operations:
1630b57cec5SDimitry Andric    string name() const;
1640b57cec5SDimitry Andric    bool operator==(const locale&) const;
1650b57cec5SDimitry Andric    bool operator!=(const locale& __y) const {return !(*this == __y);}
1660b57cec5SDimitry Andric    template <class _CharT, class _Traits, class _Allocator>
1670b57cec5SDimitry Andric      _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1680b57cec5SDimitry Andric      bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
1690b57cec5SDimitry Andric                      const basic_string<_CharT, _Traits, _Allocator>&) const;
1700b57cec5SDimitry Andric
1710b57cec5SDimitry Andric    // global locale objects:
1720b57cec5SDimitry Andric    static locale global(const locale&);
1730b57cec5SDimitry Andric    static const locale& classic();
1740b57cec5SDimitry Andric
1750b57cec5SDimitry Andricprivate:
1760b57cec5SDimitry Andric    class __imp;
1770b57cec5SDimitry Andric    __imp* __locale_;
1780b57cec5SDimitry Andric
1790b57cec5SDimitry Andric    void __install_ctor(const locale&, facet*, long);
1800b57cec5SDimitry Andric    static locale& __global();
1810b57cec5SDimitry Andric    bool has_facet(id&) const;
1820b57cec5SDimitry Andric    const facet* use_facet(id&) const;
1830b57cec5SDimitry Andric
1840b57cec5SDimitry Andric    template <class _Facet> friend bool has_facet(const locale&)  _NOEXCEPT;
1850b57cec5SDimitry Andric    template <class _Facet> friend const _Facet& use_facet(const locale&);
1860b57cec5SDimitry Andric};
1870b57cec5SDimitry Andric
1880b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS locale::facet
1890b57cec5SDimitry Andric    : public __shared_count
1900b57cec5SDimitry Andric{
1910b57cec5SDimitry Andricprotected:
1920b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1930b57cec5SDimitry Andric    explicit facet(size_t __refs = 0)
1940b57cec5SDimitry Andric        : __shared_count(static_cast<long>(__refs)-1) {}
1950b57cec5SDimitry Andric
1960b57cec5SDimitry Andric    virtual ~facet();
1970b57cec5SDimitry Andric
1980b57cec5SDimitry Andric//    facet(const facet&) = delete;     // effectively done in __shared_count
1990b57cec5SDimitry Andric//    void operator=(const facet&) = delete;
2000b57cec5SDimitry Andricprivate:
2010b57cec5SDimitry Andric    virtual void __on_zero_shared() _NOEXCEPT;
2020b57cec5SDimitry Andric};
2030b57cec5SDimitry Andric
2040b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS locale::id
2050b57cec5SDimitry Andric{
2060b57cec5SDimitry Andric    once_flag      __flag_;
2070b57cec5SDimitry Andric    int32_t        __id_;
2080b57cec5SDimitry Andric
2090b57cec5SDimitry Andric    static int32_t __next_id;
2100b57cec5SDimitry Andricpublic:
2110b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
2120eae32dcSDimitry Andric    void operator=(const id&) = delete;
2130eae32dcSDimitry Andric    id(const id&) = delete;
2140eae32dcSDimitry Andric
2150b57cec5SDimitry Andricprivate:
2160b57cec5SDimitry Andric    void __init();
2170b57cec5SDimitry Andricpublic:  // only needed for tests
2180b57cec5SDimitry Andric    long __get();
2190b57cec5SDimitry Andric
2200b57cec5SDimitry Andric    friend class locale;
2210b57cec5SDimitry Andric    friend class locale::__imp;
2220b57cec5SDimitry Andric};
2230b57cec5SDimitry Andric
2240b57cec5SDimitry Andrictemplate <class _Facet>
2250b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
2260b57cec5SDimitry Andriclocale::locale(const locale& __other, _Facet* __f)
2270b57cec5SDimitry Andric{
2280b57cec5SDimitry Andric    __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
2290b57cec5SDimitry Andric}
2300b57cec5SDimitry Andric
2310b57cec5SDimitry Andrictemplate <class _Facet>
2320b57cec5SDimitry Andriclocale
2330b57cec5SDimitry Andriclocale::combine(const locale& __other) const
2340b57cec5SDimitry Andric{
2350b57cec5SDimitry Andric    if (!_VSTD::has_facet<_Facet>(__other))
2360b57cec5SDimitry Andric        __throw_runtime_error("locale::combine: locale missing facet");
2370b57cec5SDimitry Andric
2380b57cec5SDimitry Andric    return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
2390b57cec5SDimitry Andric}
2400b57cec5SDimitry Andric
2410b57cec5SDimitry Andrictemplate <class _Facet>
2420b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
2430b57cec5SDimitry Andricbool
2440b57cec5SDimitry Andrichas_facet(const locale& __l)  _NOEXCEPT
2450b57cec5SDimitry Andric{
2460b57cec5SDimitry Andric    return __l.has_facet(_Facet::id);
2470b57cec5SDimitry Andric}
2480b57cec5SDimitry Andric
2490b57cec5SDimitry Andrictemplate <class _Facet>
2500b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
2510b57cec5SDimitry Andricconst _Facet&
2520b57cec5SDimitry Andricuse_facet(const locale& __l)
2530b57cec5SDimitry Andric{
2540b57cec5SDimitry Andric    return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
2550b57cec5SDimitry Andric}
2560b57cec5SDimitry Andric
2570b57cec5SDimitry Andric// template <class _CharT> class collate;
2580b57cec5SDimitry Andric
2590b57cec5SDimitry Andrictemplate <class _CharT>
2600b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS collate
2610b57cec5SDimitry Andric    : public locale::facet
2620b57cec5SDimitry Andric{
2630b57cec5SDimitry Andricpublic:
2640b57cec5SDimitry Andric    typedef _CharT char_type;
2650b57cec5SDimitry Andric    typedef basic_string<char_type> string_type;
2660b57cec5SDimitry Andric
2670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2680b57cec5SDimitry Andric    explicit collate(size_t __refs = 0)
2690b57cec5SDimitry Andric        : locale::facet(__refs) {}
2700b57cec5SDimitry Andric
2710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2720b57cec5SDimitry Andric    int compare(const char_type* __lo1, const char_type* __hi1,
2730b57cec5SDimitry Andric                const char_type* __lo2, const char_type* __hi2) const
2740b57cec5SDimitry Andric    {
2750b57cec5SDimitry Andric        return do_compare(__lo1, __hi1, __lo2, __hi2);
2760b57cec5SDimitry Andric    }
2770b57cec5SDimitry Andric
2780b57cec5SDimitry Andric    // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work
2790b57cec5SDimitry Andric    // around a dllimport bug that expects an external instantiation.
2800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2810b57cec5SDimitry Andric    _LIBCPP_ALWAYS_INLINE
2820b57cec5SDimitry Andric    string_type transform(const char_type* __lo, const char_type* __hi) const
2830b57cec5SDimitry Andric    {
2840b57cec5SDimitry Andric        return do_transform(__lo, __hi);
2850b57cec5SDimitry Andric    }
2860b57cec5SDimitry Andric
2870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2880b57cec5SDimitry Andric    long hash(const char_type* __lo, const char_type* __hi) const
2890b57cec5SDimitry Andric    {
2900b57cec5SDimitry Andric        return do_hash(__lo, __hi);
2910b57cec5SDimitry Andric    }
2920b57cec5SDimitry Andric
2930b57cec5SDimitry Andric    static locale::id id;
2940b57cec5SDimitry Andric
2950b57cec5SDimitry Andricprotected:
2960b57cec5SDimitry Andric    ~collate();
2970b57cec5SDimitry Andric    virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
2980b57cec5SDimitry Andric                           const char_type* __lo2, const char_type* __hi2) const;
2990b57cec5SDimitry Andric    virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
3000b57cec5SDimitry Andric        {return string_type(__lo, __hi);}
3010b57cec5SDimitry Andric    virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
3020b57cec5SDimitry Andric};
3030b57cec5SDimitry Andric
3040b57cec5SDimitry Andrictemplate <class _CharT> locale::id collate<_CharT>::id;
3050b57cec5SDimitry Andric
3060b57cec5SDimitry Andrictemplate <class _CharT>
3070b57cec5SDimitry Andriccollate<_CharT>::~collate()
3080b57cec5SDimitry Andric{
3090b57cec5SDimitry Andric}
3100b57cec5SDimitry Andric
3110b57cec5SDimitry Andrictemplate <class _CharT>
3120b57cec5SDimitry Andricint
3130b57cec5SDimitry Andriccollate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
3140b57cec5SDimitry Andric                            const char_type* __lo2, const char_type* __hi2) const
3150b57cec5SDimitry Andric{
3160b57cec5SDimitry Andric    for (; __lo2 != __hi2; ++__lo1, ++__lo2)
3170b57cec5SDimitry Andric    {
3180b57cec5SDimitry Andric        if (__lo1 == __hi1 || *__lo1 < *__lo2)
3190b57cec5SDimitry Andric            return -1;
3200b57cec5SDimitry Andric        if (*__lo2 < *__lo1)
3210b57cec5SDimitry Andric            return 1;
3220b57cec5SDimitry Andric    }
3230b57cec5SDimitry Andric    return __lo1 != __hi1;
3240b57cec5SDimitry Andric}
3250b57cec5SDimitry Andric
3260b57cec5SDimitry Andrictemplate <class _CharT>
3270b57cec5SDimitry Andriclong
3280b57cec5SDimitry Andriccollate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
3290b57cec5SDimitry Andric{
3300b57cec5SDimitry Andric    size_t __h = 0;
3310b57cec5SDimitry Andric    const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
3320b57cec5SDimitry Andric    const size_t __mask = size_t(0xF) << (__sr + 4);
3330b57cec5SDimitry Andric    for(const char_type* __p = __lo; __p != __hi; ++__p)
3340b57cec5SDimitry Andric    {
3350b57cec5SDimitry Andric        __h = (__h << 4) + static_cast<size_t>(*__p);
3360b57cec5SDimitry Andric        size_t __g = __h & __mask;
3370b57cec5SDimitry Andric        __h ^= __g | (__g >> __sr);
3380b57cec5SDimitry Andric    }
3390b57cec5SDimitry Andric    return static_cast<long>(__h);
3400b57cec5SDimitry Andric}
3410b57cec5SDimitry Andric
342e8d8bef9SDimitry Andric_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>)
343349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
344e8d8bef9SDimitry Andric_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>)
345349cc55cSDimitry Andric#endif
3460b57cec5SDimitry Andric
3470b57cec5SDimitry Andric// template <class CharT> class collate_byname;
3480b57cec5SDimitry Andric
3490b57cec5SDimitry Andrictemplate <class _CharT> class _LIBCPP_TEMPLATE_VIS collate_byname;
3500b57cec5SDimitry Andric
3510b57cec5SDimitry Andrictemplate <>
3520b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS collate_byname<char>
3530b57cec5SDimitry Andric    : public collate<char>
3540b57cec5SDimitry Andric{
3550b57cec5SDimitry Andric    locale_t __l;
3560b57cec5SDimitry Andricpublic:
3570b57cec5SDimitry Andric    typedef char char_type;
3580b57cec5SDimitry Andric    typedef basic_string<char_type> string_type;
3590b57cec5SDimitry Andric
3600b57cec5SDimitry Andric    explicit collate_byname(const char* __n, size_t __refs = 0);
3610b57cec5SDimitry Andric    explicit collate_byname(const string& __n, size_t __refs = 0);
3620b57cec5SDimitry Andric
3630b57cec5SDimitry Andricprotected:
3640b57cec5SDimitry Andric    ~collate_byname();
3650b57cec5SDimitry Andric    virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
3660b57cec5SDimitry Andric                           const char_type* __lo2, const char_type* __hi2) const;
3670b57cec5SDimitry Andric    virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
3680b57cec5SDimitry Andric};
3690b57cec5SDimitry Andric
370349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3710b57cec5SDimitry Andrictemplate <>
3720b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS collate_byname<wchar_t>
3730b57cec5SDimitry Andric    : public collate<wchar_t>
3740b57cec5SDimitry Andric{
3750b57cec5SDimitry Andric    locale_t __l;
3760b57cec5SDimitry Andricpublic:
3770b57cec5SDimitry Andric    typedef wchar_t char_type;
3780b57cec5SDimitry Andric    typedef basic_string<char_type> string_type;
3790b57cec5SDimitry Andric
3800b57cec5SDimitry Andric    explicit collate_byname(const char* __n, size_t __refs = 0);
3810b57cec5SDimitry Andric    explicit collate_byname(const string& __n, size_t __refs = 0);
3820b57cec5SDimitry Andric
3830b57cec5SDimitry Andricprotected:
3840b57cec5SDimitry Andric    ~collate_byname();
3850b57cec5SDimitry Andric
3860b57cec5SDimitry Andric    virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
3870b57cec5SDimitry Andric                           const char_type* __lo2, const char_type* __hi2) const;
3880b57cec5SDimitry Andric    virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
3890b57cec5SDimitry Andric};
390349cc55cSDimitry Andric#endif
3910b57cec5SDimitry Andric
3920b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
3930b57cec5SDimitry Andricbool
3940b57cec5SDimitry Andriclocale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
3950b57cec5SDimitry Andric                   const basic_string<_CharT, _Traits, _Allocator>& __y) const
3960b57cec5SDimitry Andric{
3970b57cec5SDimitry Andric    return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
3980b57cec5SDimitry Andric                                       __x.data(), __x.data() + __x.size(),
3990b57cec5SDimitry Andric                                       __y.data(), __y.data() + __y.size()) < 0;
4000b57cec5SDimitry Andric}
4010b57cec5SDimitry Andric
4020b57cec5SDimitry Andric// template <class charT> class ctype
4030b57cec5SDimitry Andric
4040b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS ctype_base
4050b57cec5SDimitry Andric{
4060b57cec5SDimitry Andricpublic:
407e8d8bef9SDimitry Andric#if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE)
408e8d8bef9SDimitry Andric    typedef unsigned long mask;
409e8d8bef9SDimitry Andric    static const mask space  = 1<<0;
410e8d8bef9SDimitry Andric    static const mask print  = 1<<1;
411e8d8bef9SDimitry Andric    static const mask cntrl  = 1<<2;
412e8d8bef9SDimitry Andric    static const mask upper  = 1<<3;
413e8d8bef9SDimitry Andric    static const mask lower  = 1<<4;
414e8d8bef9SDimitry Andric    static const mask alpha  = 1<<5;
415e8d8bef9SDimitry Andric    static const mask digit  = 1<<6;
416e8d8bef9SDimitry Andric    static const mask punct  = 1<<7;
417e8d8bef9SDimitry Andric    static const mask xdigit = 1<<8;
418e8d8bef9SDimitry Andric    static const mask blank  = 1<<9;
419e8d8bef9SDimitry Andric#if defined(__BIONIC__)
420e8d8bef9SDimitry Andric    // Historically this was a part of regex_traits rather than ctype_base. The
421e8d8bef9SDimitry Andric    // historical value of the constant is preserved for ABI compatibility.
422e8d8bef9SDimitry Andric    static const mask __regex_word = 0x8000;
423e8d8bef9SDimitry Andric#else
424e8d8bef9SDimitry Andric    static const mask __regex_word = 1<<10;
425e8d8bef9SDimitry Andric#endif // defined(__BIONIC__)
426e8d8bef9SDimitry Andric#elif defined(__GLIBC__)
4270b57cec5SDimitry Andric    typedef unsigned short mask;
4280b57cec5SDimitry Andric    static const mask space  = _ISspace;
4290b57cec5SDimitry Andric    static const mask print  = _ISprint;
4300b57cec5SDimitry Andric    static const mask cntrl  = _IScntrl;
4310b57cec5SDimitry Andric    static const mask upper  = _ISupper;
4320b57cec5SDimitry Andric    static const mask lower  = _ISlower;
4330b57cec5SDimitry Andric    static const mask alpha  = _ISalpha;
4340b57cec5SDimitry Andric    static const mask digit  = _ISdigit;
4350b57cec5SDimitry Andric    static const mask punct  = _ISpunct;
4360b57cec5SDimitry Andric    static const mask xdigit = _ISxdigit;
4370b57cec5SDimitry Andric    static const mask blank  = _ISblank;
4380b57cec5SDimitry Andric#if defined(__mips__)
4390b57cec5SDimitry Andric    static const mask __regex_word = static_cast<mask>(_ISbit(15));
4400b57cec5SDimitry Andric#else
4410b57cec5SDimitry Andric    static const mask __regex_word = 0x80;
4420b57cec5SDimitry Andric#endif
4430b57cec5SDimitry Andric#elif defined(_LIBCPP_MSVCRT_LIKE)
4440b57cec5SDimitry Andric    typedef unsigned short mask;
4450b57cec5SDimitry Andric    static const mask space  = _SPACE;
4460b57cec5SDimitry Andric    static const mask print  = _BLANK|_PUNCT|_ALPHA|_DIGIT;
4470b57cec5SDimitry Andric    static const mask cntrl  = _CONTROL;
4480b57cec5SDimitry Andric    static const mask upper  = _UPPER;
4490b57cec5SDimitry Andric    static const mask lower  = _LOWER;
4500b57cec5SDimitry Andric    static const mask alpha  = _ALPHA;
4510b57cec5SDimitry Andric    static const mask digit  = _DIGIT;
4520b57cec5SDimitry Andric    static const mask punct  = _PUNCT;
4530b57cec5SDimitry Andric    static const mask xdigit = _HEX;
4540b57cec5SDimitry Andric    static const mask blank  = _BLANK;
455*1fd87a68SDimitry Andric    static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used
4560b57cec5SDimitry Andric# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
4570b57cec5SDimitry Andric#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
4580b57cec5SDimitry Andric# ifdef __APPLE__
4590b57cec5SDimitry Andric    typedef __uint32_t mask;
4600b57cec5SDimitry Andric# elif defined(__FreeBSD__)
4610b57cec5SDimitry Andric    typedef unsigned long mask;
4620b57cec5SDimitry Andric# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
4630b57cec5SDimitry Andric    typedef unsigned short mask;
4640b57cec5SDimitry Andric# endif
4650b57cec5SDimitry Andric    static const mask space  = _CTYPE_S;
4660b57cec5SDimitry Andric    static const mask print  = _CTYPE_R;
4670b57cec5SDimitry Andric    static const mask cntrl  = _CTYPE_C;
4680b57cec5SDimitry Andric    static const mask upper  = _CTYPE_U;
4690b57cec5SDimitry Andric    static const mask lower  = _CTYPE_L;
4700b57cec5SDimitry Andric    static const mask alpha  = _CTYPE_A;
4710b57cec5SDimitry Andric    static const mask digit  = _CTYPE_D;
4720b57cec5SDimitry Andric    static const mask punct  = _CTYPE_P;
4730b57cec5SDimitry Andric    static const mask xdigit = _CTYPE_X;
4740b57cec5SDimitry Andric
4750b57cec5SDimitry Andric# if defined(__NetBSD__)
4760b57cec5SDimitry Andric    static const mask blank  = _CTYPE_BL;
4770b57cec5SDimitry Andric    // NetBSD defines classes up to 0x2000
4780b57cec5SDimitry Andric    // see sys/ctype_bits.h, _CTYPE_Q
4790b57cec5SDimitry Andric    static const mask __regex_word = 0x8000;
4800b57cec5SDimitry Andric# else
4810b57cec5SDimitry Andric    static const mask blank  = _CTYPE_B;
4820b57cec5SDimitry Andric    static const mask __regex_word = 0x80;
4830b57cec5SDimitry Andric# endif
4840b57cec5SDimitry Andric#elif defined(__sun__) || defined(_AIX)
4850b57cec5SDimitry Andric    typedef unsigned int mask;
4860b57cec5SDimitry Andric    static const mask space  = _ISSPACE;
4870b57cec5SDimitry Andric    static const mask print  = _ISPRINT;
4880b57cec5SDimitry Andric    static const mask cntrl  = _ISCNTRL;
4890b57cec5SDimitry Andric    static const mask upper  = _ISUPPER;
4900b57cec5SDimitry Andric    static const mask lower  = _ISLOWER;
4910b57cec5SDimitry Andric    static const mask alpha  = _ISALPHA;
4920b57cec5SDimitry Andric    static const mask digit  = _ISDIGIT;
4930b57cec5SDimitry Andric    static const mask punct  = _ISPUNCT;
4940b57cec5SDimitry Andric    static const mask xdigit = _ISXDIGIT;
4950b57cec5SDimitry Andric    static const mask blank  = _ISBLANK;
4960b57cec5SDimitry Andric    static const mask __regex_word = 0x80;
4970b57cec5SDimitry Andric#elif defined(_NEWLIB_VERSION)
4980b57cec5SDimitry Andric    // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
4990b57cec5SDimitry Andric    typedef char mask;
5000b57cec5SDimitry Andric    static const mask space  = _S;
5010b57cec5SDimitry Andric    static const mask print  = _P | _U | _L | _N | _B;
5020b57cec5SDimitry Andric    static const mask cntrl  = _C;
5030b57cec5SDimitry Andric    static const mask upper  = _U;
5040b57cec5SDimitry Andric    static const mask lower  = _L;
5050b57cec5SDimitry Andric    static const mask alpha  = _U | _L;
5060b57cec5SDimitry Andric    static const mask digit  = _N;
5070b57cec5SDimitry Andric    static const mask punct  = _P;
5080b57cec5SDimitry Andric    static const mask xdigit = _X | _N;
5090b57cec5SDimitry Andric    static const mask blank  = _B;
5100b57cec5SDimitry Andric    static const mask __regex_word = 0x80;
5110b57cec5SDimitry Andric# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
5120b57cec5SDimitry Andric# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
5130b57cec5SDimitry Andric# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
51404eeddc0SDimitry Andric#elif defined(__MVS__)
51504eeddc0SDimitry Andric# if defined(__NATIVE_ASCII_F)
51604eeddc0SDimitry Andric    typedef unsigned int mask;
51704eeddc0SDimitry Andric    static const mask space  = _ISSPACE_A;
51804eeddc0SDimitry Andric    static const mask print  = _ISPRINT_A;
51904eeddc0SDimitry Andric    static const mask cntrl  = _ISCNTRL_A;
52004eeddc0SDimitry Andric    static const mask upper  = _ISUPPER_A;
52104eeddc0SDimitry Andric    static const mask lower  = _ISLOWER_A;
52204eeddc0SDimitry Andric    static const mask alpha  = _ISALPHA_A;
52304eeddc0SDimitry Andric    static const mask digit  = _ISDIGIT_A;
52404eeddc0SDimitry Andric    static const mask punct  = _ISPUNCT_A;
52504eeddc0SDimitry Andric    static const mask xdigit = _ISXDIGIT_A;
52604eeddc0SDimitry Andric    static const mask blank  = _ISBLANK_A;
52704eeddc0SDimitry Andric# else
52804eeddc0SDimitry Andric    typedef unsigned short mask;
52904eeddc0SDimitry Andric    static const mask space  = __ISSPACE;
53004eeddc0SDimitry Andric    static const mask print  = __ISPRINT;
53104eeddc0SDimitry Andric    static const mask cntrl  = __ISCNTRL;
53204eeddc0SDimitry Andric    static const mask upper  = __ISUPPER;
53304eeddc0SDimitry Andric    static const mask lower  = __ISLOWER;
53404eeddc0SDimitry Andric    static const mask alpha  = __ISALPHA;
53504eeddc0SDimitry Andric    static const mask digit  = __ISDIGIT;
53604eeddc0SDimitry Andric    static const mask punct  = __ISPUNCT;
53704eeddc0SDimitry Andric    static const mask xdigit = __ISXDIGIT;
53804eeddc0SDimitry Andric    static const mask blank  = __ISBLANK;
53904eeddc0SDimitry Andric# endif
54004eeddc0SDimitry Andric    static const mask __regex_word = 0x8000;
5410b57cec5SDimitry Andric#else
542e8d8bef9SDimitry Andric# error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?
5430b57cec5SDimitry Andric#endif
5440b57cec5SDimitry Andric    static const mask alnum  = alpha | digit;
5450b57cec5SDimitry Andric    static const mask graph  = alnum | punct;
5460b57cec5SDimitry Andric
5470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY ctype_base() {}
548*1fd87a68SDimitry Andric
549*1fd87a68SDimitry Andric// TODO: Remove the ifndef when the assert no longer fails on AIX.
550*1fd87a68SDimitry Andric#ifndef _AIX
551*1fd87a68SDimitry Andric    static_assert((__regex_word & ~(space | print | cntrl | upper | lower | alpha | digit | punct | xdigit | blank)) == __regex_word,
552*1fd87a68SDimitry Andric                  "__regex_word can't overlap other bits");
553*1fd87a68SDimitry Andric#endif
5540b57cec5SDimitry Andric};
5550b57cec5SDimitry Andric
5560b57cec5SDimitry Andrictemplate <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
5570b57cec5SDimitry Andric
558349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
5590b57cec5SDimitry Andrictemplate <>
5600b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS ctype<wchar_t>
5610b57cec5SDimitry Andric    : public locale::facet,
5620b57cec5SDimitry Andric      public ctype_base
5630b57cec5SDimitry Andric{
5640b57cec5SDimitry Andricpublic:
5650b57cec5SDimitry Andric    typedef wchar_t char_type;
5660b57cec5SDimitry Andric
5670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5680b57cec5SDimitry Andric    explicit ctype(size_t __refs = 0)
5690b57cec5SDimitry Andric        : locale::facet(__refs) {}
5700b57cec5SDimitry Andric
5710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5720b57cec5SDimitry Andric    bool is(mask __m, char_type __c) const
5730b57cec5SDimitry Andric    {
5740b57cec5SDimitry Andric        return do_is(__m, __c);
5750b57cec5SDimitry Andric    }
5760b57cec5SDimitry Andric
5770b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5780b57cec5SDimitry Andric    const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
5790b57cec5SDimitry Andric    {
5800b57cec5SDimitry Andric        return do_is(__low, __high, __vec);
5810b57cec5SDimitry Andric    }
5820b57cec5SDimitry Andric
5830b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5840b57cec5SDimitry Andric    const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
5850b57cec5SDimitry Andric    {
5860b57cec5SDimitry Andric        return do_scan_is(__m, __low, __high);
5870b57cec5SDimitry Andric    }
5880b57cec5SDimitry Andric
5890b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5900b57cec5SDimitry Andric    const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
5910b57cec5SDimitry Andric    {
5920b57cec5SDimitry Andric        return do_scan_not(__m, __low, __high);
5930b57cec5SDimitry Andric    }
5940b57cec5SDimitry Andric
5950b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5960b57cec5SDimitry Andric    char_type toupper(char_type __c) const
5970b57cec5SDimitry Andric    {
5980b57cec5SDimitry Andric        return do_toupper(__c);
5990b57cec5SDimitry Andric    }
6000b57cec5SDimitry Andric
6010b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6020b57cec5SDimitry Andric    const char_type* toupper(char_type* __low, const char_type* __high) const
6030b57cec5SDimitry Andric    {
6040b57cec5SDimitry Andric        return do_toupper(__low, __high);
6050b57cec5SDimitry Andric    }
6060b57cec5SDimitry Andric
6070b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6080b57cec5SDimitry Andric    char_type tolower(char_type __c) const
6090b57cec5SDimitry Andric    {
6100b57cec5SDimitry Andric        return do_tolower(__c);
6110b57cec5SDimitry Andric    }
6120b57cec5SDimitry Andric
6130b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6140b57cec5SDimitry Andric    const char_type* tolower(char_type* __low, const char_type* __high) const
6150b57cec5SDimitry Andric    {
6160b57cec5SDimitry Andric        return do_tolower(__low, __high);
6170b57cec5SDimitry Andric    }
6180b57cec5SDimitry Andric
6190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6200b57cec5SDimitry Andric    char_type widen(char __c) const
6210b57cec5SDimitry Andric    {
6220b57cec5SDimitry Andric        return do_widen(__c);
6230b57cec5SDimitry Andric    }
6240b57cec5SDimitry Andric
6250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6260b57cec5SDimitry Andric    const char* widen(const char* __low, const char* __high, char_type* __to) const
6270b57cec5SDimitry Andric    {
6280b57cec5SDimitry Andric        return do_widen(__low, __high, __to);
6290b57cec5SDimitry Andric    }
6300b57cec5SDimitry Andric
6310b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6320b57cec5SDimitry Andric    char narrow(char_type __c, char __dfault) const
6330b57cec5SDimitry Andric    {
6340b57cec5SDimitry Andric        return do_narrow(__c, __dfault);
6350b57cec5SDimitry Andric    }
6360b57cec5SDimitry Andric
6370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6380b57cec5SDimitry Andric    const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
6390b57cec5SDimitry Andric    {
6400b57cec5SDimitry Andric        return do_narrow(__low, __high, __dfault, __to);
6410b57cec5SDimitry Andric    }
6420b57cec5SDimitry Andric
6430b57cec5SDimitry Andric    static locale::id id;
6440b57cec5SDimitry Andric
6450b57cec5SDimitry Andricprotected:
6460b57cec5SDimitry Andric    ~ctype();
6470b57cec5SDimitry Andric    virtual bool do_is(mask __m, char_type __c) const;
6480b57cec5SDimitry Andric    virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
6490b57cec5SDimitry Andric    virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
6500b57cec5SDimitry Andric    virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
6510b57cec5SDimitry Andric    virtual char_type do_toupper(char_type) const;
6520b57cec5SDimitry Andric    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
6530b57cec5SDimitry Andric    virtual char_type do_tolower(char_type) const;
6540b57cec5SDimitry Andric    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
6550b57cec5SDimitry Andric    virtual char_type do_widen(char) const;
6560b57cec5SDimitry Andric    virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
6570b57cec5SDimitry Andric    virtual char do_narrow(char_type, char __dfault) const;
6580b57cec5SDimitry Andric    virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
6590b57cec5SDimitry Andric};
660349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
6610b57cec5SDimitry Andric
6620b57cec5SDimitry Andrictemplate <>
6630b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS ctype<char>
6640b57cec5SDimitry Andric    : public locale::facet, public ctype_base
6650b57cec5SDimitry Andric{
6660b57cec5SDimitry Andric    const mask* __tab_;
6670b57cec5SDimitry Andric    bool        __del_;
6680b57cec5SDimitry Andricpublic:
6690b57cec5SDimitry Andric    typedef char char_type;
6700b57cec5SDimitry Andric
671e8d8bef9SDimitry Andric    explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0);
6720b57cec5SDimitry Andric
6730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6740b57cec5SDimitry Andric    bool is(mask __m, char_type __c) const
6750b57cec5SDimitry Andric    {
6760b57cec5SDimitry Andric        return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false;
6770b57cec5SDimitry Andric    }
6780b57cec5SDimitry Andric
6790b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6800b57cec5SDimitry Andric    const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
6810b57cec5SDimitry Andric    {
6820b57cec5SDimitry Andric        for (; __low != __high; ++__low, ++__vec)
6830b57cec5SDimitry Andric            *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
6840b57cec5SDimitry Andric        return __low;
6850b57cec5SDimitry Andric    }
6860b57cec5SDimitry Andric
6870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6880b57cec5SDimitry Andric    const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
6890b57cec5SDimitry Andric    {
6900b57cec5SDimitry Andric        for (; __low != __high; ++__low)
6910b57cec5SDimitry Andric            if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
6920b57cec5SDimitry Andric                break;
6930b57cec5SDimitry Andric        return __low;
6940b57cec5SDimitry Andric    }
6950b57cec5SDimitry Andric
6960b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6970b57cec5SDimitry Andric    const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
6980b57cec5SDimitry Andric    {
6990b57cec5SDimitry Andric        for (; __low != __high; ++__low)
7000b57cec5SDimitry Andric            if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)))
7010b57cec5SDimitry Andric                break;
7020b57cec5SDimitry Andric        return __low;
7030b57cec5SDimitry Andric    }
7040b57cec5SDimitry Andric
7050b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7060b57cec5SDimitry Andric    char_type toupper(char_type __c) const
7070b57cec5SDimitry Andric    {
7080b57cec5SDimitry Andric        return do_toupper(__c);
7090b57cec5SDimitry Andric    }
7100b57cec5SDimitry Andric
7110b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7120b57cec5SDimitry Andric    const char_type* toupper(char_type* __low, const char_type* __high) const
7130b57cec5SDimitry Andric    {
7140b57cec5SDimitry Andric        return do_toupper(__low, __high);
7150b57cec5SDimitry Andric    }
7160b57cec5SDimitry Andric
7170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7180b57cec5SDimitry Andric    char_type tolower(char_type __c) const
7190b57cec5SDimitry Andric    {
7200b57cec5SDimitry Andric        return do_tolower(__c);
7210b57cec5SDimitry Andric    }
7220b57cec5SDimitry Andric
7230b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7240b57cec5SDimitry Andric    const char_type* tolower(char_type* __low, const char_type* __high) const
7250b57cec5SDimitry Andric    {
7260b57cec5SDimitry Andric        return do_tolower(__low, __high);
7270b57cec5SDimitry Andric    }
7280b57cec5SDimitry Andric
7290b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7300b57cec5SDimitry Andric    char_type widen(char __c) const
7310b57cec5SDimitry Andric    {
7320b57cec5SDimitry Andric        return do_widen(__c);
7330b57cec5SDimitry Andric    }
7340b57cec5SDimitry Andric
7350b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7360b57cec5SDimitry Andric    const char* widen(const char* __low, const char* __high, char_type* __to) const
7370b57cec5SDimitry Andric    {
7380b57cec5SDimitry Andric        return do_widen(__low, __high, __to);
7390b57cec5SDimitry Andric    }
7400b57cec5SDimitry Andric
7410b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7420b57cec5SDimitry Andric    char narrow(char_type __c, char __dfault) const
7430b57cec5SDimitry Andric    {
7440b57cec5SDimitry Andric        return do_narrow(__c, __dfault);
7450b57cec5SDimitry Andric    }
7460b57cec5SDimitry Andric
7470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7480b57cec5SDimitry Andric    const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
7490b57cec5SDimitry Andric    {
7500b57cec5SDimitry Andric        return do_narrow(__low, __high, __dfault, __to);
7510b57cec5SDimitry Andric    }
7520b57cec5SDimitry Andric
7530b57cec5SDimitry Andric    static locale::id id;
7540b57cec5SDimitry Andric
7550b57cec5SDimitry Andric#ifdef _CACHED_RUNES
7560b57cec5SDimitry Andric    static const size_t table_size = _CACHED_RUNES;
7570b57cec5SDimitry Andric#else
7580b57cec5SDimitry Andric    static const size_t table_size = 256;  // FIXME: Don't hardcode this.
7590b57cec5SDimitry Andric#endif
7600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const mask* table() const  _NOEXCEPT {return __tab_;}
7610b57cec5SDimitry Andric    static const mask* classic_table()  _NOEXCEPT;
7620b57cec5SDimitry Andric#if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
7630b57cec5SDimitry Andric    static const int* __classic_upper_table() _NOEXCEPT;
7640b57cec5SDimitry Andric    static const int* __classic_lower_table() _NOEXCEPT;
7650b57cec5SDimitry Andric#endif
7660b57cec5SDimitry Andric#if defined(__NetBSD__)
7670b57cec5SDimitry Andric    static const short* __classic_upper_table() _NOEXCEPT;
7680b57cec5SDimitry Andric    static const short* __classic_lower_table() _NOEXCEPT;
7690b57cec5SDimitry Andric#endif
77004eeddc0SDimitry Andric#if defined(__MVS__)
77104eeddc0SDimitry Andric    static const unsigned short* __classic_upper_table() _NOEXCEPT;
77204eeddc0SDimitry Andric    static const unsigned short* __classic_lower_table() _NOEXCEPT;
77304eeddc0SDimitry Andric#endif
7740b57cec5SDimitry Andric
7750b57cec5SDimitry Andricprotected:
7760b57cec5SDimitry Andric    ~ctype();
7770b57cec5SDimitry Andric    virtual char_type do_toupper(char_type __c) const;
7780b57cec5SDimitry Andric    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
7790b57cec5SDimitry Andric    virtual char_type do_tolower(char_type __c) const;
7800b57cec5SDimitry Andric    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
7810b57cec5SDimitry Andric    virtual char_type do_widen(char __c) const;
7820b57cec5SDimitry Andric    virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
7830b57cec5SDimitry Andric    virtual char do_narrow(char_type __c, char __dfault) const;
7840b57cec5SDimitry Andric    virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
7850b57cec5SDimitry Andric};
7860b57cec5SDimitry Andric
7870b57cec5SDimitry Andric// template <class CharT> class ctype_byname;
7880b57cec5SDimitry Andric
7890b57cec5SDimitry Andrictemplate <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype_byname;
7900b57cec5SDimitry Andric
7910b57cec5SDimitry Andrictemplate <>
7920b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS ctype_byname<char>
7930b57cec5SDimitry Andric    : public ctype<char>
7940b57cec5SDimitry Andric{
7950b57cec5SDimitry Andric    locale_t __l;
7960b57cec5SDimitry Andric
7970b57cec5SDimitry Andricpublic:
7980b57cec5SDimitry Andric    explicit ctype_byname(const char*, size_t = 0);
7990b57cec5SDimitry Andric    explicit ctype_byname(const string&, size_t = 0);
8000b57cec5SDimitry Andric
8010b57cec5SDimitry Andricprotected:
8020b57cec5SDimitry Andric    ~ctype_byname();
8030b57cec5SDimitry Andric    virtual char_type do_toupper(char_type) const;
8040b57cec5SDimitry Andric    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
8050b57cec5SDimitry Andric    virtual char_type do_tolower(char_type) const;
8060b57cec5SDimitry Andric    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
8070b57cec5SDimitry Andric};
8080b57cec5SDimitry Andric
809349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
8100b57cec5SDimitry Andrictemplate <>
8110b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
8120b57cec5SDimitry Andric    : public ctype<wchar_t>
8130b57cec5SDimitry Andric{
8140b57cec5SDimitry Andric    locale_t __l;
8150b57cec5SDimitry Andric
8160b57cec5SDimitry Andricpublic:
8170b57cec5SDimitry Andric    explicit ctype_byname(const char*, size_t = 0);
8180b57cec5SDimitry Andric    explicit ctype_byname(const string&, size_t = 0);
8190b57cec5SDimitry Andric
8200b57cec5SDimitry Andricprotected:
8210b57cec5SDimitry Andric    ~ctype_byname();
8220b57cec5SDimitry Andric    virtual bool do_is(mask __m, char_type __c) const;
8230b57cec5SDimitry Andric    virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
8240b57cec5SDimitry Andric    virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
8250b57cec5SDimitry Andric    virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
8260b57cec5SDimitry Andric    virtual char_type do_toupper(char_type) const;
8270b57cec5SDimitry Andric    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
8280b57cec5SDimitry Andric    virtual char_type do_tolower(char_type) const;
8290b57cec5SDimitry Andric    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
8300b57cec5SDimitry Andric    virtual char_type do_widen(char) const;
8310b57cec5SDimitry Andric    virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
8320b57cec5SDimitry Andric    virtual char do_narrow(char_type, char __dfault) const;
8330b57cec5SDimitry Andric    virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
8340b57cec5SDimitry Andric};
835349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
8360b57cec5SDimitry Andric
8370b57cec5SDimitry Andrictemplate <class _CharT>
8380b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
8390b57cec5SDimitry Andricbool
8400b57cec5SDimitry Andricisspace(_CharT __c, const locale& __loc)
8410b57cec5SDimitry Andric{
8420b57cec5SDimitry Andric    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
8430b57cec5SDimitry Andric}
8440b57cec5SDimitry Andric
8450b57cec5SDimitry Andrictemplate <class _CharT>
8460b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
8470b57cec5SDimitry Andricbool
8480b57cec5SDimitry Andricisprint(_CharT __c, const locale& __loc)
8490b57cec5SDimitry Andric{
8500b57cec5SDimitry Andric    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
8510b57cec5SDimitry Andric}
8520b57cec5SDimitry Andric
8530b57cec5SDimitry Andrictemplate <class _CharT>
8540b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
8550b57cec5SDimitry Andricbool
8560b57cec5SDimitry Andriciscntrl(_CharT __c, const locale& __loc)
8570b57cec5SDimitry Andric{
8580b57cec5SDimitry Andric    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
8590b57cec5SDimitry Andric}
8600b57cec5SDimitry Andric
8610b57cec5SDimitry Andrictemplate <class _CharT>
8620b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
8630b57cec5SDimitry Andricbool
8640b57cec5SDimitry Andricisupper(_CharT __c, const locale& __loc)
8650b57cec5SDimitry Andric{
8660b57cec5SDimitry Andric    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
8670b57cec5SDimitry Andric}
8680b57cec5SDimitry Andric
8690b57cec5SDimitry Andrictemplate <class _CharT>
8700b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
8710b57cec5SDimitry Andricbool
8720b57cec5SDimitry Andricislower(_CharT __c, const locale& __loc)
8730b57cec5SDimitry Andric{
8740b57cec5SDimitry Andric    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
8750b57cec5SDimitry Andric}
8760b57cec5SDimitry Andric
8770b57cec5SDimitry Andrictemplate <class _CharT>
8780b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
8790b57cec5SDimitry Andricbool
8800b57cec5SDimitry Andricisalpha(_CharT __c, const locale& __loc)
8810b57cec5SDimitry Andric{
8820b57cec5SDimitry Andric    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
8830b57cec5SDimitry Andric}
8840b57cec5SDimitry Andric
8850b57cec5SDimitry Andrictemplate <class _CharT>
8860b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
8870b57cec5SDimitry Andricbool
8880b57cec5SDimitry Andricisdigit(_CharT __c, const locale& __loc)
8890b57cec5SDimitry Andric{
8900b57cec5SDimitry Andric    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
8910b57cec5SDimitry Andric}
8920b57cec5SDimitry Andric
8930b57cec5SDimitry Andrictemplate <class _CharT>
8940b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
8950b57cec5SDimitry Andricbool
8960b57cec5SDimitry Andricispunct(_CharT __c, const locale& __loc)
8970b57cec5SDimitry Andric{
8980b57cec5SDimitry Andric    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
8990b57cec5SDimitry Andric}
9000b57cec5SDimitry Andric
9010b57cec5SDimitry Andrictemplate <class _CharT>
9020b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9030b57cec5SDimitry Andricbool
9040b57cec5SDimitry Andricisxdigit(_CharT __c, const locale& __loc)
9050b57cec5SDimitry Andric{
9060b57cec5SDimitry Andric    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
9070b57cec5SDimitry Andric}
9080b57cec5SDimitry Andric
9090b57cec5SDimitry Andrictemplate <class _CharT>
9100b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9110b57cec5SDimitry Andricbool
9120b57cec5SDimitry Andricisalnum(_CharT __c, const locale& __loc)
9130b57cec5SDimitry Andric{
9140b57cec5SDimitry Andric    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
9150b57cec5SDimitry Andric}
9160b57cec5SDimitry Andric
9170b57cec5SDimitry Andrictemplate <class _CharT>
9180b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9190b57cec5SDimitry Andricbool
9200b57cec5SDimitry Andricisgraph(_CharT __c, const locale& __loc)
9210b57cec5SDimitry Andric{
9220b57cec5SDimitry Andric    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
9230b57cec5SDimitry Andric}
9240b57cec5SDimitry Andric
9250b57cec5SDimitry Andrictemplate <class _CharT>
9260b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9270b57cec5SDimitry Andric_CharT
9280b57cec5SDimitry Andrictoupper(_CharT __c, const locale& __loc)
9290b57cec5SDimitry Andric{
9300b57cec5SDimitry Andric    return use_facet<ctype<_CharT> >(__loc).toupper(__c);
9310b57cec5SDimitry Andric}
9320b57cec5SDimitry Andric
9330b57cec5SDimitry Andrictemplate <class _CharT>
9340b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9350b57cec5SDimitry Andric_CharT
9360b57cec5SDimitry Andrictolower(_CharT __c, const locale& __loc)
9370b57cec5SDimitry Andric{
9380b57cec5SDimitry Andric    return use_facet<ctype<_CharT> >(__loc).tolower(__c);
9390b57cec5SDimitry Andric}
9400b57cec5SDimitry Andric
9410b57cec5SDimitry Andric// codecvt_base
9420b57cec5SDimitry Andric
9430b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS codecvt_base
9440b57cec5SDimitry Andric{
9450b57cec5SDimitry Andricpublic:
9460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY codecvt_base() {}
9470b57cec5SDimitry Andric    enum result {ok, partial, error, noconv};
9480b57cec5SDimitry Andric};
9490b57cec5SDimitry Andric
9500b57cec5SDimitry Andric// template <class internT, class externT, class stateT> class codecvt;
9510b57cec5SDimitry Andric
9520b57cec5SDimitry Andrictemplate <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TEMPLATE_VIS codecvt;
9530b57cec5SDimitry Andric
9540b57cec5SDimitry Andric// template <> class codecvt<char, char, mbstate_t>
9550b57cec5SDimitry Andric
9560b57cec5SDimitry Andrictemplate <>
9570b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
9580b57cec5SDimitry Andric    : public locale::facet,
9590b57cec5SDimitry Andric      public codecvt_base
9600b57cec5SDimitry Andric{
9610b57cec5SDimitry Andricpublic:
9620b57cec5SDimitry Andric    typedef char      intern_type;
9630b57cec5SDimitry Andric    typedef char      extern_type;
9640b57cec5SDimitry Andric    typedef mbstate_t state_type;
9650b57cec5SDimitry Andric
9660b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9670b57cec5SDimitry Andric    explicit codecvt(size_t __refs = 0)
9680b57cec5SDimitry Andric        : locale::facet(__refs) {}
9690b57cec5SDimitry Andric
9700b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9710b57cec5SDimitry Andric    result out(state_type& __st,
9720b57cec5SDimitry Andric               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
9730b57cec5SDimitry Andric               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
9740b57cec5SDimitry Andric    {
9750b57cec5SDimitry Andric        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
9760b57cec5SDimitry Andric    }
9770b57cec5SDimitry Andric
9780b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9790b57cec5SDimitry Andric    result unshift(state_type& __st,
9800b57cec5SDimitry Andric                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
9810b57cec5SDimitry Andric    {
9820b57cec5SDimitry Andric        return do_unshift(__st, __to, __to_end, __to_nxt);
9830b57cec5SDimitry Andric    }
9840b57cec5SDimitry Andric
9850b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9860b57cec5SDimitry Andric    result in(state_type& __st,
9870b57cec5SDimitry Andric              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
9880b57cec5SDimitry Andric              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
9890b57cec5SDimitry Andric    {
9900b57cec5SDimitry Andric        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
9910b57cec5SDimitry Andric    }
9920b57cec5SDimitry Andric
9930b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9940b57cec5SDimitry Andric    int encoding() const  _NOEXCEPT
9950b57cec5SDimitry Andric    {
9960b57cec5SDimitry Andric        return do_encoding();
9970b57cec5SDimitry Andric    }
9980b57cec5SDimitry Andric
9990b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10000b57cec5SDimitry Andric    bool always_noconv() const  _NOEXCEPT
10010b57cec5SDimitry Andric    {
10020b57cec5SDimitry Andric        return do_always_noconv();
10030b57cec5SDimitry Andric    }
10040b57cec5SDimitry Andric
10050b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10060b57cec5SDimitry Andric    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
10070b57cec5SDimitry Andric    {
10080b57cec5SDimitry Andric        return do_length(__st, __frm, __end, __mx);
10090b57cec5SDimitry Andric    }
10100b57cec5SDimitry Andric
10110b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10120b57cec5SDimitry Andric    int max_length() const  _NOEXCEPT
10130b57cec5SDimitry Andric    {
10140b57cec5SDimitry Andric        return do_max_length();
10150b57cec5SDimitry Andric    }
10160b57cec5SDimitry Andric
10170b57cec5SDimitry Andric    static locale::id id;
10180b57cec5SDimitry Andric
10190b57cec5SDimitry Andricprotected:
10200b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10210b57cec5SDimitry Andric    explicit codecvt(const char*, size_t __refs = 0)
10220b57cec5SDimitry Andric        : locale::facet(__refs) {}
10230b57cec5SDimitry Andric
10240b57cec5SDimitry Andric    ~codecvt();
10250b57cec5SDimitry Andric
10260b57cec5SDimitry Andric    virtual result do_out(state_type& __st,
10270b57cec5SDimitry Andric                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
10280b57cec5SDimitry Andric                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
10290b57cec5SDimitry Andric    virtual result do_in(state_type& __st,
10300b57cec5SDimitry Andric                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
10310b57cec5SDimitry Andric                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
10320b57cec5SDimitry Andric    virtual result do_unshift(state_type& __st,
10330b57cec5SDimitry Andric                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
10340b57cec5SDimitry Andric    virtual int do_encoding() const  _NOEXCEPT;
10350b57cec5SDimitry Andric    virtual bool do_always_noconv() const  _NOEXCEPT;
10360b57cec5SDimitry Andric    virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
10370b57cec5SDimitry Andric    virtual int do_max_length() const  _NOEXCEPT;
10380b57cec5SDimitry Andric};
10390b57cec5SDimitry Andric
10400b57cec5SDimitry Andric// template <> class codecvt<wchar_t, char, mbstate_t>
10410b57cec5SDimitry Andric
1042349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
10430b57cec5SDimitry Andrictemplate <>
10440b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
10450b57cec5SDimitry Andric    : public locale::facet,
10460b57cec5SDimitry Andric      public codecvt_base
10470b57cec5SDimitry Andric{
10480b57cec5SDimitry Andric    locale_t __l;
10490b57cec5SDimitry Andricpublic:
10500b57cec5SDimitry Andric    typedef wchar_t   intern_type;
10510b57cec5SDimitry Andric    typedef char      extern_type;
10520b57cec5SDimitry Andric    typedef mbstate_t state_type;
10530b57cec5SDimitry Andric
10540b57cec5SDimitry Andric    explicit codecvt(size_t __refs = 0);
10550b57cec5SDimitry Andric
10560b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10570b57cec5SDimitry Andric    result out(state_type& __st,
10580b57cec5SDimitry Andric               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
10590b57cec5SDimitry Andric               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
10600b57cec5SDimitry Andric    {
10610b57cec5SDimitry Andric        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
10620b57cec5SDimitry Andric    }
10630b57cec5SDimitry Andric
10640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10650b57cec5SDimitry Andric    result unshift(state_type& __st,
10660b57cec5SDimitry Andric                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
10670b57cec5SDimitry Andric    {
10680b57cec5SDimitry Andric        return do_unshift(__st, __to, __to_end, __to_nxt);
10690b57cec5SDimitry Andric    }
10700b57cec5SDimitry Andric
10710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10720b57cec5SDimitry Andric    result in(state_type& __st,
10730b57cec5SDimitry Andric              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
10740b57cec5SDimitry Andric              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
10750b57cec5SDimitry Andric    {
10760b57cec5SDimitry Andric        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
10770b57cec5SDimitry Andric    }
10780b57cec5SDimitry Andric
10790b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10800b57cec5SDimitry Andric    int encoding() const  _NOEXCEPT
10810b57cec5SDimitry Andric    {
10820b57cec5SDimitry Andric        return do_encoding();
10830b57cec5SDimitry Andric    }
10840b57cec5SDimitry Andric
10850b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10860b57cec5SDimitry Andric    bool always_noconv() const  _NOEXCEPT
10870b57cec5SDimitry Andric    {
10880b57cec5SDimitry Andric        return do_always_noconv();
10890b57cec5SDimitry Andric    }
10900b57cec5SDimitry Andric
10910b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10920b57cec5SDimitry Andric    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
10930b57cec5SDimitry Andric    {
10940b57cec5SDimitry Andric        return do_length(__st, __frm, __end, __mx);
10950b57cec5SDimitry Andric    }
10960b57cec5SDimitry Andric
10970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10980b57cec5SDimitry Andric    int max_length() const  _NOEXCEPT
10990b57cec5SDimitry Andric    {
11000b57cec5SDimitry Andric        return do_max_length();
11010b57cec5SDimitry Andric    }
11020b57cec5SDimitry Andric
11030b57cec5SDimitry Andric    static locale::id id;
11040b57cec5SDimitry Andric
11050b57cec5SDimitry Andricprotected:
11060b57cec5SDimitry Andric    explicit codecvt(const char*, size_t __refs = 0);
11070b57cec5SDimitry Andric
11080b57cec5SDimitry Andric    ~codecvt();
11090b57cec5SDimitry Andric
11100b57cec5SDimitry Andric    virtual result do_out(state_type& __st,
11110b57cec5SDimitry Andric                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
11120b57cec5SDimitry Andric                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
11130b57cec5SDimitry Andric    virtual result do_in(state_type& __st,
11140b57cec5SDimitry Andric                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
11150b57cec5SDimitry Andric                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
11160b57cec5SDimitry Andric    virtual result do_unshift(state_type& __st,
11170b57cec5SDimitry Andric                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
11180b57cec5SDimitry Andric    virtual int do_encoding() const  _NOEXCEPT;
11190b57cec5SDimitry Andric    virtual bool do_always_noconv() const  _NOEXCEPT;
11200b57cec5SDimitry Andric    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
11210b57cec5SDimitry Andric    virtual int do_max_length() const  _NOEXCEPT;
11220b57cec5SDimitry Andric};
1123349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
11240b57cec5SDimitry Andric
1125e8d8bef9SDimitry Andric// template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20
11260b57cec5SDimitry Andric
11270b57cec5SDimitry Andrictemplate <>
1128e8d8bef9SDimitry Andricclass _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
11290b57cec5SDimitry Andric    : public locale::facet,
11300b57cec5SDimitry Andric      public codecvt_base
11310b57cec5SDimitry Andric{
11320b57cec5SDimitry Andricpublic:
11330b57cec5SDimitry Andric    typedef char16_t  intern_type;
11340b57cec5SDimitry Andric    typedef char      extern_type;
11350b57cec5SDimitry Andric    typedef mbstate_t state_type;
11360b57cec5SDimitry Andric
11370b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11380b57cec5SDimitry Andric    explicit codecvt(size_t __refs = 0)
11390b57cec5SDimitry Andric        : locale::facet(__refs) {}
11400b57cec5SDimitry Andric
11410b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11420b57cec5SDimitry Andric    result out(state_type& __st,
11430b57cec5SDimitry Andric               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
11440b57cec5SDimitry Andric               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
11450b57cec5SDimitry Andric    {
11460b57cec5SDimitry Andric        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
11470b57cec5SDimitry Andric    }
11480b57cec5SDimitry Andric
11490b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11500b57cec5SDimitry Andric    result unshift(state_type& __st,
11510b57cec5SDimitry Andric                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
11520b57cec5SDimitry Andric    {
11530b57cec5SDimitry Andric        return do_unshift(__st, __to, __to_end, __to_nxt);
11540b57cec5SDimitry Andric    }
11550b57cec5SDimitry Andric
11560b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11570b57cec5SDimitry Andric    result in(state_type& __st,
11580b57cec5SDimitry Andric              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
11590b57cec5SDimitry Andric              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
11600b57cec5SDimitry Andric    {
11610b57cec5SDimitry Andric        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
11620b57cec5SDimitry Andric    }
11630b57cec5SDimitry Andric
11640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11650b57cec5SDimitry Andric    int encoding() const  _NOEXCEPT
11660b57cec5SDimitry Andric    {
11670b57cec5SDimitry Andric        return do_encoding();
11680b57cec5SDimitry Andric    }
11690b57cec5SDimitry Andric
11700b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11710b57cec5SDimitry Andric    bool always_noconv() const  _NOEXCEPT
11720b57cec5SDimitry Andric    {
11730b57cec5SDimitry Andric        return do_always_noconv();
11740b57cec5SDimitry Andric    }
11750b57cec5SDimitry Andric
11760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11770b57cec5SDimitry Andric    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
11780b57cec5SDimitry Andric    {
11790b57cec5SDimitry Andric        return do_length(__st, __frm, __end, __mx);
11800b57cec5SDimitry Andric    }
11810b57cec5SDimitry Andric
11820b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11830b57cec5SDimitry Andric    int max_length() const  _NOEXCEPT
11840b57cec5SDimitry Andric    {
11850b57cec5SDimitry Andric        return do_max_length();
11860b57cec5SDimitry Andric    }
11870b57cec5SDimitry Andric
11880b57cec5SDimitry Andric    static locale::id id;
11890b57cec5SDimitry Andric
11900b57cec5SDimitry Andricprotected:
11910b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11920b57cec5SDimitry Andric    explicit codecvt(const char*, size_t __refs = 0)
11930b57cec5SDimitry Andric        : locale::facet(__refs) {}
11940b57cec5SDimitry Andric
11950b57cec5SDimitry Andric    ~codecvt();
11960b57cec5SDimitry Andric
11970b57cec5SDimitry Andric    virtual result do_out(state_type& __st,
11980b57cec5SDimitry Andric                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
11990b57cec5SDimitry Andric                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
12000b57cec5SDimitry Andric    virtual result do_in(state_type& __st,
12010b57cec5SDimitry Andric                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
12020b57cec5SDimitry Andric                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
12030b57cec5SDimitry Andric    virtual result do_unshift(state_type& __st,
12040b57cec5SDimitry Andric                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
12050b57cec5SDimitry Andric    virtual int do_encoding() const  _NOEXCEPT;
12060b57cec5SDimitry Andric    virtual bool do_always_noconv() const  _NOEXCEPT;
12070b57cec5SDimitry Andric    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
12080b57cec5SDimitry Andric    virtual int do_max_length() const  _NOEXCEPT;
12090b57cec5SDimitry Andric};
12100b57cec5SDimitry Andric
1211fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T
1212e8d8bef9SDimitry Andric
1213e8d8bef9SDimitry Andric// template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20
12140b57cec5SDimitry Andric
12150b57cec5SDimitry Andrictemplate <>
1216e8d8bef9SDimitry Andricclass _LIBCPP_TYPE_VIS codecvt<char16_t, char8_t, mbstate_t>
1217e8d8bef9SDimitry Andric    : public locale::facet,
1218e8d8bef9SDimitry Andric      public codecvt_base
1219e8d8bef9SDimitry Andric{
1220e8d8bef9SDimitry Andricpublic:
1221e8d8bef9SDimitry Andric    typedef char16_t  intern_type;
1222e8d8bef9SDimitry Andric    typedef char8_t   extern_type;
1223e8d8bef9SDimitry Andric    typedef mbstate_t state_type;
1224e8d8bef9SDimitry Andric
1225e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1226e8d8bef9SDimitry Andric    explicit codecvt(size_t __refs = 0)
1227e8d8bef9SDimitry Andric        : locale::facet(__refs) {}
1228e8d8bef9SDimitry Andric
1229e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1230e8d8bef9SDimitry Andric    result out(state_type& __st,
1231e8d8bef9SDimitry Andric               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1232e8d8bef9SDimitry Andric               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1233e8d8bef9SDimitry Andric    {
1234e8d8bef9SDimitry Andric        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1235e8d8bef9SDimitry Andric    }
1236e8d8bef9SDimitry Andric
1237e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1238e8d8bef9SDimitry Andric    result unshift(state_type& __st,
1239e8d8bef9SDimitry Andric                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1240e8d8bef9SDimitry Andric    {
1241e8d8bef9SDimitry Andric        return do_unshift(__st, __to, __to_end, __to_nxt);
1242e8d8bef9SDimitry Andric    }
1243e8d8bef9SDimitry Andric
1244e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1245e8d8bef9SDimitry Andric    result in(state_type& __st,
1246e8d8bef9SDimitry Andric              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1247e8d8bef9SDimitry Andric              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1248e8d8bef9SDimitry Andric    {
1249e8d8bef9SDimitry Andric        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1250e8d8bef9SDimitry Andric    }
1251e8d8bef9SDimitry Andric
1252e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1253e8d8bef9SDimitry Andric    int encoding() const  _NOEXCEPT
1254e8d8bef9SDimitry Andric    {
1255e8d8bef9SDimitry Andric        return do_encoding();
1256e8d8bef9SDimitry Andric    }
1257e8d8bef9SDimitry Andric
1258e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1259e8d8bef9SDimitry Andric    bool always_noconv() const  _NOEXCEPT
1260e8d8bef9SDimitry Andric    {
1261e8d8bef9SDimitry Andric        return do_always_noconv();
1262e8d8bef9SDimitry Andric    }
1263e8d8bef9SDimitry Andric
1264e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1265e8d8bef9SDimitry Andric    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1266e8d8bef9SDimitry Andric    {
1267e8d8bef9SDimitry Andric        return do_length(__st, __frm, __end, __mx);
1268e8d8bef9SDimitry Andric    }
1269e8d8bef9SDimitry Andric
1270e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1271e8d8bef9SDimitry Andric    int max_length() const  _NOEXCEPT
1272e8d8bef9SDimitry Andric    {
1273e8d8bef9SDimitry Andric        return do_max_length();
1274e8d8bef9SDimitry Andric    }
1275e8d8bef9SDimitry Andric
1276e8d8bef9SDimitry Andric    static locale::id id;
1277e8d8bef9SDimitry Andric
1278e8d8bef9SDimitry Andricprotected:
1279e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1280e8d8bef9SDimitry Andric    explicit codecvt(const char*, size_t __refs = 0)
1281e8d8bef9SDimitry Andric        : locale::facet(__refs) {}
1282e8d8bef9SDimitry Andric
1283e8d8bef9SDimitry Andric    ~codecvt();
1284e8d8bef9SDimitry Andric
1285e8d8bef9SDimitry Andric    virtual result do_out(state_type& __st,
1286e8d8bef9SDimitry Andric                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1287e8d8bef9SDimitry Andric                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1288e8d8bef9SDimitry Andric    virtual result do_in(state_type& __st,
1289e8d8bef9SDimitry Andric                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1290e8d8bef9SDimitry Andric                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1291e8d8bef9SDimitry Andric    virtual result do_unshift(state_type& __st,
1292e8d8bef9SDimitry Andric                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1293e8d8bef9SDimitry Andric    virtual int do_encoding() const  _NOEXCEPT;
1294e8d8bef9SDimitry Andric    virtual bool do_always_noconv() const  _NOEXCEPT;
1295e8d8bef9SDimitry Andric    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1296e8d8bef9SDimitry Andric    virtual int do_max_length() const  _NOEXCEPT;
1297e8d8bef9SDimitry Andric};
1298e8d8bef9SDimitry Andric
1299e8d8bef9SDimitry Andric#endif
1300e8d8bef9SDimitry Andric
1301e8d8bef9SDimitry Andric// template <> class codecvt<char32_t, char, mbstate_t> // deprecated in C++20
1302e8d8bef9SDimitry Andric
1303e8d8bef9SDimitry Andrictemplate <>
1304e8d8bef9SDimitry Andricclass _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
13050b57cec5SDimitry Andric    : public locale::facet,
13060b57cec5SDimitry Andric      public codecvt_base
13070b57cec5SDimitry Andric{
13080b57cec5SDimitry Andricpublic:
13090b57cec5SDimitry Andric    typedef char32_t  intern_type;
13100b57cec5SDimitry Andric    typedef char      extern_type;
13110b57cec5SDimitry Andric    typedef mbstate_t state_type;
13120b57cec5SDimitry Andric
13130b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13140b57cec5SDimitry Andric    explicit codecvt(size_t __refs = 0)
13150b57cec5SDimitry Andric        : locale::facet(__refs) {}
13160b57cec5SDimitry Andric
13170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13180b57cec5SDimitry Andric    result out(state_type& __st,
13190b57cec5SDimitry Andric               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
13200b57cec5SDimitry Andric               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
13210b57cec5SDimitry Andric    {
13220b57cec5SDimitry Andric        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
13230b57cec5SDimitry Andric    }
13240b57cec5SDimitry Andric
13250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13260b57cec5SDimitry Andric    result unshift(state_type& __st,
13270b57cec5SDimitry Andric                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
13280b57cec5SDimitry Andric    {
13290b57cec5SDimitry Andric        return do_unshift(__st, __to, __to_end, __to_nxt);
13300b57cec5SDimitry Andric    }
13310b57cec5SDimitry Andric
13320b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13330b57cec5SDimitry Andric    result in(state_type& __st,
13340b57cec5SDimitry Andric              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
13350b57cec5SDimitry Andric              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
13360b57cec5SDimitry Andric    {
13370b57cec5SDimitry Andric        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
13380b57cec5SDimitry Andric    }
13390b57cec5SDimitry Andric
13400b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13410b57cec5SDimitry Andric    int encoding() const  _NOEXCEPT
13420b57cec5SDimitry Andric    {
13430b57cec5SDimitry Andric        return do_encoding();
13440b57cec5SDimitry Andric    }
13450b57cec5SDimitry Andric
13460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13470b57cec5SDimitry Andric    bool always_noconv() const  _NOEXCEPT
13480b57cec5SDimitry Andric    {
13490b57cec5SDimitry Andric        return do_always_noconv();
13500b57cec5SDimitry Andric    }
13510b57cec5SDimitry Andric
13520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13530b57cec5SDimitry Andric    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
13540b57cec5SDimitry Andric    {
13550b57cec5SDimitry Andric        return do_length(__st, __frm, __end, __mx);
13560b57cec5SDimitry Andric    }
13570b57cec5SDimitry Andric
13580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13590b57cec5SDimitry Andric    int max_length() const  _NOEXCEPT
13600b57cec5SDimitry Andric    {
13610b57cec5SDimitry Andric        return do_max_length();
13620b57cec5SDimitry Andric    }
13630b57cec5SDimitry Andric
13640b57cec5SDimitry Andric    static locale::id id;
13650b57cec5SDimitry Andric
13660b57cec5SDimitry Andricprotected:
13670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13680b57cec5SDimitry Andric    explicit codecvt(const char*, size_t __refs = 0)
13690b57cec5SDimitry Andric        : locale::facet(__refs) {}
13700b57cec5SDimitry Andric
13710b57cec5SDimitry Andric    ~codecvt();
13720b57cec5SDimitry Andric
13730b57cec5SDimitry Andric    virtual result do_out(state_type& __st,
13740b57cec5SDimitry Andric                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
13750b57cec5SDimitry Andric                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
13760b57cec5SDimitry Andric    virtual result do_in(state_type& __st,
13770b57cec5SDimitry Andric                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
13780b57cec5SDimitry Andric                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
13790b57cec5SDimitry Andric    virtual result do_unshift(state_type& __st,
13800b57cec5SDimitry Andric                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
13810b57cec5SDimitry Andric    virtual int do_encoding() const  _NOEXCEPT;
13820b57cec5SDimitry Andric    virtual bool do_always_noconv() const  _NOEXCEPT;
13830b57cec5SDimitry Andric    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
13840b57cec5SDimitry Andric    virtual int do_max_length() const  _NOEXCEPT;
13850b57cec5SDimitry Andric};
13860b57cec5SDimitry Andric
1387fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T
1388e8d8bef9SDimitry Andric
1389e8d8bef9SDimitry Andric// template <> class codecvt<char32_t, char8_t, mbstate_t> // C++20
1390e8d8bef9SDimitry Andric
1391e8d8bef9SDimitry Andrictemplate <>
1392e8d8bef9SDimitry Andricclass _LIBCPP_TYPE_VIS codecvt<char32_t, char8_t, mbstate_t>
1393e8d8bef9SDimitry Andric    : public locale::facet,
1394e8d8bef9SDimitry Andric      public codecvt_base
1395e8d8bef9SDimitry Andric{
1396e8d8bef9SDimitry Andricpublic:
1397e8d8bef9SDimitry Andric    typedef char32_t  intern_type;
1398e8d8bef9SDimitry Andric    typedef char8_t   extern_type;
1399e8d8bef9SDimitry Andric    typedef mbstate_t state_type;
1400e8d8bef9SDimitry Andric
1401e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1402e8d8bef9SDimitry Andric    explicit codecvt(size_t __refs = 0)
1403e8d8bef9SDimitry Andric        : locale::facet(__refs) {}
1404e8d8bef9SDimitry Andric
1405e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1406e8d8bef9SDimitry Andric    result out(state_type& __st,
1407e8d8bef9SDimitry Andric               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1408e8d8bef9SDimitry Andric               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1409e8d8bef9SDimitry Andric    {
1410e8d8bef9SDimitry Andric        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1411e8d8bef9SDimitry Andric    }
1412e8d8bef9SDimitry Andric
1413e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1414e8d8bef9SDimitry Andric    result unshift(state_type& __st,
1415e8d8bef9SDimitry Andric                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1416e8d8bef9SDimitry Andric    {
1417e8d8bef9SDimitry Andric        return do_unshift(__st, __to, __to_end, __to_nxt);
1418e8d8bef9SDimitry Andric    }
1419e8d8bef9SDimitry Andric
1420e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1421e8d8bef9SDimitry Andric    result in(state_type& __st,
1422e8d8bef9SDimitry Andric              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1423e8d8bef9SDimitry Andric              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1424e8d8bef9SDimitry Andric    {
1425e8d8bef9SDimitry Andric        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1426e8d8bef9SDimitry Andric    }
1427e8d8bef9SDimitry Andric
1428e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1429e8d8bef9SDimitry Andric    int encoding() const  _NOEXCEPT
1430e8d8bef9SDimitry Andric    {
1431e8d8bef9SDimitry Andric        return do_encoding();
1432e8d8bef9SDimitry Andric    }
1433e8d8bef9SDimitry Andric
1434e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1435e8d8bef9SDimitry Andric    bool always_noconv() const  _NOEXCEPT
1436e8d8bef9SDimitry Andric    {
1437e8d8bef9SDimitry Andric        return do_always_noconv();
1438e8d8bef9SDimitry Andric    }
1439e8d8bef9SDimitry Andric
1440e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1441e8d8bef9SDimitry Andric    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1442e8d8bef9SDimitry Andric    {
1443e8d8bef9SDimitry Andric        return do_length(__st, __frm, __end, __mx);
1444e8d8bef9SDimitry Andric    }
1445e8d8bef9SDimitry Andric
1446e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1447e8d8bef9SDimitry Andric    int max_length() const  _NOEXCEPT
1448e8d8bef9SDimitry Andric    {
1449e8d8bef9SDimitry Andric        return do_max_length();
1450e8d8bef9SDimitry Andric    }
1451e8d8bef9SDimitry Andric
1452e8d8bef9SDimitry Andric    static locale::id id;
1453e8d8bef9SDimitry Andric
1454e8d8bef9SDimitry Andricprotected:
1455e8d8bef9SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
1456e8d8bef9SDimitry Andric    explicit codecvt(const char*, size_t __refs = 0)
1457e8d8bef9SDimitry Andric        : locale::facet(__refs) {}
1458e8d8bef9SDimitry Andric
1459e8d8bef9SDimitry Andric    ~codecvt();
1460e8d8bef9SDimitry Andric
1461e8d8bef9SDimitry Andric    virtual result do_out(state_type& __st,
1462e8d8bef9SDimitry Andric                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1463e8d8bef9SDimitry Andric                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1464e8d8bef9SDimitry Andric    virtual result do_in(state_type& __st,
1465e8d8bef9SDimitry Andric                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1466e8d8bef9SDimitry Andric                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1467e8d8bef9SDimitry Andric    virtual result do_unshift(state_type& __st,
1468e8d8bef9SDimitry Andric                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1469e8d8bef9SDimitry Andric    virtual int do_encoding() const  _NOEXCEPT;
1470e8d8bef9SDimitry Andric    virtual bool do_always_noconv() const  _NOEXCEPT;
1471e8d8bef9SDimitry Andric    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1472e8d8bef9SDimitry Andric    virtual int do_max_length() const  _NOEXCEPT;
1473e8d8bef9SDimitry Andric};
1474e8d8bef9SDimitry Andric
1475e8d8bef9SDimitry Andric#endif
1476e8d8bef9SDimitry Andric
14770b57cec5SDimitry Andric// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
14780b57cec5SDimitry Andric
14790b57cec5SDimitry Andrictemplate <class _InternT, class _ExternT, class _StateT>
14800b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS codecvt_byname
14810b57cec5SDimitry Andric    : public codecvt<_InternT, _ExternT, _StateT>
14820b57cec5SDimitry Andric{
14830b57cec5SDimitry Andricpublic:
14840b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14850b57cec5SDimitry Andric    explicit codecvt_byname(const char* __nm, size_t __refs = 0)
14860b57cec5SDimitry Andric        : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
14870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
14880b57cec5SDimitry Andric    explicit codecvt_byname(const string& __nm, size_t __refs = 0)
14890b57cec5SDimitry Andric        : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
14900b57cec5SDimitry Andricprotected:
14910b57cec5SDimitry Andric    ~codecvt_byname();
14920b57cec5SDimitry Andric};
14930b57cec5SDimitry Andric
1494e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_PUSH
14950b57cec5SDimitry Andrictemplate <class _InternT, class _ExternT, class _StateT>
14960b57cec5SDimitry Andriccodecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
14970b57cec5SDimitry Andric{
14980b57cec5SDimitry Andric}
1499e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_POP
15000b57cec5SDimitry Andric
1501e8d8bef9SDimitry Andric_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>)
1502349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1503e8d8bef9SDimitry Andric_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>)
1504349cc55cSDimitry Andric#endif
1505e8d8bef9SDimitry Andric_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>) // deprecated in C++20
1506e8d8bef9SDimitry Andric_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>) // deprecated in C++20
1507fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T
1508e8d8bef9SDimitry Andric_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>) // C++20
1509e8d8bef9SDimitry Andric_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>) // C++20
1510e8d8bef9SDimitry Andric#endif
15110b57cec5SDimitry Andric
15120b57cec5SDimitry Andrictemplate <size_t _Np>
15130b57cec5SDimitry Andricstruct __narrow_to_utf8
15140b57cec5SDimitry Andric{
15150b57cec5SDimitry Andric    template <class _OutputIterator, class _CharT>
15160b57cec5SDimitry Andric    _OutputIterator
15170b57cec5SDimitry Andric    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
15180b57cec5SDimitry Andric};
15190b57cec5SDimitry Andric
15200b57cec5SDimitry Andrictemplate <>
15210b57cec5SDimitry Andricstruct __narrow_to_utf8<8>
15220b57cec5SDimitry Andric{
15230b57cec5SDimitry Andric    template <class _OutputIterator, class _CharT>
15240b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15250b57cec5SDimitry Andric    _OutputIterator
15260b57cec5SDimitry Andric    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
15270b57cec5SDimitry Andric    {
15280b57cec5SDimitry Andric        for (; __wb < __we; ++__wb, ++__s)
15290b57cec5SDimitry Andric            *__s = *__wb;
15300b57cec5SDimitry Andric        return __s;
15310b57cec5SDimitry Andric    }
15320b57cec5SDimitry Andric};
15330b57cec5SDimitry Andric
1534e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_PUSH
15350b57cec5SDimitry Andrictemplate <>
1536fe6060f1SDimitry Andricstruct _LIBCPP_TYPE_VIS __narrow_to_utf8<16>
15370b57cec5SDimitry Andric    : public codecvt<char16_t, char, mbstate_t>
15380b57cec5SDimitry Andric{
15390b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15400b57cec5SDimitry Andric    __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1541e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_POP
15420b57cec5SDimitry Andric
1543fe6060f1SDimitry Andric    ~__narrow_to_utf8();
15440b57cec5SDimitry Andric
15450b57cec5SDimitry Andric    template <class _OutputIterator, class _CharT>
15460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15470b57cec5SDimitry Andric    _OutputIterator
15480b57cec5SDimitry Andric    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
15490b57cec5SDimitry Andric    {
15500b57cec5SDimitry Andric        result __r = ok;
15510b57cec5SDimitry Andric        mbstate_t __mb;
15520b57cec5SDimitry Andric        while (__wb < __we && __r != error)
15530b57cec5SDimitry Andric        {
15540b57cec5SDimitry Andric            const int __sz = 32;
15550b57cec5SDimitry Andric            char __buf[__sz];
15560b57cec5SDimitry Andric            char* __bn;
15570b57cec5SDimitry Andric            const char16_t* __wn = (const char16_t*)__wb;
15580b57cec5SDimitry Andric            __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
15590b57cec5SDimitry Andric                         __buf, __buf+__sz, __bn);
15600b57cec5SDimitry Andric            if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
15610b57cec5SDimitry Andric                __throw_runtime_error("locale not supported");
15620b57cec5SDimitry Andric            for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
15630b57cec5SDimitry Andric                *__s = *__p;
15640b57cec5SDimitry Andric            __wb = (const _CharT*)__wn;
15650b57cec5SDimitry Andric        }
15660b57cec5SDimitry Andric        return __s;
15670b57cec5SDimitry Andric    }
15680b57cec5SDimitry Andric};
15690b57cec5SDimitry Andric
1570e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_PUSH
15710b57cec5SDimitry Andrictemplate <>
1572fe6060f1SDimitry Andricstruct _LIBCPP_TYPE_VIS __narrow_to_utf8<32>
15730b57cec5SDimitry Andric    : public codecvt<char32_t, char, mbstate_t>
15740b57cec5SDimitry Andric{
15750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15760b57cec5SDimitry Andric    __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1577e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_POP
15780b57cec5SDimitry Andric
1579fe6060f1SDimitry Andric    ~__narrow_to_utf8();
15800b57cec5SDimitry Andric
15810b57cec5SDimitry Andric    template <class _OutputIterator, class _CharT>
15820b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
15830b57cec5SDimitry Andric    _OutputIterator
15840b57cec5SDimitry Andric    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
15850b57cec5SDimitry Andric    {
15860b57cec5SDimitry Andric        result __r = ok;
15870b57cec5SDimitry Andric        mbstate_t __mb;
15880b57cec5SDimitry Andric        while (__wb < __we && __r != error)
15890b57cec5SDimitry Andric        {
15900b57cec5SDimitry Andric            const int __sz = 32;
15910b57cec5SDimitry Andric            char __buf[__sz];
15920b57cec5SDimitry Andric            char* __bn;
15930b57cec5SDimitry Andric            const char32_t* __wn = (const char32_t*)__wb;
15940b57cec5SDimitry Andric            __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
15950b57cec5SDimitry Andric                         __buf, __buf+__sz, __bn);
15960b57cec5SDimitry Andric            if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
15970b57cec5SDimitry Andric                __throw_runtime_error("locale not supported");
15980b57cec5SDimitry Andric            for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
15990b57cec5SDimitry Andric                *__s = *__p;
16000b57cec5SDimitry Andric            __wb = (const _CharT*)__wn;
16010b57cec5SDimitry Andric        }
16020b57cec5SDimitry Andric        return __s;
16030b57cec5SDimitry Andric    }
16040b57cec5SDimitry Andric};
16050b57cec5SDimitry Andric
16060b57cec5SDimitry Andrictemplate <size_t _Np>
16070b57cec5SDimitry Andricstruct __widen_from_utf8
16080b57cec5SDimitry Andric{
16090b57cec5SDimitry Andric    template <class _OutputIterator>
16100b57cec5SDimitry Andric    _OutputIterator
16110b57cec5SDimitry Andric    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
16120b57cec5SDimitry Andric};
16130b57cec5SDimitry Andric
16140b57cec5SDimitry Andrictemplate <>
16150b57cec5SDimitry Andricstruct __widen_from_utf8<8>
16160b57cec5SDimitry Andric{
16170b57cec5SDimitry Andric    template <class _OutputIterator>
16180b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16190b57cec5SDimitry Andric    _OutputIterator
16200b57cec5SDimitry Andric    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
16210b57cec5SDimitry Andric    {
16220b57cec5SDimitry Andric        for (; __nb < __ne; ++__nb, ++__s)
16230b57cec5SDimitry Andric            *__s = *__nb;
16240b57cec5SDimitry Andric        return __s;
16250b57cec5SDimitry Andric    }
16260b57cec5SDimitry Andric};
16270b57cec5SDimitry Andric
1628e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_PUSH
16290b57cec5SDimitry Andrictemplate <>
1630fe6060f1SDimitry Andricstruct _LIBCPP_TYPE_VIS __widen_from_utf8<16>
16310b57cec5SDimitry Andric    : public codecvt<char16_t, char, mbstate_t>
16320b57cec5SDimitry Andric{
16330b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16340b57cec5SDimitry Andric    __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1635e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_POP
16360b57cec5SDimitry Andric
1637fe6060f1SDimitry Andric    ~__widen_from_utf8();
16380b57cec5SDimitry Andric
16390b57cec5SDimitry Andric    template <class _OutputIterator>
16400b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16410b57cec5SDimitry Andric    _OutputIterator
16420b57cec5SDimitry Andric    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
16430b57cec5SDimitry Andric    {
16440b57cec5SDimitry Andric        result __r = ok;
16450b57cec5SDimitry Andric        mbstate_t __mb;
16460b57cec5SDimitry Andric        while (__nb < __ne && __r != error)
16470b57cec5SDimitry Andric        {
16480b57cec5SDimitry Andric            const int __sz = 32;
16490b57cec5SDimitry Andric            char16_t __buf[__sz];
16500b57cec5SDimitry Andric            char16_t* __bn;
16510b57cec5SDimitry Andric            const char* __nn = __nb;
16520b57cec5SDimitry Andric            __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
16530b57cec5SDimitry Andric                        __buf, __buf+__sz, __bn);
16540b57cec5SDimitry Andric            if (__r == codecvt_base::error || __nn == __nb)
16550b57cec5SDimitry Andric                __throw_runtime_error("locale not supported");
16560b57cec5SDimitry Andric            for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
1657e8d8bef9SDimitry Andric                *__s = *__p;
16580b57cec5SDimitry Andric            __nb = __nn;
16590b57cec5SDimitry Andric        }
16600b57cec5SDimitry Andric        return __s;
16610b57cec5SDimitry Andric    }
16620b57cec5SDimitry Andric};
16630b57cec5SDimitry Andric
1664e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_PUSH
16650b57cec5SDimitry Andrictemplate <>
1666fe6060f1SDimitry Andricstruct _LIBCPP_TYPE_VIS __widen_from_utf8<32>
16670b57cec5SDimitry Andric    : public codecvt<char32_t, char, mbstate_t>
16680b57cec5SDimitry Andric{
16690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16700b57cec5SDimitry Andric    __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1671e8d8bef9SDimitry Andric_LIBCPP_SUPPRESS_DEPRECATED_POP
16720b57cec5SDimitry Andric
1673fe6060f1SDimitry Andric    ~__widen_from_utf8();
16740b57cec5SDimitry Andric
16750b57cec5SDimitry Andric    template <class _OutputIterator>
16760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
16770b57cec5SDimitry Andric    _OutputIterator
16780b57cec5SDimitry Andric    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
16790b57cec5SDimitry Andric    {
16800b57cec5SDimitry Andric        result __r = ok;
16810b57cec5SDimitry Andric        mbstate_t __mb;
16820b57cec5SDimitry Andric        while (__nb < __ne && __r != error)
16830b57cec5SDimitry Andric        {
16840b57cec5SDimitry Andric            const int __sz = 32;
16850b57cec5SDimitry Andric            char32_t __buf[__sz];
16860b57cec5SDimitry Andric            char32_t* __bn;
16870b57cec5SDimitry Andric            const char* __nn = __nb;
16880b57cec5SDimitry Andric            __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
16890b57cec5SDimitry Andric                        __buf, __buf+__sz, __bn);
16900b57cec5SDimitry Andric            if (__r == codecvt_base::error || __nn == __nb)
16910b57cec5SDimitry Andric                __throw_runtime_error("locale not supported");
16920b57cec5SDimitry Andric            for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
1693e8d8bef9SDimitry Andric                *__s = *__p;
16940b57cec5SDimitry Andric            __nb = __nn;
16950b57cec5SDimitry Andric        }
16960b57cec5SDimitry Andric        return __s;
16970b57cec5SDimitry Andric    }
16980b57cec5SDimitry Andric};
16990b57cec5SDimitry Andric
17000b57cec5SDimitry Andric// template <class charT> class numpunct
17010b57cec5SDimitry Andric
17020b57cec5SDimitry Andrictemplate <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct;
17030b57cec5SDimitry Andric
17040b57cec5SDimitry Andrictemplate <>
17050b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS numpunct<char>
17060b57cec5SDimitry Andric    : public locale::facet
17070b57cec5SDimitry Andric{
17080b57cec5SDimitry Andricpublic:
17090b57cec5SDimitry Andric    typedef char char_type;
17100b57cec5SDimitry Andric    typedef basic_string<char_type> string_type;
17110b57cec5SDimitry Andric
17120b57cec5SDimitry Andric    explicit numpunct(size_t __refs = 0);
17130b57cec5SDimitry Andric
17140b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
17150b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
17160b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY string grouping() const         {return do_grouping();}
17170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY string_type truename() const    {return do_truename();}
17180b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY string_type falsename() const   {return do_falsename();}
17190b57cec5SDimitry Andric
17200b57cec5SDimitry Andric    static locale::id id;
17210b57cec5SDimitry Andric
17220b57cec5SDimitry Andricprotected:
17230b57cec5SDimitry Andric    ~numpunct();
17240b57cec5SDimitry Andric    virtual char_type do_decimal_point() const;
17250b57cec5SDimitry Andric    virtual char_type do_thousands_sep() const;
17260b57cec5SDimitry Andric    virtual string do_grouping() const;
17270b57cec5SDimitry Andric    virtual string_type do_truename() const;
17280b57cec5SDimitry Andric    virtual string_type do_falsename() const;
17290b57cec5SDimitry Andric
17300b57cec5SDimitry Andric    char_type __decimal_point_;
17310b57cec5SDimitry Andric    char_type __thousands_sep_;
17320b57cec5SDimitry Andric    string __grouping_;
17330b57cec5SDimitry Andric};
17340b57cec5SDimitry Andric
1735349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
17360b57cec5SDimitry Andrictemplate <>
17370b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS numpunct<wchar_t>
17380b57cec5SDimitry Andric    : public locale::facet
17390b57cec5SDimitry Andric{
17400b57cec5SDimitry Andricpublic:
17410b57cec5SDimitry Andric    typedef wchar_t char_type;
17420b57cec5SDimitry Andric    typedef basic_string<char_type> string_type;
17430b57cec5SDimitry Andric
17440b57cec5SDimitry Andric    explicit numpunct(size_t __refs = 0);
17450b57cec5SDimitry Andric
17460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
17470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
17480b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY string grouping() const         {return do_grouping();}
17490b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY string_type truename() const    {return do_truename();}
17500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY string_type falsename() const   {return do_falsename();}
17510b57cec5SDimitry Andric
17520b57cec5SDimitry Andric    static locale::id id;
17530b57cec5SDimitry Andric
17540b57cec5SDimitry Andricprotected:
17550b57cec5SDimitry Andric    ~numpunct();
17560b57cec5SDimitry Andric    virtual char_type do_decimal_point() const;
17570b57cec5SDimitry Andric    virtual char_type do_thousands_sep() const;
17580b57cec5SDimitry Andric    virtual string do_grouping() const;
17590b57cec5SDimitry Andric    virtual string_type do_truename() const;
17600b57cec5SDimitry Andric    virtual string_type do_falsename() const;
17610b57cec5SDimitry Andric
17620b57cec5SDimitry Andric    char_type __decimal_point_;
17630b57cec5SDimitry Andric    char_type __thousands_sep_;
17640b57cec5SDimitry Andric    string __grouping_;
17650b57cec5SDimitry Andric};
1766349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
17670b57cec5SDimitry Andric
17680b57cec5SDimitry Andric// template <class charT> class numpunct_byname
17690b57cec5SDimitry Andric
17700b57cec5SDimitry Andrictemplate <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct_byname;
17710b57cec5SDimitry Andric
17720b57cec5SDimitry Andrictemplate <>
17730b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS numpunct_byname<char>
17740b57cec5SDimitry Andric: public numpunct<char>
17750b57cec5SDimitry Andric{
17760b57cec5SDimitry Andricpublic:
17770b57cec5SDimitry Andric    typedef char char_type;
17780b57cec5SDimitry Andric    typedef basic_string<char_type> string_type;
17790b57cec5SDimitry Andric
17800b57cec5SDimitry Andric    explicit numpunct_byname(const char* __nm, size_t __refs = 0);
17810b57cec5SDimitry Andric    explicit numpunct_byname(const string& __nm, size_t __refs = 0);
17820b57cec5SDimitry Andric
17830b57cec5SDimitry Andricprotected:
17840b57cec5SDimitry Andric    ~numpunct_byname();
17850b57cec5SDimitry Andric
17860b57cec5SDimitry Andricprivate:
17870b57cec5SDimitry Andric    void __init(const char*);
17880b57cec5SDimitry Andric};
17890b57cec5SDimitry Andric
1790349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
17910b57cec5SDimitry Andrictemplate <>
17920b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
17930b57cec5SDimitry Andric: public numpunct<wchar_t>
17940b57cec5SDimitry Andric{
17950b57cec5SDimitry Andricpublic:
17960b57cec5SDimitry Andric    typedef wchar_t char_type;
17970b57cec5SDimitry Andric    typedef basic_string<char_type> string_type;
17980b57cec5SDimitry Andric
17990b57cec5SDimitry Andric    explicit numpunct_byname(const char* __nm, size_t __refs = 0);
18000b57cec5SDimitry Andric    explicit numpunct_byname(const string& __nm, size_t __refs = 0);
18010b57cec5SDimitry Andric
18020b57cec5SDimitry Andricprotected:
18030b57cec5SDimitry Andric    ~numpunct_byname();
18040b57cec5SDimitry Andric
18050b57cec5SDimitry Andricprivate:
18060b57cec5SDimitry Andric    void __init(const char*);
18070b57cec5SDimitry Andric};
1808349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
18090b57cec5SDimitry Andric
18100b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
18110b57cec5SDimitry Andric
18120b57cec5SDimitry Andric#endif // _LIBCPP___LOCALE
1813