17a984708SDavid Chisnall// -*- C++ -*-
27a984708SDavid Chisnall//===----------------------------------------------------------------------===//
37a984708SDavid Chisnall//
47a984708SDavid Chisnall//                     The LLVM Compiler Infrastructure
57a984708SDavid Chisnall//
67a984708SDavid Chisnall// This file is dual licensed under the MIT and the University of Illinois Open
77a984708SDavid Chisnall// Source Licenses. See LICENSE.TXT for details.
87a984708SDavid Chisnall//
97a984708SDavid Chisnall//===----------------------------------------------------------------------===//
107a984708SDavid Chisnall
117a984708SDavid Chisnall#ifndef _LIBCPP___LOCALE
127a984708SDavid Chisnall#define _LIBCPP___LOCALE
137a984708SDavid Chisnall
147a984708SDavid Chisnall#include <__config>
157a984708SDavid Chisnall#include <string>
167a984708SDavid Chisnall#include <memory>
177a984708SDavid Chisnall#include <utility>
187a984708SDavid Chisnall#include <mutex>
197a984708SDavid Chisnall#include <cstdint>
207a984708SDavid Chisnall#include <cctype>
217a984708SDavid Chisnall#include <locale.h>
22f9448bf3SDimitry Andric#if defined(_LIBCPP_MSVCRT_LIKE)
237a984708SDavid Chisnall# include <support/win32/locale_win32.h>
24d72607e9SDimitry Andric#elif defined(_AIX)
254f7ab58eSDimitry Andric# include <support/ibm/xlocale.h>
26d72607e9SDimitry Andric#elif defined(__ANDROID__)
27d72607e9SDimitry Andric# include <support/android/locale_bionic.h>
28d72607e9SDimitry Andric#elif defined(__sun__)
29854fa44bSDimitry Andric# include <xlocale.h>
30d72607e9SDimitry Andric# include <support/solaris/xlocale.h>
31d72607e9SDimitry Andric#elif defined(_NEWLIB_VERSION)
32d72607e9SDimitry Andric# include <support/newlib/xlocale.h>
339dc417c3SDimitry Andric#elif (defined(__APPLE__)      || defined(__FreeBSD__) \
34d72607e9SDimitry Andric    || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
357a984708SDavid Chisnall# include <xlocale.h>
36540d2a8bSDimitry Andric#elif defined(__Fuchsia__)
37540d2a8bSDimitry Andric# include <support/fuchsia/xlocale.h>
389729cf09SDimitry Andric#elif defined(_LIBCPP_HAS_MUSL_LIBC)
399729cf09SDimitry Andric# include <support/musl/xlocale.h>
40540d2a8bSDimitry Andric#endif
417a984708SDavid Chisnall
427a984708SDavid Chisnall#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
437a984708SDavid Chisnall#pragma GCC system_header
447a984708SDavid Chisnall#endif
457a984708SDavid Chisnall
467a984708SDavid Chisnall_LIBCPP_BEGIN_NAMESPACE_STD
477a984708SDavid Chisnall
48b2c7081bSDimitry Andric#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
495517e702SDimitry Andricstruct __libcpp_locale_guard {
505517e702SDimitry Andric  _LIBCPP_INLINE_VISIBILITY
515517e702SDimitry Andric  __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
525517e702SDimitry Andric
535517e702SDimitry Andric  _LIBCPP_INLINE_VISIBILITY
545517e702SDimitry Andric  ~__libcpp_locale_guard() {
555517e702SDimitry Andric    if (__old_loc_)
565517e702SDimitry Andric      uselocale(__old_loc_);
575517e702SDimitry Andric  }
585517e702SDimitry Andric
595517e702SDimitry Andric  locale_t __old_loc_;
605517e702SDimitry Andricprivate:
615517e702SDimitry Andric  __libcpp_locale_guard(__libcpp_locale_guard const&);
625517e702SDimitry Andric  __libcpp_locale_guard& operator=(__libcpp_locale_guard const&);
635517e702SDimitry Andric};
64b2c7081bSDimitry Andric#elif defined(_LIBCPP_MSVCRT_LIKE)
65b2c7081bSDimitry Andricstruct __libcpp_locale_guard {
66b2c7081bSDimitry Andric    __libcpp_locale_guard(locale_t __l) :
67b2c7081bSDimitry Andric        __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)),
68b2c7081bSDimitry Andric        __locale_collate(setlocale(LC_COLLATE, __l.__get_locale())),
69b2c7081bSDimitry Andric        __locale_ctype(setlocale(LC_CTYPE, __l.__get_locale())),
70b2c7081bSDimitry Andric        __locale_monetary(setlocale(LC_MONETARY, __l.__get_locale())),
71b2c7081bSDimitry Andric        __locale_numeric(setlocale(LC_NUMERIC, __l.__get_locale())),
72b2c7081bSDimitry Andric        __locale_time(setlocale(LC_TIME, __l.__get_locale()))
73b2c7081bSDimitry Andric        // LC_MESSAGES is not supported on Windows.
74b2c7081bSDimitry Andric    {}
75b2c7081bSDimitry Andric    ~__libcpp_locale_guard() {
76b2c7081bSDimitry Andric        setlocale(LC_COLLATE, __locale_collate);
77b2c7081bSDimitry Andric        setlocale(LC_CTYPE, __locale_ctype);
78b2c7081bSDimitry Andric        setlocale(LC_MONETARY, __locale_monetary);
79b2c7081bSDimitry Andric        setlocale(LC_NUMERIC, __locale_numeric);
80b2c7081bSDimitry Andric        setlocale(LC_TIME, __locale_time);
81b2c7081bSDimitry Andric        _configthreadlocale(__status);
82b2c7081bSDimitry Andric    }
83b2c7081bSDimitry Andric    int __status;
84b2c7081bSDimitry Andric    char* __locale_collate;
85b2c7081bSDimitry Andric    char* __locale_ctype;
86b2c7081bSDimitry Andric    char* __locale_monetary;
87b2c7081bSDimitry Andric    char* __locale_numeric;
88b2c7081bSDimitry Andric    char* __locale_time;
89b2c7081bSDimitry Andric};
905517e702SDimitry Andric#endif
915517e702SDimitry Andric
925517e702SDimitry Andric
931bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS locale;
947a984708SDavid Chisnall
95936e9439SDimitry Andrictemplate <class _Facet>
96936e9439SDimitry Andric_LIBCPP_INLINE_VISIBILITY
97936e9439SDimitry Andricbool
98936e9439SDimitry Andrichas_facet(const locale&) _NOEXCEPT;
99936e9439SDimitry Andric
100936e9439SDimitry Andrictemplate <class _Facet>
101936e9439SDimitry Andric_LIBCPP_INLINE_VISIBILITY
102936e9439SDimitry Andricconst _Facet&
103936e9439SDimitry Andricuse_facet(const locale&);
1047a984708SDavid Chisnall
1051bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS locale
1067a984708SDavid Chisnall{
1077a984708SDavid Chisnallpublic:
1087a984708SDavid Chisnall    // types:
1091bf9f7c1SDimitry Andric    class _LIBCPP_TYPE_VIS facet;
1101bf9f7c1SDimitry Andric    class _LIBCPP_TYPE_VIS id;
1117a984708SDavid Chisnall
1127a984708SDavid Chisnall    typedef int category;
1130f5676f4SDimitry Andric    _LIBCPP_AVAILABILITY_LOCALE_CATEGORY
1147a984708SDavid Chisnall    static const category // values assigned here are for exposition only
1157a984708SDavid Chisnall        none     = 0,
1167a984708SDavid Chisnall        collate  = LC_COLLATE_MASK,
1177a984708SDavid Chisnall        ctype    = LC_CTYPE_MASK,
1187a984708SDavid Chisnall        monetary = LC_MONETARY_MASK,
1197a984708SDavid Chisnall        numeric  = LC_NUMERIC_MASK,
1207a984708SDavid Chisnall        time     = LC_TIME_MASK,
1217a984708SDavid Chisnall        messages = LC_MESSAGES_MASK,
1227a984708SDavid Chisnall        all = collate | ctype | monetary | numeric | time | messages;
1237a984708SDavid Chisnall
1247a984708SDavid Chisnall    // construct/copy/destroy:
1257a984708SDavid Chisnall    locale()  _NOEXCEPT;
1267a984708SDavid Chisnall    locale(const locale&)  _NOEXCEPT;
1277a984708SDavid Chisnall    explicit locale(const char*);
1287a984708SDavid Chisnall    explicit locale(const string&);
1297a984708SDavid Chisnall    locale(const locale&, const char*, category);
1307a984708SDavid Chisnall    locale(const locale&, const string&, category);
1317a984708SDavid Chisnall    template <class _Facet>
1327a984708SDavid Chisnall        _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
1337a984708SDavid Chisnall    locale(const locale&, const locale&, category);
1347a984708SDavid Chisnall
1357a984708SDavid Chisnall    ~locale();
1367a984708SDavid Chisnall
1377a984708SDavid Chisnall    const locale& operator=(const locale&)  _NOEXCEPT;
1387a984708SDavid Chisnall
139540d2a8bSDimitry Andric    template <class _Facet>
140540d2a8bSDimitry Andric      _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
141540d2a8bSDimitry Andric      locale combine(const locale&) const;
1427a984708SDavid Chisnall
1437a984708SDavid Chisnall    // locale operations:
1447a984708SDavid Chisnall    string name() const;
1457a984708SDavid Chisnall    bool operator==(const locale&) const;
1467a984708SDavid Chisnall    bool operator!=(const locale& __y) const {return !(*this == __y);}
1477a984708SDavid Chisnall    template <class _CharT, class _Traits, class _Allocator>
148540d2a8bSDimitry Andric      _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1497a984708SDavid Chisnall      bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
1507a984708SDavid Chisnall                      const basic_string<_CharT, _Traits, _Allocator>&) const;
1517a984708SDavid Chisnall
1527a984708SDavid Chisnall    // global locale objects:
1537a984708SDavid Chisnall    static locale global(const locale&);
1547a984708SDavid Chisnall    static const locale& classic();
1557a984708SDavid Chisnall
1567a984708SDavid Chisnallprivate:
1577a984708SDavid Chisnall    class __imp;
1587a984708SDavid Chisnall    __imp* __locale_;
1597a984708SDavid Chisnall
1607a984708SDavid Chisnall    void __install_ctor(const locale&, facet*, long);
1617a984708SDavid Chisnall    static locale& __global();
1627a984708SDavid Chisnall    bool has_facet(id&) const;
1637a984708SDavid Chisnall    const facet* use_facet(id&) const;
1647a984708SDavid Chisnall
1657a984708SDavid Chisnall    template <class _Facet> friend bool has_facet(const locale&)  _NOEXCEPT;
1667a984708SDavid Chisnall    template <class _Facet> friend const _Facet& use_facet(const locale&);
1677a984708SDavid Chisnall};
1687a984708SDavid Chisnall
1691bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS locale::facet
1707a984708SDavid Chisnall    : public __shared_count
1717a984708SDavid Chisnall{
1727a984708SDavid Chisnallprotected:
1737a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
1747a984708SDavid Chisnall    explicit facet(size_t __refs = 0)
1757a984708SDavid Chisnall        : __shared_count(static_cast<long>(__refs)-1) {}
1767a984708SDavid Chisnall
1777a984708SDavid Chisnall    virtual ~facet();
1787a984708SDavid Chisnall
1797a984708SDavid Chisnall//    facet(const facet&) = delete;     // effectively done in __shared_count
1807a984708SDavid Chisnall//    void operator=(const facet&) = delete;
1817a984708SDavid Chisnallprivate:
1827a984708SDavid Chisnall    virtual void __on_zero_shared() _NOEXCEPT;
1837a984708SDavid Chisnall};
1847a984708SDavid Chisnall
1851bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS locale::id
1867a984708SDavid Chisnall{
1877a984708SDavid Chisnall    once_flag      __flag_;
1887a984708SDavid Chisnall    int32_t        __id_;
1897a984708SDavid Chisnall
1907a984708SDavid Chisnall    static int32_t __next_id;
1917a984708SDavid Chisnallpublic:
192936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
1937a984708SDavid Chisnallprivate:
1947a984708SDavid Chisnall    void __init();
1957a984708SDavid Chisnall    void operator=(const id&); // = delete;
1967a984708SDavid Chisnall    id(const id&); // = delete;
1977a984708SDavid Chisnallpublic:  // only needed for tests
1987a984708SDavid Chisnall    long __get();
1997a984708SDavid Chisnall
2007a984708SDavid Chisnall    friend class locale;
2017a984708SDavid Chisnall    friend class locale::__imp;
2027a984708SDavid Chisnall};
2037a984708SDavid Chisnall
2047a984708SDavid Chisnalltemplate <class _Facet>
2057a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
2067a984708SDavid Chisnalllocale::locale(const locale& __other, _Facet* __f)
2077a984708SDavid Chisnall{
2087a984708SDavid Chisnall    __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
2097a984708SDavid Chisnall}
2107a984708SDavid Chisnall
2117a984708SDavid Chisnalltemplate <class _Facet>
2127a984708SDavid Chisnalllocale
2137a984708SDavid Chisnalllocale::combine(const locale& __other) const
2147a984708SDavid Chisnall{
2157a984708SDavid Chisnall    if (!_VSTD::has_facet<_Facet>(__other))
216aed8d94eSDimitry Andric        __throw_runtime_error("locale::combine: locale missing facet");
217aed8d94eSDimitry Andric
2187a984708SDavid Chisnall    return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
2197a984708SDavid Chisnall}
2207a984708SDavid Chisnall
2217a984708SDavid Chisnalltemplate <class _Facet>
2227a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
2237a984708SDavid Chisnallbool
2247a984708SDavid Chisnallhas_facet(const locale& __l)  _NOEXCEPT
2257a984708SDavid Chisnall{
2267a984708SDavid Chisnall    return __l.has_facet(_Facet::id);
2277a984708SDavid Chisnall}
2287a984708SDavid Chisnall
2297a984708SDavid Chisnalltemplate <class _Facet>
2307a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
2317a984708SDavid Chisnallconst _Facet&
2327a984708SDavid Chisnalluse_facet(const locale& __l)
2337a984708SDavid Chisnall{
2347a984708SDavid Chisnall    return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
2357a984708SDavid Chisnall}
2367a984708SDavid Chisnall
2377a984708SDavid Chisnall// template <class _CharT> class collate;
2387a984708SDavid Chisnall
2397a984708SDavid Chisnalltemplate <class _CharT>
240aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS collate
2417a984708SDavid Chisnall    : public locale::facet
2427a984708SDavid Chisnall{
2437a984708SDavid Chisnallpublic:
2447a984708SDavid Chisnall    typedef _CharT char_type;
2457a984708SDavid Chisnall    typedef basic_string<char_type> string_type;
2467a984708SDavid Chisnall
2477a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2487a984708SDavid Chisnall    explicit collate(size_t __refs = 0)
2497a984708SDavid Chisnall        : locale::facet(__refs) {}
2507a984708SDavid Chisnall
2517a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2527a984708SDavid Chisnall    int compare(const char_type* __lo1, const char_type* __hi1,
2537a984708SDavid Chisnall                const char_type* __lo2, const char_type* __hi2) const
2547a984708SDavid Chisnall    {
2557a984708SDavid Chisnall        return do_compare(__lo1, __hi1, __lo2, __hi2);
2567a984708SDavid Chisnall    }
2577a984708SDavid Chisnall
2587a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2597a984708SDavid Chisnall    string_type transform(const char_type* __lo, const char_type* __hi) const
2607a984708SDavid Chisnall    {
2617a984708SDavid Chisnall        return do_transform(__lo, __hi);
2627a984708SDavid Chisnall    }
2637a984708SDavid Chisnall
2647a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2657a984708SDavid Chisnall    long hash(const char_type* __lo, const char_type* __hi) const
2667a984708SDavid Chisnall    {
2677a984708SDavid Chisnall        return do_hash(__lo, __hi);
2687a984708SDavid Chisnall    }
2697a984708SDavid Chisnall
2707a984708SDavid Chisnall    static locale::id id;
2717a984708SDavid Chisnall
2727a984708SDavid Chisnallprotected:
2737a984708SDavid Chisnall    ~collate();
2747a984708SDavid Chisnall    virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
2757a984708SDavid Chisnall                           const char_type* __lo2, const char_type* __hi2) const;
2767a984708SDavid Chisnall    virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
2777a984708SDavid Chisnall        {return string_type(__lo, __hi);}
2787a984708SDavid Chisnall    virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
2797a984708SDavid Chisnall};
2807a984708SDavid Chisnall
2817a984708SDavid Chisnalltemplate <class _CharT> locale::id collate<_CharT>::id;
2827a984708SDavid Chisnall
2837a984708SDavid Chisnalltemplate <class _CharT>
2847a984708SDavid Chisnallcollate<_CharT>::~collate()
2857a984708SDavid Chisnall{
2867a984708SDavid Chisnall}
2877a984708SDavid Chisnall
2887a984708SDavid Chisnalltemplate <class _CharT>
2897a984708SDavid Chisnallint
2907a984708SDavid Chisnallcollate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
2917a984708SDavid Chisnall                            const char_type* __lo2, const char_type* __hi2) const
2927a984708SDavid Chisnall{
2937a984708SDavid Chisnall    for (; __lo2 != __hi2; ++__lo1, ++__lo2)
2947a984708SDavid Chisnall    {
2957a984708SDavid Chisnall        if (__lo1 == __hi1 || *__lo1 < *__lo2)
2967a984708SDavid Chisnall            return -1;
2977a984708SDavid Chisnall        if (*__lo2 < *__lo1)
2987a984708SDavid Chisnall            return 1;
2997a984708SDavid Chisnall    }
3007a984708SDavid Chisnall    return __lo1 != __hi1;
3017a984708SDavid Chisnall}
3027a984708SDavid Chisnall
3037a984708SDavid Chisnalltemplate <class _CharT>
3047a984708SDavid Chisnalllong
3057a984708SDavid Chisnallcollate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
3067a984708SDavid Chisnall{
3077a984708SDavid Chisnall    size_t __h = 0;
3087a984708SDavid Chisnall    const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
3097a984708SDavid Chisnall    const size_t __mask = size_t(0xF) << (__sr + 4);
3107a984708SDavid Chisnall    for(const char_type* __p = __lo; __p != __hi; ++__p)
3117a984708SDavid Chisnall    {
31294e3ee44SDavid Chisnall        __h = (__h << 4) + static_cast<size_t>(*__p);
3137a984708SDavid Chisnall        size_t __g = __h & __mask;
3147a984708SDavid Chisnall        __h ^= __g | (__g >> __sr);
3157a984708SDavid Chisnall    }
3167a984708SDavid Chisnall    return static_cast<long>(__h);
3177a984708SDavid Chisnall}
3187a984708SDavid Chisnall
319aed8d94eSDimitry Andric_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>)
320aed8d94eSDimitry Andric_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>)
3217a984708SDavid Chisnall
3227a984708SDavid Chisnall// template <class CharT> class collate_byname;
3237a984708SDavid Chisnall
324aed8d94eSDimitry Andrictemplate <class _CharT> class _LIBCPP_TEMPLATE_VIS collate_byname;
3257a984708SDavid Chisnall
3267a984708SDavid Chisnalltemplate <>
3271bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS collate_byname<char>
3287a984708SDavid Chisnall    : public collate<char>
3297a984708SDavid Chisnall{
3307a984708SDavid Chisnall    locale_t __l;
3317a984708SDavid Chisnallpublic:
3327a984708SDavid Chisnall    typedef char char_type;
3337a984708SDavid Chisnall    typedef basic_string<char_type> string_type;
3347a984708SDavid Chisnall
3357a984708SDavid Chisnall    explicit collate_byname(const char* __n, size_t __refs = 0);
3367a984708SDavid Chisnall    explicit collate_byname(const string& __n, size_t __refs = 0);
3377a984708SDavid Chisnall
3387a984708SDavid Chisnallprotected:
3397a984708SDavid Chisnall    ~collate_byname();
3407a984708SDavid Chisnall    virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
3417a984708SDavid Chisnall                           const char_type* __lo2, const char_type* __hi2) const;
3427a984708SDavid Chisnall    virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
3437a984708SDavid Chisnall};
3447a984708SDavid Chisnall
3457a984708SDavid Chisnalltemplate <>
3461bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS collate_byname<wchar_t>
3477a984708SDavid Chisnall    : public collate<wchar_t>
3487a984708SDavid Chisnall{
3497a984708SDavid Chisnall    locale_t __l;
3507a984708SDavid Chisnallpublic:
3517a984708SDavid Chisnall    typedef wchar_t char_type;
3527a984708SDavid Chisnall    typedef basic_string<char_type> string_type;
3537a984708SDavid Chisnall
3547a984708SDavid Chisnall    explicit collate_byname(const char* __n, size_t __refs = 0);
3557a984708SDavid Chisnall    explicit collate_byname(const string& __n, size_t __refs = 0);
3567a984708SDavid Chisnall
3577a984708SDavid Chisnallprotected:
3587a984708SDavid Chisnall    ~collate_byname();
3597a984708SDavid Chisnall
3607a984708SDavid Chisnall    virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
3617a984708SDavid Chisnall                           const char_type* __lo2, const char_type* __hi2) const;
3627a984708SDavid Chisnall    virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
3637a984708SDavid Chisnall};
3647a984708SDavid Chisnall
3657a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _Allocator>
3667a984708SDavid Chisnallbool
3677a984708SDavid Chisnalllocale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
3687a984708SDavid Chisnall                   const basic_string<_CharT, _Traits, _Allocator>& __y) const
3697a984708SDavid Chisnall{
3707a984708SDavid Chisnall    return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
3717a984708SDavid Chisnall                                       __x.data(), __x.data() + __x.size(),
3727a984708SDavid Chisnall                                       __y.data(), __y.data() + __y.size()) < 0;
3737a984708SDavid Chisnall}
3747a984708SDavid Chisnall
3757a984708SDavid Chisnall// template <class charT> class ctype
3767a984708SDavid Chisnall
3771bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS ctype_base
3787a984708SDavid Chisnall{
3797a984708SDavid Chisnallpublic:
3809729cf09SDimitry Andric#if defined(__GLIBC__)
3817a984708SDavid Chisnall    typedef unsigned short mask;
3827a984708SDavid Chisnall    static const mask space  = _ISspace;
3837a984708SDavid Chisnall    static const mask print  = _ISprint;
3847a984708SDavid Chisnall    static const mask cntrl  = _IScntrl;
3857a984708SDavid Chisnall    static const mask upper  = _ISupper;
3867a984708SDavid Chisnall    static const mask lower  = _ISlower;
3877a984708SDavid Chisnall    static const mask alpha  = _ISalpha;
3887a984708SDavid Chisnall    static const mask digit  = _ISdigit;
3897a984708SDavid Chisnall    static const mask punct  = _ISpunct;
3907a984708SDavid Chisnall    static const mask xdigit = _ISxdigit;
3917a984708SDavid Chisnall    static const mask blank  = _ISblank;
392f9448bf3SDimitry Andric#elif defined(_LIBCPP_MSVCRT_LIKE)
3937a984708SDavid Chisnall    typedef unsigned short mask;
3947a984708SDavid Chisnall    static const mask space  = _SPACE;
3957a984708SDavid Chisnall    static const mask print  = _BLANK|_PUNCT|_ALPHA|_DIGIT;
3967a984708SDavid Chisnall    static const mask cntrl  = _CONTROL;
3977a984708SDavid Chisnall    static const mask upper  = _UPPER;
3987a984708SDavid Chisnall    static const mask lower  = _LOWER;
3997a984708SDavid Chisnall    static const mask alpha  = _ALPHA;
4007a984708SDavid Chisnall    static const mask digit  = _DIGIT;
4017a984708SDavid Chisnall    static const mask punct  = _PUNCT;
4027a984708SDavid Chisnall    static const mask xdigit = _HEX;
4037a984708SDavid Chisnall    static const mask blank  = _BLANK;
404854fa44bSDimitry Andric# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
405854fa44bSDimitry Andric#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
4061bf9f7c1SDimitry Andric# ifdef __APPLE__
4077a984708SDavid Chisnall    typedef __uint32_t mask;
4081bf9f7c1SDimitry Andric# elif defined(__FreeBSD__)
4097a984708SDavid Chisnall    typedef unsigned long mask;
4104f7ab58eSDimitry Andric# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
4111bf9f7c1SDimitry Andric    typedef unsigned short mask;
4127a984708SDavid Chisnall# endif
4137a984708SDavid Chisnall    static const mask space  = _CTYPE_S;
4147a984708SDavid Chisnall    static const mask print  = _CTYPE_R;
4157a984708SDavid Chisnall    static const mask cntrl  = _CTYPE_C;
4167a984708SDavid Chisnall    static const mask upper  = _CTYPE_U;
4177a984708SDavid Chisnall    static const mask lower  = _CTYPE_L;
4187a984708SDavid Chisnall    static const mask alpha  = _CTYPE_A;
4197a984708SDavid Chisnall    static const mask digit  = _CTYPE_D;
4207a984708SDavid Chisnall    static const mask punct  = _CTYPE_P;
4217a984708SDavid Chisnall    static const mask xdigit = _CTYPE_X;
422d72607e9SDimitry Andric
4234bab9fd9SDavid Chisnall# if defined(__NetBSD__)
4244bab9fd9SDavid Chisnall    static const mask blank  = _CTYPE_BL;
4254bab9fd9SDavid Chisnall# else
4267a984708SDavid Chisnall    static const mask blank  = _CTYPE_B;
4274bab9fd9SDavid Chisnall# endif
4284f7ab58eSDimitry Andric#elif defined(__sun__) || defined(_AIX)
42994e3ee44SDavid Chisnall    typedef unsigned int mask;
43094e3ee44SDavid Chisnall    static const mask space  = _ISSPACE;
43194e3ee44SDavid Chisnall    static const mask print  = _ISPRINT;
43294e3ee44SDavid Chisnall    static const mask cntrl  = _ISCNTRL;
43394e3ee44SDavid Chisnall    static const mask upper  = _ISUPPER;
43494e3ee44SDavid Chisnall    static const mask lower  = _ISLOWER;
43594e3ee44SDavid Chisnall    static const mask alpha  = _ISALPHA;
43694e3ee44SDavid Chisnall    static const mask digit  = _ISDIGIT;
43794e3ee44SDavid Chisnall    static const mask punct  = _ISPUNCT;
43894e3ee44SDavid Chisnall    static const mask xdigit = _ISXDIGIT;
43994e3ee44SDavid Chisnall    static const mask blank  = _ISBLANK;
440854fa44bSDimitry Andric#elif defined(_NEWLIB_VERSION)
441854fa44bSDimitry Andric    // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
442854fa44bSDimitry Andric    typedef char mask;
443854fa44bSDimitry Andric    static const mask space  = _S;
444854fa44bSDimitry Andric    static const mask print  = _P | _U | _L | _N | _B;
445854fa44bSDimitry Andric    static const mask cntrl  = _C;
446854fa44bSDimitry Andric    static const mask upper  = _U;
447854fa44bSDimitry Andric    static const mask lower  = _L;
448854fa44bSDimitry Andric    static const mask alpha  = _U | _L;
449854fa44bSDimitry Andric    static const mask digit  = _N;
450854fa44bSDimitry Andric    static const mask punct  = _P;
451854fa44bSDimitry Andric    static const mask xdigit = _X | _N;
452854fa44bSDimitry Andric    static const mask blank  = _B;
453854fa44bSDimitry Andric# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
454854fa44bSDimitry Andric# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
455854fa44bSDimitry Andric# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
456854fa44bSDimitry Andric#else
4577a984708SDavid Chisnall    typedef unsigned long mask;
4587a984708SDavid Chisnall    static const mask space  = 1<<0;
4597a984708SDavid Chisnall    static const mask print  = 1<<1;
4607a984708SDavid Chisnall    static const mask cntrl  = 1<<2;
4617a984708SDavid Chisnall    static const mask upper  = 1<<3;
4627a984708SDavid Chisnall    static const mask lower  = 1<<4;
4637a984708SDavid Chisnall    static const mask alpha  = 1<<5;
4647a984708SDavid Chisnall    static const mask digit  = 1<<6;
4657a984708SDavid Chisnall    static const mask punct  = 1<<7;
4667a984708SDavid Chisnall    static const mask xdigit = 1<<8;
4677a984708SDavid Chisnall    static const mask blank  = 1<<9;
468854fa44bSDimitry Andric#endif
4697a984708SDavid Chisnall    static const mask alnum  = alpha | digit;
4707a984708SDavid Chisnall    static const mask graph  = alnum | punct;
4717a984708SDavid Chisnall
4724ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY ctype_base() {}
4737a984708SDavid Chisnall};
4747a984708SDavid Chisnall
475aed8d94eSDimitry Andrictemplate <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
4767a984708SDavid Chisnall
4777a984708SDavid Chisnalltemplate <>
4781bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS ctype<wchar_t>
4797a984708SDavid Chisnall    : public locale::facet,
4807a984708SDavid Chisnall      public ctype_base
4817a984708SDavid Chisnall{
4827a984708SDavid Chisnallpublic:
4837a984708SDavid Chisnall    typedef wchar_t char_type;
4847a984708SDavid Chisnall
4854ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4867a984708SDavid Chisnall    explicit ctype(size_t __refs = 0)
4877a984708SDavid Chisnall        : locale::facet(__refs) {}
4887a984708SDavid Chisnall
4894ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4907a984708SDavid Chisnall    bool is(mask __m, char_type __c) const
4917a984708SDavid Chisnall    {
4927a984708SDavid Chisnall        return do_is(__m, __c);
4937a984708SDavid Chisnall    }
4947a984708SDavid Chisnall
4954ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4967a984708SDavid Chisnall    const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
4977a984708SDavid Chisnall    {
4987a984708SDavid Chisnall        return do_is(__low, __high, __vec);
4997a984708SDavid Chisnall    }
5007a984708SDavid Chisnall
5014ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5027a984708SDavid Chisnall    const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
5037a984708SDavid Chisnall    {
5047a984708SDavid Chisnall        return do_scan_is(__m, __low, __high);
5057a984708SDavid Chisnall    }
5067a984708SDavid Chisnall
5074ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5087a984708SDavid Chisnall    const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
5097a984708SDavid Chisnall    {
5107a984708SDavid Chisnall        return do_scan_not(__m, __low, __high);
5117a984708SDavid Chisnall    }
5127a984708SDavid Chisnall
5134ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5147a984708SDavid Chisnall    char_type toupper(char_type __c) const
5157a984708SDavid Chisnall    {
5167a984708SDavid Chisnall        return do_toupper(__c);
5177a984708SDavid Chisnall    }
5187a984708SDavid Chisnall
5194ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5207a984708SDavid Chisnall    const char_type* toupper(char_type* __low, const char_type* __high) const
5217a984708SDavid Chisnall    {
5227a984708SDavid Chisnall        return do_toupper(__low, __high);
5237a984708SDavid Chisnall    }
5247a984708SDavid Chisnall
5254ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5267a984708SDavid Chisnall    char_type tolower(char_type __c) const
5277a984708SDavid Chisnall    {
5287a984708SDavid Chisnall        return do_tolower(__c);
5297a984708SDavid Chisnall    }
5307a984708SDavid Chisnall
5314ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5327a984708SDavid Chisnall    const char_type* tolower(char_type* __low, const char_type* __high) const
5337a984708SDavid Chisnall    {
5347a984708SDavid Chisnall        return do_tolower(__low, __high);
5357a984708SDavid Chisnall    }
5367a984708SDavid Chisnall
5374ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5387a984708SDavid Chisnall    char_type widen(char __c) const
5397a984708SDavid Chisnall    {
5407a984708SDavid Chisnall        return do_widen(__c);
5417a984708SDavid Chisnall    }
5427a984708SDavid Chisnall
5434ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5447a984708SDavid Chisnall    const char* widen(const char* __low, const char* __high, char_type* __to) const
5457a984708SDavid Chisnall    {
5467a984708SDavid Chisnall        return do_widen(__low, __high, __to);
5477a984708SDavid Chisnall    }
5487a984708SDavid Chisnall
5494ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5507a984708SDavid Chisnall    char narrow(char_type __c, char __dfault) const
5517a984708SDavid Chisnall    {
5527a984708SDavid Chisnall        return do_narrow(__c, __dfault);
5537a984708SDavid Chisnall    }
5547a984708SDavid Chisnall
5554ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5567a984708SDavid Chisnall    const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
5577a984708SDavid Chisnall    {
5587a984708SDavid Chisnall        return do_narrow(__low, __high, __dfault, __to);
5597a984708SDavid Chisnall    }
5607a984708SDavid Chisnall
5617a984708SDavid Chisnall    static locale::id id;
5627a984708SDavid Chisnall
5637a984708SDavid Chisnallprotected:
5647a984708SDavid Chisnall    ~ctype();
5657a984708SDavid Chisnall    virtual bool do_is(mask __m, char_type __c) const;
5667a984708SDavid Chisnall    virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
5677a984708SDavid Chisnall    virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
5687a984708SDavid Chisnall    virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
5697a984708SDavid Chisnall    virtual char_type do_toupper(char_type) const;
5707a984708SDavid Chisnall    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
5717a984708SDavid Chisnall    virtual char_type do_tolower(char_type) const;
5727a984708SDavid Chisnall    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
5737a984708SDavid Chisnall    virtual char_type do_widen(char) const;
5747a984708SDavid Chisnall    virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
5757a984708SDavid Chisnall    virtual char do_narrow(char_type, char __dfault) const;
5767a984708SDavid Chisnall    virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
5777a984708SDavid Chisnall};
5787a984708SDavid Chisnall
5797a984708SDavid Chisnalltemplate <>
5801bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS ctype<char>
5817a984708SDavid Chisnall    : public locale::facet, public ctype_base
5827a984708SDavid Chisnall{
5837a984708SDavid Chisnall    const mask* __tab_;
5847a984708SDavid Chisnall    bool        __del_;
5857a984708SDavid Chisnallpublic:
5867a984708SDavid Chisnall    typedef char char_type;
5877a984708SDavid Chisnall
5887a984708SDavid Chisnall    explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
5897a984708SDavid Chisnall
5904ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5917a984708SDavid Chisnall    bool is(mask __m, char_type __c) const
5927a984708SDavid Chisnall    {
5934f7ab58eSDimitry Andric        return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false;
5947a984708SDavid Chisnall    }
5957a984708SDavid Chisnall
5964ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5977a984708SDavid Chisnall    const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
5987a984708SDavid Chisnall    {
5997a984708SDavid Chisnall        for (; __low != __high; ++__low, ++__vec)
60094e3ee44SDavid Chisnall            *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
6017a984708SDavid Chisnall        return __low;
6027a984708SDavid Chisnall    }
6037a984708SDavid Chisnall
6044ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6057a984708SDavid Chisnall    const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
6067a984708SDavid Chisnall    {
6077a984708SDavid Chisnall        for (; __low != __high; ++__low)
60894e3ee44SDavid Chisnall            if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
6097a984708SDavid Chisnall                break;
6107a984708SDavid Chisnall        return __low;
6117a984708SDavid Chisnall    }
6127a984708SDavid Chisnall
6134ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6147a984708SDavid Chisnall    const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
6157a984708SDavid Chisnall    {
6167a984708SDavid Chisnall        for (; __low != __high; ++__low)
61794e3ee44SDavid Chisnall            if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)))
6187a984708SDavid Chisnall                break;
6197a984708SDavid Chisnall        return __low;
6207a984708SDavid Chisnall    }
6217a984708SDavid Chisnall
6224ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6237a984708SDavid Chisnall    char_type toupper(char_type __c) const
6247a984708SDavid Chisnall    {
6257a984708SDavid Chisnall        return do_toupper(__c);
6267a984708SDavid Chisnall    }
6277a984708SDavid Chisnall
6284ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6297a984708SDavid Chisnall    const char_type* toupper(char_type* __low, const char_type* __high) const
6307a984708SDavid Chisnall    {
6317a984708SDavid Chisnall        return do_toupper(__low, __high);
6327a984708SDavid Chisnall    }
6337a984708SDavid Chisnall
6344ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6357a984708SDavid Chisnall    char_type tolower(char_type __c) const
6367a984708SDavid Chisnall    {
6377a984708SDavid Chisnall        return do_tolower(__c);
6387a984708SDavid Chisnall    }
6397a984708SDavid Chisnall
6404ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6417a984708SDavid Chisnall    const char_type* tolower(char_type* __low, const char_type* __high) const
6427a984708SDavid Chisnall    {
6437a984708SDavid Chisnall        return do_tolower(__low, __high);
6447a984708SDavid Chisnall    }
6457a984708SDavid Chisnall
6464ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6477a984708SDavid Chisnall    char_type widen(char __c) const
6487a984708SDavid Chisnall    {
6497a984708SDavid Chisnall        return do_widen(__c);
6507a984708SDavid Chisnall    }
6517a984708SDavid Chisnall
6524ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6537a984708SDavid Chisnall    const char* widen(const char* __low, const char* __high, char_type* __to) const
6547a984708SDavid Chisnall    {
6557a984708SDavid Chisnall        return do_widen(__low, __high, __to);
6567a984708SDavid Chisnall    }
6577a984708SDavid Chisnall
6584ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6597a984708SDavid Chisnall    char narrow(char_type __c, char __dfault) const
6607a984708SDavid Chisnall    {
6617a984708SDavid Chisnall        return do_narrow(__c, __dfault);
6627a984708SDavid Chisnall    }
6637a984708SDavid Chisnall
6644ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6657a984708SDavid Chisnall    const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
6667a984708SDavid Chisnall    {
6677a984708SDavid Chisnall        return do_narrow(__low, __high, __dfault, __to);
6687a984708SDavid Chisnall    }
6697a984708SDavid Chisnall
6707a984708SDavid Chisnall    static locale::id id;
6717a984708SDavid Chisnall
6727a984708SDavid Chisnall#ifdef _CACHED_RUNES
6737a984708SDavid Chisnall    static const size_t table_size = _CACHED_RUNES;
6747a984708SDavid Chisnall#else
6757a984708SDavid Chisnall    static const size_t table_size = 256;  // FIXME: Don't hardcode this.
6767a984708SDavid Chisnall#endif
6774ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const mask* table() const  _NOEXCEPT {return __tab_;}
6787a984708SDavid Chisnall    static const mask* classic_table()  _NOEXCEPT;
6794f7ab58eSDimitry Andric#if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
6807a984708SDavid Chisnall    static const int* __classic_upper_table() _NOEXCEPT;
6817a984708SDavid Chisnall    static const int* __classic_lower_table() _NOEXCEPT;
6827a984708SDavid Chisnall#endif
6834bab9fd9SDavid Chisnall#if defined(__NetBSD__)
6844bab9fd9SDavid Chisnall    static const short* __classic_upper_table() _NOEXCEPT;
6854bab9fd9SDavid Chisnall    static const short* __classic_lower_table() _NOEXCEPT;
6864bab9fd9SDavid Chisnall#endif
6877a984708SDavid Chisnall
6887a984708SDavid Chisnallprotected:
6897a984708SDavid Chisnall    ~ctype();
6907a984708SDavid Chisnall    virtual char_type do_toupper(char_type __c) const;
6917a984708SDavid Chisnall    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
6927a984708SDavid Chisnall    virtual char_type do_tolower(char_type __c) const;
6937a984708SDavid Chisnall    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
6947a984708SDavid Chisnall    virtual char_type do_widen(char __c) const;
6957a984708SDavid Chisnall    virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
6967a984708SDavid Chisnall    virtual char do_narrow(char_type __c, char __dfault) const;
6977a984708SDavid Chisnall    virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
6987a984708SDavid Chisnall};
6997a984708SDavid Chisnall
7007a984708SDavid Chisnall// template <class CharT> class ctype_byname;
7017a984708SDavid Chisnall
702aed8d94eSDimitry Andrictemplate <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype_byname;
7037a984708SDavid Chisnall
7047a984708SDavid Chisnalltemplate <>
7051bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS ctype_byname<char>
7067a984708SDavid Chisnall    : public ctype<char>
7077a984708SDavid Chisnall{
7087a984708SDavid Chisnall    locale_t __l;
7097a984708SDavid Chisnall
7107a984708SDavid Chisnallpublic:
7117a984708SDavid Chisnall    explicit ctype_byname(const char*, size_t = 0);
7127a984708SDavid Chisnall    explicit ctype_byname(const string&, size_t = 0);
7137a984708SDavid Chisnall
7147a984708SDavid Chisnallprotected:
7157a984708SDavid Chisnall    ~ctype_byname();
7167a984708SDavid Chisnall    virtual char_type do_toupper(char_type) const;
7177a984708SDavid Chisnall    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
7187a984708SDavid Chisnall    virtual char_type do_tolower(char_type) const;
7197a984708SDavid Chisnall    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
7207a984708SDavid Chisnall};
7217a984708SDavid Chisnall
7227a984708SDavid Chisnalltemplate <>
7231bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
7247a984708SDavid Chisnall    : public ctype<wchar_t>
7257a984708SDavid Chisnall{
7267a984708SDavid Chisnall    locale_t __l;
7277a984708SDavid Chisnall
7287a984708SDavid Chisnallpublic:
7297a984708SDavid Chisnall    explicit ctype_byname(const char*, size_t = 0);
7307a984708SDavid Chisnall    explicit ctype_byname(const string&, size_t = 0);
7317a984708SDavid Chisnall
7327a984708SDavid Chisnallprotected:
7337a984708SDavid Chisnall    ~ctype_byname();
7347a984708SDavid Chisnall    virtual bool do_is(mask __m, char_type __c) const;
7357a984708SDavid Chisnall    virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
7367a984708SDavid Chisnall    virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
7377a984708SDavid Chisnall    virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
7387a984708SDavid Chisnall    virtual char_type do_toupper(char_type) const;
7397a984708SDavid Chisnall    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
7407a984708SDavid Chisnall    virtual char_type do_tolower(char_type) const;
7417a984708SDavid Chisnall    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
7427a984708SDavid Chisnall    virtual char_type do_widen(char) const;
7437a984708SDavid Chisnall    virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
7447a984708SDavid Chisnall    virtual char do_narrow(char_type, char __dfault) const;
7457a984708SDavid Chisnall    virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
7467a984708SDavid Chisnall};
7477a984708SDavid Chisnall
7487a984708SDavid Chisnalltemplate <class _CharT>
7497a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
7507a984708SDavid Chisnallbool
7517a984708SDavid Chisnallisspace(_CharT __c, const locale& __loc)
7527a984708SDavid Chisnall{
7537a984708SDavid Chisnall    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
7547a984708SDavid Chisnall}
7557a984708SDavid Chisnall
7567a984708SDavid Chisnalltemplate <class _CharT>
7577a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
7587a984708SDavid Chisnallbool
7597a984708SDavid Chisnallisprint(_CharT __c, const locale& __loc)
7607a984708SDavid Chisnall{
7617a984708SDavid Chisnall    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
7627a984708SDavid Chisnall}
7637a984708SDavid Chisnall
7647a984708SDavid Chisnalltemplate <class _CharT>
7657a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
7667a984708SDavid Chisnallbool
7677a984708SDavid Chisnalliscntrl(_CharT __c, const locale& __loc)
7687a984708SDavid Chisnall{
7697a984708SDavid Chisnall    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
7707a984708SDavid Chisnall}
7717a984708SDavid Chisnall
7727a984708SDavid Chisnalltemplate <class _CharT>
7737a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
7747a984708SDavid Chisnallbool
7757a984708SDavid Chisnallisupper(_CharT __c, const locale& __loc)
7767a984708SDavid Chisnall{
7777a984708SDavid Chisnall    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
7787a984708SDavid Chisnall}
7797a984708SDavid Chisnall
7807a984708SDavid Chisnalltemplate <class _CharT>
7817a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
7827a984708SDavid Chisnallbool
7837a984708SDavid Chisnallislower(_CharT __c, const locale& __loc)
7847a984708SDavid Chisnall{
7857a984708SDavid Chisnall    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
7867a984708SDavid Chisnall}
7877a984708SDavid Chisnall
7887a984708SDavid Chisnalltemplate <class _CharT>
7897a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
7907a984708SDavid Chisnallbool
7917a984708SDavid Chisnallisalpha(_CharT __c, const locale& __loc)
7927a984708SDavid Chisnall{
7937a984708SDavid Chisnall    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
7947a984708SDavid Chisnall}
7957a984708SDavid Chisnall
7967a984708SDavid Chisnalltemplate <class _CharT>
7977a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
7987a984708SDavid Chisnallbool
7997a984708SDavid Chisnallisdigit(_CharT __c, const locale& __loc)
8007a984708SDavid Chisnall{
8017a984708SDavid Chisnall    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
8027a984708SDavid Chisnall}
8037a984708SDavid Chisnall
8047a984708SDavid Chisnalltemplate <class _CharT>
8057a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
8067a984708SDavid Chisnallbool
8077a984708SDavid Chisnallispunct(_CharT __c, const locale& __loc)
8087a984708SDavid Chisnall{
8097a984708SDavid Chisnall    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
8107a984708SDavid Chisnall}
8117a984708SDavid Chisnall
8127a984708SDavid Chisnalltemplate <class _CharT>
8137a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
8147a984708SDavid Chisnallbool
8157a984708SDavid Chisnallisxdigit(_CharT __c, const locale& __loc)
8167a984708SDavid Chisnall{
8177a984708SDavid Chisnall    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
8187a984708SDavid Chisnall}
8197a984708SDavid Chisnall
8207a984708SDavid Chisnalltemplate <class _CharT>
8217a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
8227a984708SDavid Chisnallbool
8237a984708SDavid Chisnallisalnum(_CharT __c, const locale& __loc)
8247a984708SDavid Chisnall{
8257a984708SDavid Chisnall    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
8267a984708SDavid Chisnall}
8277a984708SDavid Chisnall
8287a984708SDavid Chisnalltemplate <class _CharT>
8297a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
8307a984708SDavid Chisnallbool
8317a984708SDavid Chisnallisgraph(_CharT __c, const locale& __loc)
8327a984708SDavid Chisnall{
8337a984708SDavid Chisnall    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
8347a984708SDavid Chisnall}
8357a984708SDavid Chisnall
8367a984708SDavid Chisnalltemplate <class _CharT>
8377a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
8387a984708SDavid Chisnall_CharT
8397a984708SDavid Chisnalltoupper(_CharT __c, const locale& __loc)
8407a984708SDavid Chisnall{
8417a984708SDavid Chisnall    return use_facet<ctype<_CharT> >(__loc).toupper(__c);
8427a984708SDavid Chisnall}
8437a984708SDavid Chisnall
8447a984708SDavid Chisnalltemplate <class _CharT>
8457a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
8467a984708SDavid Chisnall_CharT
8477a984708SDavid Chisnalltolower(_CharT __c, const locale& __loc)
8487a984708SDavid Chisnall{
8497a984708SDavid Chisnall    return use_facet<ctype<_CharT> >(__loc).tolower(__c);
8507a984708SDavid Chisnall}
8517a984708SDavid Chisnall
8527a984708SDavid Chisnall// codecvt_base
8537a984708SDavid Chisnall
8541bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS codecvt_base
8557a984708SDavid Chisnall{
8567a984708SDavid Chisnallpublic:
8574ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY codecvt_base() {}
8587a984708SDavid Chisnall    enum result {ok, partial, error, noconv};
8597a984708SDavid Chisnall};
8607a984708SDavid Chisnall
8617a984708SDavid Chisnall// template <class internT, class externT, class stateT> class codecvt;
8627a984708SDavid Chisnall
863aed8d94eSDimitry Andrictemplate <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TEMPLATE_VIS codecvt;
8647a984708SDavid Chisnall
8657a984708SDavid Chisnall// template <> class codecvt<char, char, mbstate_t>
8667a984708SDavid Chisnall
8677a984708SDavid Chisnalltemplate <>
8681bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
8697a984708SDavid Chisnall    : public locale::facet,
8707a984708SDavid Chisnall      public codecvt_base
8717a984708SDavid Chisnall{
8727a984708SDavid Chisnallpublic:
8737a984708SDavid Chisnall    typedef char      intern_type;
8747a984708SDavid Chisnall    typedef char      extern_type;
8757a984708SDavid Chisnall    typedef mbstate_t state_type;
8767a984708SDavid Chisnall
8774ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8787a984708SDavid Chisnall    explicit codecvt(size_t __refs = 0)
8797a984708SDavid Chisnall        : locale::facet(__refs) {}
8807a984708SDavid Chisnall
8814ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8827a984708SDavid Chisnall    result out(state_type& __st,
8837a984708SDavid Chisnall               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
8847a984708SDavid Chisnall               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
8857a984708SDavid Chisnall    {
8867a984708SDavid Chisnall        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
8877a984708SDavid Chisnall    }
8887a984708SDavid Chisnall
8894ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8907a984708SDavid Chisnall    result unshift(state_type& __st,
8917a984708SDavid Chisnall                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
8927a984708SDavid Chisnall    {
8937a984708SDavid Chisnall        return do_unshift(__st, __to, __to_end, __to_nxt);
8947a984708SDavid Chisnall    }
8957a984708SDavid Chisnall
8964ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8977a984708SDavid Chisnall    result in(state_type& __st,
8987a984708SDavid Chisnall              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
8997a984708SDavid Chisnall              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
9007a984708SDavid Chisnall    {
9017a984708SDavid Chisnall        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
9027a984708SDavid Chisnall    }
9037a984708SDavid Chisnall
9044ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9057a984708SDavid Chisnall    int encoding() const  _NOEXCEPT
9067a984708SDavid Chisnall    {
9077a984708SDavid Chisnall        return do_encoding();
9087a984708SDavid Chisnall    }
9097a984708SDavid Chisnall
9104ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9117a984708SDavid Chisnall    bool always_noconv() const  _NOEXCEPT
9127a984708SDavid Chisnall    {
9137a984708SDavid Chisnall        return do_always_noconv();
9147a984708SDavid Chisnall    }
9157a984708SDavid Chisnall
9164ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9177a984708SDavid Chisnall    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
9187a984708SDavid Chisnall    {
9197a984708SDavid Chisnall        return do_length(__st, __frm, __end, __mx);
9207a984708SDavid Chisnall    }
9217a984708SDavid Chisnall
9224ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9237a984708SDavid Chisnall    int max_length() const  _NOEXCEPT
9247a984708SDavid Chisnall    {
9257a984708SDavid Chisnall        return do_max_length();
9267a984708SDavid Chisnall    }
9277a984708SDavid Chisnall
9287a984708SDavid Chisnall    static locale::id id;
9297a984708SDavid Chisnall
9307a984708SDavid Chisnallprotected:
9314ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9327a984708SDavid Chisnall    explicit codecvt(const char*, size_t __refs = 0)
9337a984708SDavid Chisnall        : locale::facet(__refs) {}
9347a984708SDavid Chisnall
9357a984708SDavid Chisnall    ~codecvt();
9367a984708SDavid Chisnall
9377a984708SDavid Chisnall    virtual result do_out(state_type& __st,
9387a984708SDavid Chisnall                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
9397a984708SDavid Chisnall                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
9407a984708SDavid Chisnall    virtual result do_in(state_type& __st,
9417a984708SDavid Chisnall                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
9427a984708SDavid Chisnall                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
9437a984708SDavid Chisnall    virtual result do_unshift(state_type& __st,
9447a984708SDavid Chisnall                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
9457a984708SDavid Chisnall    virtual int do_encoding() const  _NOEXCEPT;
9467a984708SDavid Chisnall    virtual bool do_always_noconv() const  _NOEXCEPT;
9477a984708SDavid Chisnall    virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
9487a984708SDavid Chisnall    virtual int do_max_length() const  _NOEXCEPT;
9497a984708SDavid Chisnall};
9507a984708SDavid Chisnall
9517a984708SDavid Chisnall// template <> class codecvt<wchar_t, char, mbstate_t>
9527a984708SDavid Chisnall
9537a984708SDavid Chisnalltemplate <>
9541bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
9557a984708SDavid Chisnall    : public locale::facet,
9567a984708SDavid Chisnall      public codecvt_base
9577a984708SDavid Chisnall{
9587a984708SDavid Chisnall    locale_t __l;
9597a984708SDavid Chisnallpublic:
9607a984708SDavid Chisnall    typedef wchar_t   intern_type;
9617a984708SDavid Chisnall    typedef char      extern_type;
9627a984708SDavid Chisnall    typedef mbstate_t state_type;
9637a984708SDavid Chisnall
9647a984708SDavid Chisnall    explicit codecvt(size_t __refs = 0);
9657a984708SDavid Chisnall
9664ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9677a984708SDavid Chisnall    result out(state_type& __st,
9687a984708SDavid Chisnall               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
9697a984708SDavid Chisnall               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
9707a984708SDavid Chisnall    {
9717a984708SDavid Chisnall        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
9727a984708SDavid Chisnall    }
9737a984708SDavid Chisnall
9744ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9757a984708SDavid Chisnall    result unshift(state_type& __st,
9767a984708SDavid Chisnall                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
9777a984708SDavid Chisnall    {
9787a984708SDavid Chisnall        return do_unshift(__st, __to, __to_end, __to_nxt);
9797a984708SDavid Chisnall    }
9807a984708SDavid Chisnall
9814ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9827a984708SDavid Chisnall    result in(state_type& __st,
9837a984708SDavid Chisnall              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
9847a984708SDavid Chisnall              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
9857a984708SDavid Chisnall    {
9867a984708SDavid Chisnall        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
9877a984708SDavid Chisnall    }
9887a984708SDavid Chisnall
9894ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9907a984708SDavid Chisnall    int encoding() const  _NOEXCEPT
9917a984708SDavid Chisnall    {
9927a984708SDavid Chisnall        return do_encoding();
9937a984708SDavid Chisnall    }
9947a984708SDavid Chisnall
9954ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9967a984708SDavid Chisnall    bool always_noconv() const  _NOEXCEPT
9977a984708SDavid Chisnall    {
9987a984708SDavid Chisnall        return do_always_noconv();
9997a984708SDavid Chisnall    }
10007a984708SDavid Chisnall
10014ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10027a984708SDavid Chisnall    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
10037a984708SDavid Chisnall    {
10047a984708SDavid Chisnall        return do_length(__st, __frm, __end, __mx);
10057a984708SDavid Chisnall    }
10067a984708SDavid Chisnall
10074ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10087a984708SDavid Chisnall    int max_length() const  _NOEXCEPT
10097a984708SDavid Chisnall    {
10107a984708SDavid Chisnall        return do_max_length();
10117a984708SDavid Chisnall    }
10127a984708SDavid Chisnall
10137a984708SDavid Chisnall    static locale::id id;
10147a984708SDavid Chisnall
10157a984708SDavid Chisnallprotected:
10167a984708SDavid Chisnall    explicit codecvt(const char*, size_t __refs = 0);
10177a984708SDavid Chisnall
10187a984708SDavid Chisnall    ~codecvt();
10197a984708SDavid Chisnall
10207a984708SDavid Chisnall    virtual result do_out(state_type& __st,
10217a984708SDavid Chisnall                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
10227a984708SDavid Chisnall                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
10237a984708SDavid Chisnall    virtual result do_in(state_type& __st,
10247a984708SDavid Chisnall                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
10257a984708SDavid Chisnall                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
10267a984708SDavid Chisnall    virtual result do_unshift(state_type& __st,
10277a984708SDavid Chisnall                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
10287a984708SDavid Chisnall    virtual int do_encoding() const  _NOEXCEPT;
10297a984708SDavid Chisnall    virtual bool do_always_noconv() const  _NOEXCEPT;
10307a984708SDavid Chisnall    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
10317a984708SDavid Chisnall    virtual int do_max_length() const  _NOEXCEPT;
10327a984708SDavid Chisnall};
10337a984708SDavid Chisnall
10347a984708SDavid Chisnall// template <> class codecvt<char16_t, char, mbstate_t>
10357a984708SDavid Chisnall
10367a984708SDavid Chisnalltemplate <>
10371bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
10387a984708SDavid Chisnall    : public locale::facet,
10397a984708SDavid Chisnall      public codecvt_base
10407a984708SDavid Chisnall{
10417a984708SDavid Chisnallpublic:
10427a984708SDavid Chisnall    typedef char16_t  intern_type;
10437a984708SDavid Chisnall    typedef char      extern_type;
10447a984708SDavid Chisnall    typedef mbstate_t state_type;
10457a984708SDavid Chisnall
10464ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10477a984708SDavid Chisnall    explicit codecvt(size_t __refs = 0)
10487a984708SDavid Chisnall        : locale::facet(__refs) {}
10497a984708SDavid Chisnall
10504ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10517a984708SDavid Chisnall    result out(state_type& __st,
10527a984708SDavid Chisnall               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
10537a984708SDavid Chisnall               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
10547a984708SDavid Chisnall    {
10557a984708SDavid Chisnall        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
10567a984708SDavid Chisnall    }
10577a984708SDavid Chisnall
10584ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10597a984708SDavid Chisnall    result unshift(state_type& __st,
10607a984708SDavid Chisnall                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
10617a984708SDavid Chisnall    {
10627a984708SDavid Chisnall        return do_unshift(__st, __to, __to_end, __to_nxt);
10637a984708SDavid Chisnall    }
10647a984708SDavid Chisnall
10654ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10667a984708SDavid Chisnall    result in(state_type& __st,
10677a984708SDavid Chisnall              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
10687a984708SDavid Chisnall              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
10697a984708SDavid Chisnall    {
10707a984708SDavid Chisnall        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
10717a984708SDavid Chisnall    }
10727a984708SDavid Chisnall
10734ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10747a984708SDavid Chisnall    int encoding() const  _NOEXCEPT
10757a984708SDavid Chisnall    {
10767a984708SDavid Chisnall        return do_encoding();
10777a984708SDavid Chisnall    }
10787a984708SDavid Chisnall
10794ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10807a984708SDavid Chisnall    bool always_noconv() const  _NOEXCEPT
10817a984708SDavid Chisnall    {
10827a984708SDavid Chisnall        return do_always_noconv();
10837a984708SDavid Chisnall    }
10847a984708SDavid Chisnall
10854ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10867a984708SDavid Chisnall    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
10877a984708SDavid Chisnall    {
10887a984708SDavid Chisnall        return do_length(__st, __frm, __end, __mx);
10897a984708SDavid Chisnall    }
10907a984708SDavid Chisnall
10914ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
10927a984708SDavid Chisnall    int max_length() const  _NOEXCEPT
10937a984708SDavid Chisnall    {
10947a984708SDavid Chisnall        return do_max_length();
10957a984708SDavid Chisnall    }
10967a984708SDavid Chisnall
10977a984708SDavid Chisnall    static locale::id id;
10987a984708SDavid Chisnall
10997a984708SDavid Chisnallprotected:
11004ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11017a984708SDavid Chisnall    explicit codecvt(const char*, size_t __refs = 0)
11027a984708SDavid Chisnall        : locale::facet(__refs) {}
11037a984708SDavid Chisnall
11047a984708SDavid Chisnall    ~codecvt();
11057a984708SDavid Chisnall
11067a984708SDavid Chisnall    virtual result do_out(state_type& __st,
11077a984708SDavid Chisnall                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
11087a984708SDavid Chisnall                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
11097a984708SDavid Chisnall    virtual result do_in(state_type& __st,
11107a984708SDavid Chisnall                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
11117a984708SDavid Chisnall                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
11127a984708SDavid Chisnall    virtual result do_unshift(state_type& __st,
11137a984708SDavid Chisnall                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
11147a984708SDavid Chisnall    virtual int do_encoding() const  _NOEXCEPT;
11157a984708SDavid Chisnall    virtual bool do_always_noconv() const  _NOEXCEPT;
11167a984708SDavid Chisnall    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
11177a984708SDavid Chisnall    virtual int do_max_length() const  _NOEXCEPT;
11187a984708SDavid Chisnall};
11197a984708SDavid Chisnall
11207a984708SDavid Chisnall// template <> class codecvt<char32_t, char, mbstate_t>
11217a984708SDavid Chisnall
11227a984708SDavid Chisnalltemplate <>
11231bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
11247a984708SDavid Chisnall    : public locale::facet,
11257a984708SDavid Chisnall      public codecvt_base
11267a984708SDavid Chisnall{
11277a984708SDavid Chisnallpublic:
11287a984708SDavid Chisnall    typedef char32_t  intern_type;
11297a984708SDavid Chisnall    typedef char      extern_type;
11307a984708SDavid Chisnall    typedef mbstate_t state_type;
11317a984708SDavid Chisnall
11324ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11337a984708SDavid Chisnall    explicit codecvt(size_t __refs = 0)
11347a984708SDavid Chisnall        : locale::facet(__refs) {}
11357a984708SDavid Chisnall
11364ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11377a984708SDavid Chisnall    result out(state_type& __st,
11387a984708SDavid Chisnall               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
11397a984708SDavid Chisnall               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
11407a984708SDavid Chisnall    {
11417a984708SDavid Chisnall        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
11427a984708SDavid Chisnall    }
11437a984708SDavid Chisnall
11444ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11457a984708SDavid Chisnall    result unshift(state_type& __st,
11467a984708SDavid Chisnall                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
11477a984708SDavid Chisnall    {
11487a984708SDavid Chisnall        return do_unshift(__st, __to, __to_end, __to_nxt);
11497a984708SDavid Chisnall    }
11507a984708SDavid Chisnall
11514ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11527a984708SDavid Chisnall    result in(state_type& __st,
11537a984708SDavid Chisnall              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
11547a984708SDavid Chisnall              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
11557a984708SDavid Chisnall    {
11567a984708SDavid Chisnall        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
11577a984708SDavid Chisnall    }
11587a984708SDavid Chisnall
11594ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11607a984708SDavid Chisnall    int encoding() const  _NOEXCEPT
11617a984708SDavid Chisnall    {
11627a984708SDavid Chisnall        return do_encoding();
11637a984708SDavid Chisnall    }
11647a984708SDavid Chisnall
11654ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11667a984708SDavid Chisnall    bool always_noconv() const  _NOEXCEPT
11677a984708SDavid Chisnall    {
11687a984708SDavid Chisnall        return do_always_noconv();
11697a984708SDavid Chisnall    }
11707a984708SDavid Chisnall
11714ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11727a984708SDavid Chisnall    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
11737a984708SDavid Chisnall    {
11747a984708SDavid Chisnall        return do_length(__st, __frm, __end, __mx);
11757a984708SDavid Chisnall    }
11767a984708SDavid Chisnall
11774ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11787a984708SDavid Chisnall    int max_length() const  _NOEXCEPT
11797a984708SDavid Chisnall    {
11807a984708SDavid Chisnall        return do_max_length();
11817a984708SDavid Chisnall    }
11827a984708SDavid Chisnall
11837a984708SDavid Chisnall    static locale::id id;
11847a984708SDavid Chisnall
11857a984708SDavid Chisnallprotected:
11864ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
11877a984708SDavid Chisnall    explicit codecvt(const char*, size_t __refs = 0)
11887a984708SDavid Chisnall        : locale::facet(__refs) {}
11897a984708SDavid Chisnall
11907a984708SDavid Chisnall    ~codecvt();
11917a984708SDavid Chisnall
11927a984708SDavid Chisnall    virtual result do_out(state_type& __st,
11937a984708SDavid Chisnall                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
11947a984708SDavid Chisnall                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
11957a984708SDavid Chisnall    virtual result do_in(state_type& __st,
11967a984708SDavid Chisnall                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
11977a984708SDavid Chisnall                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
11987a984708SDavid Chisnall    virtual result do_unshift(state_type& __st,
11997a984708SDavid Chisnall                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
12007a984708SDavid Chisnall    virtual int do_encoding() const  _NOEXCEPT;
12017a984708SDavid Chisnall    virtual bool do_always_noconv() const  _NOEXCEPT;
12027a984708SDavid Chisnall    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
12037a984708SDavid Chisnall    virtual int do_max_length() const  _NOEXCEPT;
12047a984708SDavid Chisnall};
12057a984708SDavid Chisnall
12067a984708SDavid Chisnall// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
12077a984708SDavid Chisnall
12087a984708SDavid Chisnalltemplate <class _InternT, class _ExternT, class _StateT>
1209aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS codecvt_byname
12107a984708SDavid Chisnall    : public codecvt<_InternT, _ExternT, _StateT>
12117a984708SDavid Chisnall{
12127a984708SDavid Chisnallpublic:
12134ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12147a984708SDavid Chisnall    explicit codecvt_byname(const char* __nm, size_t __refs = 0)
12157a984708SDavid Chisnall        : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
12164ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12177a984708SDavid Chisnall    explicit codecvt_byname(const string& __nm, size_t __refs = 0)
12187a984708SDavid Chisnall        : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
12197a984708SDavid Chisnallprotected:
12207a984708SDavid Chisnall    ~codecvt_byname();
12217a984708SDavid Chisnall};
12227a984708SDavid Chisnall
12237a984708SDavid Chisnalltemplate <class _InternT, class _ExternT, class _StateT>
12247a984708SDavid Chisnallcodecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
12257a984708SDavid Chisnall{
12267a984708SDavid Chisnall}
12277a984708SDavid Chisnall
1228aed8d94eSDimitry Andric_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>)
1229aed8d94eSDimitry Andric_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>)
1230aed8d94eSDimitry Andric_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>)
1231aed8d94eSDimitry Andric_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>)
12327a984708SDavid Chisnall
123394e3ee44SDavid Chisnalltemplate <size_t _Np>
12347a984708SDavid Chisnallstruct __narrow_to_utf8
12357a984708SDavid Chisnall{
12367a984708SDavid Chisnall    template <class _OutputIterator, class _CharT>
12377a984708SDavid Chisnall    _OutputIterator
12387a984708SDavid Chisnall    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
12397a984708SDavid Chisnall};
12407a984708SDavid Chisnall
12417a984708SDavid Chisnalltemplate <>
12427a984708SDavid Chisnallstruct __narrow_to_utf8<8>
12437a984708SDavid Chisnall{
12447a984708SDavid Chisnall    template <class _OutputIterator, class _CharT>
12454ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12467a984708SDavid Chisnall    _OutputIterator
12477a984708SDavid Chisnall    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
12487a984708SDavid Chisnall    {
12497a984708SDavid Chisnall        for (; __wb < __we; ++__wb, ++__s)
12507a984708SDavid Chisnall            *__s = *__wb;
12517a984708SDavid Chisnall        return __s;
12527a984708SDavid Chisnall    }
12537a984708SDavid Chisnall};
12547a984708SDavid Chisnall
12557a984708SDavid Chisnalltemplate <>
1256*b5893f02SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS __narrow_to_utf8<16>
12577a984708SDavid Chisnall    : public codecvt<char16_t, char, mbstate_t>
12587a984708SDavid Chisnall{
12594ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12607a984708SDavid Chisnall    __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
12617a984708SDavid Chisnall
1262*b5893f02SDimitry Andric    _LIBCPP_EXPORTED_FROM_ABI ~__narrow_to_utf8();
12637a984708SDavid Chisnall
12647a984708SDavid Chisnall    template <class _OutputIterator, class _CharT>
12654ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12667a984708SDavid Chisnall    _OutputIterator
12677a984708SDavid Chisnall    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
12687a984708SDavid Chisnall    {
12697a984708SDavid Chisnall        result __r = ok;
12707a984708SDavid Chisnall        mbstate_t __mb;
12717a984708SDavid Chisnall        while (__wb < __we && __r != error)
12727a984708SDavid Chisnall        {
12737a984708SDavid Chisnall            const int __sz = 32;
12747a984708SDavid Chisnall            char __buf[__sz];
12757a984708SDavid Chisnall            char* __bn;
12767a984708SDavid Chisnall            const char16_t* __wn = (const char16_t*)__wb;
12777a984708SDavid Chisnall            __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
12787a984708SDavid Chisnall                         __buf, __buf+__sz, __bn);
12797a984708SDavid Chisnall            if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
12807a984708SDavid Chisnall                __throw_runtime_error("locale not supported");
12817a984708SDavid Chisnall            for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
12827a984708SDavid Chisnall                *__s = *__p;
12837a984708SDavid Chisnall            __wb = (const _CharT*)__wn;
12847a984708SDavid Chisnall        }
12857a984708SDavid Chisnall        return __s;
12867a984708SDavid Chisnall    }
12877a984708SDavid Chisnall};
12887a984708SDavid Chisnall
12897a984708SDavid Chisnalltemplate <>
1290*b5893f02SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS __narrow_to_utf8<32>
12917a984708SDavid Chisnall    : public codecvt<char32_t, char, mbstate_t>
12927a984708SDavid Chisnall{
12934ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
12947a984708SDavid Chisnall    __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
12957a984708SDavid Chisnall
1296*b5893f02SDimitry Andric    _LIBCPP_EXPORTED_FROM_ABI ~__narrow_to_utf8();
12977a984708SDavid Chisnall
12987a984708SDavid Chisnall    template <class _OutputIterator, class _CharT>
12994ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13007a984708SDavid Chisnall    _OutputIterator
13017a984708SDavid Chisnall    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
13027a984708SDavid Chisnall    {
13037a984708SDavid Chisnall        result __r = ok;
13047a984708SDavid Chisnall        mbstate_t __mb;
13057a984708SDavid Chisnall        while (__wb < __we && __r != error)
13067a984708SDavid Chisnall        {
13077a984708SDavid Chisnall            const int __sz = 32;
13087a984708SDavid Chisnall            char __buf[__sz];
13097a984708SDavid Chisnall            char* __bn;
13107a984708SDavid Chisnall            const char32_t* __wn = (const char32_t*)__wb;
13117a984708SDavid Chisnall            __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
13127a984708SDavid Chisnall                         __buf, __buf+__sz, __bn);
13137a984708SDavid Chisnall            if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
13147a984708SDavid Chisnall                __throw_runtime_error("locale not supported");
13157a984708SDavid Chisnall            for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
13167a984708SDavid Chisnall                *__s = *__p;
13177a984708SDavid Chisnall            __wb = (const _CharT*)__wn;
13187a984708SDavid Chisnall        }
13197a984708SDavid Chisnall        return __s;
13207a984708SDavid Chisnall    }
13217a984708SDavid Chisnall};
13227a984708SDavid Chisnall
132394e3ee44SDavid Chisnalltemplate <size_t _Np>
13247a984708SDavid Chisnallstruct __widen_from_utf8
13257a984708SDavid Chisnall{
13267a984708SDavid Chisnall    template <class _OutputIterator>
13277a984708SDavid Chisnall    _OutputIterator
13287a984708SDavid Chisnall    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
13297a984708SDavid Chisnall};
13307a984708SDavid Chisnall
13317a984708SDavid Chisnalltemplate <>
13327a984708SDavid Chisnallstruct __widen_from_utf8<8>
13337a984708SDavid Chisnall{
13347a984708SDavid Chisnall    template <class _OutputIterator>
13354ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13367a984708SDavid Chisnall    _OutputIterator
13377a984708SDavid Chisnall    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
13387a984708SDavid Chisnall    {
13397a984708SDavid Chisnall        for (; __nb < __ne; ++__nb, ++__s)
13407a984708SDavid Chisnall            *__s = *__nb;
13417a984708SDavid Chisnall        return __s;
13427a984708SDavid Chisnall    }
13437a984708SDavid Chisnall};
13447a984708SDavid Chisnall
13457a984708SDavid Chisnalltemplate <>
1346*b5893f02SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS __widen_from_utf8<16>
13477a984708SDavid Chisnall    : public codecvt<char16_t, char, mbstate_t>
13487a984708SDavid Chisnall{
13494ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13507a984708SDavid Chisnall    __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
13517a984708SDavid Chisnall
1352*b5893f02SDimitry Andric    _LIBCPP_EXPORTED_FROM_ABI ~__widen_from_utf8();
13537a984708SDavid Chisnall
13547a984708SDavid Chisnall    template <class _OutputIterator>
13554ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13567a984708SDavid Chisnall    _OutputIterator
13577a984708SDavid Chisnall    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
13587a984708SDavid Chisnall    {
13597a984708SDavid Chisnall        result __r = ok;
13607a984708SDavid Chisnall        mbstate_t __mb;
13617a984708SDavid Chisnall        while (__nb < __ne && __r != error)
13627a984708SDavid Chisnall        {
13637a984708SDavid Chisnall            const int __sz = 32;
13647a984708SDavid Chisnall            char16_t __buf[__sz];
13657a984708SDavid Chisnall            char16_t* __bn;
13667a984708SDavid Chisnall            const char* __nn = __nb;
13677a984708SDavid Chisnall            __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
13687a984708SDavid Chisnall                        __buf, __buf+__sz, __bn);
13697a984708SDavid Chisnall            if (__r == codecvt_base::error || __nn == __nb)
13707a984708SDavid Chisnall                __throw_runtime_error("locale not supported");
13717a984708SDavid Chisnall            for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
13727a984708SDavid Chisnall                *__s = (wchar_t)*__p;
13737a984708SDavid Chisnall            __nb = __nn;
13747a984708SDavid Chisnall        }
13757a984708SDavid Chisnall        return __s;
13767a984708SDavid Chisnall    }
13777a984708SDavid Chisnall};
13787a984708SDavid Chisnall
13797a984708SDavid Chisnalltemplate <>
1380*b5893f02SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS __widen_from_utf8<32>
13817a984708SDavid Chisnall    : public codecvt<char32_t, char, mbstate_t>
13827a984708SDavid Chisnall{
13834ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13847a984708SDavid Chisnall    __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
13857a984708SDavid Chisnall
1386*b5893f02SDimitry Andric    _LIBCPP_EXPORTED_FROM_ABI ~__widen_from_utf8();
13877a984708SDavid Chisnall
13887a984708SDavid Chisnall    template <class _OutputIterator>
13894ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
13907a984708SDavid Chisnall    _OutputIterator
13917a984708SDavid Chisnall    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
13927a984708SDavid Chisnall    {
13937a984708SDavid Chisnall        result __r = ok;
13947a984708SDavid Chisnall        mbstate_t __mb;
13957a984708SDavid Chisnall        while (__nb < __ne && __r != error)
13967a984708SDavid Chisnall        {
13977a984708SDavid Chisnall            const int __sz = 32;
13987a984708SDavid Chisnall            char32_t __buf[__sz];
13997a984708SDavid Chisnall            char32_t* __bn;
14007a984708SDavid Chisnall            const char* __nn = __nb;
14017a984708SDavid Chisnall            __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
14027a984708SDavid Chisnall                        __buf, __buf+__sz, __bn);
14037a984708SDavid Chisnall            if (__r == codecvt_base::error || __nn == __nb)
14047a984708SDavid Chisnall                __throw_runtime_error("locale not supported");
14057a984708SDavid Chisnall            for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
14067a984708SDavid Chisnall                *__s = (wchar_t)*__p;
14077a984708SDavid Chisnall            __nb = __nn;
14087a984708SDavid Chisnall        }
14097a984708SDavid Chisnall        return __s;
14107a984708SDavid Chisnall    }
14117a984708SDavid Chisnall};
14127a984708SDavid Chisnall
14137a984708SDavid Chisnall// template <class charT> class numpunct
14147a984708SDavid Chisnall
1415aed8d94eSDimitry Andrictemplate <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct;
14167a984708SDavid Chisnall
14177a984708SDavid Chisnalltemplate <>
14181bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS numpunct<char>
14197a984708SDavid Chisnall    : public locale::facet
14207a984708SDavid Chisnall{
14217a984708SDavid Chisnallpublic:
14227a984708SDavid Chisnall    typedef char char_type;
14237a984708SDavid Chisnall    typedef basic_string<char_type> string_type;
14247a984708SDavid Chisnall
14257a984708SDavid Chisnall    explicit numpunct(size_t __refs = 0);
14267a984708SDavid Chisnall
14274ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
14284ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
14294ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY string grouping() const         {return do_grouping();}
14304ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY string_type truename() const    {return do_truename();}
14314ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY string_type falsename() const   {return do_falsename();}
14327a984708SDavid Chisnall
14337a984708SDavid Chisnall    static locale::id id;
14347a984708SDavid Chisnall
14357a984708SDavid Chisnallprotected:
14367a984708SDavid Chisnall    ~numpunct();
14377a984708SDavid Chisnall    virtual char_type do_decimal_point() const;
14387a984708SDavid Chisnall    virtual char_type do_thousands_sep() const;
14397a984708SDavid Chisnall    virtual string do_grouping() const;
14407a984708SDavid Chisnall    virtual string_type do_truename() const;
14417a984708SDavid Chisnall    virtual string_type do_falsename() const;
14427a984708SDavid Chisnall
14437a984708SDavid Chisnall    char_type __decimal_point_;
14447a984708SDavid Chisnall    char_type __thousands_sep_;
14457a984708SDavid Chisnall    string __grouping_;
14467a984708SDavid Chisnall};
14477a984708SDavid Chisnall
14487a984708SDavid Chisnalltemplate <>
14491bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS numpunct<wchar_t>
14507a984708SDavid Chisnall    : public locale::facet
14517a984708SDavid Chisnall{
14527a984708SDavid Chisnallpublic:
14537a984708SDavid Chisnall    typedef wchar_t char_type;
14547a984708SDavid Chisnall    typedef basic_string<char_type> string_type;
14557a984708SDavid Chisnall
14567a984708SDavid Chisnall    explicit numpunct(size_t __refs = 0);
14577a984708SDavid Chisnall
14584ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
14594ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
14604ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY string grouping() const         {return do_grouping();}
14614ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY string_type truename() const    {return do_truename();}
14624ba319b5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY string_type falsename() const   {return do_falsename();}
14637a984708SDavid Chisnall
14647a984708SDavid Chisnall    static locale::id id;
14657a984708SDavid Chisnall
14667a984708SDavid Chisnallprotected:
14677a984708SDavid Chisnall    ~numpunct();
14687a984708SDavid Chisnall    virtual char_type do_decimal_point() const;
14697a984708SDavid Chisnall    virtual char_type do_thousands_sep() const;
14707a984708SDavid Chisnall    virtual string do_grouping() const;
14717a984708SDavid Chisnall    virtual string_type do_truename() const;
14727a984708SDavid Chisnall    virtual string_type do_falsename() const;
14737a984708SDavid Chisnall
14747a984708SDavid Chisnall    char_type __decimal_point_;
14757a984708SDavid Chisnall    char_type __thousands_sep_;
14767a984708SDavid Chisnall    string __grouping_;
14777a984708SDavid Chisnall};
14787a984708SDavid Chisnall
14797a984708SDavid Chisnall// template <class charT> class numpunct_byname
14807a984708SDavid Chisnall
1481aed8d94eSDimitry Andrictemplate <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct_byname;
14827a984708SDavid Chisnall
14837a984708SDavid Chisnalltemplate <>
14841bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS numpunct_byname<char>
14857a984708SDavid Chisnall: public numpunct<char>
14867a984708SDavid Chisnall{
14877a984708SDavid Chisnallpublic:
14887a984708SDavid Chisnall    typedef char char_type;
14897a984708SDavid Chisnall    typedef basic_string<char_type> string_type;
14907a984708SDavid Chisnall
14917a984708SDavid Chisnall    explicit numpunct_byname(const char* __nm, size_t __refs = 0);
14927a984708SDavid Chisnall    explicit numpunct_byname(const string& __nm, size_t __refs = 0);
14937a984708SDavid Chisnall
14947a984708SDavid Chisnallprotected:
14957a984708SDavid Chisnall    ~numpunct_byname();
14967a984708SDavid Chisnall
14977a984708SDavid Chisnallprivate:
14987a984708SDavid Chisnall    void __init(const char*);
14997a984708SDavid Chisnall};
15007a984708SDavid Chisnall
15017a984708SDavid Chisnalltemplate <>
15021bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
15037a984708SDavid Chisnall: public numpunct<wchar_t>
15047a984708SDavid Chisnall{
15057a984708SDavid Chisnallpublic:
15067a984708SDavid Chisnall    typedef wchar_t char_type;
15077a984708SDavid Chisnall    typedef basic_string<char_type> string_type;
15087a984708SDavid Chisnall
15097a984708SDavid Chisnall    explicit numpunct_byname(const char* __nm, size_t __refs = 0);
15107a984708SDavid Chisnall    explicit numpunct_byname(const string& __nm, size_t __refs = 0);
15117a984708SDavid Chisnall
15127a984708SDavid Chisnallprotected:
15137a984708SDavid Chisnall    ~numpunct_byname();
15147a984708SDavid Chisnall
15157a984708SDavid Chisnallprivate:
15167a984708SDavid Chisnall    void __init(const char*);
15177a984708SDavid Chisnall};
15187a984708SDavid Chisnall
15197a984708SDavid Chisnall_LIBCPP_END_NAMESPACE_STD
15207a984708SDavid Chisnall
15217a984708SDavid Chisnall#endif  // _LIBCPP___LOCALE
1522