Coverage Report

Created: 2021-01-19 06:58

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