Coverage Report

Created: 2022-07-16 07:03

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