Coverage Report

Created: 2021-08-24 07:12

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