Coverage Report

Created: 2020-07-11 14:00

/Users/buildslave/jenkins/workspace/coverage/llvm-project/libcxx/include/__locale
Line
Count
Source (jump to first uncovered line)
1
// -*- C++ -*-
2
//===----------------------------------------------------------------------===//
3
//
4
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5
// See https://llvm.org/LICENSE.txt for license information.
6
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef _LIBCPP___LOCALE
11
#define _LIBCPP___LOCALE
12
13
#include <__config>
14
#include <string>
15
#include <memory>
16
#include <utility>
17
#include <mutex>
18
#include <cstdint>
19
#include <cctype>
20
#include <locale.h>
21
#if defined(_LIBCPP_MSVCRT_LIKE)
22
# include <cstring>
23
# include <support/win32/locale_win32.h>
24
#elif defined(_AIX)
25
# include <support/ibm/xlocale.h>
26
#elif defined(__ANDROID__)
27
# include <support/android/locale_bionic.h>
28
#elif defined(__sun__)
29
# include <xlocale.h>
30
# include <support/solaris/xlocale.h>
31
#elif defined(_NEWLIB_VERSION)
32
# include <support/newlib/xlocale.h>
33
#elif (defined(__APPLE__)      || defined(__FreeBSD__) \
34
    || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
35
# include <xlocale.h>
36
#elif defined(__Fuchsia__)
37
# include <support/fuchsia/xlocale.h>
38
#elif defined(__wasi__)
39
// WASI libc uses musl's locales support.
40
# include <support/musl/xlocale.h>
41
#elif defined(_LIBCPP_HAS_MUSL_LIBC)
42
# include <support/musl/xlocale.h>
43
#endif
44
45
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
46
#pragma GCC system_header
47
#endif
48
49
_LIBCPP_BEGIN_NAMESPACE_STD
50
51
#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
52
struct __libcpp_locale_guard {
53
  _LIBCPP_INLINE_VISIBILITY
54
  __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
55
56
  _LIBCPP_INLINE_VISIBILITY
57
  ~__libcpp_locale_guard() {
58
    if (__old_loc_)
59
      uselocale(__old_loc_);
60
  }
61
62
  locale_t __old_loc_;
63
private:
64
  __libcpp_locale_guard(__libcpp_locale_guard const&);
65
  __libcpp_locale_guard& operator=(__libcpp_locale_guard const&);
66
};
67
#elif defined(_LIBCPP_MSVCRT_LIKE)
68
struct __libcpp_locale_guard {
69
    __libcpp_locale_guard(locale_t __l) :
70
        __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) {
71
      // Setting the locale can be expensive even when the locale given is
72
      // already the current locale, so do an explicit check to see if the
73
      // current locale is already the one we want.
74
      const char* __lc = __setlocale(nullptr);
75
      // If every category is the same, the locale string will simply be the
76
      // locale name, otherwise it will be a semicolon-separated string listing
77
      // each category.  In the second case, we know at least one category won't
78
      // be what we want, so we only have to check the first case.
79
      if (strcmp(__l.__get_locale(), __lc) != 0) {
80
        __locale_all = _strdup(__lc);
81
        if (__locale_all == nullptr)
82
          __throw_bad_alloc();
83
        __setlocale(__l.__get_locale());
84
      }
85
    }
86
    ~__libcpp_locale_guard() {
87
      // The CRT documentation doesn't explicitly say, but setlocale() does the
88
      // right thing when given a semicolon-separated list of locale settings
89
      // for the different categories in the same format as returned by
90
      // setlocale(LC_ALL, nullptr).
91
      if (__locale_all != nullptr) {
92
        __setlocale(__locale_all);
93
        free(__locale_all);
94
      }
95
      _configthreadlocale(__status);
96
    }
97
    static const char* __setlocale(const char* __locale) {
98
      const char* __new_locale = setlocale(LC_ALL, __locale);
99
      if (__new_locale == nullptr)
100
        __throw_bad_alloc();
101
      return __new_locale;
102
    }
103
    int __status;
104
    char* __locale_all = nullptr;
105
};
106
#endif
107
108
109
class _LIBCPP_TYPE_VIS locale;
110
111
template <class _Facet>
112
_LIBCPP_INLINE_VISIBILITY
113
bool
114
has_facet(const locale&) _NOEXCEPT;
115
116
template <class _Facet>
117
_LIBCPP_INLINE_VISIBILITY
118
const _Facet&
119
use_facet(const locale&);
120
121
class _LIBCPP_TYPE_VIS locale
122
{
123
public:
124
    // types:
125
    class _LIBCPP_TYPE_VIS facet;
126
    class _LIBCPP_TYPE_VIS id;
127
128
    typedef int category;
129
    _LIBCPP_AVAILABILITY_LOCALE_CATEGORY
130
    static const category // values assigned here are for exposition only
131
        none     = 0,
132
        collate  = LC_COLLATE_MASK,
133
        ctype    = LC_CTYPE_MASK,
134
        monetary = LC_MONETARY_MASK,
135
        numeric  = LC_NUMERIC_MASK,
136
        time     = LC_TIME_MASK,
137
        messages = LC_MESSAGES_MASK,
138
        all = collate | ctype | monetary | numeric | time | messages;
139
140
    // construct/copy/destroy:
141
    locale()  _NOEXCEPT;
142
    locale(const locale&)  _NOEXCEPT;
143
    explicit locale(const char*);
144
    explicit locale(const string&);
145
    locale(const locale&, const char*, category);
146
    locale(const locale&, const string&, category);
147
    template <class _Facet>
148
        _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
149
    locale(const locale&, const locale&, category);
150
151
    ~locale();
152
153
    const locale& operator=(const locale&)  _NOEXCEPT;
154
155
    template <class _Facet>
156
      _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
157
      locale combine(const locale&) const;
158
159
    // locale operations:
160
    string name() const;
161
    bool operator==(const locale&) const;
162
0
    bool operator!=(const locale& __y) const {return !(*this == __y);}
163
    template <class _CharT, class _Traits, class _Allocator>
164
      _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
165
      bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
166
                      const basic_string<_CharT, _Traits, _Allocator>&) const;
167
168
    // global locale objects:
169
    static locale global(const locale&);
170
    static const locale& classic();
171
172
private:
173
    class __imp;
174
    __imp* __locale_;
175
176
    void __install_ctor(const locale&, facet*, long);
177
    static locale& __global();
178
    bool has_facet(id&) const;
179
    const facet* use_facet(id&) const;
180
181
    template <class _Facet> friend bool has_facet(const locale&)  _NOEXCEPT;
182
    template <class _Facet> friend const _Facet& use_facet(const locale&);
183
};
184
185
class _LIBCPP_TYPE_VIS locale::facet
186
    : public __shared_count
187
{
188
protected:
189
    _LIBCPP_INLINE_VISIBILITY
190
    explicit facet(size_t __refs = 0)
191
246k
        : __shared_count(static_cast<long>(__refs)-1) {}
192
193
    virtual ~facet();
194
195
//    facet(const facet&) = delete;     // effectively done in __shared_count
196
//    void operator=(const facet&) = delete;
197
private:
198
    virtual void __on_zero_shared() _NOEXCEPT;
199
};
200
201
class _LIBCPP_TYPE_VIS locale::id
202
{
203
    once_flag      __flag_;
204
    int32_t        __id_;
205
206
    static int32_t __next_id;
207
public:
208
0
    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
209
private:
210
    void __init();
211
    void operator=(const id&); // = delete;
212
    id(const id&); // = delete;
213
public:  // only needed for tests
214
    long __get();
215
216
    friend class locale;
217
    friend class locale::__imp;
218
};
219
220
template <class _Facet>
221
inline _LIBCPP_INLINE_VISIBILITY
222
locale::locale(const locale& __other, _Facet* __f)
223
{
224
    __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
225
}
226
227
template <class _Facet>
228
locale
229
locale::combine(const locale& __other) const
230
{
231
    if (!_VSTD::has_facet<_Facet>(__other))
232
        __throw_runtime_error("locale::combine: locale missing facet");
233
234
    return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
235
}
236
237
template <class _Facet>
238
inline _LIBCPP_INLINE_VISIBILITY
239
bool
240
has_facet(const locale& __l)  _NOEXCEPT
241
{
242
    return __l.has_facet(_Facet::id);
243
}
244
245
template <class _Facet>
246
inline _LIBCPP_INLINE_VISIBILITY
247
const _Facet&
248
use_facet(const locale& __l)
249
19.7M
{
250
19.7M
    return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
251
19.7M
}
std::__1::ctype<char> const& std::__1::use_facet<std::__1::ctype<char> >(std::__1::locale const&)
Line
Count
Source
249
16.5M
{
250
16.5M
    return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
251
16.5M
}
Unexecuted instantiation: std::__1::num_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > > const& std::__1::use_facet<std::__1::num_get<char, std::__1::istreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::locale const&)
std::__1::ctype<wchar_t> const& std::__1::use_facet<std::__1::ctype<wchar_t> >(std::__1::locale const&)
Line
Count
Source
249
8
{
250
8
    return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
251
8
}
Unexecuted instantiation: std::__1::num_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > const& std::__1::use_facet<std::__1::num_get<wchar_t, std::__1::istreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::locale const&)
std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > > const& std::__1::use_facet<std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > > >(std::__1::locale const&)
Line
Count
Source
249
3.06M
{
250
3.06M
    return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
251
3.06M
}
Unexecuted instantiation: std::__1::num_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > const& std::__1::use_facet<std::__1::num_put<wchar_t, std::__1::ostreambuf_iterator<wchar_t, std::__1::char_traits<wchar_t> > > >(std::__1::locale const&)
std::__1::codecvt<char, char, __mbstate_t> const& std::__1::use_facet<std::__1::codecvt<char, char, __mbstate_t> >(std::__1::locale const&)
Line
Count
Source
249
25.6k
{
250
25.6k
    return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
251
25.6k
}
std::__1::codecvt<wchar_t, char, __mbstate_t> const& std::__1::use_facet<std::__1::codecvt<wchar_t, char, __mbstate_t> >(std::__1::locale const&)
Line
Count
Source
249
25.5k
{
250
25.5k
    return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
251
25.5k
}
std::__1::numpunct<char> const& std::__1::use_facet<std::__1::numpunct<char> >(std::__1::locale const&)
Line
Count
Source
249
57.3k
{
250
57.3k
    return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
251
57.3k
}
Unexecuted instantiation: std::__1::numpunct<wchar_t> const& std::__1::use_facet<std::__1::numpunct<wchar_t> >(std::__1::locale const&)
Unexecuted instantiation: std::__1::moneypunct<char, true> const& std::__1::use_facet<std::__1::moneypunct<char, true> >(std::__1::locale const&)
Unexecuted instantiation: std::__1::moneypunct<char, false> const& std::__1::use_facet<std::__1::moneypunct<char, false> >(std::__1::locale const&)
Unexecuted instantiation: std::__1::moneypunct<wchar_t, true> const& std::__1::use_facet<std::__1::moneypunct<wchar_t, true> >(std::__1::locale const&)
Unexecuted instantiation: std::__1::moneypunct<wchar_t, false> const& std::__1::use_facet<std::__1::moneypunct<wchar_t, false> >(std::__1::locale const&)
252
253
// template <class _CharT> class collate;
254
255
template <class _CharT>
256
class _LIBCPP_TEMPLATE_VIS collate
257
    : public locale::facet
258
{
259
public:
260
    typedef _CharT char_type;
261
    typedef basic_string<char_type> string_type;
262
263
    _LIBCPP_INLINE_VISIBILITY
264
    explicit collate(size_t __refs = 0)
265
17.0k
        : locale::facet(__refs) {}
std::__1::collate<char>::collate(unsigned long)
Line
Count
Source
265
8.50k
        : locale::facet(__refs) {}
std::__1::collate<wchar_t>::collate(unsigned long)
Line
Count
Source
265
8.50k
        : locale::facet(__refs) {}
266
267
    _LIBCPP_INLINE_VISIBILITY
268
    int compare(const char_type* __lo1, const char_type* __hi1,
269
                const char_type* __lo2, const char_type* __hi2) const
270
    {
271
        return do_compare(__lo1, __hi1, __lo2, __hi2);
272
    }
273
274
    // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work
275
    // around a dllimport bug that expects an external instantiation.
276
    _LIBCPP_INLINE_VISIBILITY
277
    _LIBCPP_ALWAYS_INLINE
278
    string_type transform(const char_type* __lo, const char_type* __hi) const
279
    {
280
        return do_transform(__lo, __hi);
281
    }
282
283
    _LIBCPP_INLINE_VISIBILITY
284
    long hash(const char_type* __lo, const char_type* __hi) const
285
    {
286
        return do_hash(__lo, __hi);
287
    }
288
289
    static locale::id id;
290
291
protected:
292
    ~collate();
293
    virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
294
                           const char_type* __lo2, const char_type* __hi2) const;
295
    virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
296
0
        {return string_type(__lo, __hi);}
Unexecuted instantiation: std::__1::collate<char>::do_transform(char const*, char const*) const
Unexecuted instantiation: std::__1::collate<wchar_t>::do_transform(wchar_t const*, wchar_t const*) const
297
    virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
298
};
299
300
template <class _CharT> locale::id collate<_CharT>::id;
301
302
template <class _CharT>
303
collate<_CharT>::~collate()
304
0
{
305
0
}
Unexecuted instantiation: std::__1::collate<char>::~collate()
Unexecuted instantiation: std::__1::collate<wchar_t>::~collate()
306
307
template <class _CharT>
308
int
309
collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
310
                            const char_type* __lo2, const char_type* __hi2) const
311
0
{
312
0
    for (; __lo2 != __hi2; ++__lo1, ++__lo2)
313
0
    {
314
0
        if (__lo1 == __hi1 || *__lo1 < *__lo2)
315
0
            return -1;
316
0
        if (*__lo2 < *__lo1)
317
0
            return 1;
318
0
    }
319
0
    return __lo1 != __hi1;
320
0
}
Unexecuted instantiation: std::__1::collate<char>::do_compare(char const*, char const*, char const*, char const*) const
Unexecuted instantiation: std::__1::collate<wchar_t>::do_compare(wchar_t const*, wchar_t const*, wchar_t const*, wchar_t const*) const
321
322
template <class _CharT>
323
long
324
collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
325
0
{
326
0
    size_t __h = 0;
327
0
    const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
328
0
    const size_t __mask = size_t(0xF) << (__sr + 4);
329
0
    for(const char_type* __p = __lo; __p != __hi; ++__p)
330
0
    {
331
0
        __h = (__h << 4) + static_cast<size_t>(*__p);
332
0
        size_t __g = __h & __mask;
333
0
        __h ^= __g | (__g >> __sr);
334
0
    }
335
0
    return static_cast<long>(__h);
336
0
}
Unexecuted instantiation: std::__1::collate<char>::do_hash(char const*, char const*) const
Unexecuted instantiation: std::__1::collate<wchar_t>::do_hash(wchar_t const*, wchar_t const*) const
337
338
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>)
339
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>)
340
341
// template <class CharT> class collate_byname;
342
343
template <class _CharT> class _LIBCPP_TEMPLATE_VIS collate_byname;
344
345
template <>
346
class _LIBCPP_TYPE_VIS collate_byname<char>
347
    : public collate<char>
348
{
349
    locale_t __l;
350
public:
351
    typedef char char_type;
352
    typedef basic_string<char_type> string_type;
353
354
    explicit collate_byname(const char* __n, size_t __refs = 0);
355
    explicit collate_byname(const string& __n, size_t __refs = 0);
356
357
protected:
358
    ~collate_byname();
359
    virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
360
                           const char_type* __lo2, const char_type* __hi2) const;
361
    virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
362
};
363
364
template <>
365
class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
366
    : public collate<wchar_t>
367
{
368
    locale_t __l;
369
public:
370
    typedef wchar_t char_type;
371
    typedef basic_string<char_type> string_type;
372
373
    explicit collate_byname(const char* __n, size_t __refs = 0);
374
    explicit collate_byname(const string& __n, size_t __refs = 0);
375
376
protected:
377
    ~collate_byname();
378
379
    virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
380
                           const char_type* __lo2, const char_type* __hi2) const;
381
    virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
382
};
383
384
template <class _CharT, class _Traits, class _Allocator>
385
bool
386
locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
387
                   const basic_string<_CharT, _Traits, _Allocator>& __y) const
388
{
389
    return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
390
                                       __x.data(), __x.data() + __x.size(),
391
                                       __y.data(), __y.data() + __y.size()) < 0;
392
}
393
394
// template <class charT> class ctype
395
396
class _LIBCPP_TYPE_VIS ctype_base
397
{
398
public:
399
#if defined(__GLIBC__)
400
    typedef unsigned short mask;
401
    static const mask space  = _ISspace;
402
    static const mask print  = _ISprint;
403
    static const mask cntrl  = _IScntrl;
404
    static const mask upper  = _ISupper;
405
    static const mask lower  = _ISlower;
406
    static const mask alpha  = _ISalpha;
407
    static const mask digit  = _ISdigit;
408
    static const mask punct  = _ISpunct;
409
    static const mask xdigit = _ISxdigit;
410
    static const mask blank  = _ISblank;
411
#if defined(__mips__)
412
    static const mask __regex_word = static_cast<mask>(_ISbit(15));
413
#else
414
    static const mask __regex_word = 0x80;
415
#endif
416
#elif defined(_LIBCPP_MSVCRT_LIKE)
417
    typedef unsigned short mask;
418
    static const mask space  = _SPACE;
419
    static const mask print  = _BLANK|_PUNCT|_ALPHA|_DIGIT;
420
    static const mask cntrl  = _CONTROL;
421
    static const mask upper  = _UPPER;
422
    static const mask lower  = _LOWER;
423
    static const mask alpha  = _ALPHA;
424
    static const mask digit  = _DIGIT;
425
    static const mask punct  = _PUNCT;
426
    static const mask xdigit = _HEX;
427
    static const mask blank  = _BLANK;
428
    static const mask __regex_word = 0x80;
429
# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
430
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
431
# ifdef __APPLE__
432
    typedef __uint32_t mask;
433
# elif defined(__FreeBSD__)
434
    typedef unsigned long mask;
435
# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
436
    typedef unsigned short mask;
437
# endif
438
    static const mask space  = _CTYPE_S;
439
    static const mask print  = _CTYPE_R;
440
    static const mask cntrl  = _CTYPE_C;
441
    static const mask upper  = _CTYPE_U;
442
    static const mask lower  = _CTYPE_L;
443
    static const mask alpha  = _CTYPE_A;
444
    static const mask digit  = _CTYPE_D;
445
    static const mask punct  = _CTYPE_P;
446
    static const mask xdigit = _CTYPE_X;
447
448
# if defined(__NetBSD__)
449
    static const mask blank  = _CTYPE_BL;
450
    // NetBSD defines classes up to 0x2000
451
    // see sys/ctype_bits.h, _CTYPE_Q
452
    static const mask __regex_word = 0x8000;
453
# else
454
    static const mask blank  = _CTYPE_B;
455
    static const mask __regex_word = 0x80;
456
# endif
457
#elif defined(__sun__) || defined(_AIX)
458
    typedef unsigned int mask;
459
    static const mask space  = _ISSPACE;
460
    static const mask print  = _ISPRINT;
461
    static const mask cntrl  = _ISCNTRL;
462
    static const mask upper  = _ISUPPER;
463
    static const mask lower  = _ISLOWER;
464
    static const mask alpha  = _ISALPHA;
465
    static const mask digit  = _ISDIGIT;
466
    static const mask punct  = _ISPUNCT;
467
    static const mask xdigit = _ISXDIGIT;
468
    static const mask blank  = _ISBLANK;
469
    static const mask __regex_word = 0x80;
470
#elif defined(_NEWLIB_VERSION)
471
    // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
472
    typedef char mask;
473
    static const mask space  = _S;
474
    static const mask print  = _P | _U | _L | _N | _B;
475
    static const mask cntrl  = _C;
476
    static const mask upper  = _U;
477
    static const mask lower  = _L;
478
    static const mask alpha  = _U | _L;
479
    static const mask digit  = _N;
480
    static const mask punct  = _P;
481
    static const mask xdigit = _X | _N;
482
    static const mask blank  = _B;
483
    static const mask __regex_word = 0x80;
484
# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
485
# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
486
# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
487
#else
488
    typedef unsigned long mask;
489
    static const mask space  = 1<<0;
490
    static const mask print  = 1<<1;
491
    static const mask cntrl  = 1<<2;
492
    static const mask upper  = 1<<3;
493
    static const mask lower  = 1<<4;
494
    static const mask alpha  = 1<<5;
495
    static const mask digit  = 1<<6;
496
    static const mask punct  = 1<<7;
497
    static const mask xdigit = 1<<8;
498
    static const mask blank  = 1<<9;
499
#if defined(__BIONIC__)
500
    // Historically this was a part of regex_traits rather than ctype_base. The
501
    // historical value of the constant is preserved for ABI compatibility.
502
    static const mask __regex_word = 0x8000;
503
#else
504
    static const mask __regex_word = 1<<10;
505
#endif // defined(__BIONIC__)
506
#endif
507
    static const mask alnum  = alpha | digit;
508
    static const mask graph  = alnum | punct;
509
510
17.0k
    _LIBCPP_INLINE_VISIBILITY ctype_base() {}
511
};
512
513
template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
514
515
template <>
516
class _LIBCPP_TYPE_VIS ctype<wchar_t>
517
    : public locale::facet,
518
      public ctype_base
519
{
520
public:
521
    typedef wchar_t char_type;
522
523
    _LIBCPP_INLINE_VISIBILITY
524
    explicit ctype(size_t __refs = 0)
525
8.50k
        : locale::facet(__refs) {}
526
527
    _LIBCPP_INLINE_VISIBILITY
528
    bool is(mask __m, char_type __c) const
529
0
    {
530
0
        return do_is(__m, __c);
531
0
    }
532
533
    _LIBCPP_INLINE_VISIBILITY
534
    const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
535
0
    {
536
0
        return do_is(__low, __high, __vec);
537
0
    }
538
539
    _LIBCPP_INLINE_VISIBILITY
540
    const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
541
0
    {
542
0
        return do_scan_is(__m, __low, __high);
543
0
    }
544
545
    _LIBCPP_INLINE_VISIBILITY
546
    const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
547
0
    {
548
0
        return do_scan_not(__m, __low, __high);
549
0
    }
550
551
    _LIBCPP_INLINE_VISIBILITY
552
    char_type toupper(char_type __c) const
553
0
    {
554
0
        return do_toupper(__c);
555
0
    }
556
557
    _LIBCPP_INLINE_VISIBILITY
558
    const char_type* toupper(char_type* __low, const char_type* __high) const
559
0
    {
560
0
        return do_toupper(__low, __high);
561
0
    }
562
563
    _LIBCPP_INLINE_VISIBILITY
564
    char_type tolower(char_type __c) const
565
0
    {
566
0
        return do_tolower(__c);
567
0
    }
568
569
    _LIBCPP_INLINE_VISIBILITY
570
    const char_type* tolower(char_type* __low, const char_type* __high) const
571
0
    {
572
0
        return do_tolower(__low, __high);
573
0
    }
574
575
    _LIBCPP_INLINE_VISIBILITY
576
    char_type widen(char __c) const
577
8
    {
578
8
        return do_widen(__c);
579
8
    }
580
581
    _LIBCPP_INLINE_VISIBILITY
582
    const char* widen(const char* __low, const char* __high, char_type* __to) const
583
0
    {
584
0
        return do_widen(__low, __high, __to);
585
0
    }
586
587
    _LIBCPP_INLINE_VISIBILITY
588
    char narrow(char_type __c, char __dfault) const
589
0
    {
590
0
        return do_narrow(__c, __dfault);
591
0
    }
592
593
    _LIBCPP_INLINE_VISIBILITY
594
    const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
595
0
    {
596
0
        return do_narrow(__low, __high, __dfault, __to);
597
0
    }
598
599
    static locale::id id;
600
601
protected:
602
    ~ctype();
603
    virtual bool do_is(mask __m, char_type __c) const;
604
    virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
605
    virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
606
    virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
607
    virtual char_type do_toupper(char_type) const;
608
    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
609
    virtual char_type do_tolower(char_type) const;
610
    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
611
    virtual char_type do_widen(char) const;
612
    virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
613
    virtual char do_narrow(char_type, char __dfault) const;
614
    virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
615
};
616
617
template <>
618
class _LIBCPP_TYPE_VIS ctype<char>
619
    : public locale::facet, public ctype_base
620
{
621
    const mask* __tab_;
622
    bool        __del_;
623
public:
624
    typedef char char_type;
625
626
    explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
627
628
    _LIBCPP_INLINE_VISIBILITY
629
    bool is(mask __m, char_type __c) const
630
9
    {
631
9
        return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : 
false0
;
632
9
    }
633
634
    _LIBCPP_INLINE_VISIBILITY
635
    const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
636
0
    {
637
0
        for (; __low != __high; ++__low, ++__vec)
638
0
            *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
639
0
        return __low;
640
0
    }
641
642
    _LIBCPP_INLINE_VISIBILITY
643
    const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
644
0
    {
645
0
        for (; __low != __high; ++__low)
646
0
            if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
647
0
                break;
648
0
        return __low;
649
0
    }
650
651
    _LIBCPP_INLINE_VISIBILITY
652
    const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
653
0
    {
654
0
        for (; __low != __high; ++__low)
655
0
            if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)))
656
0
                break;
657
0
        return __low;
658
0
    }
659
660
    _LIBCPP_INLINE_VISIBILITY
661
    char_type toupper(char_type __c) const
662
0
    {
663
0
        return do_toupper(__c);
664
0
    }
665
666
    _LIBCPP_INLINE_VISIBILITY
667
    const char_type* toupper(char_type* __low, const char_type* __high) const
668
0
    {
669
0
        return do_toupper(__low, __high);
670
0
    }
671
672
    _LIBCPP_INLINE_VISIBILITY
673
    char_type tolower(char_type __c) const
674
0
    {
675
0
        return do_tolower(__c);
676
0
    }
677
678
    _LIBCPP_INLINE_VISIBILITY
679
    const char_type* tolower(char_type* __low, const char_type* __high) const
680
0
    {
681
0
        return do_tolower(__low, __high);
682
0
    }
683
684
    _LIBCPP_INLINE_VISIBILITY
685
    char_type widen(char __c) const
686
13.5M
    {
687
13.5M
        return do_widen(__c);
688
13.5M
    }
689
690
    _LIBCPP_INLINE_VISIBILITY
691
    const char* widen(const char* __low, const char* __high, char_type* __to) const
692
3.06M
    {
693
3.06M
        return do_widen(__low, __high, __to);
694
3.06M
    }
695
696
    _LIBCPP_INLINE_VISIBILITY
697
    char narrow(char_type __c, char __dfault) const
698
0
    {
699
0
        return do_narrow(__c, __dfault);
700
0
    }
701
702
    _LIBCPP_INLINE_VISIBILITY
703
    const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
704
0
    {
705
0
        return do_narrow(__low, __high, __dfault, __to);
706
0
    }
707
708
    static locale::id id;
709
710
#ifdef _CACHED_RUNES
711
    static const size_t table_size = _CACHED_RUNES;
712
#else
713
    static const size_t table_size = 256;  // FIXME: Don't hardcode this.
714
#endif
715
0
    _LIBCPP_INLINE_VISIBILITY const mask* table() const  _NOEXCEPT {return __tab_;}
716
    static const mask* classic_table()  _NOEXCEPT;
717
#if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
718
    static const int* __classic_upper_table() _NOEXCEPT;
719
    static const int* __classic_lower_table() _NOEXCEPT;
720
#endif
721
#if defined(__NetBSD__)
722
    static const short* __classic_upper_table() _NOEXCEPT;
723
    static const short* __classic_lower_table() _NOEXCEPT;
724
#endif
725
726
protected:
727
    ~ctype();
728
    virtual char_type do_toupper(char_type __c) const;
729
    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
730
    virtual char_type do_tolower(char_type __c) const;
731
    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
732
    virtual char_type do_widen(char __c) const;
733
    virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
734
    virtual char do_narrow(char_type __c, char __dfault) const;
735
    virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
736
};
737
738
// template <class CharT> class ctype_byname;
739
740
template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype_byname;
741
742
template <>
743
class _LIBCPP_TYPE_VIS ctype_byname<char>
744
    : public ctype<char>
745
{
746
    locale_t __l;
747
748
public:
749
    explicit ctype_byname(const char*, size_t = 0);
750
    explicit ctype_byname(const string&, size_t = 0);
751
752
protected:
753
    ~ctype_byname();
754
    virtual char_type do_toupper(char_type) const;
755
    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
756
    virtual char_type do_tolower(char_type) const;
757
    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
758
};
759
760
template <>
761
class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
762
    : public ctype<wchar_t>
763
{
764
    locale_t __l;
765
766
public:
767
    explicit ctype_byname(const char*, size_t = 0);
768
    explicit ctype_byname(const string&, size_t = 0);
769
770
protected:
771
    ~ctype_byname();
772
    virtual bool do_is(mask __m, char_type __c) const;
773
    virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
774
    virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
775
    virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
776
    virtual char_type do_toupper(char_type) const;
777
    virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
778
    virtual char_type do_tolower(char_type) const;
779
    virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
780
    virtual char_type do_widen(char) const;
781
    virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
782
    virtual char do_narrow(char_type, char __dfault) const;
783
    virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
784
};
785
786
template <class _CharT>
787
inline _LIBCPP_INLINE_VISIBILITY
788
bool
789
isspace(_CharT __c, const locale& __loc)
790
{
791
    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
792
}
793
794
template <class _CharT>
795
inline _LIBCPP_INLINE_VISIBILITY
796
bool
797
isprint(_CharT __c, const locale& __loc)
798
{
799
    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
800
}
801
802
template <class _CharT>
803
inline _LIBCPP_INLINE_VISIBILITY
804
bool
805
iscntrl(_CharT __c, const locale& __loc)
806
{
807
    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
808
}
809
810
template <class _CharT>
811
inline _LIBCPP_INLINE_VISIBILITY
812
bool
813
isupper(_CharT __c, const locale& __loc)
814
{
815
    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
816
}
817
818
template <class _CharT>
819
inline _LIBCPP_INLINE_VISIBILITY
820
bool
821
islower(_CharT __c, const locale& __loc)
822
{
823
    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
824
}
825
826
template <class _CharT>
827
inline _LIBCPP_INLINE_VISIBILITY
828
bool
829
isalpha(_CharT __c, const locale& __loc)
830
{
831
    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
832
}
833
834
template <class _CharT>
835
inline _LIBCPP_INLINE_VISIBILITY
836
bool
837
isdigit(_CharT __c, const locale& __loc)
838
{
839
    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
840
}
841
842
template <class _CharT>
843
inline _LIBCPP_INLINE_VISIBILITY
844
bool
845
ispunct(_CharT __c, const locale& __loc)
846
{
847
    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
848
}
849
850
template <class _CharT>
851
inline _LIBCPP_INLINE_VISIBILITY
852
bool
853
isxdigit(_CharT __c, const locale& __loc)
854
{
855
    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
856
}
857
858
template <class _CharT>
859
inline _LIBCPP_INLINE_VISIBILITY
860
bool
861
isalnum(_CharT __c, const locale& __loc)
862
{
863
    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
864
}
865
866
template <class _CharT>
867
inline _LIBCPP_INLINE_VISIBILITY
868
bool
869
isgraph(_CharT __c, const locale& __loc)
870
{
871
    return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
872
}
873
874
template <class _CharT>
875
inline _LIBCPP_INLINE_VISIBILITY
876
_CharT
877
toupper(_CharT __c, const locale& __loc)
878
{
879
    return use_facet<ctype<_CharT> >(__loc).toupper(__c);
880
}
881
882
template <class _CharT>
883
inline _LIBCPP_INLINE_VISIBILITY
884
_CharT
885
tolower(_CharT __c, const locale& __loc)
886
{
887
    return use_facet<ctype<_CharT> >(__loc).tolower(__c);
888
}
889
890
// codecvt_base
891
892
class _LIBCPP_TYPE_VIS codecvt_base
893
{
894
public:
895
34.0k
    _LIBCPP_INLINE_VISIBILITY codecvt_base() {}
896
    enum result {ok, partial, error, noconv};
897
};
898
899
// template <class internT, class externT, class stateT> class codecvt;
900
901
template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TEMPLATE_VIS codecvt;
902
903
// template <> class codecvt<char, char, mbstate_t>
904
905
template <>
906
class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
907
    : public locale::facet,
908
      public codecvt_base
909
{
910
public:
911
    typedef char      intern_type;
912
    typedef char      extern_type;
913
    typedef mbstate_t state_type;
914
915
    _LIBCPP_INLINE_VISIBILITY
916
    explicit codecvt(size_t __refs = 0)
917
8.50k
        : locale::facet(__refs) {}
918
919
    _LIBCPP_INLINE_VISIBILITY
920
    result out(state_type& __st,
921
               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
922
               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
923
0
    {
924
0
        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
925
0
    }
926
927
    _LIBCPP_INLINE_VISIBILITY
928
    result unshift(state_type& __st,
929
                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
930
17.0k
    {
931
17.0k
        return do_unshift(__st, __to, __to_end, __to_nxt);
932
17.0k
    }
933
934
    _LIBCPP_INLINE_VISIBILITY
935
    result in(state_type& __st,
936
              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
937
              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
938
0
    {
939
0
        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
940
0
    }
941
942
    _LIBCPP_INLINE_VISIBILITY
943
    int encoding() const  _NOEXCEPT
944
8.50k
    {
945
8.50k
        return do_encoding();
946
8.50k
    }
947
948
    _LIBCPP_INLINE_VISIBILITY
949
    bool always_noconv() const  _NOEXCEPT
950
25.6k
    {
951
25.6k
        return do_always_noconv();
952
25.6k
    }
953
954
    _LIBCPP_INLINE_VISIBILITY
955
    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
956
0
    {
957
0
        return do_length(__st, __frm, __end, __mx);
958
0
    }
959
960
    _LIBCPP_INLINE_VISIBILITY
961
    int max_length() const  _NOEXCEPT
962
0
    {
963
0
        return do_max_length();
964
0
    }
965
966
    static locale::id id;
967
968
protected:
969
    _LIBCPP_INLINE_VISIBILITY
970
    explicit codecvt(const char*, size_t __refs = 0)
971
0
        : locale::facet(__refs) {}
972
973
    ~codecvt();
974
975
    virtual result do_out(state_type& __st,
976
                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
977
                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
978
    virtual result do_in(state_type& __st,
979
                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
980
                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
981
    virtual result do_unshift(state_type& __st,
982
                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
983
    virtual int do_encoding() const  _NOEXCEPT;
984
    virtual bool do_always_noconv() const  _NOEXCEPT;
985
    virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
986
    virtual int do_max_length() const  _NOEXCEPT;
987
};
988
989
// template <> class codecvt<wchar_t, char, mbstate_t>
990
991
template <>
992
class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
993
    : public locale::facet,
994
      public codecvt_base
995
{
996
    locale_t __l;
997
public:
998
    typedef wchar_t   intern_type;
999
    typedef char      extern_type;
1000
    typedef mbstate_t state_type;
1001
1002
    explicit codecvt(size_t __refs = 0);
1003
1004
    _LIBCPP_INLINE_VISIBILITY
1005
    result out(state_type& __st,
1006
               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1007
               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1008
37
    {
1009
37
        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1010
37
    }
1011
1012
    _LIBCPP_INLINE_VISIBILITY
1013
    result unshift(state_type& __st,
1014
                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1015
17.0k
    {
1016
17.0k
        return do_unshift(__st, __to, __to_end, __to_nxt);
1017
17.0k
    }
1018
1019
    _LIBCPP_INLINE_VISIBILITY
1020
    result in(state_type& __st,
1021
              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1022
              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1023
856
    {
1024
856
        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1025
856
    }
1026
1027
    _LIBCPP_INLINE_VISIBILITY
1028
    int encoding() const  _NOEXCEPT
1029
8.50k
    {
1030
8.50k
        return do_encoding();
1031
8.50k
    }
1032
1033
    _LIBCPP_INLINE_VISIBILITY
1034
    bool always_noconv() const  _NOEXCEPT
1035
25.5k
    {
1036
25.5k
        return do_always_noconv();
1037
25.5k
    }
1038
1039
    _LIBCPP_INLINE_VISIBILITY
1040
    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1041
0
    {
1042
0
        return do_length(__st, __frm, __end, __mx);
1043
0
    }
1044
1045
    _LIBCPP_INLINE_VISIBILITY
1046
    int max_length() const  _NOEXCEPT
1047
0
    {
1048
0
        return do_max_length();
1049
0
    }
1050
1051
    static locale::id id;
1052
1053
protected:
1054
    explicit codecvt(const char*, size_t __refs = 0);
1055
1056
    ~codecvt();
1057
1058
    virtual result do_out(state_type& __st,
1059
                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1060
                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1061
    virtual result do_in(state_type& __st,
1062
                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1063
                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1064
    virtual result do_unshift(state_type& __st,
1065
                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1066
    virtual int do_encoding() const  _NOEXCEPT;
1067
    virtual bool do_always_noconv() const  _NOEXCEPT;
1068
    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1069
    virtual int do_max_length() const  _NOEXCEPT;
1070
};
1071
1072
// template <> class codecvt<char16_t, char, mbstate_t>
1073
1074
template <>
1075
class _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
1076
    : public locale::facet,
1077
      public codecvt_base
1078
{
1079
public:
1080
    typedef char16_t  intern_type;
1081
    typedef char      extern_type;
1082
    typedef mbstate_t state_type;
1083
1084
    _LIBCPP_INLINE_VISIBILITY
1085
    explicit codecvt(size_t __refs = 0)
1086
8.50k
        : locale::facet(__refs) {}
1087
1088
    _LIBCPP_INLINE_VISIBILITY
1089
    result out(state_type& __st,
1090
               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1091
               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1092
0
    {
1093
0
        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1094
0
    }
1095
1096
    _LIBCPP_INLINE_VISIBILITY
1097
    result unshift(state_type& __st,
1098
                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1099
0
    {
1100
0
        return do_unshift(__st, __to, __to_end, __to_nxt);
1101
0
    }
1102
1103
    _LIBCPP_INLINE_VISIBILITY
1104
    result in(state_type& __st,
1105
              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1106
              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1107
0
    {
1108
0
        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1109
0
    }
1110
1111
    _LIBCPP_INLINE_VISIBILITY
1112
    int encoding() const  _NOEXCEPT
1113
0
    {
1114
0
        return do_encoding();
1115
0
    }
1116
1117
    _LIBCPP_INLINE_VISIBILITY
1118
    bool always_noconv() const  _NOEXCEPT
1119
0
    {
1120
0
        return do_always_noconv();
1121
0
    }
1122
1123
    _LIBCPP_INLINE_VISIBILITY
1124
    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1125
0
    {
1126
0
        return do_length(__st, __frm, __end, __mx);
1127
0
    }
1128
1129
    _LIBCPP_INLINE_VISIBILITY
1130
    int max_length() const  _NOEXCEPT
1131
0
    {
1132
0
        return do_max_length();
1133
0
    }
1134
1135
    static locale::id id;
1136
1137
protected:
1138
    _LIBCPP_INLINE_VISIBILITY
1139
    explicit codecvt(const char*, size_t __refs = 0)
1140
0
        : locale::facet(__refs) {}
1141
1142
    ~codecvt();
1143
1144
    virtual result do_out(state_type& __st,
1145
                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1146
                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1147
    virtual result do_in(state_type& __st,
1148
                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1149
                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1150
    virtual result do_unshift(state_type& __st,
1151
                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1152
    virtual int do_encoding() const  _NOEXCEPT;
1153
    virtual bool do_always_noconv() const  _NOEXCEPT;
1154
    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1155
    virtual int do_max_length() const  _NOEXCEPT;
1156
};
1157
1158
// template <> class codecvt<char32_t, char, mbstate_t>
1159
1160
template <>
1161
class _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
1162
    : public locale::facet,
1163
      public codecvt_base
1164
{
1165
public:
1166
    typedef char32_t  intern_type;
1167
    typedef char      extern_type;
1168
    typedef mbstate_t state_type;
1169
1170
    _LIBCPP_INLINE_VISIBILITY
1171
    explicit codecvt(size_t __refs = 0)
1172
8.50k
        : locale::facet(__refs) {}
1173
1174
    _LIBCPP_INLINE_VISIBILITY
1175
    result out(state_type& __st,
1176
               const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1177
               extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1178
0
    {
1179
0
        return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1180
0
    }
1181
1182
    _LIBCPP_INLINE_VISIBILITY
1183
    result unshift(state_type& __st,
1184
                   extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1185
0
    {
1186
0
        return do_unshift(__st, __to, __to_end, __to_nxt);
1187
0
    }
1188
1189
    _LIBCPP_INLINE_VISIBILITY
1190
    result in(state_type& __st,
1191
              const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1192
              intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1193
0
    {
1194
0
        return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1195
0
    }
1196
1197
    _LIBCPP_INLINE_VISIBILITY
1198
    int encoding() const  _NOEXCEPT
1199
0
    {
1200
0
        return do_encoding();
1201
0
    }
1202
1203
    _LIBCPP_INLINE_VISIBILITY
1204
    bool always_noconv() const  _NOEXCEPT
1205
0
    {
1206
0
        return do_always_noconv();
1207
0
    }
1208
1209
    _LIBCPP_INLINE_VISIBILITY
1210
    int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1211
0
    {
1212
0
        return do_length(__st, __frm, __end, __mx);
1213
0
    }
1214
1215
    _LIBCPP_INLINE_VISIBILITY
1216
    int max_length() const  _NOEXCEPT
1217
0
    {
1218
0
        return do_max_length();
1219
0
    }
1220
1221
    static locale::id id;
1222
1223
protected:
1224
    _LIBCPP_INLINE_VISIBILITY
1225
    explicit codecvt(const char*, size_t __refs = 0)
1226
0
        : locale::facet(__refs) {}
1227
1228
    ~codecvt();
1229
1230
    virtual result do_out(state_type& __st,
1231
                          const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1232
                          extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1233
    virtual result do_in(state_type& __st,
1234
                         const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1235
                         intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1236
    virtual result do_unshift(state_type& __st,
1237
                              extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1238
    virtual int do_encoding() const  _NOEXCEPT;
1239
    virtual bool do_always_noconv() const  _NOEXCEPT;
1240
    virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1241
    virtual int do_max_length() const  _NOEXCEPT;
1242
};
1243
1244
// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
1245
1246
template <class _InternT, class _ExternT, class _StateT>
1247
class _LIBCPP_TEMPLATE_VIS codecvt_byname
1248
    : public codecvt<_InternT, _ExternT, _StateT>
1249
{
1250
public:
1251
    _LIBCPP_INLINE_VISIBILITY
1252
    explicit codecvt_byname(const char* __nm, size_t __refs = 0)
1253
        : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
1254
    _LIBCPP_INLINE_VISIBILITY
1255
    explicit codecvt_byname(const string& __nm, size_t __refs = 0)
1256
0
        : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
Unexecuted instantiation: std::__1::codecvt_byname<char, char, __mbstate_t>::codecvt_byname(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long)
Unexecuted instantiation: std::__1::codecvt_byname<wchar_t, char, __mbstate_t>::codecvt_byname(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long)
Unexecuted instantiation: std::__1::codecvt_byname<char16_t, char, __mbstate_t>::codecvt_byname(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long)
Unexecuted instantiation: std::__1::codecvt_byname<char32_t, char, __mbstate_t>::codecvt_byname(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long)
1257
protected:
1258
    ~codecvt_byname();
1259
};
1260
1261
template <class _InternT, class _ExternT, class _StateT>
1262
codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
1263
0
{
1264
0
}
Unexecuted instantiation: std::__1::codecvt_byname<char, char, __mbstate_t>::~codecvt_byname()
Unexecuted instantiation: std::__1::codecvt_byname<wchar_t, char, __mbstate_t>::~codecvt_byname()
Unexecuted instantiation: std::__1::codecvt_byname<char16_t, char, __mbstate_t>::~codecvt_byname()
Unexecuted instantiation: std::__1::codecvt_byname<char32_t, char, __mbstate_t>::~codecvt_byname()
1265
1266
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>)
1267
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>)
1268
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>)
1269
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>)
1270
1271
template <size_t _Np>
1272
struct __narrow_to_utf8
1273
{
1274
    template <class _OutputIterator, class _CharT>
1275
    _OutputIterator
1276
    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
1277
};
1278
1279
template <>
1280
struct __narrow_to_utf8<8>
1281
{
1282
    template <class _OutputIterator, class _CharT>
1283
    _LIBCPP_INLINE_VISIBILITY
1284
    _OutputIterator
1285
    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1286
0
    {
1287
0
        for (; __wb < __we; ++__wb, ++__s)
1288
0
            *__s = *__wb;
1289
0
        return __s;
1290
0
    }
1291
};
1292
1293
template <>
1294
struct _LIBCPP_TEMPLATE_VIS __narrow_to_utf8<16>
1295
    : public codecvt<char16_t, char, mbstate_t>
1296
{
1297
    _LIBCPP_INLINE_VISIBILITY
1298
0
    __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1299
1300
    _LIBCPP_EXPORTED_FROM_ABI ~__narrow_to_utf8();
1301
1302
    template <class _OutputIterator, class _CharT>
1303
    _LIBCPP_INLINE_VISIBILITY
1304
    _OutputIterator
1305
    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1306
    {
1307
        result __r = ok;
1308
        mbstate_t __mb;
1309
        while (__wb < __we && __r != error)
1310
        {
1311
            const int __sz = 32;
1312
            char __buf[__sz];
1313
            char* __bn;
1314
            const char16_t* __wn = (const char16_t*)__wb;
1315
            __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
1316
                         __buf, __buf+__sz, __bn);
1317
            if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
1318
                __throw_runtime_error("locale not supported");
1319
            for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1320
                *__s = *__p;
1321
            __wb = (const _CharT*)__wn;
1322
        }
1323
        return __s;
1324
    }
1325
};
1326
1327
template <>
1328
struct _LIBCPP_TEMPLATE_VIS __narrow_to_utf8<32>
1329
    : public codecvt<char32_t, char, mbstate_t>
1330
{
1331
    _LIBCPP_INLINE_VISIBILITY
1332
0
    __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1333
1334
    _LIBCPP_EXPORTED_FROM_ABI ~__narrow_to_utf8();
1335
1336
    template <class _OutputIterator, class _CharT>
1337
    _LIBCPP_INLINE_VISIBILITY
1338
    _OutputIterator
1339
    operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1340
0
    {
1341
0
        result __r = ok;
1342
0
        mbstate_t __mb;
1343
0
        while (__wb < __we && __r != error)
1344
0
        {
1345
0
            const int __sz = 32;
1346
0
            char __buf[__sz];
1347
0
            char* __bn;
1348
0
            const char32_t* __wn = (const char32_t*)__wb;
1349
0
            __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
1350
0
                         __buf, __buf+__sz, __bn);
1351
0
            if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
1352
0
                __throw_runtime_error("locale not supported");
1353
0
            for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1354
0
                *__s = *__p;
1355
0
            __wb = (const _CharT*)__wn;
1356
0
        }
1357
0
        return __s;
1358
0
    }
1359
};
1360
1361
template <size_t _Np>
1362
struct __widen_from_utf8
1363
{
1364
    template <class _OutputIterator>
1365
    _OutputIterator
1366
    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
1367
};
1368
1369
template <>
1370
struct __widen_from_utf8<8>
1371
{
1372
    template <class _OutputIterator>
1373
    _LIBCPP_INLINE_VISIBILITY
1374
    _OutputIterator
1375
    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1376
0
    {
1377
0
        for (; __nb < __ne; ++__nb, ++__s)
1378
0
            *__s = *__nb;
1379
0
        return __s;
1380
0
    }
1381
};
1382
1383
template <>
1384
struct _LIBCPP_TEMPLATE_VIS __widen_from_utf8<16>
1385
    : public codecvt<char16_t, char, mbstate_t>
1386
{
1387
    _LIBCPP_INLINE_VISIBILITY
1388
0
    __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1389
1390
    _LIBCPP_EXPORTED_FROM_ABI ~__widen_from_utf8();
1391
1392
    template <class _OutputIterator>
1393
    _LIBCPP_INLINE_VISIBILITY
1394
    _OutputIterator
1395
    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1396
0
    {
1397
0
        result __r = ok;
1398
0
        mbstate_t __mb;
1399
0
        while (__nb < __ne && __r != error)
1400
0
        {
1401
0
            const int __sz = 32;
1402
0
            char16_t __buf[__sz];
1403
0
            char16_t* __bn;
1404
0
            const char* __nn = __nb;
1405
0
            __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1406
0
                        __buf, __buf+__sz, __bn);
1407
0
            if (__r == codecvt_base::error || __nn == __nb)
1408
0
                __throw_runtime_error("locale not supported");
1409
0
            for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
1410
0
                *__s = (wchar_t)*__p;
1411
0
            __nb = __nn;
1412
0
        }
1413
0
        return __s;
1414
0
    }
1415
};
1416
1417
template <>
1418
struct _LIBCPP_TEMPLATE_VIS __widen_from_utf8<32>
1419
    : public codecvt<char32_t, char, mbstate_t>
1420
{
1421
    _LIBCPP_INLINE_VISIBILITY
1422
0
    __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1423
1424
    _LIBCPP_EXPORTED_FROM_ABI ~__widen_from_utf8();
1425
1426
    template <class _OutputIterator>
1427
    _LIBCPP_INLINE_VISIBILITY
1428
    _OutputIterator
1429
    operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1430
0
    {
1431
0
        result __r = ok;
1432
0
        mbstate_t __mb;
1433
0
        while (__nb < __ne && __r != error)
1434
0
        {
1435
0
            const int __sz = 32;
1436
0
            char32_t __buf[__sz];
1437
0
            char32_t* __bn;
1438
0
            const char* __nn = __nb;
1439
0
            __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1440
0
                        __buf, __buf+__sz, __bn);
1441
0
            if (__r == codecvt_base::error || __nn == __nb)
1442
0
                __throw_runtime_error("locale not supported");
1443
0
            for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
1444
0
                *__s = (wchar_t)*__p;
1445
0
            __nb = __nn;
1446
0
        }
1447
0
        return __s;
1448
0
    }
Unexecuted instantiation: std::__1::back_insert_iterator<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > > std::__1::__widen_from_utf8<32ul>::operator()<std::__1::back_insert_iterator<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > > >(std::__1::back_insert_iterator<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > >, char const*, char const*) const
Unexecuted instantiation: std::__1::back_insert_iterator<std::__1::basic_string<char32_t, std::__1::char_traits<char32_t>, std::__1::allocator<char32_t> > > std::__1::__widen_from_utf8<32ul>::operator()<std::__1::back_insert_iterator<std::__1::basic_string<char32_t, std::__1::char_traits<char32_t>, std::__1::allocator<char32_t> > > >(std::__1::back_insert_iterator<std::__1::basic_string<char32_t, std::__1::char_traits<char32_t>, std::__1::allocator<char32_t> > >, char const*, char const*) const
1449
};
1450
1451
// template <class charT> class numpunct
1452
1453
template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct;
1454
1455
template <>
1456
class _LIBCPP_TYPE_VIS numpunct<char>
1457
    : public locale::facet
1458
{
1459
public:
1460
    typedef char char_type;
1461
    typedef basic_string<char_type> string_type;
1462
1463
    explicit numpunct(size_t __refs = 0);
1464
1465
0
    _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
1466
0
    _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
1467
57.3k
    _LIBCPP_INLINE_VISIBILITY string grouping() const         {return do_grouping();}
1468
0
    _LIBCPP_INLINE_VISIBILITY string_type truename() const    {return do_truename();}
1469
0
    _LIBCPP_INLINE_VISIBILITY string_type falsename() const   {return do_falsename();}
1470
1471
    static locale::id id;
1472
1473
protected:
1474
    ~numpunct();
1475
    virtual char_type do_decimal_point() const;
1476
    virtual char_type do_thousands_sep() const;
1477
    virtual string do_grouping() const;
1478
    virtual string_type do_truename() const;
1479
    virtual string_type do_falsename() const;
1480
1481
    char_type __decimal_point_;
1482
    char_type __thousands_sep_;
1483
    string __grouping_;
1484
};
1485
1486
template <>
1487
class _LIBCPP_TYPE_VIS numpunct<wchar_t>
1488
    : public locale::facet
1489
{
1490
public:
1491
    typedef wchar_t char_type;
1492
    typedef basic_string<char_type> string_type;
1493
1494
    explicit numpunct(size_t __refs = 0);
1495
1496
0
    _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
1497
0
    _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
1498
0
    _LIBCPP_INLINE_VISIBILITY string grouping() const         {return do_grouping();}
1499
0
    _LIBCPP_INLINE_VISIBILITY string_type truename() const    {return do_truename();}
1500
0
    _LIBCPP_INLINE_VISIBILITY string_type falsename() const   {return do_falsename();}
1501
1502
    static locale::id id;
1503
1504
protected:
1505
    ~numpunct();
1506
    virtual char_type do_decimal_point() const;
1507
    virtual char_type do_thousands_sep() const;
1508
    virtual string do_grouping() const;
1509
    virtual string_type do_truename() const;
1510
    virtual string_type do_falsename() const;
1511
1512
    char_type __decimal_point_;
1513
    char_type __thousands_sep_;
1514
    string __grouping_;
1515
};
1516
1517
// template <class charT> class numpunct_byname
1518
1519
template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct_byname;
1520
1521
template <>
1522
class _LIBCPP_TYPE_VIS numpunct_byname<char>
1523
: public numpunct<char>
1524
{
1525
public:
1526
    typedef char char_type;
1527
    typedef basic_string<char_type> string_type;
1528
1529
    explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1530
    explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1531
1532
protected:
1533
    ~numpunct_byname();
1534
1535
private:
1536
    void __init(const char*);
1537
};
1538
1539
template <>
1540
class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
1541
: public numpunct<wchar_t>
1542
{
1543
public:
1544
    typedef wchar_t char_type;
1545
    typedef basic_string<char_type> string_type;
1546
1547
    explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1548
    explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1549
1550
protected:
1551
    ~numpunct_byname();
1552
1553
private:
1554
    void __init(const char*);
1555
};
1556
1557
_LIBCPP_END_NAMESPACE_STD
1558
1559
#endif  // _LIBCPP___LOCALE