Coverage Report

Created: 2022-01-22 13:19

/Users/buildslave/jenkins/workspace/coverage/llvm-project/libcxx/src/locale.cpp
Line
Count
Source (jump to first uncovered line)
1
//===----------------------------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
// On Solaris, we need to define something to make the C99 parts of localeconv
10
// visible.
11
#ifdef __sun__
12
#define _LCONV_C99
13
#endif
14
15
#include "algorithm"
16
#include "clocale"
17
#include "codecvt"
18
#include "cstdio"
19
#include "cstdlib"
20
#include "cstring"
21
#include "locale"
22
#include "string"
23
#include "type_traits"
24
#include "typeinfo"
25
#include "vector"
26
27
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
28
#   include "cwctype"
29
#endif
30
31
#if defined(_AIX)
32
#   include <sys/localedef.h> // for __lc_ctype_ptr
33
#endif
34
35
#if defined(_LIBCPP_MSVCRT)
36
#   define _CTYPE_DISABLE_MACROS
37
#endif
38
39
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
40
#   include "__support/win32/locale_win32.h"
41
#elif !defined(__BIONIC__) && !defined(__NuttX__)
42
#   include <langinfo.h>
43
#endif
44
45
#include "include/atomic_support.h"
46
#include "include/sso_allocator.h"
47
#include "__undef_macros"
48
49
// On Linux, wint_t and wchar_t have different signed-ness, and this causes
50
// lots of noise in the build log, but no bugs that I know of.
51
#if defined(__clang__)
52
#pragma clang diagnostic ignored "-Wsign-conversion"
53
#endif
54
55
_LIBCPP_BEGIN_NAMESPACE_STD
56
57
struct __libcpp_unique_locale {
58
0
  __libcpp_unique_locale(const char* nm) : __loc_(newlocale(LC_ALL_MASK, nm, 0)) {}
59
60
0
  ~__libcpp_unique_locale() {
61
0
    if (__loc_)
62
0
      freelocale(__loc_);
63
0
  }
64
65
0
  explicit operator bool() const { return __loc_; }
66
67
0
  locale_t& get() { return __loc_; }
68
69
  locale_t __loc_;
70
private:
71
  __libcpp_unique_locale(__libcpp_unique_locale const&);
72
  __libcpp_unique_locale& operator=(__libcpp_unique_locale const&);
73
};
74
75
#ifdef __cloc_defined
76
locale_t __cloc() {
77
  // In theory this could create a race condition. In practice
78
  // the race condition is non-fatal since it will just create
79
  // a little resource leak. Better approach would be appreciated.
80
  static locale_t result = newlocale(LC_ALL_MASK, "C", 0);
81
  return result;
82
}
83
#endif // __cloc_defined
84
85
namespace {
86
87
struct release
88
{
89
0
    void operator()(locale::facet* p) {p->__release_shared();}
90
};
91
92
template <class T, class ...Args>
93
T& make(Args ...args)
94
471k
{
95
471k
    static typename aligned_storage<sizeof(T)>::type buf;
96
471k
    auto *obj = ::new (&buf) T(args...);
97
471k
    return *obj;
98
471k
}
locale.cpp:std::__1::collate<char>& std::__1::(anonymous namespace)::make<std::__1::collate<char>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::collate<wchar_t>& std::__1::(anonymous namespace)::make<std::__1::collate<wchar_t>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::ctype<char>& std::__1::(anonymous namespace)::make<std::__1::ctype<char>, std::nullptr_t, bool, unsigned int>(std::nullptr_t, bool, unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::ctype<wchar_t>& std::__1::(anonymous namespace)::make<std::__1::ctype<wchar_t>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::codecvt<char, char, __mbstate_t>& std::__1::(anonymous namespace)::make<std::__1::codecvt<char, char, __mbstate_t>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::codecvt<wchar_t, char, __mbstate_t>& std::__1::(anonymous namespace)::make<std::__1::codecvt<wchar_t, char, __mbstate_t>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::codecvt<char16_t, char, __mbstate_t>& std::__1::(anonymous namespace)::make<std::__1::codecvt<char16_t, char, __mbstate_t>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::codecvt<char32_t, char, __mbstate_t>& std::__1::(anonymous namespace)::make<std::__1::codecvt<char32_t, char, __mbstate_t>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::codecvt<char16_t, char8_t, __mbstate_t>& std::__1::(anonymous namespace)::make<std::__1::codecvt<char16_t, char8_t, __mbstate_t>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::codecvt<char32_t, char8_t, __mbstate_t>& std::__1::(anonymous namespace)::make<std::__1::codecvt<char32_t, char8_t, __mbstate_t>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::numpunct<char>& std::__1::(anonymous namespace)::make<std::__1::numpunct<char>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::numpunct<wchar_t>& std::__1::(anonymous namespace)::make<std::__1::numpunct<wchar_t>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::num_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >& std::__1::(anonymous namespace)::make<std::__1::num_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::num_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >& std::__1::(anonymous namespace)::make<std::__1::num_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >& std::__1::(anonymous namespace)::make<std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::num_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >& std::__1::(anonymous namespace)::make<std::__1::num_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::moneypunct<char, false>& std::__1::(anonymous namespace)::make<std::__1::moneypunct<char, false>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::moneypunct<char, true>& std::__1::(anonymous namespace)::make<std::__1::moneypunct<char, true>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::moneypunct<wchar_t, false>& std::__1::(anonymous namespace)::make<std::__1::moneypunct<wchar_t, false>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::moneypunct<wchar_t, true>& std::__1::(anonymous namespace)::make<std::__1::moneypunct<wchar_t, true>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::money_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >& std::__1::(anonymous namespace)::make<std::__1::money_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::money_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >& std::__1::(anonymous namespace)::make<std::__1::money_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::money_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >& std::__1::(anonymous namespace)::make<std::__1::money_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::money_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >& std::__1::(anonymous namespace)::make<std::__1::money_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::time_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >& std::__1::(anonymous namespace)::make<std::__1::time_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::time_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >& std::__1::(anonymous namespace)::make<std::__1::time_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::time_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >& std::__1::(anonymous namespace)::make<std::__1::time_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::time_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >& std::__1::(anonymous namespace)::make<std::__1::time_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::messages<char>& std::__1::(anonymous namespace)::make<std::__1::messages<char>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::messages<wchar_t>& std::__1::(anonymous namespace)::make<std::__1::messages<wchar_t>, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
locale.cpp:std::__1::locale::__imp& std::__1::(anonymous namespace)::make<std::__1::locale::__imp, unsigned int>(unsigned int)
Line
Count
Source
94
15.2k
{
95
15.2k
    static typename aligned_storage<sizeof(T)>::type buf;
96
15.2k
    auto *obj = ::new (&buf) T(args...);
97
15.2k
    return *obj;
98
15.2k
}
99
100
template <typename T, size_t N>
101
inline
102
_LIBCPP_CONSTEXPR
103
size_t
104
countof(const T (&)[N])
105
0
{
106
0
    return N;
107
0
}
Unexecuted instantiation: locale.cpp:unsigned long std::__1::(anonymous namespace)::countof<char, 100ul>(char const (&) [100ul])
Unexecuted instantiation: locale.cpp:unsigned long std::__1::(anonymous namespace)::countof<wchar_t, 100ul>(wchar_t const (&) [100ul])
108
109
template <typename T>
110
inline
111
_LIBCPP_CONSTEXPR
112
size_t
113
countof(const T * const begin, const T * const end)
114
0
{
115
0
    return static_cast<size_t>(end - begin);
116
0
}
Unexecuted instantiation: locale.cpp:unsigned long std::__1::(anonymous namespace)::countof<char>(char const*, char const*)
Unexecuted instantiation: locale.cpp:unsigned long std::__1::(anonymous namespace)::countof<wchar_t>(wchar_t const*, wchar_t const*)
117
118
_LIBCPP_NORETURN static void __throw_runtime_error(const string &msg)
119
0
{
120
0
#ifndef _LIBCPP_NO_EXCEPTIONS
121
0
    throw runtime_error(msg);
122
#else
123
    (void)msg;
124
    _VSTD::abort();
125
#endif
126
0
}
127
128
}
129
130
#if defined(_AIX)
131
// Set priority to INT_MIN + 256 + 150
132
# pragma priority ( -2147483242 )
133
#endif
134
135
const locale::category locale::none;
136
const locale::category locale::collate;
137
const locale::category locale::ctype;
138
const locale::category locale::monetary;
139
const locale::category locale::numeric;
140
const locale::category locale::time;
141
const locale::category locale::messages;
142
const locale::category locale::all;
143
144
class _LIBCPP_HIDDEN locale::__imp
145
    : public facet
146
{
147
    enum {N = 30};
148
#if defined(_LIBCPP_COMPILER_MSVC)
149
// FIXME: MSVC doesn't support aligned parameters by value.
150
// I can't get the __sso_allocator to work here
151
// for MSVC I think for this reason.
152
    vector<facet*> facets_;
153
#else
154
    vector<facet*, __sso_allocator<facet*, N> > facets_;
155
#endif
156
    string         name_;
157
public:
158
    explicit __imp(size_t refs = 0);
159
    explicit __imp(const string& name, size_t refs = 0);
160
    __imp(const __imp&);
161
    __imp(const __imp&, const string&, locale::category c);
162
    __imp(const __imp& other, const __imp& one, locale::category c);
163
    __imp(const __imp&, facet* f, long id);
164
    ~__imp();
165
166
0
    const string& name() const {return name_;}
167
    bool has_facet(long id) const
168
63.7M
        {return static_cast<size_t>(id) < facets_.size() && facets_[static_cast<size_t>(id)];}
169
    const locale::facet* use_facet(long id) const;
170
171
    static const locale& make_classic();
172
    static       locale& make_global();
173
private:
174
    void install(facet* f, long id);
175
456k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::collate<char> >(std::__1::collate<char>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::collate<wchar_t> >(std::__1::collate<wchar_t>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::ctype<char> >(std::__1::ctype<char>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::ctype<wchar_t> >(std::__1::ctype<wchar_t>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::codecvt<char, char, __mbstate_t> >(std::__1::codecvt<char, char, __mbstate_t>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::codecvt<wchar_t, char, __mbstate_t> >(std::__1::codecvt<wchar_t, char, __mbstate_t>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::codecvt<char16_t, char, __mbstate_t> >(std::__1::codecvt<char16_t, char, __mbstate_t>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::codecvt<char32_t, char, __mbstate_t> >(std::__1::codecvt<char32_t, char, __mbstate_t>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::codecvt<char16_t, char8_t, __mbstate_t> >(std::__1::codecvt<char16_t, char8_t, __mbstate_t>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::codecvt<char32_t, char8_t, __mbstate_t> >(std::__1::codecvt<char32_t, char8_t, __mbstate_t>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::numpunct<char> >(std::__1::numpunct<char>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::numpunct<wchar_t> >(std::__1::numpunct<wchar_t>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::num_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::num_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::num_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::num_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::num_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::num_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::moneypunct<char, false> >(std::__1::moneypunct<char, false>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::moneypunct<char, true> >(std::__1::moneypunct<char, true>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::moneypunct<wchar_t, false> >(std::__1::moneypunct<wchar_t, false>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::moneypunct<wchar_t, true> >(std::__1::moneypunct<wchar_t, true>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::money_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::money_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::money_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::money_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::money_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::money_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::money_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::money_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::time_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::time_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::time_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::time_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::time_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::time_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::time_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::time_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::messages<char> >(std::__1::messages<char>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
void std::__1::locale::__imp::install<std::__1::messages<wchar_t> >(std::__1::messages<wchar_t>*)
Line
Count
Source
175
15.2k
    template <class F> void install(F* f) {install(f, f->id.__get());}
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::collate_byname<char> >(std::__1::collate_byname<char>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::collate_byname<wchar_t> >(std::__1::collate_byname<wchar_t>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::ctype_byname<char> >(std::__1::ctype_byname<char>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::ctype_byname<wchar_t> >(std::__1::ctype_byname<wchar_t>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::codecvt_byname<char, char, __mbstate_t> >(std::__1::codecvt_byname<char, char, __mbstate_t>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::codecvt_byname<wchar_t, char, __mbstate_t> >(std::__1::codecvt_byname<wchar_t, char, __mbstate_t>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::codecvt_byname<char16_t, char, __mbstate_t> >(std::__1::codecvt_byname<char16_t, char, __mbstate_t>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::codecvt_byname<char32_t, char, __mbstate_t> >(std::__1::codecvt_byname<char32_t, char, __mbstate_t>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::codecvt_byname<char16_t, char8_t, __mbstate_t> >(std::__1::codecvt_byname<char16_t, char8_t, __mbstate_t>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::codecvt_byname<char32_t, char8_t, __mbstate_t> >(std::__1::codecvt_byname<char32_t, char8_t, __mbstate_t>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::numpunct_byname<char> >(std::__1::numpunct_byname<char>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::numpunct_byname<wchar_t> >(std::__1::numpunct_byname<wchar_t>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::moneypunct_byname<char, false> >(std::__1::moneypunct_byname<char, false>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::moneypunct_byname<char, true> >(std::__1::moneypunct_byname<char, true>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::moneypunct_byname<wchar_t, false> >(std::__1::moneypunct_byname<wchar_t, false>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::moneypunct_byname<wchar_t, true> >(std::__1::moneypunct_byname<wchar_t, true>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::time_get_byname<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::time_get_byname<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > >*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::time_get_byname<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::time_get_byname<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::time_put_byname<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::time_put_byname<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::time_put_byname<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::time_put_byname<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > >*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::messages_byname<char> >(std::__1::messages_byname<char>*)
Unexecuted instantiation: void std::__1::locale::__imp::install<std::__1::messages_byname<wchar_t> >(std::__1::messages_byname<wchar_t>*)
176
    template <class F> void install_from(const __imp& other);
177
};
178
179
locale::__imp::__imp(size_t refs)
180
    : facet(refs),
181
      facets_(N),
182
      name_("C")
183
15.2k
{
184
15.2k
    facets_.clear();
185
15.2k
    install(&make<_VSTD::collate<char> >(1u));
186
15.2k
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
187
15.2k
    install(&make<_VSTD::collate<wchar_t> >(1u));
188
15.2k
#endif
189
15.2k
    install(&make<_VSTD::ctype<char> >(nullptr, false, 1u));
190
15.2k
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
191
15.2k
    install(&make<_VSTD::ctype<wchar_t> >(1u));
192
15.2k
#endif
193
15.2k
    install(&make<codecvt<char, char, mbstate_t> >(1u));
194
15.2k
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
195
15.2k
    install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));
196
15.2k
#endif
197
15.2k
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
198
15.2k
    install(&make<codecvt<char16_t, char, mbstate_t> >(1u));
199
15.2k
    install(&make<codecvt<char32_t, char, mbstate_t> >(1u));
200
15.2k
_LIBCPP_SUPPRESS_DEPRECATED_POP
201
15.2k
#ifndef _LIBCPP_HAS_NO_CHAR8_T
202
15.2k
    install(&make<codecvt<char16_t, char8_t, mbstate_t> >(1u));
203
15.2k
    install(&make<codecvt<char32_t, char8_t, mbstate_t> >(1u));
204
15.2k
#endif
205
15.2k
    install(&make<numpunct<char> >(1u));
206
15.2k
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
207
15.2k
    install(&make<numpunct<wchar_t> >(1u));
208
15.2k
#endif
209
15.2k
    install(&make<num_get<char> >(1u));
210
15.2k
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
211
15.2k
    install(&make<num_get<wchar_t> >(1u));
212
15.2k
#endif
213
15.2k
    install(&make<num_put<char> >(1u));
214
15.2k
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
215
15.2k
    install(&make<num_put<wchar_t> >(1u));
216
15.2k
#endif
217
15.2k
    install(&make<moneypunct<char, false> >(1u));
218
15.2k
    install(&make<moneypunct<char, true> >(1u));
219
15.2k
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
220
15.2k
    install(&make<moneypunct<wchar_t, false> >(1u));
221
15.2k
    install(&make<moneypunct<wchar_t, true> >(1u));
222
15.2k
#endif
223
15.2k
    install(&make<money_get<char> >(1u));
224
15.2k
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
225
15.2k
    install(&make<money_get<wchar_t> >(1u));
226
15.2k
#endif
227
15.2k
    install(&make<money_put<char> >(1u));
228
15.2k
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
229
15.2k
    install(&make<money_put<wchar_t> >(1u));
230
15.2k
#endif
231
15.2k
    install(&make<time_get<char> >(1u));
232
15.2k
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
233
15.2k
    install(&make<time_get<wchar_t> >(1u));
234
15.2k
#endif
235
15.2k
    install(&make<time_put<char> >(1u));
236
15.2k
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
237
15.2k
    install(&make<time_put<wchar_t> >(1u));
238
15.2k
#endif
239
15.2k
    install(&make<_VSTD::messages<char> >(1u));
240
15.2k
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
241
15.2k
    install(&make<_VSTD::messages<wchar_t> >(1u));
242
15.2k
#endif
243
15.2k
}
244
245
locale::__imp::__imp(const string& name, size_t refs)
246
    : facet(refs),
247
      facets_(N),
248
      name_(name)
249
0
{
250
0
#ifndef _LIBCPP_NO_EXCEPTIONS
251
0
    try
252
0
    {
253
0
#endif // _LIBCPP_NO_EXCEPTIONS
254
0
        facets_ = locale::classic().__locale_->facets_;
255
0
        for (unsigned i = 0; i < facets_.size(); ++i)
256
0
            if (facets_[i])
257
0
                facets_[i]->__add_shared();
258
0
        install(new collate_byname<char>(name_));
259
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
260
0
        install(new collate_byname<wchar_t>(name_));
261
0
#endif
262
0
        install(new ctype_byname<char>(name_));
263
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
264
0
        install(new ctype_byname<wchar_t>(name_));
265
0
#endif
266
0
        install(new codecvt_byname<char, char, mbstate_t>(name_));
267
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
268
0
        install(new codecvt_byname<wchar_t, char, mbstate_t>(name_));
269
0
#endif
270
0
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
271
0
        install(new codecvt_byname<char16_t, char, mbstate_t>(name_));
272
0
        install(new codecvt_byname<char32_t, char, mbstate_t>(name_));
273
0
_LIBCPP_SUPPRESS_DEPRECATED_POP
274
0
#ifndef _LIBCPP_HAS_NO_CHAR8_T
275
0
        install(new codecvt_byname<char16_t, char8_t, mbstate_t>(name_));
276
0
        install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name_));
277
0
#endif
278
0
        install(new numpunct_byname<char>(name_));
279
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
280
0
        install(new numpunct_byname<wchar_t>(name_));
281
0
#endif
282
0
        install(new moneypunct_byname<char, false>(name_));
283
0
        install(new moneypunct_byname<char, true>(name_));
284
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
285
0
        install(new moneypunct_byname<wchar_t, false>(name_));
286
0
        install(new moneypunct_byname<wchar_t, true>(name_));
287
0
#endif
288
0
        install(new time_get_byname<char>(name_));
289
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
290
0
        install(new time_get_byname<wchar_t>(name_));
291
0
#endif
292
0
        install(new time_put_byname<char>(name_));
293
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
294
0
        install(new time_put_byname<wchar_t>(name_));
295
0
#endif
296
0
        install(new messages_byname<char>(name_));
297
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
298
0
        install(new messages_byname<wchar_t>(name_));
299
0
#endif
300
0
#ifndef _LIBCPP_NO_EXCEPTIONS
301
0
    }
302
0
    catch (...)
303
0
    {
304
0
        for (unsigned i = 0; i < facets_.size(); ++i)
305
0
            if (facets_[i])
306
0
                facets_[i]->__release_shared();
307
0
        throw;
308
0
    }
309
0
#endif // _LIBCPP_NO_EXCEPTIONS
310
0
}
311
312
locale::__imp::__imp(const __imp& other)
313
    : facets_(max<size_t>(N, other.facets_.size())),
314
      name_(other.name_)
315
0
{
316
0
    facets_ = other.facets_;
317
0
    for (unsigned i = 0; i < facets_.size(); ++i)
318
0
        if (facets_[i])
319
0
            facets_[i]->__add_shared();
320
0
}
321
322
locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
323
    : facets_(N),
324
      name_("*")
325
0
{
326
0
    facets_ = other.facets_;
327
0
    for (unsigned i = 0; i < facets_.size(); ++i)
328
0
        if (facets_[i])
329
0
            facets_[i]->__add_shared();
330
0
#ifndef _LIBCPP_NO_EXCEPTIONS
331
0
    try
332
0
    {
333
0
#endif // _LIBCPP_NO_EXCEPTIONS
334
0
        if (c & locale::collate)
335
0
        {
336
0
            install(new collate_byname<char>(name));
337
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
338
0
            install(new collate_byname<wchar_t>(name));
339
0
#endif
340
0
        }
341
0
        if (c & locale::ctype)
342
0
        {
343
0
            install(new ctype_byname<char>(name));
344
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
345
0
            install(new ctype_byname<wchar_t>(name));
346
0
#endif
347
0
            install(new codecvt_byname<char, char, mbstate_t>(name));
348
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
349
0
            install(new codecvt_byname<wchar_t, char, mbstate_t>(name));
350
0
#endif
351
0
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
352
0
            install(new codecvt_byname<char16_t, char, mbstate_t>(name));
353
0
            install(new codecvt_byname<char32_t, char, mbstate_t>(name));
354
0
_LIBCPP_SUPPRESS_DEPRECATED_POP
355
0
#ifndef _LIBCPP_HAS_NO_CHAR8_T
356
0
            install(new codecvt_byname<char16_t, char8_t, mbstate_t>(name));
357
0
            install(new codecvt_byname<char32_t, char8_t, mbstate_t>(name));
358
0
#endif
359
0
        }
360
0
        if (c & locale::monetary)
361
0
        {
362
0
            install(new moneypunct_byname<char, false>(name));
363
0
            install(new moneypunct_byname<char, true>(name));
364
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
365
0
            install(new moneypunct_byname<wchar_t, false>(name));
366
0
            install(new moneypunct_byname<wchar_t, true>(name));
367
0
#endif
368
0
        }
369
0
        if (c & locale::numeric)
370
0
        {
371
0
            install(new numpunct_byname<char>(name));
372
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
373
0
            install(new numpunct_byname<wchar_t>(name));
374
0
#endif
375
0
        }
376
0
        if (c & locale::time)
377
0
        {
378
0
            install(new time_get_byname<char>(name));
379
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
380
0
            install(new time_get_byname<wchar_t>(name));
381
0
#endif
382
0
            install(new time_put_byname<char>(name));
383
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
384
0
            install(new time_put_byname<wchar_t>(name));
385
0
#endif
386
0
        }
387
0
        if (c & locale::messages)
388
0
        {
389
0
            install(new messages_byname<char>(name));
390
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
391
0
            install(new messages_byname<wchar_t>(name));
392
0
#endif
393
0
        }
394
0
#ifndef _LIBCPP_NO_EXCEPTIONS
395
0
    }
396
0
    catch (...)
397
0
    {
398
0
        for (unsigned i = 0; i < facets_.size(); ++i)
399
0
            if (facets_[i])
400
0
                facets_[i]->__release_shared();
401
0
        throw;
402
0
    }
403
0
#endif // _LIBCPP_NO_EXCEPTIONS
404
0
}
405
406
template<class F>
407
inline
408
void
409
locale::__imp::install_from(const locale::__imp& one)
410
0
{
411
0
    long id = F::id.__get();
412
0
    install(const_cast<F*>(static_cast<const F*>(one.use_facet(id))), id);
413
0
}
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::collate<char> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::collate<wchar_t> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::ctype<char> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::ctype<wchar_t> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::codecvt<char, char, __mbstate_t> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::codecvt<char16_t, char, __mbstate_t> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::codecvt<char32_t, char, __mbstate_t> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::codecvt<char16_t, char8_t, __mbstate_t> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::codecvt<char32_t, char8_t, __mbstate_t> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::codecvt<wchar_t, char, __mbstate_t> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::moneypunct<char, false> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::moneypunct<char, true> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::moneypunct<wchar_t, false> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::moneypunct<wchar_t, true> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::money_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::money_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::money_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::money_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::numpunct<char> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::numpunct<wchar_t> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::num_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::num_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::num_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::time_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::time_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::time_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::time_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::messages<char> >(std::__1::locale::__imp const&)
Unexecuted instantiation: void std::__1::locale::__imp::install_from<std::__1::messages<wchar_t> >(std::__1::locale::__imp const&)
414
415
locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)
416
    : facets_(N),
417
      name_("*")
418
0
{
419
0
    facets_ = other.facets_;
420
0
    for (unsigned i = 0; i < facets_.size(); ++i)
421
0
        if (facets_[i])
422
0
            facets_[i]->__add_shared();
423
0
#ifndef _LIBCPP_NO_EXCEPTIONS
424
0
    try
425
0
    {
426
0
#endif // _LIBCPP_NO_EXCEPTIONS
427
0
        if (c & locale::collate)
428
0
        {
429
0
            install_from<_VSTD::collate<char> >(one);
430
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
431
0
            install_from<_VSTD::collate<wchar_t> >(one);
432
0
#endif
433
0
        }
434
0
        if (c & locale::ctype)
435
0
        {
436
0
            install_from<_VSTD::ctype<char> >(one);
437
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
438
0
            install_from<_VSTD::ctype<wchar_t> >(one);
439
0
#endif
440
0
            install_from<_VSTD::codecvt<char, char, mbstate_t> >(one);
441
0
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
442
0
            install_from<_VSTD::codecvt<char16_t, char, mbstate_t> >(one);
443
0
            install_from<_VSTD::codecvt<char32_t, char, mbstate_t> >(one);
444
0
_LIBCPP_SUPPRESS_DEPRECATED_POP
445
0
#ifndef _LIBCPP_HAS_NO_CHAR8_T
446
0
            install_from<_VSTD::codecvt<char16_t, char8_t, mbstate_t> >(one);
447
0
            install_from<_VSTD::codecvt<char32_t, char8_t, mbstate_t> >(one);
448
0
#endif
449
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
450
0
            install_from<_VSTD::codecvt<wchar_t, char, mbstate_t> >(one);
451
0
#endif
452
0
        }
453
0
        if (c & locale::monetary)
454
0
        {
455
0
            install_from<moneypunct<char, false> >(one);
456
0
            install_from<moneypunct<char, true> >(one);
457
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
458
0
            install_from<moneypunct<wchar_t, false> >(one);
459
0
            install_from<moneypunct<wchar_t, true> >(one);
460
0
#endif
461
0
            install_from<money_get<char> >(one);
462
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
463
0
            install_from<money_get<wchar_t> >(one);
464
0
#endif
465
0
            install_from<money_put<char> >(one);
466
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
467
0
            install_from<money_put<wchar_t> >(one);
468
0
#endif
469
0
        }
470
0
        if (c & locale::numeric)
471
0
        {
472
0
            install_from<numpunct<char> >(one);
473
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
474
0
            install_from<numpunct<wchar_t> >(one);
475
0
#endif
476
0
            install_from<num_get<char> >(one);
477
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
478
0
            install_from<num_get<wchar_t> >(one);
479
0
#endif
480
0
            install_from<num_put<char> >(one);
481
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
482
0
            install_from<num_put<wchar_t> >(one);
483
0
#endif
484
0
        }
485
0
        if (c & locale::time)
486
0
        {
487
0
            install_from<time_get<char> >(one);
488
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
489
0
            install_from<time_get<wchar_t> >(one);
490
0
#endif
491
0
            install_from<time_put<char> >(one);
492
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
493
0
            install_from<time_put<wchar_t> >(one);
494
0
#endif
495
0
        }
496
0
        if (c & locale::messages)
497
0
        {
498
0
            install_from<_VSTD::messages<char> >(one);
499
0
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
500
0
            install_from<_VSTD::messages<wchar_t> >(one);
501
0
#endif
502
0
        }
503
0
#ifndef _LIBCPP_NO_EXCEPTIONS
504
0
    }
505
0
    catch (...)
506
0
    {
507
0
        for (unsigned i = 0; i < facets_.size(); ++i)
508
0
            if (facets_[i])
509
0
                facets_[i]->__release_shared();
510
0
        throw;
511
0
    }
512
0
#endif // _LIBCPP_NO_EXCEPTIONS
513
0
}
514
515
locale::__imp::__imp(const __imp& other, facet* f, long id)
516
    : facets_(max<size_t>(N, other.facets_.size()+1)),
517
      name_("*")
518
0
{
519
0
    f->__add_shared();
520
0
    unique_ptr<facet, release> hold(f);
521
0
    facets_ = other.facets_;
522
0
    for (unsigned i = 0; i < other.facets_.size(); ++i)
523
0
        if (facets_[i])
524
0
            facets_[i]->__add_shared();
525
0
    install(hold.get(), id);
526
0
}
527
528
locale::__imp::~__imp()
529
0
{
530
0
    for (unsigned i = 0; i < facets_.size(); ++i)
531
0
        if (facets_[i])
532
0
            facets_[i]->__release_shared();
533
0
}
534
535
void
536
locale::__imp::install(facet* f, long id)
537
456k
{
538
456k
    f->__add_shared();
539
456k
    unique_ptr<facet, release> hold(f);
540
456k
    if (static_cast<size_t>(id) >= facets_.size())
541
456k
        facets_.resize(static_cast<size_t>(id+1));
542
456k
    if (facets_[static_cast<size_t>(id)])
543
0
        facets_[static_cast<size_t>(id)]->__release_shared();
544
456k
    facets_[static_cast<size_t>(id)] = hold.release();
545
456k
}
546
547
const locale::facet*
548
locale::__imp::use_facet(long id) const
549
63.7M
{
550
63.7M
    if (!has_facet(id))
551
0
        __throw_bad_cast();
552
63.7M
    return facets_[static_cast<size_t>(id)];
553
63.7M
}
554
555
// locale
556
557
const locale&
558
locale::__imp::make_classic()
559
15.2k
{
560
    // only one thread can get in here and it only gets in once
561
15.2k
    static aligned_storage<sizeof(locale)>::type buf;
562
15.2k
    locale* c = reinterpret_cast<locale*>(&buf);
563
15.2k
    c->__locale_ = &make<__imp>(1u);
564
15.2k
    return *c;
565
15.2k
}
566
567
const locale&
568
locale::classic()
569
15.2k
{
570
15.2k
    static const locale& c = __imp::make_classic();
571
15.2k
    return c;
572
15.2k
}
573
574
locale&
575
locale::__imp::make_global()
576
15.2k
{
577
    // only one thread can get in here and it only gets in once
578
15.2k
    static aligned_storage<sizeof(locale)>::type buf;
579
15.2k
    auto *obj = ::new (&buf) locale(locale::classic());
580
15.2k
    return *obj;
581
15.2k
}
582
583
locale&
584
locale::__global()
585
341M
{
586
341M
    static locale& g = __imp::make_global();
587
341M
    return g;
588
341M
}
589
590
locale::locale() noexcept
591
    : __locale_(__global().__locale_)
592
341M
{
593
341M
    __locale_->__add_shared();
594
341M
}
595
596
locale::locale(const locale& l) noexcept
597
    : __locale_(l.__locale_)
598
63.7M
{
599
63.7M
    __locale_->__add_shared();
600
63.7M
}
601
602
locale::~locale()
603
404M
{
604
404M
    __locale_->__release_shared();
605
404M
}
606
607
const locale&
608
locale::operator=(const locale& other) noexcept
609
0
{
610
0
    other.__locale_->__add_shared();
611
0
    __locale_->__release_shared();
612
0
    __locale_ = other.__locale_;
613
0
    return *this;
614
0
}
615
616
locale::locale(const char* name)
617
    : __locale_(name ? new __imp(name)
618
                     : (__throw_runtime_error("locale constructed with null"), nullptr))
619
0
{
620
0
    __locale_->__add_shared();
621
0
}
622
623
locale::locale(const string& name)
624
    : __locale_(new __imp(name))
625
0
{
626
0
    __locale_->__add_shared();
627
0
}
628
629
locale::locale(const locale& other, const char* name, category c)
630
    : __locale_(name ? new __imp(*other.__locale_, name, c)
631
                     : (__throw_runtime_error("locale constructed with null"), nullptr))
632
0
{
633
0
    __locale_->__add_shared();
634
0
}
635
636
locale::locale(const locale& other, const string& name, category c)
637
    : __locale_(new __imp(*other.__locale_, name, c))
638
0
{
639
0
    __locale_->__add_shared();
640
0
}
641
642
locale::locale(const locale& other, const locale& one, category c)
643
    : __locale_(new __imp(*other.__locale_, *one.__locale_, c))
644
0
{
645
0
    __locale_->__add_shared();
646
0
}
647
648
string
649
locale::name() const
650
0
{
651
0
    return __locale_->name();
652
0
}
653
654
void
655
locale::__install_ctor(const locale& other, facet* f, long id)
656
0
{
657
0
    if (f)
658
0
        __locale_ = new __imp(*other.__locale_, f, id);
659
0
    else
660
0
        __locale_ = other.__locale_;
661
0
    __locale_->__add_shared();
662
0
}
663
664
locale
665
locale::global(const locale& loc)
666
0
{
667
0
    locale& g = __global();
668
0
    locale r = g;
669
0
    g = loc;
670
0
    if (g.name() != "*")
671
0
        setlocale(LC_ALL, g.name().c_str());
672
0
    return r;
673
0
}
674
675
bool
676
locale::has_facet(id& x) const
677
41
{
678
41
    return __locale_->has_facet(x.__get());
679
41
}
680
681
const locale::facet*
682
locale::use_facet(id& x) const
683
63.7M
{
684
63.7M
    return __locale_->use_facet(x.__get());
685
63.7M
}
686
687
bool
688
locale::operator==(const locale& y) const
689
0
{
690
0
    return (__locale_ == y.__locale_)
691
0
        || (__locale_->name() != "*" && __locale_->name() == y.__locale_->name());
692
0
}
693
694
// locale::facet
695
696
locale::facet::~facet()
697
0
{
698
0
}
699
700
void
701
locale::facet::__on_zero_shared() noexcept
702
0
{
703
0
    delete this;
704
0
}
705
706
// locale::id
707
708
int32_t locale::id::__next_id = 0;
709
710
namespace
711
{
712
713
class __fake_bind
714
{
715
    locale::id* id_;
716
    void (locale::id::* pmf_)();
717
public:
718
    __fake_bind(void (locale::id::* pmf)(), locale::id* id)
719
64.2M
        : id_(id), pmf_(pmf) {}
720
721
    void operator()() const
722
456k
    {
723
456k
        (id_->*pmf_)();
724
456k
    }
725
};
726
727
}
728
729
long
730
locale::id::__get()
731
64.2M
{
732
64.2M
    call_once(__flag_, __fake_bind(&locale::id::__init, this));
733
64.2M
    return __id_ - 1;
734
64.2M
}
735
736
void
737
locale::id::__init()
738
456k
{
739
456k
    __id_ = __libcpp_atomic_add(&__next_id, 1);
740
456k
}
741
742
// template <> class collate_byname<char>
743
744
collate_byname<char>::collate_byname(const char* n, size_t refs)
745
    : collate<char>(refs),
746
      __l(newlocale(LC_ALL_MASK, n, 0))
747
0
{
748
0
    if (__l == 0)
749
0
        __throw_runtime_error("collate_byname<char>::collate_byname"
750
0
                            " failed to construct for " + string(n));
751
0
}
752
753
collate_byname<char>::collate_byname(const string& name, size_t refs)
754
    : collate<char>(refs),
755
      __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
756
0
{
757
0
    if (__l == 0)
758
0
        __throw_runtime_error("collate_byname<char>::collate_byname"
759
0
                            " failed to construct for " + name);
760
0
}
761
762
collate_byname<char>::~collate_byname()
763
0
{
764
0
    freelocale(__l);
765
0
}
766
767
int
768
collate_byname<char>::do_compare(const char_type* __lo1, const char_type* __hi1,
769
                                 const char_type* __lo2, const char_type* __hi2) const
770
0
{
771
0
    string_type lhs(__lo1, __hi1);
772
0
    string_type rhs(__lo2, __hi2);
773
0
    int r = strcoll_l(lhs.c_str(), rhs.c_str(), __l);
774
0
    if (r < 0)
775
0
        return -1;
776
0
    if (r > 0)
777
0
        return 1;
778
0
    return r;
779
0
}
780
781
collate_byname<char>::string_type
782
collate_byname<char>::do_transform(const char_type* lo, const char_type* hi) const
783
0
{
784
0
    const string_type in(lo, hi);
785
0
    string_type out(strxfrm_l(0, in.c_str(), 0, __l), char());
786
0
    strxfrm_l(const_cast<char*>(out.c_str()), in.c_str(), out.size()+1, __l);
787
0
    return out;
788
0
}
789
790
// template <> class collate_byname<wchar_t>
791
792
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
793
collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)
794
    : collate<wchar_t>(refs),
795
      __l(newlocale(LC_ALL_MASK, n, 0))
796
0
{
797
0
    if (__l == 0)
798
0
        __throw_runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
799
0
                            " failed to construct for " + string(n));
800
0
}
801
802
collate_byname<wchar_t>::collate_byname(const string& name, size_t refs)
803
    : collate<wchar_t>(refs),
804
      __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
805
0
{
806
0
    if (__l == 0)
807
0
        __throw_runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
808
0
                            " failed to construct for " + name);
809
0
}
810
811
collate_byname<wchar_t>::~collate_byname()
812
0
{
813
0
    freelocale(__l);
814
0
}
815
816
int
817
collate_byname<wchar_t>::do_compare(const char_type* __lo1, const char_type* __hi1,
818
                                 const char_type* __lo2, const char_type* __hi2) const
819
0
{
820
0
    string_type lhs(__lo1, __hi1);
821
0
    string_type rhs(__lo2, __hi2);
822
0
    int r = wcscoll_l(lhs.c_str(), rhs.c_str(), __l);
823
0
    if (r < 0)
824
0
        return -1;
825
0
    if (r > 0)
826
0
        return 1;
827
0
    return r;
828
0
}
829
830
collate_byname<wchar_t>::string_type
831
collate_byname<wchar_t>::do_transform(const char_type* lo, const char_type* hi) const
832
0
{
833
0
    const string_type in(lo, hi);
834
0
    string_type out(wcsxfrm_l(0, in.c_str(), 0, __l), wchar_t());
835
0
    wcsxfrm_l(const_cast<wchar_t*>(out.c_str()), in.c_str(), out.size()+1, __l);
836
0
    return out;
837
0
}
838
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
839
840
const ctype_base::mask ctype_base::space;
841
const ctype_base::mask ctype_base::print;
842
const ctype_base::mask ctype_base::cntrl;
843
const ctype_base::mask ctype_base::upper;
844
const ctype_base::mask ctype_base::lower;
845
const ctype_base::mask ctype_base::alpha;
846
const ctype_base::mask ctype_base::digit;
847
const ctype_base::mask ctype_base::punct;
848
const ctype_base::mask ctype_base::xdigit;
849
const ctype_base::mask ctype_base::blank;
850
const ctype_base::mask ctype_base::alnum;
851
const ctype_base::mask ctype_base::graph;
852
853
// template <> class ctype<wchar_t>;
854
855
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
856
locale::id ctype<wchar_t>::id;
857
858
ctype<wchar_t>::~ctype()
859
0
{
860
0
}
861
862
bool
863
ctype<wchar_t>::do_is(mask m, char_type c) const
864
0
{
865
0
    return isascii(c) ? (ctype<char>::classic_table()[c] & m) != 0 : false;
866
0
}
867
868
const wchar_t*
869
ctype<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const
870
0
{
871
0
    for (; low != high; ++low, ++vec)
872
0
        *vec = static_cast<mask>(isascii(*low) ?
873
0
                                   ctype<char>::classic_table()[*low] : 0);
874
0
    return low;
875
0
}
876
877
const wchar_t*
878
ctype<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const
879
0
{
880
0
    for (; low != high; ++low)
881
0
        if (isascii(*low) && (ctype<char>::classic_table()[*low] & m))
882
0
            break;
883
0
    return low;
884
0
}
885
886
const wchar_t*
887
ctype<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
888
0
{
889
0
    for (; low != high; ++low)
890
0
        if (!(isascii(*low) && (ctype<char>::classic_table()[*low] & m)))
891
0
            break;
892
0
    return low;
893
0
}
894
895
wchar_t
896
ctype<wchar_t>::do_toupper(char_type c) const
897
0
{
898
0
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
899
0
    return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
900
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
901
      defined(__NetBSD__) || defined(__MVS__)
902
    return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
903
#else
904
    return (isascii(c) && iswlower_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'a'+L'A' : c;
905
#endif
906
0
}
907
908
const wchar_t*
909
ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
910
0
{
911
0
    for (; low != high; ++low)
912
0
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
913
0
        *low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
914
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
915
      defined(__NetBSD__) || defined(__MVS__)
916
        *low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
917
                             : *low;
918
#else
919
        *low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? (*low-L'a'+L'A') : *low;
920
#endif
921
0
    return low;
922
0
}
923
924
wchar_t
925
ctype<wchar_t>::do_tolower(char_type c) const
926
0
{
927
0
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
928
0
    return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
929
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
930
      defined(__NetBSD__) || defined(__MVS__)
931
    return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
932
#else
933
    return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'A'+'a' : c;
934
#endif
935
0
}
936
937
const wchar_t*
938
ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const
939
0
{
940
0
    for (; low != high; ++low)
941
0
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
942
0
        *low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
943
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
944
      defined(__NetBSD__) || defined(__MVS__)
945
        *low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
946
                             : *low;
947
#else
948
        *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-L'A'+L'a' : *low;
949
#endif
950
0
    return low;
951
0
}
952
953
wchar_t
954
ctype<wchar_t>::do_widen(char c) const
955
0
{
956
0
    return c;
957
0
}
958
959
const char*
960
ctype<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
961
0
{
962
0
    for (; low != high; ++low, ++dest)
963
0
        *dest = *low;
964
0
    return low;
965
0
}
966
967
char
968
ctype<wchar_t>::do_narrow(char_type c, char dfault) const
969
0
{
970
0
    if (isascii(c))
971
0
        return static_cast<char>(c);
972
0
    return dfault;
973
0
}
974
975
const wchar_t*
976
ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
977
0
{
978
0
    for (; low != high; ++low, ++dest)
979
0
        if (isascii(*low))
980
0
            *dest = static_cast<char>(*low);
981
0
        else
982
0
            *dest = dfault;
983
0
    return low;
984
0
}
985
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
986
987
// template <> class ctype<char>;
988
989
locale::id ctype<char>::id;
990
991
const size_t ctype<char>::table_size;
992
993
ctype<char>::ctype(const mask* tab, bool del, size_t refs)
994
    : locale::facet(refs),
995
      __tab_(tab),
996
      __del_(del)
997
15.2k
{
998
15.2k
  if (__tab_ == 0)
999
15.2k
      __tab_ = classic_table();
1000
15.2k
}
1001
1002
ctype<char>::~ctype()
1003
0
{
1004
0
    if (__tab_ && __del_)
1005
0
        delete [] __tab_;
1006
0
}
1007
1008
char
1009
ctype<char>::do_toupper(char_type c) const
1010
0
{
1011
0
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
1012
0
    return isascii(c) ?
1013
0
      static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
1014
#elif defined(__NetBSD__)
1015
    return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]);
1016
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
1017
    return isascii(c) ?
1018
      static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c;
1019
#else
1020
    return (isascii(c) && islower_l(c, _LIBCPP_GET_C_LOCALE)) ? c-'a'+'A' : c;
1021
#endif
1022
0
}
1023
1024
const char*
1025
ctype<char>::do_toupper(char_type* low, const char_type* high) const
1026
0
{
1027
0
    for (; low != high; ++low)
1028
0
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
1029
0
        *low = isascii(*low) ?
1030
0
          static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
1031
#elif defined(__NetBSD__)
1032
        *low = static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(*low)]);
1033
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
1034
        *low = isascii(*low) ?
1035
          static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
1036
#else
1037
        *low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-'a'+'A' : *low;
1038
#endif
1039
0
    return low;
1040
0
}
1041
1042
char
1043
ctype<char>::do_tolower(char_type c) const
1044
0
{
1045
0
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
1046
0
    return isascii(c) ?
1047
0
      static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
1048
#elif defined(__NetBSD__)
1049
    return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(c)]);
1050
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
1051
    return isascii(c) ?
1052
      static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
1053
#else
1054
    return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c-'A'+'a' : c;
1055
#endif
1056
0
}
1057
1058
const char*
1059
ctype<char>::do_tolower(char_type* low, const char_type* high) const
1060
0
{
1061
0
    for (; low != high; ++low)
1062
0
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
1063
0
        *low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;
1064
#elif defined(__NetBSD__)
1065
        *low = static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(*low)]);
1066
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || defined(__MVS__)
1067
        *low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
1068
#else
1069
        *low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-'A'+'a' : *low;
1070
#endif
1071
0
    return low;
1072
0
}
1073
1074
char
1075
ctype<char>::do_widen(char c) const
1076
56.6M
{
1077
56.6M
    return c;
1078
56.6M
}
1079
1080
const char*
1081
ctype<char>::do_widen(const char* low, const char* high, char_type* dest) const
1082
3.49M
{
1083
41.4M
    for (; low != high; 
++low, ++dest37.9M
)
1084
37.9M
        *dest = *low;
1085
3.49M
    return low;
1086
3.49M
}
1087
1088
char
1089
ctype<char>::do_narrow(char_type c, char dfault) const
1090
0
{
1091
0
    if (isascii(c))
1092
0
        return static_cast<char>(c);
1093
0
    return dfault;
1094
0
}
1095
1096
const char*
1097
ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
1098
0
{
1099
0
    for (; low != high; ++low, ++dest)
1100
0
        if (isascii(*low))
1101
0
            *dest = *low;
1102
0
        else
1103
0
            *dest = dfault;
1104
0
    return low;
1105
0
}
1106
1107
#if defined(__EMSCRIPTEN__)
1108
extern "C" const unsigned short ** __ctype_b_loc();
1109
extern "C" const int ** __ctype_tolower_loc();
1110
extern "C" const int ** __ctype_toupper_loc();
1111
#endif
1112
1113
#ifdef _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
1114
const ctype<char>::mask*
1115
ctype<char>::classic_table() noexcept
1116
{
1117
    static _LIBCPP_CONSTEXPR const ctype<char>::mask builtin_table[table_size] = {
1118
        cntrl,                          cntrl,
1119
        cntrl,                          cntrl,
1120
        cntrl,                          cntrl,
1121
        cntrl,                          cntrl,
1122
        cntrl,                          cntrl | space | blank,
1123
        cntrl | space,                  cntrl | space,
1124
        cntrl | space,                  cntrl | space,
1125
        cntrl,                          cntrl,
1126
        cntrl,                          cntrl,
1127
        cntrl,                          cntrl,
1128
        cntrl,                          cntrl,
1129
        cntrl,                          cntrl,
1130
        cntrl,                          cntrl,
1131
        cntrl,                          cntrl,
1132
        cntrl,                          cntrl,
1133
        cntrl,                          cntrl,
1134
        space | blank | print,          punct | print,
1135
        punct | print,                  punct | print,
1136
        punct | print,                  punct | print,
1137
        punct | print,                  punct | print,
1138
        punct | print,                  punct | print,
1139
        punct | print,                  punct | print,
1140
        punct | print,                  punct | print,
1141
        punct | print,                  punct | print,
1142
        digit | print | xdigit,         digit | print | xdigit,
1143
        digit | print | xdigit,         digit | print | xdigit,
1144
        digit | print | xdigit,         digit | print | xdigit,
1145
        digit | print | xdigit,         digit | print | xdigit,
1146
        digit | print | xdigit,         digit | print | xdigit,
1147
        punct | print,                  punct | print,
1148
        punct | print,                  punct | print,
1149
        punct | print,                  punct | print,
1150
        punct | print,                  upper | xdigit | print | alpha,
1151
        upper | xdigit | print | alpha, upper | xdigit | print | alpha,
1152
        upper | xdigit | print | alpha, upper | xdigit | print | alpha,
1153
        upper | xdigit | print | alpha, upper | print | alpha,
1154
        upper | print | alpha,          upper | print | alpha,
1155
        upper | print | alpha,          upper | print | alpha,
1156
        upper | print | alpha,          upper | print | alpha,
1157
        upper | print | alpha,          upper | print | alpha,
1158
        upper | print | alpha,          upper | print | alpha,
1159
        upper | print | alpha,          upper | print | alpha,
1160
        upper | print | alpha,          upper | print | alpha,
1161
        upper | print | alpha,          upper | print | alpha,
1162
        upper | print | alpha,          upper | print | alpha,
1163
        upper | print | alpha,          punct | print,
1164
        punct | print,                  punct | print,
1165
        punct | print,                  punct | print,
1166
        punct | print,                  lower | xdigit | print | alpha,
1167
        lower | xdigit | print | alpha, lower | xdigit | print | alpha,
1168
        lower | xdigit | print | alpha, lower | xdigit | print | alpha,
1169
        lower | xdigit | print | alpha, lower | print | alpha,
1170
        lower | print | alpha,          lower | print | alpha,
1171
        lower | print | alpha,          lower | print | alpha,
1172
        lower | print | alpha,          lower | print | alpha,
1173
        lower | print | alpha,          lower | print | alpha,
1174
        lower | print | alpha,          lower | print | alpha,
1175
        lower | print | alpha,          lower | print | alpha,
1176
        lower | print | alpha,          lower | print | alpha,
1177
        lower | print | alpha,          lower | print | alpha,
1178
        lower | print | alpha,          lower | print | alpha,
1179
        lower | print | alpha,          punct | print,
1180
        punct | print,                  punct | print,
1181
        punct | print,                  cntrl,
1182
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1183
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1184
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1185
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1186
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1187
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1188
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1189
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1190
    };
1191
    return builtin_table;
1192
}
1193
#else
1194
const ctype<char>::mask*
1195
ctype<char>::classic_table() noexcept
1196
15.2k
{
1197
15.2k
#if defined(__APPLE__) || defined(__FreeBSD__)
1198
15.2k
    return _DefaultRuneLocale.__runetype;
1199
#elif defined(__NetBSD__)
1200
    return _C_ctype_tab_ + 1;
1201
#elif defined(__GLIBC__)
1202
    return _LIBCPP_GET_C_LOCALE->__ctype_b;
1203
#elif defined(__sun__)
1204
    return __ctype_mask;
1205
#elif defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
1206
    return __pctype_func();
1207
#elif defined(__EMSCRIPTEN__)
1208
    return *__ctype_b_loc();
1209
#elif defined(_NEWLIB_VERSION)
1210
    // Newlib has a 257-entry table in ctype_.c, where (char)0 starts at [1].
1211
    return _ctype_ + 1;
1212
#elif defined(_AIX)
1213
    return (const unsigned int *)__lc_ctype_ptr->obj->mask;
1214
#elif defined(__MVS__)
1215
# if defined(__NATIVE_ASCII_F)
1216
    return const_cast<const ctype<char>::mask*> (__OBJ_DATA(__lc_ctype_a)->mask);
1217
# else
1218
    return const_cast<const ctype<char>::mask*> (__ctypec);
1219
# endif
1220
#else
1221
    // Platform not supported: abort so the person doing the port knows what to
1222
    // fix
1223
# warning  ctype<char>::classic_table() is not implemented
1224
    printf("ctype<char>::classic_table() is not implemented\n");
1225
    abort();
1226
    return NULL;
1227
#endif
1228
15.2k
}
1229
#endif
1230
1231
#if defined(__GLIBC__)
1232
const int*
1233
ctype<char>::__classic_lower_table() noexcept
1234
{
1235
    return _LIBCPP_GET_C_LOCALE->__ctype_tolower;
1236
}
1237
1238
const int*
1239
ctype<char>::__classic_upper_table() noexcept
1240
{
1241
    return _LIBCPP_GET_C_LOCALE->__ctype_toupper;
1242
}
1243
#elif defined(__NetBSD__)
1244
const short*
1245
ctype<char>::__classic_lower_table() noexcept
1246
{
1247
    return _C_tolower_tab_ + 1;
1248
}
1249
1250
const short*
1251
ctype<char>::__classic_upper_table() noexcept
1252
{
1253
    return _C_toupper_tab_ + 1;
1254
}
1255
1256
#elif defined(__EMSCRIPTEN__)
1257
const int*
1258
ctype<char>::__classic_lower_table() noexcept
1259
{
1260
    return *__ctype_tolower_loc();
1261
}
1262
1263
const int*
1264
ctype<char>::__classic_upper_table() noexcept
1265
{
1266
    return *__ctype_toupper_loc();
1267
}
1268
#elif defined(__MVS__)
1269
const unsigned short*
1270
ctype<char>::__classic_lower_table() _NOEXCEPT
1271
{
1272
# if defined(__NATIVE_ASCII_F)
1273
  return const_cast<const unsigned short*>(__OBJ_DATA(__lc_ctype_a)->lower);
1274
# else
1275
  return const_cast<const unsigned short*>(__ctype + __TOLOWER_INDEX);
1276
# endif
1277
}
1278
const unsigned short *
1279
ctype<char>::__classic_upper_table() _NOEXCEPT
1280
{
1281
# if defined(__NATIVE_ASCII_F)
1282
  return const_cast<const unsigned short*>(__OBJ_DATA(__lc_ctype_a)->upper);
1283
# else
1284
  return const_cast<const unsigned short*>(__ctype + __TOUPPER_INDEX);
1285
# endif
1286
}
1287
#endif // __GLIBC__ || __NETBSD__ || __EMSCRIPTEN__ || __MVS__
1288
1289
// template <> class ctype_byname<char>
1290
1291
ctype_byname<char>::ctype_byname(const char* name, size_t refs)
1292
    : ctype<char>(0, false, refs),
1293
      __l(newlocale(LC_ALL_MASK, name, 0))
1294
0
{
1295
0
    if (__l == 0)
1296
0
        __throw_runtime_error("ctype_byname<char>::ctype_byname"
1297
0
                            " failed to construct for " + string(name));
1298
0
}
1299
1300
ctype_byname<char>::ctype_byname(const string& name, size_t refs)
1301
    : ctype<char>(0, false, refs),
1302
      __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
1303
0
{
1304
0
    if (__l == 0)
1305
0
        __throw_runtime_error("ctype_byname<char>::ctype_byname"
1306
0
                            " failed to construct for " + name);
1307
0
}
1308
1309
ctype_byname<char>::~ctype_byname()
1310
0
{
1311
0
    freelocale(__l);
1312
0
}
1313
1314
char
1315
ctype_byname<char>::do_toupper(char_type c) const
1316
0
{
1317
0
    return static_cast<char>(toupper_l(static_cast<unsigned char>(c), __l));
1318
0
}
1319
1320
const char*
1321
ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const
1322
0
{
1323
0
    for (; low != high; ++low)
1324
0
        *low = static_cast<char>(toupper_l(static_cast<unsigned char>(*low), __l));
1325
0
    return low;
1326
0
}
1327
1328
char
1329
ctype_byname<char>::do_tolower(char_type c) const
1330
0
{
1331
0
    return static_cast<char>(tolower_l(static_cast<unsigned char>(c), __l));
1332
0
}
1333
1334
const char*
1335
ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
1336
0
{
1337
0
    for (; low != high; ++low)
1338
0
        *low = static_cast<char>(tolower_l(static_cast<unsigned char>(*low), __l));
1339
0
    return low;
1340
0
}
1341
1342
// template <> class ctype_byname<wchar_t>
1343
1344
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1345
ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
1346
    : ctype<wchar_t>(refs),
1347
      __l(newlocale(LC_ALL_MASK, name, 0))
1348
0
{
1349
0
    if (__l == 0)
1350
0
        __throw_runtime_error("ctype_byname<wchar_t>::ctype_byname"
1351
0
                            " failed to construct for " + string(name));
1352
0
}
1353
1354
ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)
1355
    : ctype<wchar_t>(refs),
1356
      __l(newlocale(LC_ALL_MASK, name.c_str(), 0))
1357
0
{
1358
0
    if (__l == 0)
1359
0
        __throw_runtime_error("ctype_byname<wchar_t>::ctype_byname"
1360
0
                            " failed to construct for " + name);
1361
0
}
1362
1363
ctype_byname<wchar_t>::~ctype_byname()
1364
0
{
1365
0
    freelocale(__l);
1366
0
}
1367
1368
bool
1369
ctype_byname<wchar_t>::do_is(mask m, char_type c) const
1370
0
{
1371
0
#ifdef _LIBCPP_WCTYPE_IS_MASK
1372
0
    return static_cast<bool>(iswctype_l(c, m, __l));
1373
#else
1374
    bool result = false;
1375
    wint_t ch = static_cast<wint_t>(c);
1376
    if ((m & space) == space) result |= (iswspace_l(ch, __l) != 0);
1377
    if ((m & print) == print) result |= (iswprint_l(ch, __l) != 0);
1378
    if ((m & cntrl) == cntrl) result |= (iswcntrl_l(ch, __l) != 0);
1379
    if ((m & upper) == upper) result |= (iswupper_l(ch, __l) != 0);
1380
    if ((m & lower) == lower) result |= (iswlower_l(ch, __l) != 0);
1381
    if ((m & alpha) == alpha) result |= (iswalpha_l(ch, __l) != 0);
1382
    if ((m & digit) == digit) result |= (iswdigit_l(ch, __l) != 0);
1383
    if ((m & punct) == punct) result |= (iswpunct_l(ch, __l) != 0);
1384
    if ((m & xdigit) == xdigit) result |= (iswxdigit_l(ch, __l) != 0);
1385
    if ((m & blank) == blank) result |= (iswblank_l(ch, __l) != 0);
1386
    return result;
1387
#endif
1388
0
}
1389
1390
const wchar_t*
1391
ctype_byname<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const
1392
0
{
1393
0
    for (; low != high; ++low, ++vec)
1394
0
    {
1395
0
        if (isascii(*low))
1396
0
            *vec = static_cast<mask>(ctype<char>::classic_table()[*low]);
1397
0
        else
1398
0
        {
1399
0
            *vec = 0;
1400
0
            wint_t ch = static_cast<wint_t>(*low);
1401
0
            if (iswspace_l(ch, __l))
1402
0
                *vec |= space;
1403
0
#ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
1404
0
            if (iswprint_l(ch, __l))
1405
0
                *vec |= print;
1406
0
#endif
1407
0
            if (iswcntrl_l(ch, __l))
1408
0
                *vec |= cntrl;
1409
0
            if (iswupper_l(ch, __l))
1410
0
                *vec |= upper;
1411
0
            if (iswlower_l(ch, __l))
1412
0
                *vec |= lower;
1413
0
#ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
1414
0
            if (iswalpha_l(ch, __l))
1415
0
                *vec |= alpha;
1416
0
#endif
1417
0
            if (iswdigit_l(ch, __l))
1418
0
                *vec |= digit;
1419
0
            if (iswpunct_l(ch, __l))
1420
0
                *vec |= punct;
1421
0
#ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
1422
0
            if (iswxdigit_l(ch, __l))
1423
0
                *vec |= xdigit;
1424
0
#endif
1425
0
#if !defined(__sun__)
1426
0
            if (iswblank_l(ch, __l))
1427
0
                *vec |= blank;
1428
0
#endif
1429
0
        }
1430
0
    }
1431
0
    return low;
1432
0
}
1433
1434
const wchar_t*
1435
ctype_byname<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const
1436
0
{
1437
0
    for (; low != high; ++low)
1438
0
    {
1439
0
#ifdef _LIBCPP_WCTYPE_IS_MASK
1440
0
        if (iswctype_l(*low, m, __l))
1441
0
            break;
1442
#else
1443
        wint_t ch = static_cast<wint_t>(*low);
1444
        if ((m & space) == space && iswspace_l(ch, __l)) break;
1445
        if ((m & print) == print && iswprint_l(ch, __l)) break;
1446
        if ((m & cntrl) == cntrl && iswcntrl_l(ch, __l)) break;
1447
        if ((m & upper) == upper && iswupper_l(ch, __l)) break;
1448
        if ((m & lower) == lower && iswlower_l(ch, __l)) break;
1449
        if ((m & alpha) == alpha && iswalpha_l(ch, __l)) break;
1450
        if ((m & digit) == digit && iswdigit_l(ch, __l)) break;
1451
        if ((m & punct) == punct && iswpunct_l(ch, __l)) break;
1452
        if ((m & xdigit) == xdigit && iswxdigit_l(ch, __l)) break;
1453
        if ((m & blank) == blank && iswblank_l(ch, __l)) break;
1454
#endif
1455
0
    }
1456
0
    return low;
1457
0
}
1458
1459
const wchar_t*
1460
ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
1461
0
{
1462
0
    for (; low != high; ++low)
1463
0
    {
1464
0
#ifdef _LIBCPP_WCTYPE_IS_MASK
1465
0
        if (!iswctype_l(*low, m, __l))
1466
0
            break;
1467
#else
1468
        wint_t ch = static_cast<wint_t>(*low);
1469
        if ((m & space) == space && iswspace_l(ch, __l)) continue;
1470
        if ((m & print) == print && iswprint_l(ch, __l)) continue;
1471
        if ((m & cntrl) == cntrl && iswcntrl_l(ch, __l)) continue;
1472
        if ((m & upper) == upper && iswupper_l(ch, __l)) continue;
1473
        if ((m & lower) == lower && iswlower_l(ch, __l)) continue;
1474
        if ((m & alpha) == alpha && iswalpha_l(ch, __l)) continue;
1475
        if ((m & digit) == digit && iswdigit_l(ch, __l)) continue;
1476
        if ((m & punct) == punct && iswpunct_l(ch, __l)) continue;
1477
        if ((m & xdigit) == xdigit && iswxdigit_l(ch, __l)) continue;
1478
        if ((m & blank) == blank && iswblank_l(ch, __l)) continue;
1479
        break;
1480
#endif
1481
0
    }
1482
0
    return low;
1483
0
}
1484
1485
wchar_t
1486
ctype_byname<wchar_t>::do_toupper(char_type c) const
1487
0
{
1488
0
    return towupper_l(c, __l);
1489
0
}
1490
1491
const wchar_t*
1492
ctype_byname<wchar_t>::do_toupper(char_type* low, const char_type* high) const
1493
0
{
1494
0
    for (; low != high; ++low)
1495
0
        *low = towupper_l(*low, __l);
1496
0
    return low;
1497
0
}
1498
1499
wchar_t
1500
ctype_byname<wchar_t>::do_tolower(char_type c) const
1501
0
{
1502
0
    return towlower_l(c, __l);
1503
0
}
1504
1505
const wchar_t*
1506
ctype_byname<wchar_t>::do_tolower(char_type* low, const char_type* high) const
1507
0
{
1508
0
    for (; low != high; ++low)
1509
0
        *low = towlower_l(*low, __l);
1510
0
    return low;
1511
0
}
1512
1513
wchar_t
1514
ctype_byname<wchar_t>::do_widen(char c) const
1515
0
{
1516
0
    return __libcpp_btowc_l(c, __l);
1517
0
}
1518
1519
const char*
1520
ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
1521
0
{
1522
0
    for (; low != high; ++low, ++dest)
1523
0
        *dest = __libcpp_btowc_l(*low, __l);
1524
0
    return low;
1525
0
}
1526
1527
char
1528
ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const
1529
0
{
1530
0
    int r = __libcpp_wctob_l(c, __l);
1531
0
    return r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
1532
0
}
1533
1534
const wchar_t*
1535
ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
1536
0
{
1537
0
    for (; low != high; ++low, ++dest)
1538
0
    {
1539
0
        int r = __libcpp_wctob_l(*low, __l);
1540
0
        *dest = r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
1541
0
    }
1542
0
    return low;
1543
0
}
1544
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1545
1546
// template <> class codecvt<char, char, mbstate_t>
1547
1548
locale::id codecvt<char, char, mbstate_t>::id;
1549
1550
codecvt<char, char, mbstate_t>::~codecvt()
1551
0
{
1552
0
}
1553
1554
codecvt<char, char, mbstate_t>::result
1555
codecvt<char, char, mbstate_t>::do_out(state_type&,
1556
    const intern_type* frm, const intern_type*, const intern_type*& frm_nxt,
1557
    extern_type* to, extern_type*, extern_type*& to_nxt) const
1558
0
{
1559
0
    frm_nxt = frm;
1560
0
    to_nxt = to;
1561
0
    return noconv;
1562
0
}
1563
1564
codecvt<char, char, mbstate_t>::result
1565
codecvt<char, char, mbstate_t>::do_in(state_type&,
1566
    const extern_type* frm, const extern_type*, const extern_type*& frm_nxt,
1567
    intern_type* to, intern_type*, intern_type*& to_nxt) const
1568
0
{
1569
0
    frm_nxt = frm;
1570
0
    to_nxt = to;
1571
0
    return noconv;
1572
0
}
1573
1574
codecvt<char, char, mbstate_t>::result
1575
codecvt<char, char, mbstate_t>::do_unshift(state_type&,
1576
    extern_type* to, extern_type*, extern_type*& to_nxt) const
1577
31
{
1578
31
    to_nxt = to;
1579
31
    return noconv;
1580
31
}
1581
1582
int
1583
codecvt<char, char, mbstate_t>::do_encoding() const noexcept
1584
15.2k
{
1585
15.2k
    return 1;
1586
15.2k
}
1587
1588
bool
1589
codecvt<char, char, mbstate_t>::do_always_noconv() const noexcept
1590
45.6k
{
1591
45.6k
    return true;
1592
45.6k
}
1593
1594
int
1595
codecvt<char, char, mbstate_t>::do_length(state_type&,
1596
    const extern_type* frm, const extern_type* end, size_t mx) const
1597
0
{
1598
0
    return static_cast<int>(min<size_t>(mx, static_cast<size_t>(end-frm)));
1599
0
}
1600
1601
int
1602
codecvt<char, char, mbstate_t>::do_max_length() const noexcept
1603
0
{
1604
0
    return 1;
1605
0
}
1606
1607
// template <> class codecvt<wchar_t, char, mbstate_t>
1608
1609
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1610
locale::id codecvt<wchar_t, char, mbstate_t>::id;
1611
1612
codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs)
1613
    : locale::facet(refs),
1614
      __l(_LIBCPP_GET_C_LOCALE)
1615
15.2k
{
1616
15.2k
}
1617
1618
codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs)
1619
    : locale::facet(refs),
1620
      __l(newlocale(LC_ALL_MASK, nm, 0))
1621
0
{
1622
0
    if (__l == 0)
1623
0
        __throw_runtime_error("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname"
1624
0
                            " failed to construct for " + string(nm));
1625
0
}
1626
1627
codecvt<wchar_t, char, mbstate_t>::~codecvt()
1628
0
{
1629
0
    if (__l != _LIBCPP_GET_C_LOCALE)
1630
0
        freelocale(__l);
1631
0
}
1632
1633
codecvt<wchar_t, char, mbstate_t>::result
1634
codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
1635
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
1636
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
1637
0
{
1638
    // look for first internal null in frm
1639
0
    const intern_type* fend = frm;
1640
0
    for (; fend != frm_end; ++fend)
1641
0
        if (*fend == 0)
1642
0
            break;
1643
    // loop over all null-terminated sequences in frm
1644
0
    to_nxt = to;
1645
0
    for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
1646
0
    {
1647
        // save state in case it is needed to recover to_nxt on error
1648
0
        mbstate_t save_state = st;
1649
0
        size_t n = __libcpp_wcsnrtombs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
1650
0
                                     static_cast<size_t>(to_end-to), &st, __l);
1651
0
        if (n == size_t(-1))
1652
0
        {
1653
            // need to recover to_nxt
1654
0
            for (to_nxt = to; frm != frm_nxt; ++frm)
1655
0
            {
1656
0
                n = __libcpp_wcrtomb_l(to_nxt, *frm, &save_state, __l);
1657
0
                if (n == size_t(-1))
1658
0
                    break;
1659
0
                to_nxt += n;
1660
0
            }
1661
0
            frm_nxt = frm;
1662
0
            return error;
1663
0
        }
1664
0
        if (n == 0)
1665
0
            return partial;
1666
0
        to_nxt += n;
1667
0
        if (to_nxt == to_end)
1668
0
            break;
1669
0
        if (fend != frm_end)  // set up next null terminated sequence
1670
0
        {
1671
            // Try to write the terminating null
1672
0
            extern_type tmp[MB_LEN_MAX];
1673
0
            n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l);
1674
0
            if (n == size_t(-1))  // on error
1675
0
                return error;
1676
0
            if (n > static_cast<size_t>(to_end-to_nxt))  // is there room?
1677
0
                return partial;
1678
0
            for (extern_type* p = tmp; n; --n)  // write it
1679
0
                *to_nxt++ = *p++;
1680
0
            ++frm_nxt;
1681
            // look for next null in frm
1682
0
            for (fend = frm_nxt; fend != frm_end; ++fend)
1683
0
                if (*fend == 0)
1684
0
                    break;
1685
0
        }
1686
0
    }
1687
0
    return frm_nxt == frm_end ? ok : partial;
1688
0
}
1689
1690
codecvt<wchar_t, char, mbstate_t>::result
1691
codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
1692
    const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
1693
    intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
1694
0
{
1695
    // look for first internal null in frm
1696
0
    const extern_type* fend = frm;
1697
0
    for (; fend != frm_end; ++fend)
1698
0
        if (*fend == 0)
1699
0
            break;
1700
    // loop over all null-terminated sequences in frm
1701
0
    to_nxt = to;
1702
0
    for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
1703
0
    {
1704
        // save state in case it is needed to recover to_nxt on error
1705
0
        mbstate_t save_state = st;
1706
0
        size_t n = __libcpp_mbsnrtowcs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
1707
0
                                     static_cast<size_t>(to_end-to), &st, __l);
1708
0
        if (n == size_t(-1))
1709
0
        {
1710
            // need to recover to_nxt
1711
0
            for (to_nxt = to; frm != frm_nxt; ++to_nxt)
1712
0
            {
1713
0
                n = __libcpp_mbrtowc_l(to_nxt, frm, static_cast<size_t>(fend-frm),
1714
0
                                   &save_state, __l);
1715
0
                switch (n)
1716
0
                {
1717
0
                case 0:
1718
0
                    ++frm;
1719
0
                    break;
1720
0
                case size_t(-1):
1721
0
                    frm_nxt = frm;
1722
0
                    return error;
1723
0
                case size_t(-2):
1724
0
                    frm_nxt = frm;
1725
0
                    return partial;
1726
0
                default:
1727
0
                    frm += n;
1728
0
                    break;
1729
0
                }
1730
0
            }
1731
0
            frm_nxt = frm;
1732
0
            return frm_nxt == frm_end ? ok : partial;
1733
0
        }
1734
0
        if (n == size_t(-1))
1735
0
            return error;
1736
0
        to_nxt += n;
1737
0
        if (to_nxt == to_end)
1738
0
            break;
1739
0
        if (fend != frm_end)  // set up next null terminated sequence
1740
0
        {
1741
            // Try to write the terminating null
1742
0
            n = __libcpp_mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l);
1743
0
            if (n != 0)  // on error
1744
0
                return error;
1745
0
            ++to_nxt;
1746
0
            ++frm_nxt;
1747
            // look for next null in frm
1748
0
            for (fend = frm_nxt; fend != frm_end; ++fend)
1749
0
                if (*fend == 0)
1750
0
                    break;
1751
0
        }
1752
0
    }
1753
0
    return frm_nxt == frm_end ? ok : partial;
1754
0
}
1755
1756
codecvt<wchar_t, char, mbstate_t>::result
1757
codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st,
1758
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
1759
0
{
1760
0
    to_nxt = to;
1761
0
    extern_type tmp[MB_LEN_MAX];
1762
0
    size_t n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l);
1763
0
    if (n == size_t(-1) || n == 0)  // on error
1764
0
        return error;
1765
0
    --n;
1766
0
    if (n > static_cast<size_t>(to_end-to_nxt))  // is there room?
1767
0
        return partial;
1768
0
    for (extern_type* p = tmp; n; --n)  // write it
1769
0
        *to_nxt++ = *p++;
1770
0
    return ok;
1771
0
}
1772
1773
int
1774
codecvt<wchar_t, char, mbstate_t>::do_encoding() const noexcept
1775
15.2k
{
1776
15.2k
    if (__libcpp_mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) != 0)
1777
0
        return -1;
1778
1779
    // stateless encoding
1780
15.2k
    if (__l == 0 || 
__libcpp_mb_cur_max_l0
(__l) == 10
) // there are no known constant length encodings
1781
15.2k
        return 1;                // which take more than 1 char to form a wchar_t
1782
0
    return 0;
1783
15.2k
}
1784
1785
bool
1786
codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const noexcept
1787
45.6k
{
1788
45.6k
    return false;
1789
45.6k
}
1790
1791
int
1792
codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st,
1793
    const extern_type* frm, const extern_type* frm_end, size_t mx) const
1794
0
{
1795
0
    int nbytes = 0;
1796
0
    for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t)
1797
0
    {
1798
0
        size_t n = __libcpp_mbrlen_l(frm, static_cast<size_t>(frm_end-frm), &st, __l);
1799
0
        switch (n)
1800
0
        {
1801
0
        case 0:
1802
0
            ++nbytes;
1803
0
            ++frm;
1804
0
            break;
1805
0
        case size_t(-1):
1806
0
        case size_t(-2):
1807
0
            return nbytes;
1808
0
        default:
1809
0
            nbytes += n;
1810
0
            frm += n;
1811
0
            break;
1812
0
        }
1813
0
    }
1814
0
    return nbytes;
1815
0
}
1816
1817
int
1818
codecvt<wchar_t, char, mbstate_t>::do_max_length() const noexcept
1819
0
{
1820
0
    return __l == 0 ? 1 : static_cast<int>(__libcpp_mb_cur_max_l(__l));
1821
0
}
1822
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1823
1824
//                                     Valid UTF ranges
1825
//     UTF-32               UTF-16                          UTF-8               # of code points
1826
//                     first      second       first   second    third   fourth
1827
// 000000 - 00007F  0000 - 007F               00 - 7F                                 127
1828
// 000080 - 0007FF  0080 - 07FF               C2 - DF, 80 - BF                       1920
1829
// 000800 - 000FFF  0800 - 0FFF               E0 - E0, A0 - BF, 80 - BF              2048
1830
// 001000 - 00CFFF  1000 - CFFF               E1 - EC, 80 - BF, 80 - BF             49152
1831
// 00D000 - 00D7FF  D000 - D7FF               ED - ED, 80 - 9F, 80 - BF              2048
1832
// 00D800 - 00DFFF                invalid
1833
// 00E000 - 00FFFF  E000 - FFFF               EE - EF, 80 - BF, 80 - BF              8192
1834
// 010000 - 03FFFF  D800 - D8BF, DC00 - DFFF  F0 - F0, 90 - BF, 80 - BF, 80 - BF   196608
1835
// 040000 - 0FFFFF  D8C0 - DBBF, DC00 - DFFF  F1 - F3, 80 - BF, 80 - BF, 80 - BF   786432
1836
// 100000 - 10FFFF  DBC0 - DBFF, DC00 - DFFF  F4 - F4, 80 - 8F, 80 - BF, 80 - BF    65536
1837
1838
static
1839
codecvt_base::result
1840
utf16_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
1841
              uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
1842
              unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1843
0
{
1844
0
    frm_nxt = frm;
1845
0
    to_nxt = to;
1846
0
    if (mode & generate_header)
1847
0
    {
1848
0
        if (to_end-to_nxt < 3)
1849
0
            return codecvt_base::partial;
1850
0
        *to_nxt++ = static_cast<uint8_t>(0xEF);
1851
0
        *to_nxt++ = static_cast<uint8_t>(0xBB);
1852
0
        *to_nxt++ = static_cast<uint8_t>(0xBF);
1853
0
    }
1854
0
    for (; frm_nxt < frm_end; ++frm_nxt)
1855
0
    {
1856
0
        uint16_t wc1 = *frm_nxt;
1857
0
        if (wc1 > Maxcode)
1858
0
            return codecvt_base::error;
1859
0
        if (wc1 < 0x0080)
1860
0
        {
1861
0
            if (to_end-to_nxt < 1)
1862
0
                return codecvt_base::partial;
1863
0
            *to_nxt++ = static_cast<uint8_t>(wc1);
1864
0
        }
1865
0
        else if (wc1 < 0x0800)
1866
0
        {
1867
0
            if (to_end-to_nxt < 2)
1868
0
                return codecvt_base::partial;
1869
0
            *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
1870
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
1871
0
        }
1872
0
        else if (wc1 < 0xD800)
1873
0
        {
1874
0
            if (to_end-to_nxt < 3)
1875
0
                return codecvt_base::partial;
1876
0
            *to_nxt++ = static_cast<uint8_t>(0xE0 |  (wc1 >> 12));
1877
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1878
0
            *to_nxt++ = static_cast<uint8_t>(0x80 |  (wc1 & 0x003F));
1879
0
        }
1880
0
        else if (wc1 < 0xDC00)
1881
0
        {
1882
0
            if (frm_end-frm_nxt < 2)
1883
0
                return codecvt_base::partial;
1884
0
            uint16_t wc2 = frm_nxt[1];
1885
0
            if ((wc2 & 0xFC00) != 0xDC00)
1886
0
                return codecvt_base::error;
1887
0
            if (to_end-to_nxt < 4)
1888
0
                return codecvt_base::partial;
1889
0
            if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) +
1890
0
                ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
1891
0
                return codecvt_base::error;
1892
0
            ++frm_nxt;
1893
0
            uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
1894
0
            *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
1895
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4)     | ((wc1 & 0x003C) >> 2));
1896
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
1897
0
            *to_nxt++ = static_cast<uint8_t>(0x80 |  (wc2 & 0x003F));
1898
0
        }
1899
0
        else if (wc1 < 0xE000)
1900
0
        {
1901
0
            return codecvt_base::error;
1902
0
        }
1903
0
        else
1904
0
        {
1905
0
            if (to_end-to_nxt < 3)
1906
0
                return codecvt_base::partial;
1907
0
            *to_nxt++ = static_cast<uint8_t>(0xE0 |  (wc1 >> 12));
1908
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1909
0
            *to_nxt++ = static_cast<uint8_t>(0x80 |  (wc1 & 0x003F));
1910
0
        }
1911
0
    }
1912
0
    return codecvt_base::ok;
1913
0
}
1914
1915
static
1916
codecvt_base::result
1917
utf16_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
1918
              uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
1919
              unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1920
0
{
1921
0
    frm_nxt = frm;
1922
0
    to_nxt = to;
1923
0
    if (mode & generate_header)
1924
0
    {
1925
0
        if (to_end-to_nxt < 3)
1926
0
            return codecvt_base::partial;
1927
0
        *to_nxt++ = static_cast<uint8_t>(0xEF);
1928
0
        *to_nxt++ = static_cast<uint8_t>(0xBB);
1929
0
        *to_nxt++ = static_cast<uint8_t>(0xBF);
1930
0
    }
1931
0
    for (; frm_nxt < frm_end; ++frm_nxt)
1932
0
    {
1933
0
        uint16_t wc1 = static_cast<uint16_t>(*frm_nxt);
1934
0
        if (wc1 > Maxcode)
1935
0
            return codecvt_base::error;
1936
0
        if (wc1 < 0x0080)
1937
0
        {
1938
0
            if (to_end-to_nxt < 1)
1939
0
                return codecvt_base::partial;
1940
0
            *to_nxt++ = static_cast<uint8_t>(wc1);
1941
0
        }
1942
0
        else if (wc1 < 0x0800)
1943
0
        {
1944
0
            if (to_end-to_nxt < 2)
1945
0
                return codecvt_base::partial;
1946
0
            *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
1947
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
1948
0
        }
1949
0
        else if (wc1 < 0xD800)
1950
0
        {
1951
0
            if (to_end-to_nxt < 3)
1952
0
                return codecvt_base::partial;
1953
0
            *to_nxt++ = static_cast<uint8_t>(0xE0 |  (wc1 >> 12));
1954
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1955
0
            *to_nxt++ = static_cast<uint8_t>(0x80 |  (wc1 & 0x003F));
1956
0
        }
1957
0
        else if (wc1 < 0xDC00)
1958
0
        {
1959
0
            if (frm_end-frm_nxt < 2)
1960
0
                return codecvt_base::partial;
1961
0
            uint16_t wc2 = static_cast<uint16_t>(frm_nxt[1]);
1962
0
            if ((wc2 & 0xFC00) != 0xDC00)
1963
0
                return codecvt_base::error;
1964
0
            if (to_end-to_nxt < 4)
1965
0
                return codecvt_base::partial;
1966
0
            if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) +
1967
0
                ((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
1968
0
                return codecvt_base::error;
1969
0
            ++frm_nxt;
1970
0
            uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
1971
0
            *to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
1972
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4)     | ((wc1 & 0x003C) >> 2));
1973
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
1974
0
            *to_nxt++ = static_cast<uint8_t>(0x80 |  (wc2 & 0x003F));
1975
0
        }
1976
0
        else if (wc1 < 0xE000)
1977
0
        {
1978
0
            return codecvt_base::error;
1979
0
        }
1980
0
        else
1981
0
        {
1982
0
            if (to_end-to_nxt < 3)
1983
0
                return codecvt_base::partial;
1984
0
            *to_nxt++ = static_cast<uint8_t>(0xE0 |  (wc1 >> 12));
1985
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
1986
0
            *to_nxt++ = static_cast<uint8_t>(0x80 |  (wc1 & 0x003F));
1987
0
        }
1988
0
    }
1989
0
    return codecvt_base::ok;
1990
0
}
1991
1992
static
1993
codecvt_base::result
1994
utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
1995
              uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
1996
              unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
1997
0
{
1998
0
    frm_nxt = frm;
1999
0
    to_nxt = to;
2000
0
    if (mode & consume_header)
2001
0
    {
2002
0
        if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2003
0
                                                          frm_nxt[2] == 0xBF)
2004
0
            frm_nxt += 3;
2005
0
    }
2006
0
    for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
2007
0
    {
2008
0
        uint8_t c1 = *frm_nxt;
2009
0
        if (c1 > Maxcode)
2010
0
            return codecvt_base::error;
2011
0
        if (c1 < 0x80)
2012
0
        {
2013
0
            *to_nxt = static_cast<uint16_t>(c1);
2014
0
            ++frm_nxt;
2015
0
        }
2016
0
        else if (c1 < 0xC2)
2017
0
        {
2018
0
            return codecvt_base::error;
2019
0
        }
2020
0
        else if (c1 < 0xE0)
2021
0
        {
2022
0
            if (frm_end-frm_nxt < 2)
2023
0
                return codecvt_base::partial;
2024
0
            uint8_t c2 = frm_nxt[1];
2025
0
            if ((c2 & 0xC0) != 0x80)
2026
0
                return codecvt_base::error;
2027
0
            uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
2028
0
            if (t > Maxcode)
2029
0
                return codecvt_base::error;
2030
0
            *to_nxt = t;
2031
0
            frm_nxt += 2;
2032
0
        }
2033
0
        else if (c1 < 0xF0)
2034
0
        {
2035
0
            if (frm_end-frm_nxt < 3)
2036
0
                return codecvt_base::partial;
2037
0
            uint8_t c2 = frm_nxt[1];
2038
0
            uint8_t c3 = frm_nxt[2];
2039
0
            switch (c1)
2040
0
            {
2041
0
            case 0xE0:
2042
0
                if ((c2 & 0xE0) != 0xA0)
2043
0
                    return codecvt_base::error;
2044
0
                 break;
2045
0
            case 0xED:
2046
0
                if ((c2 & 0xE0) != 0x80)
2047
0
                    return codecvt_base::error;
2048
0
                 break;
2049
0
            default:
2050
0
                if ((c2 & 0xC0) != 0x80)
2051
0
                    return codecvt_base::error;
2052
0
                 break;
2053
0
            }
2054
0
            if ((c3 & 0xC0) != 0x80)
2055
0
                return codecvt_base::error;
2056
0
            uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
2057
0
                                             | ((c2 & 0x3F) << 6)
2058
0
                                             |  (c3 & 0x3F));
2059
0
            if (t > Maxcode)
2060
0
                return codecvt_base::error;
2061
0
            *to_nxt = t;
2062
0
            frm_nxt += 3;
2063
0
        }
2064
0
        else if (c1 < 0xF5)
2065
0
        {
2066
0
            if (frm_end-frm_nxt < 4)
2067
0
                return codecvt_base::partial;
2068
0
            uint8_t c2 = frm_nxt[1];
2069
0
            uint8_t c3 = frm_nxt[2];
2070
0
            uint8_t c4 = frm_nxt[3];
2071
0
            switch (c1)
2072
0
            {
2073
0
            case 0xF0:
2074
0
                if (!(0x90 <= c2 && c2 <= 0xBF))
2075
0
                    return codecvt_base::error;
2076
0
                 break;
2077
0
            case 0xF4:
2078
0
                if ((c2 & 0xF0) != 0x80)
2079
0
                    return codecvt_base::error;
2080
0
                 break;
2081
0
            default:
2082
0
                if ((c2 & 0xC0) != 0x80)
2083
0
                    return codecvt_base::error;
2084
0
                 break;
2085
0
            }
2086
0
            if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2087
0
                return codecvt_base::error;
2088
0
            if (to_end-to_nxt < 2)
2089
0
                return codecvt_base::partial;
2090
0
            if ((((c1 & 7UL) << 18) +
2091
0
                ((c2 & 0x3FUL) << 12) +
2092
0
                ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
2093
0
                return codecvt_base::error;
2094
0
            *to_nxt = static_cast<uint16_t>(
2095
0
                    0xD800
2096
0
                  | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
2097
0
                  | ((c2 & 0x0F) << 2)
2098
0
                  | ((c3 & 0x30) >> 4));
2099
0
            *++to_nxt = static_cast<uint16_t>(
2100
0
                    0xDC00
2101
0
                  | ((c3 & 0x0F) << 6)
2102
0
                  |  (c4 & 0x3F));
2103
0
            frm_nxt += 4;
2104
0
        }
2105
0
        else
2106
0
        {
2107
0
            return codecvt_base::error;
2108
0
        }
2109
0
    }
2110
0
    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2111
0
}
2112
2113
static
2114
codecvt_base::result
2115
utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2116
              uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2117
              unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2118
0
{
2119
0
    frm_nxt = frm;
2120
0
    to_nxt = to;
2121
0
    if (mode & consume_header)
2122
0
    {
2123
0
        if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2124
0
                                                          frm_nxt[2] == 0xBF)
2125
0
            frm_nxt += 3;
2126
0
    }
2127
0
    for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
2128
0
    {
2129
0
        uint8_t c1 = *frm_nxt;
2130
0
        if (c1 > Maxcode)
2131
0
            return codecvt_base::error;
2132
0
        if (c1 < 0x80)
2133
0
        {
2134
0
            *to_nxt = static_cast<uint32_t>(c1);
2135
0
            ++frm_nxt;
2136
0
        }
2137
0
        else if (c1 < 0xC2)
2138
0
        {
2139
0
            return codecvt_base::error;
2140
0
        }
2141
0
        else if (c1 < 0xE0)
2142
0
        {
2143
0
            if (frm_end-frm_nxt < 2)
2144
0
                return codecvt_base::partial;
2145
0
            uint8_t c2 = frm_nxt[1];
2146
0
            if ((c2 & 0xC0) != 0x80)
2147
0
                return codecvt_base::error;
2148
0
            uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
2149
0
            if (t > Maxcode)
2150
0
                return codecvt_base::error;
2151
0
            *to_nxt = static_cast<uint32_t>(t);
2152
0
            frm_nxt += 2;
2153
0
        }
2154
0
        else if (c1 < 0xF0)
2155
0
        {
2156
0
            if (frm_end-frm_nxt < 3)
2157
0
                return codecvt_base::partial;
2158
0
            uint8_t c2 = frm_nxt[1];
2159
0
            uint8_t c3 = frm_nxt[2];
2160
0
            switch (c1)
2161
0
            {
2162
0
            case 0xE0:
2163
0
                if ((c2 & 0xE0) != 0xA0)
2164
0
                    return codecvt_base::error;
2165
0
                 break;
2166
0
            case 0xED:
2167
0
                if ((c2 & 0xE0) != 0x80)
2168
0
                    return codecvt_base::error;
2169
0
                 break;
2170
0
            default:
2171
0
                if ((c2 & 0xC0) != 0x80)
2172
0
                    return codecvt_base::error;
2173
0
                 break;
2174
0
            }
2175
0
            if ((c3 & 0xC0) != 0x80)
2176
0
                return codecvt_base::error;
2177
0
            uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
2178
0
                                             | ((c2 & 0x3F) << 6)
2179
0
                                             |  (c3 & 0x3F));
2180
0
            if (t > Maxcode)
2181
0
                return codecvt_base::error;
2182
0
            *to_nxt = static_cast<uint32_t>(t);
2183
0
            frm_nxt += 3;
2184
0
        }
2185
0
        else if (c1 < 0xF5)
2186
0
        {
2187
0
            if (frm_end-frm_nxt < 4)
2188
0
                return codecvt_base::partial;
2189
0
            uint8_t c2 = frm_nxt[1];
2190
0
            uint8_t c3 = frm_nxt[2];
2191
0
            uint8_t c4 = frm_nxt[3];
2192
0
            switch (c1)
2193
0
            {
2194
0
            case 0xF0:
2195
0
                if (!(0x90 <= c2 && c2 <= 0xBF))
2196
0
                    return codecvt_base::error;
2197
0
                 break;
2198
0
            case 0xF4:
2199
0
                if ((c2 & 0xF0) != 0x80)
2200
0
                    return codecvt_base::error;
2201
0
                 break;
2202
0
            default:
2203
0
                if ((c2 & 0xC0) != 0x80)
2204
0
                    return codecvt_base::error;
2205
0
                 break;
2206
0
            }
2207
0
            if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2208
0
                return codecvt_base::error;
2209
0
            if (to_end-to_nxt < 2)
2210
0
                return codecvt_base::partial;
2211
0
            if ((((c1 & 7UL) << 18) +
2212
0
                ((c2 & 0x3FUL) << 12) +
2213
0
                ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
2214
0
                return codecvt_base::error;
2215
0
            *to_nxt = static_cast<uint32_t>(
2216
0
                    0xD800
2217
0
                  | (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
2218
0
                  | ((c2 & 0x0F) << 2)
2219
0
                  | ((c3 & 0x30) >> 4));
2220
0
            *++to_nxt = static_cast<uint32_t>(
2221
0
                    0xDC00
2222
0
                  | ((c3 & 0x0F) << 6)
2223
0
                  |  (c4 & 0x3F));
2224
0
            frm_nxt += 4;
2225
0
        }
2226
0
        else
2227
0
        {
2228
0
            return codecvt_base::error;
2229
0
        }
2230
0
    }
2231
0
    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2232
0
}
2233
2234
static
2235
int
2236
utf8_to_utf16_length(const uint8_t* frm, const uint8_t* frm_end,
2237
                     size_t mx, unsigned long Maxcode = 0x10FFFF,
2238
                     codecvt_mode mode = codecvt_mode(0))
2239
0
{
2240
0
    const uint8_t* frm_nxt = frm;
2241
0
    if (mode & consume_header)
2242
0
    {
2243
0
        if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2244
0
                                                          frm_nxt[2] == 0xBF)
2245
0
            frm_nxt += 3;
2246
0
    }
2247
0
    for (size_t nchar16_t = 0; frm_nxt < frm_end && nchar16_t < mx; ++nchar16_t)
2248
0
    {
2249
0
        uint8_t c1 = *frm_nxt;
2250
0
        if (c1 > Maxcode)
2251
0
            break;
2252
0
        if (c1 < 0x80)
2253
0
        {
2254
0
            ++frm_nxt;
2255
0
        }
2256
0
        else if (c1 < 0xC2)
2257
0
        {
2258
0
            break;
2259
0
        }
2260
0
        else if (c1 < 0xE0)
2261
0
        {
2262
0
            if ((frm_end-frm_nxt < 2) || (frm_nxt[1] & 0xC0) != 0x80)
2263
0
                break;
2264
0
            uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F));
2265
0
            if (t > Maxcode)
2266
0
                break;
2267
0
            frm_nxt += 2;
2268
0
        }
2269
0
        else if (c1 < 0xF0)
2270
0
        {
2271
0
            if (frm_end-frm_nxt < 3)
2272
0
                break;
2273
0
            uint8_t c2 = frm_nxt[1];
2274
0
            uint8_t c3 = frm_nxt[2];
2275
0
            switch (c1)
2276
0
            {
2277
0
            case 0xE0:
2278
0
                if ((c2 & 0xE0) != 0xA0)
2279
0
                    return static_cast<int>(frm_nxt - frm);
2280
0
                break;
2281
0
            case 0xED:
2282
0
                if ((c2 & 0xE0) != 0x80)
2283
0
                    return static_cast<int>(frm_nxt - frm);
2284
0
                 break;
2285
0
            default:
2286
0
                if ((c2 & 0xC0) != 0x80)
2287
0
                    return static_cast<int>(frm_nxt - frm);
2288
0
                 break;
2289
0
            }
2290
0
            if ((c3 & 0xC0) != 0x80)
2291
0
                break;
2292
0
            if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
2293
0
                break;
2294
0
            frm_nxt += 3;
2295
0
        }
2296
0
        else if (c1 < 0xF5)
2297
0
        {
2298
0
            if (frm_end-frm_nxt < 4 || mx-nchar16_t < 2)
2299
0
                break;
2300
0
            uint8_t c2 = frm_nxt[1];
2301
0
            uint8_t c3 = frm_nxt[2];
2302
0
            uint8_t c4 = frm_nxt[3];
2303
0
            switch (c1)
2304
0
            {
2305
0
            case 0xF0:
2306
0
                if (!(0x90 <= c2 && c2 <= 0xBF))
2307
0
                    return static_cast<int>(frm_nxt - frm);
2308
0
                 break;
2309
0
            case 0xF4:
2310
0
                if ((c2 & 0xF0) != 0x80)
2311
0
                    return static_cast<int>(frm_nxt - frm);
2312
0
                 break;
2313
0
            default:
2314
0
                if ((c2 & 0xC0) != 0x80)
2315
0
                    return static_cast<int>(frm_nxt - frm);
2316
0
                 break;
2317
0
            }
2318
0
            if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2319
0
                break;
2320
0
            if ((((c1 & 7UL) << 18) +
2321
0
                ((c2 & 0x3FUL) << 12) +
2322
0
                ((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
2323
0
                break;
2324
0
            ++nchar16_t;
2325
0
            frm_nxt += 4;
2326
0
        }
2327
0
        else
2328
0
        {
2329
0
            break;
2330
0
        }
2331
0
    }
2332
0
    return static_cast<int>(frm_nxt - frm);
2333
0
}
2334
2335
static
2336
codecvt_base::result
2337
ucs4_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
2338
             uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2339
             unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2340
0
{
2341
0
    frm_nxt = frm;
2342
0
    to_nxt = to;
2343
0
    if (mode & generate_header)
2344
0
    {
2345
0
        if (to_end-to_nxt < 3)
2346
0
            return codecvt_base::partial;
2347
0
        *to_nxt++ = static_cast<uint8_t>(0xEF);
2348
0
        *to_nxt++ = static_cast<uint8_t>(0xBB);
2349
0
        *to_nxt++ = static_cast<uint8_t>(0xBF);
2350
0
    }
2351
0
    for (; frm_nxt < frm_end; ++frm_nxt)
2352
0
    {
2353
0
        uint32_t wc = *frm_nxt;
2354
0
        if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
2355
0
            return codecvt_base::error;
2356
0
        if (wc < 0x000080)
2357
0
        {
2358
0
            if (to_end-to_nxt < 1)
2359
0
                return codecvt_base::partial;
2360
0
            *to_nxt++ = static_cast<uint8_t>(wc);
2361
0
        }
2362
0
        else if (wc < 0x000800)
2363
0
        {
2364
0
            if (to_end-to_nxt < 2)
2365
0
                return codecvt_base::partial;
2366
0
            *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
2367
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
2368
0
        }
2369
0
        else if (wc < 0x010000)
2370
0
        {
2371
0
            if (to_end-to_nxt < 3)
2372
0
                return codecvt_base::partial;
2373
0
            *to_nxt++ = static_cast<uint8_t>(0xE0 |  (wc >> 12));
2374
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
2375
0
            *to_nxt++ = static_cast<uint8_t>(0x80 |  (wc & 0x003F));
2376
0
        }
2377
0
        else // if (wc < 0x110000)
2378
0
        {
2379
0
            if (to_end-to_nxt < 4)
2380
0
                return codecvt_base::partial;
2381
0
            *to_nxt++ = static_cast<uint8_t>(0xF0 |  (wc >> 18));
2382
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x03F000) >> 12));
2383
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x000FC0) >> 6));
2384
0
            *to_nxt++ = static_cast<uint8_t>(0x80 |  (wc & 0x00003F));
2385
0
        }
2386
0
    }
2387
0
    return codecvt_base::ok;
2388
0
}
2389
2390
static
2391
codecvt_base::result
2392
utf8_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2393
             uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2394
             unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2395
0
{
2396
0
    frm_nxt = frm;
2397
0
    to_nxt = to;
2398
0
    if (mode & consume_header)
2399
0
    {
2400
0
        if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2401
0
                                                          frm_nxt[2] == 0xBF)
2402
0
            frm_nxt += 3;
2403
0
    }
2404
0
    for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
2405
0
    {
2406
0
        uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2407
0
        if (c1 < 0x80)
2408
0
        {
2409
0
            if (c1 > Maxcode)
2410
0
                return codecvt_base::error;
2411
0
            *to_nxt = static_cast<uint32_t>(c1);
2412
0
            ++frm_nxt;
2413
0
        }
2414
0
        else if (c1 < 0xC2)
2415
0
        {
2416
0
            return codecvt_base::error;
2417
0
        }
2418
0
        else if (c1 < 0xE0)
2419
0
        {
2420
0
            if (frm_end-frm_nxt < 2)
2421
0
                return codecvt_base::partial;
2422
0
            uint8_t c2 = frm_nxt[1];
2423
0
            if ((c2 & 0xC0) != 0x80)
2424
0
                return codecvt_base::error;
2425
0
            uint32_t t = static_cast<uint32_t>(((c1 & 0x1F) << 6)
2426
0
                                              | (c2 & 0x3F));
2427
0
            if (t > Maxcode)
2428
0
                return codecvt_base::error;
2429
0
            *to_nxt = t;
2430
0
            frm_nxt += 2;
2431
0
        }
2432
0
        else if (c1 < 0xF0)
2433
0
        {
2434
0
            if (frm_end-frm_nxt < 3)
2435
0
                return codecvt_base::partial;
2436
0
            uint8_t c2 = frm_nxt[1];
2437
0
            uint8_t c3 = frm_nxt[2];
2438
0
            switch (c1)
2439
0
            {
2440
0
            case 0xE0:
2441
0
                if ((c2 & 0xE0) != 0xA0)
2442
0
                    return codecvt_base::error;
2443
0
                 break;
2444
0
            case 0xED:
2445
0
                if ((c2 & 0xE0) != 0x80)
2446
0
                    return codecvt_base::error;
2447
0
                 break;
2448
0
            default:
2449
0
                if ((c2 & 0xC0) != 0x80)
2450
0
                    return codecvt_base::error;
2451
0
                 break;
2452
0
            }
2453
0
            if ((c3 & 0xC0) != 0x80)
2454
0
                return codecvt_base::error;
2455
0
            uint32_t t = static_cast<uint32_t>(((c1 & 0x0F) << 12)
2456
0
                                             | ((c2 & 0x3F) << 6)
2457
0
                                             |  (c3 & 0x3F));
2458
0
            if (t > Maxcode)
2459
0
                return codecvt_base::error;
2460
0
            *to_nxt = t;
2461
0
            frm_nxt += 3;
2462
0
        }
2463
0
        else if (c1 < 0xF5)
2464
0
        {
2465
0
            if (frm_end-frm_nxt < 4)
2466
0
                return codecvt_base::partial;
2467
0
            uint8_t c2 = frm_nxt[1];
2468
0
            uint8_t c3 = frm_nxt[2];
2469
0
            uint8_t c4 = frm_nxt[3];
2470
0
            switch (c1)
2471
0
            {
2472
0
            case 0xF0:
2473
0
                if (!(0x90 <= c2 && c2 <= 0xBF))
2474
0
                    return codecvt_base::error;
2475
0
                 break;
2476
0
            case 0xF4:
2477
0
                if ((c2 & 0xF0) != 0x80)
2478
0
                    return codecvt_base::error;
2479
0
                 break;
2480
0
            default:
2481
0
                if ((c2 & 0xC0) != 0x80)
2482
0
                    return codecvt_base::error;
2483
0
                 break;
2484
0
            }
2485
0
            if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2486
0
                return codecvt_base::error;
2487
0
            uint32_t t = static_cast<uint32_t>(((c1 & 0x07) << 18)
2488
0
                                             | ((c2 & 0x3F) << 12)
2489
0
                                             | ((c3 & 0x3F) << 6)
2490
0
                                             |  (c4 & 0x3F));
2491
0
            if (t > Maxcode)
2492
0
                return codecvt_base::error;
2493
0
            *to_nxt = t;
2494
0
            frm_nxt += 4;
2495
0
        }
2496
0
        else
2497
0
        {
2498
0
            return codecvt_base::error;
2499
0
        }
2500
0
    }
2501
0
    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2502
0
}
2503
2504
static
2505
int
2506
utf8_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
2507
                    size_t mx, unsigned long Maxcode = 0x10FFFF,
2508
                    codecvt_mode mode = codecvt_mode(0))
2509
0
{
2510
0
    const uint8_t* frm_nxt = frm;
2511
0
    if (mode & consume_header)
2512
0
    {
2513
0
        if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2514
0
                                                          frm_nxt[2] == 0xBF)
2515
0
            frm_nxt += 3;
2516
0
    }
2517
0
    for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
2518
0
    {
2519
0
        uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2520
0
        if (c1 < 0x80)
2521
0
        {
2522
0
            if (c1 > Maxcode)
2523
0
                break;
2524
0
            ++frm_nxt;
2525
0
        }
2526
0
        else if (c1 < 0xC2)
2527
0
        {
2528
0
            break;
2529
0
        }
2530
0
        else if (c1 < 0xE0)
2531
0
        {
2532
0
            if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
2533
0
                break;
2534
0
            if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
2535
0
                break;
2536
0
            frm_nxt += 2;
2537
0
        }
2538
0
        else if (c1 < 0xF0)
2539
0
        {
2540
0
            if (frm_end-frm_nxt < 3)
2541
0
                break;
2542
0
            uint8_t c2 = frm_nxt[1];
2543
0
            uint8_t c3 = frm_nxt[2];
2544
0
            switch (c1)
2545
0
            {
2546
0
            case 0xE0:
2547
0
                if ((c2 & 0xE0) != 0xA0)
2548
0
                    return static_cast<int>(frm_nxt - frm);
2549
0
                break;
2550
0
            case 0xED:
2551
0
                if ((c2 & 0xE0) != 0x80)
2552
0
                    return static_cast<int>(frm_nxt - frm);
2553
0
                 break;
2554
0
            default:
2555
0
                if ((c2 & 0xC0) != 0x80)
2556
0
                    return static_cast<int>(frm_nxt - frm);
2557
0
                 break;
2558
0
            }
2559
0
            if ((c3 & 0xC0) != 0x80)
2560
0
                break;
2561
0
            if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
2562
0
                break;
2563
0
            frm_nxt += 3;
2564
0
        }
2565
0
        else if (c1 < 0xF5)
2566
0
        {
2567
0
            if (frm_end-frm_nxt < 4)
2568
0
                break;
2569
0
            uint8_t c2 = frm_nxt[1];
2570
0
            uint8_t c3 = frm_nxt[2];
2571
0
            uint8_t c4 = frm_nxt[3];
2572
0
            switch (c1)
2573
0
            {
2574
0
            case 0xF0:
2575
0
                if (!(0x90 <= c2 && c2 <= 0xBF))
2576
0
                    return static_cast<int>(frm_nxt - frm);
2577
0
                 break;
2578
0
            case 0xF4:
2579
0
                if ((c2 & 0xF0) != 0x80)
2580
0
                    return static_cast<int>(frm_nxt - frm);
2581
0
                 break;
2582
0
            default:
2583
0
                if ((c2 & 0xC0) != 0x80)
2584
0
                    return static_cast<int>(frm_nxt - frm);
2585
0
                 break;
2586
0
            }
2587
0
            if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
2588
0
                break;
2589
0
            if ((((c1 & 0x07u) << 18) | ((c2 & 0x3Fu) << 12) |
2590
0
                 ((c3 & 0x3Fu) << 6)  |  (c4 & 0x3Fu)) > Maxcode)
2591
0
                break;
2592
0
            frm_nxt += 4;
2593
0
        }
2594
0
        else
2595
0
        {
2596
0
            break;
2597
0
        }
2598
0
    }
2599
0
    return static_cast<int>(frm_nxt - frm);
2600
0
}
2601
2602
static
2603
codecvt_base::result
2604
ucs2_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
2605
             uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2606
             unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2607
0
{
2608
0
    frm_nxt = frm;
2609
0
    to_nxt = to;
2610
0
    if (mode & generate_header)
2611
0
    {
2612
0
        if (to_end-to_nxt < 3)
2613
0
            return codecvt_base::partial;
2614
0
        *to_nxt++ = static_cast<uint8_t>(0xEF);
2615
0
        *to_nxt++ = static_cast<uint8_t>(0xBB);
2616
0
        *to_nxt++ = static_cast<uint8_t>(0xBF);
2617
0
    }
2618
0
    for (; frm_nxt < frm_end; ++frm_nxt)
2619
0
    {
2620
0
        uint16_t wc = *frm_nxt;
2621
0
        if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
2622
0
            return codecvt_base::error;
2623
0
        if (wc < 0x0080)
2624
0
        {
2625
0
            if (to_end-to_nxt < 1)
2626
0
                return codecvt_base::partial;
2627
0
            *to_nxt++ = static_cast<uint8_t>(wc);
2628
0
        }
2629
0
        else if (wc < 0x0800)
2630
0
        {
2631
0
            if (to_end-to_nxt < 2)
2632
0
                return codecvt_base::partial;
2633
0
            *to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
2634
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
2635
0
        }
2636
0
        else // if (wc <= 0xFFFF)
2637
0
        {
2638
0
            if (to_end-to_nxt < 3)
2639
0
                return codecvt_base::partial;
2640
0
            *to_nxt++ = static_cast<uint8_t>(0xE0 |  (wc >> 12));
2641
0
            *to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
2642
0
            *to_nxt++ = static_cast<uint8_t>(0x80 |  (wc & 0x003F));
2643
0
        }
2644
0
    }
2645
0
    return codecvt_base::ok;
2646
0
}
2647
2648
static
2649
codecvt_base::result
2650
utf8_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2651
             uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
2652
             unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2653
0
{
2654
0
    frm_nxt = frm;
2655
0
    to_nxt = to;
2656
0
    if (mode & consume_header)
2657
0
    {
2658
0
        if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2659
0
                                                          frm_nxt[2] == 0xBF)
2660
0
            frm_nxt += 3;
2661
0
    }
2662
0
    for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
2663
0
    {
2664
0
        uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2665
0
        if (c1 < 0x80)
2666
0
        {
2667
0
            if (c1 > Maxcode)
2668
0
                return codecvt_base::error;
2669
0
            *to_nxt = static_cast<uint16_t>(c1);
2670
0
            ++frm_nxt;
2671
0
        }
2672
0
        else if (c1 < 0xC2)
2673
0
        {
2674
0
            return codecvt_base::error;
2675
0
        }
2676
0
        else if (c1 < 0xE0)
2677
0
        {
2678
0
            if (frm_end-frm_nxt < 2)
2679
0
                return codecvt_base::partial;
2680
0
            uint8_t c2 = frm_nxt[1];
2681
0
            if ((c2 & 0xC0) != 0x80)
2682
0
                return codecvt_base::error;
2683
0
            uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6)
2684
0
                                              | (c2 & 0x3F));
2685
0
            if (t > Maxcode)
2686
0
                return codecvt_base::error;
2687
0
            *to_nxt = t;
2688
0
            frm_nxt += 2;
2689
0
        }
2690
0
        else if (c1 < 0xF0)
2691
0
        {
2692
0
            if (frm_end-frm_nxt < 3)
2693
0
                return codecvt_base::partial;
2694
0
            uint8_t c2 = frm_nxt[1];
2695
0
            uint8_t c3 = frm_nxt[2];
2696
0
            switch (c1)
2697
0
            {
2698
0
            case 0xE0:
2699
0
                if ((c2 & 0xE0) != 0xA0)
2700
0
                    return codecvt_base::error;
2701
0
                 break;
2702
0
            case 0xED:
2703
0
                if ((c2 & 0xE0) != 0x80)
2704
0
                    return codecvt_base::error;
2705
0
                 break;
2706
0
            default:
2707
0
                if ((c2 & 0xC0) != 0x80)
2708
0
                    return codecvt_base::error;
2709
0
                 break;
2710
0
            }
2711
0
            if ((c3 & 0xC0) != 0x80)
2712
0
                return codecvt_base::error;
2713
0
            uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
2714
0
                                             | ((c2 & 0x3F) << 6)
2715
0
                                             |  (c3 & 0x3F));
2716
0
            if (t > Maxcode)
2717
0
                return codecvt_base::error;
2718
0
            *to_nxt = t;
2719
0
            frm_nxt += 3;
2720
0
        }
2721
0
        else
2722
0
        {
2723
0
            return codecvt_base::error;
2724
0
        }
2725
0
    }
2726
0
    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2727
0
}
2728
2729
static
2730
int
2731
utf8_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
2732
                    size_t mx, unsigned long Maxcode = 0x10FFFF,
2733
                    codecvt_mode mode = codecvt_mode(0))
2734
0
{
2735
0
    const uint8_t* frm_nxt = frm;
2736
0
    if (mode & consume_header)
2737
0
    {
2738
0
        if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
2739
0
                                                          frm_nxt[2] == 0xBF)
2740
0
            frm_nxt += 3;
2741
0
    }
2742
0
    for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
2743
0
    {
2744
0
        uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
2745
0
        if (c1 < 0x80)
2746
0
        {
2747
0
            if (c1 > Maxcode)
2748
0
                break;
2749
0
            ++frm_nxt;
2750
0
        }
2751
0
        else if (c1 < 0xC2)
2752
0
        {
2753
0
            break;
2754
0
        }
2755
0
        else if (c1 < 0xE0)
2756
0
        {
2757
0
            if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
2758
0
                break;
2759
0
            if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
2760
0
                break;
2761
0
            frm_nxt += 2;
2762
0
        }
2763
0
        else if (c1 < 0xF0)
2764
0
        {
2765
0
            if (frm_end-frm_nxt < 3)
2766
0
                break;
2767
0
            uint8_t c2 = frm_nxt[1];
2768
0
            uint8_t c3 = frm_nxt[2];
2769
0
            switch (c1)
2770
0
            {
2771
0
            case 0xE0:
2772
0
                if ((c2 & 0xE0) != 0xA0)
2773
0
                    return static_cast<int>(frm_nxt - frm);
2774
0
                break;
2775
0
            case 0xED:
2776
0
                if ((c2 & 0xE0) != 0x80)
2777
0
                    return static_cast<int>(frm_nxt - frm);
2778
0
                 break;
2779
0
            default:
2780
0
                if ((c2 & 0xC0) != 0x80)
2781
0
                    return static_cast<int>(frm_nxt - frm);
2782
0
                 break;
2783
0
            }
2784
0
            if ((c3 & 0xC0) != 0x80)
2785
0
                break;
2786
0
            if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
2787
0
                break;
2788
0
            frm_nxt += 3;
2789
0
        }
2790
0
        else
2791
0
        {
2792
0
            break;
2793
0
        }
2794
0
    }
2795
0
    return static_cast<int>(frm_nxt - frm);
2796
0
}
2797
2798
static
2799
codecvt_base::result
2800
ucs4_to_utf16be(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
2801
                uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2802
                unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2803
0
{
2804
0
    frm_nxt = frm;
2805
0
    to_nxt = to;
2806
0
    if (mode & generate_header)
2807
0
    {
2808
0
        if (to_end-to_nxt < 2)
2809
0
            return codecvt_base::partial;
2810
0
        *to_nxt++ = static_cast<uint8_t>(0xFE);
2811
0
        *to_nxt++ = static_cast<uint8_t>(0xFF);
2812
0
    }
2813
0
    for (; frm_nxt < frm_end; ++frm_nxt)
2814
0
    {
2815
0
        uint32_t wc = *frm_nxt;
2816
0
        if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
2817
0
            return codecvt_base::error;
2818
0
        if (wc < 0x010000)
2819
0
        {
2820
0
            if (to_end-to_nxt < 2)
2821
0
                return codecvt_base::partial;
2822
0
            *to_nxt++ = static_cast<uint8_t>(wc >> 8);
2823
0
            *to_nxt++ = static_cast<uint8_t>(wc);
2824
0
        }
2825
0
        else
2826
0
        {
2827
0
            if (to_end-to_nxt < 4)
2828
0
                return codecvt_base::partial;
2829
0
            uint16_t t = static_cast<uint16_t>(
2830
0
                    0xD800
2831
0
                  | ((((wc & 0x1F0000) >> 16) - 1) << 6)
2832
0
                  |   ((wc & 0x00FC00) >> 10));
2833
0
            *to_nxt++ = static_cast<uint8_t>(t >> 8);
2834
0
            *to_nxt++ = static_cast<uint8_t>(t);
2835
0
            t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
2836
0
            *to_nxt++ = static_cast<uint8_t>(t >> 8);
2837
0
            *to_nxt++ = static_cast<uint8_t>(t);
2838
0
        }
2839
0
    }
2840
0
    return codecvt_base::ok;
2841
0
}
2842
2843
static
2844
codecvt_base::result
2845
utf16be_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2846
                uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2847
                unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2848
0
{
2849
0
    frm_nxt = frm;
2850
0
    to_nxt = to;
2851
0
    if (mode & consume_header)
2852
0
    {
2853
0
        if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2854
0
            frm_nxt += 2;
2855
0
    }
2856
0
    for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2857
0
    {
2858
0
        uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2859
0
        if ((c1 & 0xFC00) == 0xDC00)
2860
0
            return codecvt_base::error;
2861
0
        if ((c1 & 0xFC00) != 0xD800)
2862
0
        {
2863
0
            if (c1 > Maxcode)
2864
0
                return codecvt_base::error;
2865
0
            *to_nxt = static_cast<uint32_t>(c1);
2866
0
            frm_nxt += 2;
2867
0
        }
2868
0
        else
2869
0
        {
2870
0
            if (frm_end-frm_nxt < 4)
2871
0
                return codecvt_base::partial;
2872
0
            uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
2873
0
            if ((c2 & 0xFC00) != 0xDC00)
2874
0
                return codecvt_base::error;
2875
0
            uint32_t t = static_cast<uint32_t>(
2876
0
                    ((((c1 & 0x03C0) >> 6) + 1) << 16)
2877
0
                  |   ((c1 & 0x003F) << 10)
2878
0
                  |    (c2 & 0x03FF));
2879
0
            if (t > Maxcode)
2880
0
                return codecvt_base::error;
2881
0
            *to_nxt = t;
2882
0
            frm_nxt += 4;
2883
0
        }
2884
0
    }
2885
0
    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
2886
0
}
2887
2888
static
2889
int
2890
utf16be_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
2891
                       size_t mx, unsigned long Maxcode = 0x10FFFF,
2892
                       codecvt_mode mode = codecvt_mode(0))
2893
0
{
2894
0
    const uint8_t* frm_nxt = frm;
2895
0
    if (mode & consume_header)
2896
0
    {
2897
0
        if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
2898
0
            frm_nxt += 2;
2899
0
    }
2900
0
    for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
2901
0
    {
2902
0
        uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
2903
0
        if ((c1 & 0xFC00) == 0xDC00)
2904
0
            break;
2905
0
        if ((c1 & 0xFC00) != 0xD800)
2906
0
        {
2907
0
            if (c1 > Maxcode)
2908
0
                break;
2909
0
            frm_nxt += 2;
2910
0
        }
2911
0
        else
2912
0
        {
2913
0
            if (frm_end-frm_nxt < 4)
2914
0
                break;
2915
0
            uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
2916
0
            if ((c2 & 0xFC00) != 0xDC00)
2917
0
                break;
2918
0
            uint32_t t = static_cast<uint32_t>(
2919
0
                    ((((c1 & 0x03C0) >> 6) + 1) << 16)
2920
0
                  |   ((c1 & 0x003F) << 10)
2921
0
                  |    (c2 & 0x03FF));
2922
0
            if (t > Maxcode)
2923
0
                break;
2924
0
            frm_nxt += 4;
2925
0
        }
2926
0
    }
2927
0
    return static_cast<int>(frm_nxt - frm);
2928
0
}
2929
2930
static
2931
codecvt_base::result
2932
ucs4_to_utf16le(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
2933
                uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
2934
                unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2935
0
{
2936
0
    frm_nxt = frm;
2937
0
    to_nxt = to;
2938
0
    if (mode & generate_header)
2939
0
    {
2940
0
        if (to_end - to_nxt < 2)
2941
0
            return codecvt_base::partial;
2942
0
        *to_nxt++ = static_cast<uint8_t>(0xFF);
2943
0
        *to_nxt++ = static_cast<uint8_t>(0xFE);
2944
0
    }
2945
0
    for (; frm_nxt < frm_end; ++frm_nxt)
2946
0
    {
2947
0
        uint32_t wc = *frm_nxt;
2948
0
        if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
2949
0
            return codecvt_base::error;
2950
0
        if (wc < 0x010000)
2951
0
        {
2952
0
            if (to_end-to_nxt < 2)
2953
0
                return codecvt_base::partial;
2954
0
            *to_nxt++ = static_cast<uint8_t>(wc);
2955
0
            *to_nxt++ = static_cast<uint8_t>(wc >> 8);
2956
0
        }
2957
0
        else
2958
0
        {
2959
0
            if (to_end-to_nxt < 4)
2960
0
                return codecvt_base::partial;
2961
0
            uint16_t t = static_cast<uint16_t>(
2962
0
                    0xD800
2963
0
                  | ((((wc & 0x1F0000) >> 16) - 1) << 6)
2964
0
                  |   ((wc & 0x00FC00) >> 10));
2965
0
            *to_nxt++ = static_cast<uint8_t>(t);
2966
0
            *to_nxt++ = static_cast<uint8_t>(t >> 8);
2967
0
            t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
2968
0
            *to_nxt++ = static_cast<uint8_t>(t);
2969
0
            *to_nxt++ = static_cast<uint8_t>(t >> 8);
2970
0
        }
2971
0
    }
2972
0
    return codecvt_base::ok;
2973
0
}
2974
2975
static
2976
codecvt_base::result
2977
utf16le_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
2978
                uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
2979
                unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
2980
0
{
2981
0
    frm_nxt = frm;
2982
0
    to_nxt = to;
2983
0
    if (mode & consume_header)
2984
0
    {
2985
0
        if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
2986
0
            frm_nxt += 2;
2987
0
    }
2988
0
    for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
2989
0
    {
2990
0
        uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
2991
0
        if ((c1 & 0xFC00) == 0xDC00)
2992
0
            return codecvt_base::error;
2993
0
        if ((c1 & 0xFC00) != 0xD800)
2994
0
        {
2995
0
            if (c1 > Maxcode)
2996
0
                return codecvt_base::error;
2997
0
            *to_nxt = static_cast<uint32_t>(c1);
2998
0
            frm_nxt += 2;
2999
0
        }
3000
0
        else
3001
0
        {
3002
0
            if (frm_end-frm_nxt < 4)
3003
0
                return codecvt_base::partial;
3004
0
            uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
3005
0
            if ((c2 & 0xFC00) != 0xDC00)
3006
0
                return codecvt_base::error;
3007
0
            uint32_t t = static_cast<uint32_t>(
3008
0
                    ((((c1 & 0x03C0) >> 6) + 1) << 16)
3009
0
                  |   ((c1 & 0x003F) << 10)
3010
0
                  |    (c2 & 0x03FF));
3011
0
            if (t > Maxcode)
3012
0
                return codecvt_base::error;
3013
0
            *to_nxt = t;
3014
0
            frm_nxt += 4;
3015
0
        }
3016
0
    }
3017
0
    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
3018
0
}
3019
3020
static
3021
int
3022
utf16le_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
3023
                       size_t mx, unsigned long Maxcode = 0x10FFFF,
3024
                       codecvt_mode mode = codecvt_mode(0))
3025
0
{
3026
0
    const uint8_t* frm_nxt = frm;
3027
0
    if (mode & consume_header)
3028
0
    {
3029
0
        if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
3030
0
            frm_nxt += 2;
3031
0
    }
3032
0
    for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
3033
0
    {
3034
0
        uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
3035
0
        if ((c1 & 0xFC00) == 0xDC00)
3036
0
            break;
3037
0
        if ((c1 & 0xFC00) != 0xD800)
3038
0
        {
3039
0
            if (c1 > Maxcode)
3040
0
                break;
3041
0
            frm_nxt += 2;
3042
0
        }
3043
0
        else
3044
0
        {
3045
0
            if (frm_end-frm_nxt < 4)
3046
0
                break;
3047
0
            uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
3048
0
            if ((c2 & 0xFC00) != 0xDC00)
3049
0
                break;
3050
0
            uint32_t t = static_cast<uint32_t>(
3051
0
                    ((((c1 & 0x03C0) >> 6) + 1) << 16)
3052
0
                  |   ((c1 & 0x003F) << 10)
3053
0
                  |    (c2 & 0x03FF));
3054
0
            if (t > Maxcode)
3055
0
                break;
3056
0
            frm_nxt += 4;
3057
0
        }
3058
0
    }
3059
0
    return static_cast<int>(frm_nxt - frm);
3060
0
}
3061
3062
static
3063
codecvt_base::result
3064
ucs2_to_utf16be(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
3065
                uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
3066
                unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
3067
0
{
3068
0
    frm_nxt = frm;
3069
0
    to_nxt = to;
3070
0
    if (mode & generate_header)
3071
0
    {
3072
0
        if (to_end-to_nxt < 2)
3073
0
            return codecvt_base::partial;
3074
0
        *to_nxt++ = static_cast<uint8_t>(0xFE);
3075
0
        *to_nxt++ = static_cast<uint8_t>(0xFF);
3076
0
    }
3077
0
    for (; frm_nxt < frm_end; ++frm_nxt)
3078
0
    {
3079
0
        uint16_t wc = *frm_nxt;
3080
0
        if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
3081
0
            return codecvt_base::error;
3082
0
        if (to_end-to_nxt < 2)
3083
0
            return codecvt_base::partial;
3084
0
        *to_nxt++ = static_cast<uint8_t>(wc >> 8);
3085
0
        *to_nxt++ = static_cast<uint8_t>(wc);
3086
0
    }
3087
0
    return codecvt_base::ok;
3088
0
}
3089
3090
static
3091
codecvt_base::result
3092
utf16be_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
3093
                uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
3094
                unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
3095
0
{
3096
0
    frm_nxt = frm;
3097
0
    to_nxt = to;
3098
0
    if (mode & consume_header)
3099
0
    {
3100
0
        if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
3101
0
            frm_nxt += 2;
3102
0
    }
3103
0
    for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
3104
0
    {
3105
0
        uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
3106
0
        if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
3107
0
            return codecvt_base::error;
3108
0
        *to_nxt = c1;
3109
0
        frm_nxt += 2;
3110
0
    }
3111
0
    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
3112
0
}
3113
3114
static
3115
int
3116
utf16be_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
3117
                       size_t mx, unsigned long Maxcode = 0x10FFFF,
3118
                       codecvt_mode mode = codecvt_mode(0))
3119
0
{
3120
0
    const uint8_t* frm_nxt = frm;
3121
0
    if (mode & consume_header)
3122
0
    {
3123
0
        if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
3124
0
            frm_nxt += 2;
3125
0
    }
3126
0
    for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
3127
0
    {
3128
0
        uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
3129
0
        if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
3130
0
            break;
3131
0
        frm_nxt += 2;
3132
0
    }
3133
0
    return static_cast<int>(frm_nxt - frm);
3134
0
}
3135
3136
static
3137
codecvt_base::result
3138
ucs2_to_utf16le(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
3139
                uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
3140
                unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
3141
0
{
3142
0
    frm_nxt = frm;
3143
0
    to_nxt = to;
3144
0
    if (mode & generate_header)
3145
0
    {
3146
0
        if (to_end-to_nxt < 2)
3147
0
            return codecvt_base::partial;
3148
0
        *to_nxt++ = static_cast<uint8_t>(0xFF);
3149
0
        *to_nxt++ = static_cast<uint8_t>(0xFE);
3150
0
    }
3151
0
    for (; frm_nxt < frm_end; ++frm_nxt)
3152
0
    {
3153
0
        uint16_t wc = *frm_nxt;
3154
0
        if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
3155
0
            return codecvt_base::error;
3156
0
        if (to_end-to_nxt < 2)
3157
0
            return codecvt_base::partial;
3158
0
        *to_nxt++ = static_cast<uint8_t>(wc);
3159
0
        *to_nxt++ = static_cast<uint8_t>(wc >> 8);
3160
0
    }
3161
0
    return codecvt_base::ok;
3162
0
}
3163
3164
static
3165
codecvt_base::result
3166
utf16le_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
3167
                uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
3168
                unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
3169
0
{
3170
0
    frm_nxt = frm;
3171
0
    to_nxt = to;
3172
0
    if (mode & consume_header)
3173
0
    {
3174
0
        if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
3175
0
            frm_nxt += 2;
3176
0
    }
3177
0
    for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
3178
0
    {
3179
0
        uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
3180
0
        if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
3181
0
            return codecvt_base::error;
3182
0
        *to_nxt = c1;
3183
0
        frm_nxt += 2;
3184
0
    }
3185
0
    return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
3186
0
}
3187
3188
static
3189
int
3190
utf16le_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
3191
                       size_t mx, unsigned long Maxcode = 0x10FFFF,
3192
                       codecvt_mode mode = codecvt_mode(0))
3193
0
{
3194
0
    const uint8_t* frm_nxt = frm;
3195
0
    frm_nxt = frm;
3196
0
    if (mode & consume_header)
3197
0
    {
3198
0
        if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
3199
0
            frm_nxt += 2;
3200
0
    }
3201
0
    for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
3202
0
    {
3203
0
        uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
3204
0
        if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
3205
0
            break;
3206
0
        frm_nxt += 2;
3207
0
    }
3208
0
    return static_cast<int>(frm_nxt - frm);
3209
0
}
3210
3211
// template <> class codecvt<char16_t, char, mbstate_t>
3212
3213
locale::id codecvt<char16_t, char, mbstate_t>::id;
3214
3215
codecvt<char16_t, char, mbstate_t>::~codecvt()
3216
0
{
3217
0
}
3218
3219
codecvt<char16_t, char, mbstate_t>::result
3220
codecvt<char16_t, char, mbstate_t>::do_out(state_type&,
3221
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3222
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3223
0
{
3224
0
    const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3225
0
    const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3226
0
    const uint16_t* _frm_nxt = _frm;
3227
0
    uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3228
0
    uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3229
0
    uint8_t* _to_nxt = _to;
3230
0
    result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3231
0
    frm_nxt = frm + (_frm_nxt - _frm);
3232
0
    to_nxt = to + (_to_nxt - _to);
3233
0
    return r;
3234
0
}
3235
3236
codecvt<char16_t, char, mbstate_t>::result
3237
codecvt<char16_t, char, mbstate_t>::do_in(state_type&,
3238
    const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3239
    intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3240
0
{
3241
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3242
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3243
0
    const uint8_t* _frm_nxt = _frm;
3244
0
    uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3245
0
    uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3246
0
    uint16_t* _to_nxt = _to;
3247
0
    result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3248
0
    frm_nxt = frm + (_frm_nxt - _frm);
3249
0
    to_nxt = to + (_to_nxt - _to);
3250
0
    return r;
3251
0
}
3252
3253
codecvt<char16_t, char, mbstate_t>::result
3254
codecvt<char16_t, char, mbstate_t>::do_unshift(state_type&,
3255
    extern_type* to, extern_type*, extern_type*& to_nxt) const
3256
0
{
3257
0
    to_nxt = to;
3258
0
    return noconv;
3259
0
}
3260
3261
int
3262
codecvt<char16_t, char, mbstate_t>::do_encoding() const noexcept
3263
0
{
3264
0
    return 0;
3265
0
}
3266
3267
bool
3268
codecvt<char16_t, char, mbstate_t>::do_always_noconv() const noexcept
3269
0
{
3270
0
    return false;
3271
0
}
3272
3273
int
3274
codecvt<char16_t, char, mbstate_t>::do_length(state_type&,
3275
    const extern_type* frm, const extern_type* frm_end, size_t mx) const
3276
0
{
3277
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3278
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3279
0
    return utf8_to_utf16_length(_frm, _frm_end, mx);
3280
0
}
3281
3282
int
3283
codecvt<char16_t, char, mbstate_t>::do_max_length() const noexcept
3284
0
{
3285
0
    return 4;
3286
0
}
3287
3288
#ifndef _LIBCPP_HAS_NO_CHAR8_T
3289
3290
// template <> class codecvt<char16_t, char8_t, mbstate_t>
3291
3292
locale::id codecvt<char16_t, char8_t, mbstate_t>::id;
3293
3294
codecvt<char16_t, char8_t, mbstate_t>::~codecvt()
3295
0
{
3296
0
}
3297
3298
codecvt<char16_t, char8_t, mbstate_t>::result
3299
codecvt<char16_t, char8_t, mbstate_t>::do_out(state_type&,
3300
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3301
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3302
0
{
3303
0
    const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3304
0
    const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3305
0
    const uint16_t* _frm_nxt = _frm;
3306
0
    uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3307
0
    uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3308
0
    uint8_t* _to_nxt = _to;
3309
0
    result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3310
0
    frm_nxt = frm + (_frm_nxt - _frm);
3311
0
    to_nxt = to + (_to_nxt - _to);
3312
0
    return r;
3313
0
}
3314
3315
codecvt<char16_t, char8_t, mbstate_t>::result
3316
codecvt<char16_t, char8_t, mbstate_t>::do_in(state_type&,
3317
    const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3318
    intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3319
0
{
3320
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3321
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3322
0
    const uint8_t* _frm_nxt = _frm;
3323
0
    uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3324
0
    uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3325
0
    uint16_t* _to_nxt = _to;
3326
0
    result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3327
0
    frm_nxt = frm + (_frm_nxt - _frm);
3328
0
    to_nxt = to + (_to_nxt - _to);
3329
0
    return r;
3330
0
}
3331
3332
codecvt<char16_t, char8_t, mbstate_t>::result
3333
codecvt<char16_t, char8_t, mbstate_t>::do_unshift(state_type&,
3334
    extern_type* to, extern_type*, extern_type*& to_nxt) const
3335
0
{
3336
0
    to_nxt = to;
3337
0
    return noconv;
3338
0
}
3339
3340
int
3341
codecvt<char16_t, char8_t, mbstate_t>::do_encoding() const noexcept
3342
0
{
3343
0
    return 0;
3344
0
}
3345
3346
bool
3347
codecvt<char16_t, char8_t, mbstate_t>::do_always_noconv() const noexcept
3348
0
{
3349
0
    return false;
3350
0
}
3351
3352
int
3353
codecvt<char16_t, char8_t, mbstate_t>::do_length(state_type&,
3354
    const extern_type* frm, const extern_type* frm_end, size_t mx) const
3355
0
{
3356
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3357
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3358
0
    return utf8_to_utf16_length(_frm, _frm_end, mx);
3359
0
}
3360
3361
int
3362
codecvt<char16_t, char8_t, mbstate_t>::do_max_length() const noexcept
3363
0
{
3364
0
    return 4;
3365
0
}
3366
3367
#endif
3368
3369
// template <> class codecvt<char32_t, char, mbstate_t>
3370
3371
locale::id codecvt<char32_t, char, mbstate_t>::id;
3372
3373
codecvt<char32_t, char, mbstate_t>::~codecvt()
3374
0
{
3375
0
}
3376
3377
codecvt<char32_t, char, mbstate_t>::result
3378
codecvt<char32_t, char, mbstate_t>::do_out(state_type&,
3379
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3380
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3381
0
{
3382
0
    const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3383
0
    const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3384
0
    const uint32_t* _frm_nxt = _frm;
3385
0
    uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3386
0
    uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3387
0
    uint8_t* _to_nxt = _to;
3388
0
    result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3389
0
    frm_nxt = frm + (_frm_nxt - _frm);
3390
0
    to_nxt = to + (_to_nxt - _to);
3391
0
    return r;
3392
0
}
3393
3394
codecvt<char32_t, char, mbstate_t>::result
3395
codecvt<char32_t, char, mbstate_t>::do_in(state_type&,
3396
    const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3397
    intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3398
0
{
3399
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3400
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3401
0
    const uint8_t* _frm_nxt = _frm;
3402
0
    uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3403
0
    uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3404
0
    uint32_t* _to_nxt = _to;
3405
0
    result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3406
0
    frm_nxt = frm + (_frm_nxt - _frm);
3407
0
    to_nxt = to + (_to_nxt - _to);
3408
0
    return r;
3409
0
}
3410
3411
codecvt<char32_t, char, mbstate_t>::result
3412
codecvt<char32_t, char, mbstate_t>::do_unshift(state_type&,
3413
    extern_type* to, extern_type*, extern_type*& to_nxt) const
3414
0
{
3415
0
    to_nxt = to;
3416
0
    return noconv;
3417
0
}
3418
3419
int
3420
codecvt<char32_t, char, mbstate_t>::do_encoding() const noexcept
3421
0
{
3422
0
    return 0;
3423
0
}
3424
3425
bool
3426
codecvt<char32_t, char, mbstate_t>::do_always_noconv() const noexcept
3427
0
{
3428
0
    return false;
3429
0
}
3430
3431
int
3432
codecvt<char32_t, char, mbstate_t>::do_length(state_type&,
3433
    const extern_type* frm, const extern_type* frm_end, size_t mx) const
3434
0
{
3435
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3436
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3437
0
    return utf8_to_ucs4_length(_frm, _frm_end, mx);
3438
0
}
3439
3440
int
3441
codecvt<char32_t, char, mbstate_t>::do_max_length() const noexcept
3442
0
{
3443
0
    return 4;
3444
0
}
3445
3446
#ifndef _LIBCPP_HAS_NO_CHAR8_T
3447
3448
// template <> class codecvt<char32_t, char8_t, mbstate_t>
3449
3450
locale::id codecvt<char32_t, char8_t, mbstate_t>::id;
3451
3452
codecvt<char32_t, char8_t, mbstate_t>::~codecvt()
3453
0
{
3454
0
}
3455
3456
codecvt<char32_t, char8_t, mbstate_t>::result
3457
codecvt<char32_t, char8_t, mbstate_t>::do_out(state_type&,
3458
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3459
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3460
0
{
3461
0
    const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3462
0
    const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3463
0
    const uint32_t* _frm_nxt = _frm;
3464
0
    uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3465
0
    uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3466
0
    uint8_t* _to_nxt = _to;
3467
0
    result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3468
0
    frm_nxt = frm + (_frm_nxt - _frm);
3469
0
    to_nxt = to + (_to_nxt - _to);
3470
0
    return r;
3471
0
}
3472
3473
codecvt<char32_t, char8_t, mbstate_t>::result
3474
codecvt<char32_t, char8_t, mbstate_t>::do_in(state_type&,
3475
    const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3476
    intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3477
0
{
3478
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3479
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3480
0
    const uint8_t* _frm_nxt = _frm;
3481
0
    uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3482
0
    uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3483
0
    uint32_t* _to_nxt = _to;
3484
0
    result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
3485
0
    frm_nxt = frm + (_frm_nxt - _frm);
3486
0
    to_nxt = to + (_to_nxt - _to);
3487
0
    return r;
3488
0
}
3489
3490
codecvt<char32_t, char8_t, mbstate_t>::result
3491
codecvt<char32_t, char8_t, mbstate_t>::do_unshift(state_type&,
3492
    extern_type* to, extern_type*, extern_type*& to_nxt) const
3493
0
{
3494
0
    to_nxt = to;
3495
0
    return noconv;
3496
0
}
3497
3498
int
3499
codecvt<char32_t, char8_t, mbstate_t>::do_encoding() const noexcept
3500
0
{
3501
0
    return 0;
3502
0
}
3503
3504
bool
3505
codecvt<char32_t, char8_t, mbstate_t>::do_always_noconv() const noexcept
3506
0
{
3507
0
    return false;
3508
0
}
3509
3510
int
3511
codecvt<char32_t, char8_t, mbstate_t>::do_length(state_type&,
3512
    const extern_type* frm, const extern_type* frm_end, size_t mx) const
3513
0
{
3514
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3515
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3516
0
    return utf8_to_ucs4_length(_frm, _frm_end, mx);
3517
0
}
3518
3519
int
3520
codecvt<char32_t, char8_t, mbstate_t>::do_max_length() const noexcept
3521
0
{
3522
0
    return 4;
3523
0
}
3524
3525
#endif
3526
3527
// __codecvt_utf8<wchar_t>
3528
3529
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3530
__codecvt_utf8<wchar_t>::result
3531
__codecvt_utf8<wchar_t>::do_out(state_type&,
3532
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3533
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3534
0
{
3535
#if defined(_LIBCPP_SHORT_WCHAR)
3536
    const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3537
    const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3538
    const uint16_t* _frm_nxt = _frm;
3539
#else
3540
0
    const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3541
0
    const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3542
0
    const uint32_t* _frm_nxt = _frm;
3543
0
#endif
3544
0
    uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3545
0
    uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3546
0
    uint8_t* _to_nxt = _to;
3547
#if defined(_LIBCPP_SHORT_WCHAR)
3548
    result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3549
                            _Maxcode_, _Mode_);
3550
#else
3551
0
    result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3552
0
                            _Maxcode_, _Mode_);
3553
0
#endif
3554
0
    frm_nxt = frm + (_frm_nxt - _frm);
3555
0
    to_nxt = to + (_to_nxt - _to);
3556
0
    return r;
3557
0
}
3558
3559
__codecvt_utf8<wchar_t>::result
3560
__codecvt_utf8<wchar_t>::do_in(state_type&,
3561
    const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3562
    intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3563
0
{
3564
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3565
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3566
0
    const uint8_t* _frm_nxt = _frm;
3567
#if defined(_LIBCPP_SHORT_WCHAR)
3568
    uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3569
    uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3570
    uint16_t* _to_nxt = _to;
3571
    result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3572
                            _Maxcode_, _Mode_);
3573
#else
3574
0
    uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3575
0
    uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3576
0
    uint32_t* _to_nxt = _to;
3577
0
    result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3578
0
                            _Maxcode_, _Mode_);
3579
0
#endif
3580
0
    frm_nxt = frm + (_frm_nxt - _frm);
3581
0
    to_nxt = to + (_to_nxt - _to);
3582
0
    return r;
3583
0
}
3584
3585
__codecvt_utf8<wchar_t>::result
3586
__codecvt_utf8<wchar_t>::do_unshift(state_type&,
3587
    extern_type* to, extern_type*, extern_type*& to_nxt) const
3588
0
{
3589
0
    to_nxt = to;
3590
0
    return noconv;
3591
0
}
3592
3593
int
3594
__codecvt_utf8<wchar_t>::do_encoding() const noexcept
3595
0
{
3596
0
    return 0;
3597
0
}
3598
3599
bool
3600
__codecvt_utf8<wchar_t>::do_always_noconv() const noexcept
3601
0
{
3602
0
    return false;
3603
0
}
3604
3605
int
3606
__codecvt_utf8<wchar_t>::do_length(state_type&,
3607
    const extern_type* frm, const extern_type* frm_end, size_t mx) const
3608
0
{
3609
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3610
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3611
#if defined(_LIBCPP_SHORT_WCHAR)
3612
    return utf8_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3613
#else
3614
0
    return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3615
0
#endif
3616
0
}
3617
3618
int
3619
__codecvt_utf8<wchar_t>::do_max_length() const noexcept
3620
0
{
3621
#if defined(_LIBCPP_SHORT_WCHAR)
3622
    if (_Mode_ & consume_header)
3623
        return 6;
3624
    return 3;
3625
#else
3626
0
    if (_Mode_ & consume_header)
3627
0
        return 7;
3628
0
    return 4;
3629
0
#endif
3630
0
}
3631
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
3632
3633
// __codecvt_utf8<char16_t>
3634
3635
__codecvt_utf8<char16_t>::result
3636
__codecvt_utf8<char16_t>::do_out(state_type&,
3637
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3638
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3639
0
{
3640
0
    const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3641
0
    const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3642
0
    const uint16_t* _frm_nxt = _frm;
3643
0
    uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3644
0
    uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3645
0
    uint8_t* _to_nxt = _to;
3646
0
    result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3647
0
                            _Maxcode_, _Mode_);
3648
0
    frm_nxt = frm + (_frm_nxt - _frm);
3649
0
    to_nxt = to + (_to_nxt - _to);
3650
0
    return r;
3651
0
}
3652
3653
__codecvt_utf8<char16_t>::result
3654
__codecvt_utf8<char16_t>::do_in(state_type&,
3655
    const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3656
    intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3657
0
{
3658
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3659
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3660
0
    const uint8_t* _frm_nxt = _frm;
3661
0
    uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3662
0
    uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3663
0
    uint16_t* _to_nxt = _to;
3664
0
    result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3665
0
                            _Maxcode_, _Mode_);
3666
0
    frm_nxt = frm + (_frm_nxt - _frm);
3667
0
    to_nxt = to + (_to_nxt - _to);
3668
0
    return r;
3669
0
}
3670
3671
__codecvt_utf8<char16_t>::result
3672
__codecvt_utf8<char16_t>::do_unshift(state_type&,
3673
    extern_type* to, extern_type*, extern_type*& to_nxt) const
3674
0
{
3675
0
    to_nxt = to;
3676
0
    return noconv;
3677
0
}
3678
3679
int
3680
__codecvt_utf8<char16_t>::do_encoding() const noexcept
3681
0
{
3682
0
    return 0;
3683
0
}
3684
3685
bool
3686
__codecvt_utf8<char16_t>::do_always_noconv() const noexcept
3687
0
{
3688
0
    return false;
3689
0
}
3690
3691
int
3692
__codecvt_utf8<char16_t>::do_length(state_type&,
3693
    const extern_type* frm, const extern_type* frm_end, size_t mx) const
3694
0
{
3695
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3696
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3697
0
    return utf8_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3698
0
}
3699
3700
int
3701
__codecvt_utf8<char16_t>::do_max_length() const noexcept
3702
0
{
3703
0
    if (_Mode_ & consume_header)
3704
0
        return 6;
3705
0
    return 3;
3706
0
}
3707
3708
// __codecvt_utf8<char32_t>
3709
3710
__codecvt_utf8<char32_t>::result
3711
__codecvt_utf8<char32_t>::do_out(state_type&,
3712
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3713
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3714
0
{
3715
0
    const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3716
0
    const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3717
0
    const uint32_t* _frm_nxt = _frm;
3718
0
    uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3719
0
    uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3720
0
    uint8_t* _to_nxt = _to;
3721
0
    result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3722
0
                            _Maxcode_, _Mode_);
3723
0
    frm_nxt = frm + (_frm_nxt - _frm);
3724
0
    to_nxt = to + (_to_nxt - _to);
3725
0
    return r;
3726
0
}
3727
3728
__codecvt_utf8<char32_t>::result
3729
__codecvt_utf8<char32_t>::do_in(state_type&,
3730
    const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3731
    intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3732
0
{
3733
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3734
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3735
0
    const uint8_t* _frm_nxt = _frm;
3736
0
    uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3737
0
    uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3738
0
    uint32_t* _to_nxt = _to;
3739
0
    result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3740
0
                            _Maxcode_, _Mode_);
3741
0
    frm_nxt = frm + (_frm_nxt - _frm);
3742
0
    to_nxt = to + (_to_nxt - _to);
3743
0
    return r;
3744
0
}
3745
3746
__codecvt_utf8<char32_t>::result
3747
__codecvt_utf8<char32_t>::do_unshift(state_type&,
3748
    extern_type* to, extern_type*, extern_type*& to_nxt) const
3749
0
{
3750
0
    to_nxt = to;
3751
0
    return noconv;
3752
0
}
3753
3754
int
3755
__codecvt_utf8<char32_t>::do_encoding() const noexcept
3756
0
{
3757
0
    return 0;
3758
0
}
3759
3760
bool
3761
__codecvt_utf8<char32_t>::do_always_noconv() const noexcept
3762
0
{
3763
0
    return false;
3764
0
}
3765
3766
int
3767
__codecvt_utf8<char32_t>::do_length(state_type&,
3768
    const extern_type* frm, const extern_type* frm_end, size_t mx) const
3769
0
{
3770
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3771
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3772
0
    return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3773
0
}
3774
3775
int
3776
__codecvt_utf8<char32_t>::do_max_length() const noexcept
3777
0
{
3778
0
    if (_Mode_ & consume_header)
3779
0
        return 7;
3780
0
    return 4;
3781
0
}
3782
3783
// __codecvt_utf16<wchar_t, false>
3784
3785
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
3786
__codecvt_utf16<wchar_t, false>::result
3787
__codecvt_utf16<wchar_t, false>::do_out(state_type&,
3788
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3789
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3790
0
{
3791
#if defined(_LIBCPP_SHORT_WCHAR)
3792
    const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3793
    const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3794
    const uint16_t* _frm_nxt = _frm;
3795
#else
3796
0
    const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3797
0
    const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3798
0
    const uint32_t* _frm_nxt = _frm;
3799
0
#endif
3800
0
    uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3801
0
    uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3802
0
    uint8_t* _to_nxt = _to;
3803
#if defined(_LIBCPP_SHORT_WCHAR)
3804
    result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3805
                               _Maxcode_, _Mode_);
3806
#else
3807
0
    result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3808
0
                               _Maxcode_, _Mode_);
3809
0
#endif
3810
0
    frm_nxt = frm + (_frm_nxt - _frm);
3811
0
    to_nxt = to + (_to_nxt - _to);
3812
0
    return r;
3813
0
}
3814
3815
__codecvt_utf16<wchar_t, false>::result
3816
__codecvt_utf16<wchar_t, false>::do_in(state_type&,
3817
    const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3818
    intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3819
0
{
3820
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3821
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3822
0
    const uint8_t* _frm_nxt = _frm;
3823
#if defined(_LIBCPP_SHORT_WCHAR)
3824
    uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3825
    uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3826
    uint16_t* _to_nxt = _to;
3827
    result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3828
                               _Maxcode_, _Mode_);
3829
#else
3830
0
    uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3831
0
    uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3832
0
    uint32_t* _to_nxt = _to;
3833
0
    result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3834
0
                               _Maxcode_, _Mode_);
3835
0
#endif
3836
0
    frm_nxt = frm + (_frm_nxt - _frm);
3837
0
    to_nxt = to + (_to_nxt - _to);
3838
0
    return r;
3839
0
}
3840
3841
__codecvt_utf16<wchar_t, false>::result
3842
__codecvt_utf16<wchar_t, false>::do_unshift(state_type&,
3843
    extern_type* to, extern_type*, extern_type*& to_nxt) const
3844
0
{
3845
0
    to_nxt = to;
3846
0
    return noconv;
3847
0
}
3848
3849
int
3850
__codecvt_utf16<wchar_t, false>::do_encoding() const noexcept
3851
0
{
3852
0
    return 0;
3853
0
}
3854
3855
bool
3856
__codecvt_utf16<wchar_t, false>::do_always_noconv() const noexcept
3857
0
{
3858
0
    return false;
3859
0
}
3860
3861
int
3862
__codecvt_utf16<wchar_t, false>::do_length(state_type&,
3863
    const extern_type* frm, const extern_type* frm_end, size_t mx) const
3864
0
{
3865
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3866
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3867
#if defined(_LIBCPP_SHORT_WCHAR)
3868
    return utf16be_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3869
#else
3870
0
    return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3871
0
#endif
3872
0
}
3873
3874
int
3875
__codecvt_utf16<wchar_t, false>::do_max_length() const noexcept
3876
0
{
3877
#if defined(_LIBCPP_SHORT_WCHAR)
3878
    if (_Mode_ & consume_header)
3879
        return 4;
3880
    return 2;
3881
#else
3882
0
    if (_Mode_ & consume_header)
3883
0
        return 6;
3884
0
    return 4;
3885
0
#endif
3886
0
}
3887
3888
// __codecvt_utf16<wchar_t, true>
3889
3890
__codecvt_utf16<wchar_t, true>::result
3891
__codecvt_utf16<wchar_t, true>::do_out(state_type&,
3892
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3893
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3894
0
{
3895
#if defined(_LIBCPP_SHORT_WCHAR)
3896
    const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
3897
    const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
3898
    const uint16_t* _frm_nxt = _frm;
3899
#else
3900
0
    const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
3901
0
    const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
3902
0
    const uint32_t* _frm_nxt = _frm;
3903
0
#endif
3904
0
    uint8_t* _to = reinterpret_cast<uint8_t*>(to);
3905
0
    uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
3906
0
    uint8_t* _to_nxt = _to;
3907
#if defined(_LIBCPP_SHORT_WCHAR)
3908
    result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3909
                               _Maxcode_, _Mode_);
3910
#else
3911
0
    result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3912
0
                               _Maxcode_, _Mode_);
3913
0
#endif
3914
0
    frm_nxt = frm + (_frm_nxt - _frm);
3915
0
    to_nxt = to + (_to_nxt - _to);
3916
0
    return r;
3917
0
}
3918
3919
__codecvt_utf16<wchar_t, true>::result
3920
__codecvt_utf16<wchar_t, true>::do_in(state_type&,
3921
    const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
3922
    intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
3923
0
{
3924
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3925
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3926
0
    const uint8_t* _frm_nxt = _frm;
3927
#if defined(_LIBCPP_SHORT_WCHAR)
3928
    uint16_t* _to = reinterpret_cast<uint16_t*>(to);
3929
    uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
3930
    uint16_t* _to_nxt = _to;
3931
    result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3932
                               _Maxcode_, _Mode_);
3933
#else
3934
0
    uint32_t* _to = reinterpret_cast<uint32_t*>(to);
3935
0
    uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
3936
0
    uint32_t* _to_nxt = _to;
3937
0
    result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
3938
0
                               _Maxcode_, _Mode_);
3939
0
#endif
3940
0
    frm_nxt = frm + (_frm_nxt - _frm);
3941
0
    to_nxt = to + (_to_nxt - _to);
3942
0
    return r;
3943
0
}
3944
3945
__codecvt_utf16<wchar_t, true>::result
3946
__codecvt_utf16<wchar_t, true>::do_unshift(state_type&,
3947
    extern_type* to, extern_type*, extern_type*& to_nxt) const
3948
0
{
3949
0
    to_nxt = to;
3950
0
    return noconv;
3951
0
}
3952
3953
int
3954
__codecvt_utf16<wchar_t, true>::do_encoding() const noexcept
3955
0
{
3956
0
    return 0;
3957
0
}
3958
3959
bool
3960
__codecvt_utf16<wchar_t, true>::do_always_noconv() const noexcept
3961
0
{
3962
0
    return false;
3963
0
}
3964
3965
int
3966
__codecvt_utf16<wchar_t, true>::do_length(state_type&,
3967
    const extern_type* frm, const extern_type* frm_end, size_t mx) const
3968
0
{
3969
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
3970
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
3971
#if defined(_LIBCPP_SHORT_WCHAR)
3972
    return utf16le_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3973
#else
3974
0
    return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
3975
0
#endif
3976
0
}
3977
3978
int
3979
__codecvt_utf16<wchar_t, true>::do_max_length() const noexcept
3980
0
{
3981
#if defined(_LIBCPP_SHORT_WCHAR)
3982
    if (_Mode_ & consume_header)
3983
        return 4;
3984
    return 2;
3985
#else
3986
0
    if (_Mode_ & consume_header)
3987
0
        return 6;
3988
0
    return 4;
3989
0
#endif
3990
0
}
3991
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
3992
3993
// __codecvt_utf16<char16_t, false>
3994
3995
__codecvt_utf16<char16_t, false>::result
3996
__codecvt_utf16<char16_t, false>::do_out(state_type&,
3997
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
3998
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
3999
0
{
4000
0
    const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
4001
0
    const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
4002
0
    const uint16_t* _frm_nxt = _frm;
4003
0
    uint8_t* _to = reinterpret_cast<uint8_t*>(to);
4004
0
    uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
4005
0
    uint8_t* _to_nxt = _to;
4006
0
    result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4007
0
                               _Maxcode_, _Mode_);
4008
0
    frm_nxt = frm + (_frm_nxt - _frm);
4009
0
    to_nxt = to + (_to_nxt - _to);
4010
0
    return r;
4011
0
}
4012
4013
__codecvt_utf16<char16_t, false>::result
4014
__codecvt_utf16<char16_t, false>::do_in(state_type&,
4015
    const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
4016
    intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
4017
0
{
4018
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4019
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4020
0
    const uint8_t* _frm_nxt = _frm;
4021
0
    uint16_t* _to = reinterpret_cast<uint16_t*>(to);
4022
0
    uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
4023
0
    uint16_t* _to_nxt = _to;
4024
0
    result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4025
0
                               _Maxcode_, _Mode_);
4026
0
    frm_nxt = frm + (_frm_nxt - _frm);
4027
0
    to_nxt = to + (_to_nxt - _to);
4028
0
    return r;
4029
0
}
4030
4031
__codecvt_utf16<char16_t, false>::result
4032
__codecvt_utf16<char16_t, false>::do_unshift(state_type&,
4033
    extern_type* to, extern_type*, extern_type*& to_nxt) const
4034
0
{
4035
0
    to_nxt = to;
4036
0
    return noconv;
4037
0
}
4038
4039
int
4040
__codecvt_utf16<char16_t, false>::do_encoding() const noexcept
4041
0
{
4042
0
    return 0;
4043
0
}
4044
4045
bool
4046
__codecvt_utf16<char16_t, false>::do_always_noconv() const noexcept
4047
0
{
4048
0
    return false;
4049
0
}
4050
4051
int
4052
__codecvt_utf16<char16_t, false>::do_length(state_type&,
4053
    const extern_type* frm, const extern_type* frm_end, size_t mx) const
4054
0
{
4055
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4056
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4057
0
    return utf16be_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
4058
0
}
4059
4060
int
4061
__codecvt_utf16<char16_t, false>::do_max_length() const noexcept
4062
0
{
4063
0
    if (_Mode_ & consume_header)
4064
0
        return 4;
4065
0
    return 2;
4066
0
}
4067
4068
// __codecvt_utf16<char16_t, true>
4069
4070
__codecvt_utf16<char16_t, true>::result
4071
__codecvt_utf16<char16_t, true>::do_out(state_type&,
4072
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
4073
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
4074
0
{
4075
0
    const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
4076
0
    const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
4077
0
    const uint16_t* _frm_nxt = _frm;
4078
0
    uint8_t* _to = reinterpret_cast<uint8_t*>(to);
4079
0
    uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
4080
0
    uint8_t* _to_nxt = _to;
4081
0
    result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4082
0
                               _Maxcode_, _Mode_);
4083
0
    frm_nxt = frm + (_frm_nxt - _frm);
4084
0
    to_nxt = to + (_to_nxt - _to);
4085
0
    return r;
4086
0
}
4087
4088
__codecvt_utf16<char16_t, true>::result
4089
__codecvt_utf16<char16_t, true>::do_in(state_type&,
4090
    const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
4091
    intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
4092
0
{
4093
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4094
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4095
0
    const uint8_t* _frm_nxt = _frm;
4096
0
    uint16_t* _to = reinterpret_cast<uint16_t*>(to);
4097
0
    uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
4098
0
    uint16_t* _to_nxt = _to;
4099
0
    result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4100
0
                               _Maxcode_, _Mode_);
4101
0
    frm_nxt = frm + (_frm_nxt - _frm);
4102
0
    to_nxt = to + (_to_nxt - _to);
4103
0
    return r;
4104
0
}
4105
4106
__codecvt_utf16<char16_t, true>::result
4107
__codecvt_utf16<char16_t, true>::do_unshift(state_type&,
4108
    extern_type* to, extern_type*, extern_type*& to_nxt) const
4109
0
{
4110
0
    to_nxt = to;
4111
0
    return noconv;
4112
0
}
4113
4114
int
4115
__codecvt_utf16<char16_t, true>::do_encoding() const noexcept
4116
0
{
4117
0
    return 0;
4118
0
}
4119
4120
bool
4121
__codecvt_utf16<char16_t, true>::do_always_noconv() const noexcept
4122
0
{
4123
0
    return false;
4124
0
}
4125
4126
int
4127
__codecvt_utf16<char16_t, true>::do_length(state_type&,
4128
    const extern_type* frm, const extern_type* frm_end, size_t mx) const
4129
0
{
4130
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4131
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4132
0
    return utf16le_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
4133
0
}
4134
4135
int
4136
__codecvt_utf16<char16_t, true>::do_max_length() const noexcept
4137
0
{
4138
0
    if (_Mode_ & consume_header)
4139
0
        return 4;
4140
0
    return 2;
4141
0
}
4142
4143
// __codecvt_utf16<char32_t, false>
4144
4145
__codecvt_utf16<char32_t, false>::result
4146
__codecvt_utf16<char32_t, false>::do_out(state_type&,
4147
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
4148
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
4149
0
{
4150
0
    const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
4151
0
    const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
4152
0
    const uint32_t* _frm_nxt = _frm;
4153
0
    uint8_t* _to = reinterpret_cast<uint8_t*>(to);
4154
0
    uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
4155
0
    uint8_t* _to_nxt = _to;
4156
0
    result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4157
0
                               _Maxcode_, _Mode_);
4158
0
    frm_nxt = frm + (_frm_nxt - _frm);
4159
0
    to_nxt = to + (_to_nxt - _to);
4160
0
    return r;
4161
0
}
4162
4163
__codecvt_utf16<char32_t, false>::result
4164
__codecvt_utf16<char32_t, false>::do_in(state_type&,
4165
    const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
4166
    intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
4167
0
{
4168
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4169
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4170
0
    const uint8_t* _frm_nxt = _frm;
4171
0
    uint32_t* _to = reinterpret_cast<uint32_t*>(to);
4172
0
    uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
4173
0
    uint32_t* _to_nxt = _to;
4174
0
    result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4175
0
                               _Maxcode_, _Mode_);
4176
0
    frm_nxt = frm + (_frm_nxt - _frm);
4177
0
    to_nxt = to + (_to_nxt - _to);
4178
0
    return r;
4179
0
}
4180
4181
__codecvt_utf16<char32_t, false>::result
4182
__codecvt_utf16<char32_t, false>::do_unshift(state_type&,
4183
    extern_type* to, extern_type*, extern_type*& to_nxt) const
4184
0
{
4185
0
    to_nxt = to;
4186
0
    return noconv;
4187
0
}
4188
4189
int
4190
__codecvt_utf16<char32_t, false>::do_encoding() const noexcept
4191
0
{
4192
0
    return 0;
4193
0
}
4194
4195
bool
4196
__codecvt_utf16<char32_t, false>::do_always_noconv() const noexcept
4197
0
{
4198
0
    return false;
4199
0
}
4200
4201
int
4202
__codecvt_utf16<char32_t, false>::do_length(state_type&,
4203
    const extern_type* frm, const extern_type* frm_end, size_t mx) const
4204
0
{
4205
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4206
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4207
0
    return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
4208
0
}
4209
4210
int
4211
__codecvt_utf16<char32_t, false>::do_max_length() const noexcept
4212
0
{
4213
0
    if (_Mode_ & consume_header)
4214
0
        return 6;
4215
0
    return 4;
4216
0
}
4217
4218
// __codecvt_utf16<char32_t, true>
4219
4220
__codecvt_utf16<char32_t, true>::result
4221
__codecvt_utf16<char32_t, true>::do_out(state_type&,
4222
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
4223
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
4224
0
{
4225
0
    const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
4226
0
    const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
4227
0
    const uint32_t* _frm_nxt = _frm;
4228
0
    uint8_t* _to = reinterpret_cast<uint8_t*>(to);
4229
0
    uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
4230
0
    uint8_t* _to_nxt = _to;
4231
0
    result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4232
0
                               _Maxcode_, _Mode_);
4233
0
    frm_nxt = frm + (_frm_nxt - _frm);
4234
0
    to_nxt = to + (_to_nxt - _to);
4235
0
    return r;
4236
0
}
4237
4238
__codecvt_utf16<char32_t, true>::result
4239
__codecvt_utf16<char32_t, true>::do_in(state_type&,
4240
    const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
4241
    intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
4242
0
{
4243
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4244
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4245
0
    const uint8_t* _frm_nxt = _frm;
4246
0
    uint32_t* _to = reinterpret_cast<uint32_t*>(to);
4247
0
    uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
4248
0
    uint32_t* _to_nxt = _to;
4249
0
    result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4250
0
                               _Maxcode_, _Mode_);
4251
0
    frm_nxt = frm + (_frm_nxt - _frm);
4252
0
    to_nxt = to + (_to_nxt - _to);
4253
0
    return r;
4254
0
}
4255
4256
__codecvt_utf16<char32_t, true>::result
4257
__codecvt_utf16<char32_t, true>::do_unshift(state_type&,
4258
    extern_type* to, extern_type*, extern_type*& to_nxt) const
4259
0
{
4260
0
    to_nxt = to;
4261
0
    return noconv;
4262
0
}
4263
4264
int
4265
__codecvt_utf16<char32_t, true>::do_encoding() const noexcept
4266
0
{
4267
0
    return 0;
4268
0
}
4269
4270
bool
4271
__codecvt_utf16<char32_t, true>::do_always_noconv() const noexcept
4272
0
{
4273
0
    return false;
4274
0
}
4275
4276
int
4277
__codecvt_utf16<char32_t, true>::do_length(state_type&,
4278
    const extern_type* frm, const extern_type* frm_end, size_t mx) const
4279
0
{
4280
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4281
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4282
0
    return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
4283
0
}
4284
4285
int
4286
__codecvt_utf16<char32_t, true>::do_max_length() const noexcept
4287
0
{
4288
0
    if (_Mode_ & consume_header)
4289
0
        return 6;
4290
0
    return 4;
4291
0
}
4292
4293
// __codecvt_utf8_utf16<wchar_t>
4294
4295
#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4296
__codecvt_utf8_utf16<wchar_t>::result
4297
__codecvt_utf8_utf16<wchar_t>::do_out(state_type&,
4298
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
4299
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
4300
0
{
4301
#if defined(_LIBCPP_SHORT_WCHAR)
4302
    const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
4303
    const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
4304
    const uint16_t* _frm_nxt = _frm;
4305
#else
4306
0
    const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
4307
0
    const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
4308
0
    const uint32_t* _frm_nxt = _frm;
4309
0
#endif
4310
0
    uint8_t* _to = reinterpret_cast<uint8_t*>(to);
4311
0
    uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
4312
0
    uint8_t* _to_nxt = _to;
4313
0
    result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4314
0
                             _Maxcode_, _Mode_);
4315
0
    frm_nxt = frm + (_frm_nxt - _frm);
4316
0
    to_nxt = to + (_to_nxt - _to);
4317
0
    return r;
4318
0
}
4319
4320
__codecvt_utf8_utf16<wchar_t>::result
4321
__codecvt_utf8_utf16<wchar_t>::do_in(state_type&,
4322
    const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
4323
    intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
4324
0
{
4325
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4326
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4327
0
    const uint8_t* _frm_nxt = _frm;
4328
#if defined(_LIBCPP_SHORT_WCHAR)
4329
    uint16_t* _to = reinterpret_cast<uint16_t*>(to);
4330
    uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
4331
    uint16_t* _to_nxt = _to;
4332
#else
4333
0
    uint32_t* _to = reinterpret_cast<uint32_t*>(to);
4334
0
    uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
4335
0
    uint32_t* _to_nxt = _to;
4336
0
#endif
4337
0
    result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
4338
0
                             _Maxcode_, _Mode_);
4339
0
    frm_nxt = frm + (_frm_nxt - _frm);
4340
0
    to_nxt = to + (_to_nxt - _to);
4341
0
    return r;
4342
0
}
4343
4344
__codecvt_utf8_utf16<wchar_t>::result
4345
__codecvt_utf8_utf16<wchar_t>::do_unshift(state_type&,
4346
    extern_type* to, extern_type*, extern_type*& to_nxt) const
4347
0
{
4348
0
    to_nxt = to;
4349
0
    return noconv;
4350
0
}
4351
4352
int
4353
__codecvt_utf8_utf16<wchar_t>::do_encoding() const noexcept
4354
0
{
4355
0
    return 0;
4356
0
}
4357
4358
bool
4359
__codecvt_utf8_utf16<wchar_t>::do_always_noconv() const noexcept
4360
0
{
4361
0
    return false;
4362
0
}
4363
4364
int
4365
__codecvt_utf8_utf16<wchar_t>::do_length(state_type&,
4366
    const extern_type* frm, const extern_type* frm_end, size_t mx) const
4367
0
{
4368
0
    const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
4369
0
    const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
4370
0
    return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
4371
0
}
4372
4373
int
4374
__codecvt_utf8_utf16<wchar_t>::do_max_length() const noexcept
4375
0
{
4376
0
    if (_Mode_ & consume_header)
4377
0
        return 7;
4378
0
    return 4;
4379
0
}
4380
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
4381
4382
// __codecvt_utf8_utf16<char16_t>
4383
4384
__codecvt_utf8_utf16<char16_t>::result
4385
__codecvt_utf8_utf16<char16_t>::do_out(state_type&,
4386
    const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
4387
    extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
4388
0
{