Coverage Report

Created: 2020-09-19 12:23

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