blob: d1d66f94d0d757c27ec9d4d8dfa5ffaf15f4da32 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
Chandler Carruth7c3769d2019-01-19 10:56:404// 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
Howard Hinnantbc8d3f92010-05-11 19:42:167//
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>
Howard Hinnantadff4892010-05-24 17:49:4120#include <locale.h>
Eric Fiselier7b7ac672017-05-31 22:14:0521#if defined(_LIBCPP_MSVCRT_LIKE)
Howard Hinnant14fa9f92011-09-29 20:33:1022# include <support/win32/locale_win32.h>
Marshall Clowbe3d1172014-03-11 17:18:4723#elif defined(_AIX)
Howard Hinnant7f764502013-08-14 18:00:2024# include <support/ibm/xlocale.h>
Marshall Clowa6439262014-07-10 15:20:2825#elif defined(__ANDROID__)
Saleem Abdulrasool8dd2afa2018-04-13 18:14:5726# include <support/android/locale_bionic.h>
Eric Fiselier6cb69ff2014-11-25 21:57:4127#elif defined(__sun__)
Eric Fiselierf51d6762015-01-23 22:22:3628# include <xlocale.h>
Eric Fiselier6cb69ff2014-11-25 21:57:4129# include <support/solaris/xlocale.h>
Sergey Dmitrouk984f8f62014-12-12 08:36:1630#elif defined(_NEWLIB_VERSION)
31# include <support/newlib/xlocale.h>
Eric Fiselier6e02e892017-08-03 04:28:1032#elif (defined(__APPLE__) || defined(__FreeBSD__) \
Eric Fiselier6cb69ff2014-11-25 21:57:4133 || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
Howard Hinnant92a07002011-09-22 19:10:1834# include <xlocale.h>
Petr Hosek82a50d62017-04-13 21:29:2135#elif defined(__Fuchsia__)
36# include <support/fuchsia/xlocale.h>
Vasileios Kalintiris579b42b2015-11-09 10:21:0437#elif defined(_LIBCPP_HAS_MUSL_LIBC)
38# include <support/musl/xlocale.h>
Petr Hosek82a50d62017-04-13 21:29:2139#endif
Howard Hinnantbc8d3f92010-05-11 19:42:1640
Howard Hinnant08e17472011-10-17 20:05:1041#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:1642#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:1043#endif
Howard Hinnantbc8d3f92010-05-11 19:42:1644
45_LIBCPP_BEGIN_NAMESPACE_STD
46
Martin Storsjo9de86592017-11-23 10:38:1847#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
Eric Fiselier2ec6d392017-05-08 22:02:4348struct __libcpp_locale_guard {
49 _LIBCPP_INLINE_VISIBILITY
50 __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
51
52 _LIBCPP_INLINE_VISIBILITY
53 ~__libcpp_locale_guard() {
54 if (__old_loc_)
55 uselocale(__old_loc_);
56 }
57
58 locale_t __old_loc_;
59private:
60 __libcpp_locale_guard(__libcpp_locale_guard const&);
61 __libcpp_locale_guard& operator=(__libcpp_locale_guard const&);
62};
Martin Storsjo9de86592017-11-23 10:38:1863#elif defined(_LIBCPP_MSVCRT_LIKE)
64struct __libcpp_locale_guard {
65 __libcpp_locale_guard(locale_t __l) :
66 __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)),
67 __locale_collate(setlocale(LC_COLLATE, __l.__get_locale())),
68 __locale_ctype(setlocale(LC_CTYPE, __l.__get_locale())),
69 __locale_monetary(setlocale(LC_MONETARY, __l.__get_locale())),
70 __locale_numeric(setlocale(LC_NUMERIC, __l.__get_locale())),
71 __locale_time(setlocale(LC_TIME, __l.__get_locale()))
72 // LC_MESSAGES is not supported on Windows.
73 {}
74 ~__libcpp_locale_guard() {
75 setlocale(LC_COLLATE, __locale_collate);
76 setlocale(LC_CTYPE, __locale_ctype);
77 setlocale(LC_MONETARY, __locale_monetary);
78 setlocale(LC_NUMERIC, __locale_numeric);
79 setlocale(LC_TIME, __locale_time);
80 _configthreadlocale(__status);
81 }
82 int __status;
83 char* __locale_collate;
84 char* __locale_ctype;
85 char* __locale_monetary;
86 char* __locale_numeric;
87 char* __locale_time;
88};
Eric Fiselier2ec6d392017-05-08 22:02:4389#endif
90
91
Howard Hinnant83eade62013-03-06 23:30:1992class _LIBCPP_TYPE_VIS locale;
Howard Hinnantbc8d3f92010-05-11 19:42:1693
Howard Hinnant33be35e2012-09-14 00:39:1694template <class _Facet>
95_LIBCPP_INLINE_VISIBILITY
96bool
97has_facet(const locale&) _NOEXCEPT;
98
99template <class _Facet>
100_LIBCPP_INLINE_VISIBILITY
101const _Facet&
102use_facet(const locale&);
Howard Hinnantbc8d3f92010-05-11 19:42:16103
Howard Hinnant83eade62013-03-06 23:30:19104class _LIBCPP_TYPE_VIS locale
Howard Hinnantbc8d3f92010-05-11 19:42:16105{
106public:
107 // types:
Howard Hinnant83eade62013-03-06 23:30:19108 class _LIBCPP_TYPE_VIS facet;
109 class _LIBCPP_TYPE_VIS id;
Howard Hinnantbc8d3f92010-05-11 19:42:16110
111 typedef int category;
Mehdi Amini907c1192017-05-04 17:08:54112 _LIBCPP_AVAILABILITY_LOCALE_CATEGORY
Howard Hinnantbc8d3f92010-05-11 19:42:16113 static const category // values assigned here are for exposition only
114 none = 0,
115 collate = LC_COLLATE_MASK,
116 ctype = LC_CTYPE_MASK,
117 monetary = LC_MONETARY_MASK,
118 numeric = LC_NUMERIC_MASK,
119 time = LC_TIME_MASK,
120 messages = LC_MESSAGES_MASK,
121 all = collate | ctype | monetary | numeric | time | messages;
122
123 // construct/copy/destroy:
Howard Hinnantc9834542011-05-31 15:34:58124 locale() _NOEXCEPT;
125 locale(const locale&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16126 explicit locale(const char*);
127 explicit locale(const string&);
128 locale(const locale&, const char*, category);
129 locale(const locale&, const string&, category);
Howard Hinnant2d72b1e2010-12-17 14:46:43130 template <class _Facet>
131 _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
Howard Hinnantbc8d3f92010-05-11 19:42:16132 locale(const locale&, const locale&, category);
133
Howard Hinnantc9834542011-05-31 15:34:58134 ~locale();
Howard Hinnantbc8d3f92010-05-11 19:42:16135
Howard Hinnantc9834542011-05-31 15:34:58136 const locale& operator=(const locale&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16137
Shoaib Meenai6b734922017-03-02 03:22:18138 template <class _Facet>
139 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
140 locale combine(const locale&) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16141
142 // locale operations:
143 string name() const;
144 bool operator==(const locale&) const;
145 bool operator!=(const locale& __y) const {return !(*this == __y);}
146 template <class _CharT, class _Traits, class _Allocator>
Shoaib Meenai6b734922017-03-02 03:22:18147 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Howard Hinnantbc8d3f92010-05-11 19:42:16148 bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
149 const basic_string<_CharT, _Traits, _Allocator>&) const;
150
151 // global locale objects:
152 static locale global(const locale&);
153 static const locale& classic();
154
155private:
156 class __imp;
157 __imp* __locale_;
158
159 void __install_ctor(const locale&, facet*, long);
160 static locale& __global();
161 bool has_facet(id&) const;
162 const facet* use_facet(id&) const;
163
Howard Hinnantc9834542011-05-31 15:34:58164 template <class _Facet> friend bool has_facet(const locale&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16165 template <class _Facet> friend const _Facet& use_facet(const locale&);
166};
167
Howard Hinnant83eade62013-03-06 23:30:19168class _LIBCPP_TYPE_VIS locale::facet
Howard Hinnantbc8d3f92010-05-11 19:42:16169 : public __shared_count
170{
171protected:
Howard Hinnantb0be42b2010-09-21 18:58:51172 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16173 explicit facet(size_t __refs = 0)
174 : __shared_count(static_cast<long>(__refs)-1) {}
175
176 virtual ~facet();
177
178// facet(const facet&) = delete; // effectively done in __shared_count
179// void operator=(const facet&) = delete;
180private:
Howard Hinnant1694d232011-05-28 14:41:13181 virtual void __on_zero_shared() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16182};
183
Howard Hinnant83eade62013-03-06 23:30:19184class _LIBCPP_TYPE_VIS locale::id
Howard Hinnantbc8d3f92010-05-11 19:42:16185{
186 once_flag __flag_;
187 int32_t __id_;
Howard Hinnant324bb032010-08-22 00:02:43188
Howard Hinnantbc8d3f92010-05-11 19:42:16189 static int32_t __next_id;
190public:
Howard Hinnantf3d62ea2012-07-26 16:14:37191 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16192private:
193 void __init();
194 void operator=(const id&); // = delete;
195 id(const id&); // = delete;
196public: // only needed for tests
197 long __get();
198
199 friend class locale;
200 friend class locale::__imp;
201};
202
203template <class _Facet>
204inline _LIBCPP_INLINE_VISIBILITY
205locale::locale(const locale& __other, _Facet* __f)
206{
207 __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
208}
209
210template <class _Facet>
211locale
212locale::combine(const locale& __other) const
213{
Howard Hinnant0949eed2011-06-30 21:18:19214 if (!_VSTD::has_facet<_Facet>(__other))
Marshall Clow14c09a22016-08-25 15:09:01215 __throw_runtime_error("locale::combine: locale missing facet");
216
Howard Hinnant0949eed2011-06-30 21:18:19217 return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
Howard Hinnantbc8d3f92010-05-11 19:42:16218}
219
220template <class _Facet>
221inline _LIBCPP_INLINE_VISIBILITY
222bool
Howard Hinnantc9834542011-05-31 15:34:58223has_facet(const locale& __l) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16224{
225 return __l.has_facet(_Facet::id);
226}
227
228template <class _Facet>
229inline _LIBCPP_INLINE_VISIBILITY
230const _Facet&
231use_facet(const locale& __l)
232{
233 return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
234}
235
236// template <class _CharT> class collate;
237
238template <class _CharT>
Eric Fiselierc3589a82017-01-04 23:56:00239class _LIBCPP_TEMPLATE_VIS collate
Howard Hinnantbc8d3f92010-05-11 19:42:16240 : public locale::facet
241{
242public:
243 typedef _CharT char_type;
244 typedef basic_string<char_type> string_type;
245
Howard Hinnantb0be42b2010-09-21 18:58:51246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16247 explicit collate(size_t __refs = 0)
248 : locale::facet(__refs) {}
249
Howard Hinnantb0be42b2010-09-21 18:58:51250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16251 int compare(const char_type* __lo1, const char_type* __hi1,
252 const char_type* __lo2, const char_type* __hi2) const
253 {
254 return do_compare(__lo1, __hi1, __lo2, __hi2);
255 }
256
Howard Hinnantb0be42b2010-09-21 18:58:51257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16258 string_type transform(const char_type* __lo, const char_type* __hi) const
259 {
260 return do_transform(__lo, __hi);
261 }
262
Howard Hinnantb0be42b2010-09-21 18:58:51263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16264 long hash(const char_type* __lo, const char_type* __hi) const
265 {
266 return do_hash(__lo, __hi);
267 }
268
269 static locale::id id;
270
271protected:
272 ~collate();
273 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
274 const char_type* __lo2, const char_type* __hi2) const;
275 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
276 {return string_type(__lo, __hi);}
277 virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
278};
279
280template <class _CharT> locale::id collate<_CharT>::id;
281
282template <class _CharT>
283collate<_CharT>::~collate()
284{
285}
286
287template <class _CharT>
288int
289collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
290 const char_type* __lo2, const char_type* __hi2) const
291{
292 for (; __lo2 != __hi2; ++__lo1, ++__lo2)
293 {
294 if (__lo1 == __hi1 || *__lo1 < *__lo2)
295 return -1;
296 if (*__lo2 < *__lo1)
297 return 1;
298 }
299 return __lo1 != __hi1;
300}
301
302template <class _CharT>
303long
Howard Hinnant11624452011-10-11 16:00:46304collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
Howard Hinnantbc8d3f92010-05-11 19:42:16305{
Howard Hinnant11624452011-10-11 16:00:46306 size_t __h = 0;
307 const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
308 const size_t __mask = size_t(0xF) << (__sr + 4);
309 for(const char_type* __p = __lo; __p != __hi; ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16310 {
Howard Hinnantec3773c2011-12-01 20:21:04311 __h = (__h << 4) + static_cast<size_t>(*__p);
Howard Hinnant11624452011-10-11 16:00:46312 size_t __g = __h & __mask;
313 __h ^= __g | (__g >> __sr);
Howard Hinnantbc8d3f92010-05-11 19:42:16314 }
Howard Hinnant11624452011-10-11 16:00:46315 return static_cast<long>(__h);
Howard Hinnantbc8d3f92010-05-11 19:42:16316}
317
Eric Fiselier833d6442016-09-15 22:27:07318_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>)
319_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>)
Howard Hinnantbc8d3f92010-05-11 19:42:16320
321// template <class CharT> class collate_byname;
322
Eric Fiselierc3589a82017-01-04 23:56:00323template <class _CharT> class _LIBCPP_TEMPLATE_VIS collate_byname;
Howard Hinnantbc8d3f92010-05-11 19:42:16324
325template <>
Howard Hinnant83eade62013-03-06 23:30:19326class _LIBCPP_TYPE_VIS collate_byname<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16327 : public collate<char>
328{
329 locale_t __l;
330public:
331 typedef char char_type;
332 typedef basic_string<char_type> string_type;
333
334 explicit collate_byname(const char* __n, size_t __refs = 0);
335 explicit collate_byname(const string& __n, size_t __refs = 0);
336
337protected:
338 ~collate_byname();
339 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
340 const char_type* __lo2, const char_type* __hi2) const;
341 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
342};
343
344template <>
Howard Hinnant83eade62013-03-06 23:30:19345class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16346 : public collate<wchar_t>
347{
348 locale_t __l;
349public:
350 typedef wchar_t char_type;
351 typedef basic_string<char_type> string_type;
352
353 explicit collate_byname(const char* __n, size_t __refs = 0);
354 explicit collate_byname(const string& __n, size_t __refs = 0);
355
356protected:
357 ~collate_byname();
358
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
364template <class _CharT, class _Traits, class _Allocator>
365bool
366locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
367 const basic_string<_CharT, _Traits, _Allocator>& __y) const
368{
Howard Hinnant0949eed2011-06-30 21:18:19369 return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
Howard Hinnantbc8d3f92010-05-11 19:42:16370 __x.data(), __x.data() + __x.size(),
371 __y.data(), __y.data() + __y.size()) < 0;
372}
373
374// template <class charT> class ctype
375
Howard Hinnant83eade62013-03-06 23:30:19376class _LIBCPP_TYPE_VIS ctype_base
Howard Hinnantb0be42b2010-09-21 18:58:51377{
Howard Hinnantbc8d3f92010-05-11 19:42:16378public:
Vasileios Kalintiris579b42b2015-11-09 10:21:04379#if defined(__GLIBC__)
Sean Hunt62a6ac32011-07-09 00:56:23380 typedef unsigned short mask;
Howard Hinnantadff4892010-05-24 17:49:41381 static const mask space = _ISspace;
382 static const mask print = _ISprint;
383 static const mask cntrl = _IScntrl;
384 static const mask upper = _ISupper;
385 static const mask lower = _ISlower;
386 static const mask alpha = _ISalpha;
387 static const mask digit = _ISdigit;
388 static const mask punct = _ISpunct;
389 static const mask xdigit = _ISxdigit;
390 static const mask blank = _ISblank;
Eric Fiselier7b7ac672017-05-31 22:14:05391#elif defined(_LIBCPP_MSVCRT_LIKE)
Howard Hinnant3c466fc2011-09-29 13:33:15392 typedef unsigned short mask;
Howard Hinnant92a07002011-09-22 19:10:18393 static const mask space = _SPACE;
394 static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT;
395 static const mask cntrl = _CONTROL;
396 static const mask upper = _UPPER;
397 static const mask lower = _LOWER;
398 static const mask alpha = _ALPHA;
399 static const mask digit = _DIGIT;
400 static const mask punct = _PUNCT;
401 static const mask xdigit = _HEX;
402 static const mask blank = _BLANK;
Jonathan Roelofs6fb33ea2015-03-11 17:00:28403# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
Dan Albert6272ae52015-03-11 00:51:06404#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
JF Bastiena14f7cb2015-02-25 22:16:46405# ifdef __APPLE__
David Chisnallc512df12011-09-21 08:39:44406 typedef __uint32_t mask;
JF Bastiena14f7cb2015-02-25 22:16:46407# elif defined(__FreeBSD__)
David Chisnallc512df12011-09-21 08:39:44408 typedef unsigned long mask;
Vasileios Kalintiris5e00a712015-11-24 10:24:54409# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
Howard Hinnantfc2f0212013-03-29 18:27:28410 typedef unsigned short mask;
JF Bastiena14f7cb2015-02-25 22:16:46411# endif
David Chisnallc512df12011-09-21 08:39:44412 static const mask space = _CTYPE_S;
413 static const mask print = _CTYPE_R;
414 static const mask cntrl = _CTYPE_C;
415 static const mask upper = _CTYPE_U;
416 static const mask lower = _CTYPE_L;
417 static const mask alpha = _CTYPE_A;
418 static const mask digit = _CTYPE_D;
419 static const mask punct = _CTYPE_P;
420 static const mask xdigit = _CTYPE_X;
Dan Albert2a52a322014-07-23 19:32:03421
Joerg Sonnenbergera71a9522013-05-17 21:17:34422# if defined(__NetBSD__)
423 static const mask blank = _CTYPE_BL;
424# else
David Chisnallc512df12011-09-21 08:39:44425 static const mask blank = _CTYPE_B;
Joerg Sonnenbergera71a9522013-05-17 21:17:34426# endif
Howard Hinnantcb0e6b62013-08-30 14:42:39427#elif defined(__sun__) || defined(_AIX)
David Chisnall997e4542012-02-29 13:05:08428 typedef unsigned int mask;
429 static const mask space = _ISSPACE;
430 static const mask print = _ISPRINT;
431 static const mask cntrl = _ISCNTRL;
432 static const mask upper = _ISUPPER;
433 static const mask lower = _ISLOWER;
434 static const mask alpha = _ISALPHA;
435 static const mask digit = _ISDIGIT;
436 static const mask punct = _ISPUNCT;
437 static const mask xdigit = _ISXDIGIT;
438 static const mask blank = _ISBLANK;
JF Bastiena14f7cb2015-02-25 22:16:46439#elif defined(_NEWLIB_VERSION)
440 // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
441 typedef char mask;
442 static const mask space = _S;
443 static const mask print = _P | _U | _L | _N | _B;
444 static const mask cntrl = _C;
445 static const mask upper = _U;
446 static const mask lower = _L;
447 static const mask alpha = _U | _L;
448 static const mask digit = _N;
449 static const mask punct = _P;
450 static const mask xdigit = _X | _N;
451 static const mask blank = _B;
Jonathan Roelofs6fb33ea2015-03-11 17:00:28452# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
453# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
454# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
JF Bastiena14f7cb2015-02-25 22:16:46455#else
Howard Hinnant11624452011-10-11 16:00:46456 typedef unsigned long mask;
457 static const mask space = 1<<0;
458 static const mask print = 1<<1;
459 static const mask cntrl = 1<<2;
460 static const mask upper = 1<<3;
461 static const mask lower = 1<<4;
462 static const mask alpha = 1<<5;
463 static const mask digit = 1<<6;
464 static const mask punct = 1<<7;
465 static const mask xdigit = 1<<8;
466 static const mask blank = 1<<9;
JF Bastiena14f7cb2015-02-25 22:16:46467#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16468 static const mask alnum = alpha | digit;
469 static const mask graph = alnum | punct;
470
Louis Dionne54238052018-07-11 23:14:33471 _LIBCPP_INLINE_VISIBILITY ctype_base() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16472};
473
Eric Fiselierc3589a82017-01-04 23:56:00474template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
Howard Hinnantbc8d3f92010-05-11 19:42:16475
476template <>
Howard Hinnant83eade62013-03-06 23:30:19477class _LIBCPP_TYPE_VIS ctype<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16478 : public locale::facet,
479 public ctype_base
480{
481public:
482 typedef wchar_t char_type;
Howard Hinnant324bb032010-08-22 00:02:43483
Louis Dionne54238052018-07-11 23:14:33484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16485 explicit ctype(size_t __refs = 0)
486 : locale::facet(__refs) {}
487
Louis Dionne54238052018-07-11 23:14:33488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16489 bool is(mask __m, char_type __c) const
490 {
491 return do_is(__m, __c);
492 }
493
Louis Dionne54238052018-07-11 23:14:33494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16495 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
496 {
497 return do_is(__low, __high, __vec);
498 }
499
Louis Dionne54238052018-07-11 23:14:33500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16501 const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
502 {
503 return do_scan_is(__m, __low, __high);
504 }
505
Louis Dionne54238052018-07-11 23:14:33506 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16507 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
508 {
509 return do_scan_not(__m, __low, __high);
510 }
511
Louis Dionne54238052018-07-11 23:14:33512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16513 char_type toupper(char_type __c) const
514 {
515 return do_toupper(__c);
516 }
517
Louis Dionne54238052018-07-11 23:14:33518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16519 const char_type* toupper(char_type* __low, const char_type* __high) const
520 {
521 return do_toupper(__low, __high);
522 }
523
Louis Dionne54238052018-07-11 23:14:33524 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16525 char_type tolower(char_type __c) const
526 {
527 return do_tolower(__c);
528 }
529
Louis Dionne54238052018-07-11 23:14:33530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16531 const char_type* tolower(char_type* __low, const char_type* __high) const
532 {
533 return do_tolower(__low, __high);
534 }
535
Louis Dionne54238052018-07-11 23:14:33536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16537 char_type widen(char __c) const
538 {
539 return do_widen(__c);
540 }
541
Louis Dionne54238052018-07-11 23:14:33542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16543 const char* widen(const char* __low, const char* __high, char_type* __to) const
544 {
545 return do_widen(__low, __high, __to);
546 }
547
Louis Dionne54238052018-07-11 23:14:33548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16549 char narrow(char_type __c, char __dfault) const
550 {
551 return do_narrow(__c, __dfault);
552 }
553
Louis Dionne54238052018-07-11 23:14:33554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16555 const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
556 {
557 return do_narrow(__low, __high, __dfault, __to);
558 }
559
560 static locale::id id;
561
562protected:
563 ~ctype();
564 virtual bool do_is(mask __m, char_type __c) const;
565 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
566 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
567 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
568 virtual char_type do_toupper(char_type) const;
569 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
570 virtual char_type do_tolower(char_type) const;
571 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
572 virtual char_type do_widen(char) const;
573 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
574 virtual char do_narrow(char_type, char __dfault) const;
575 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
576};
577
578template <>
Howard Hinnant83eade62013-03-06 23:30:19579class _LIBCPP_TYPE_VIS ctype<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16580 : public locale::facet, public ctype_base
581{
582 const mask* __tab_;
583 bool __del_;
584public:
585 typedef char char_type;
586
587 explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
588
Louis Dionne54238052018-07-11 23:14:33589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16590 bool is(mask __m, char_type __c) const
591 {
Marshall Clow8a43fca2013-10-21 14:41:05592 return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false;
Howard Hinnantbc8d3f92010-05-11 19:42:16593 }
594
Louis Dionne54238052018-07-11 23:14:33595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16596 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
597 {
598 for (; __low != __high; ++__low, ++__vec)
Howard Hinnantec3773c2011-12-01 20:21:04599 *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16600 return __low;
601 }
602
Louis Dionne54238052018-07-11 23:14:33603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16604 const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
605 {
606 for (; __low != __high; ++__low)
Howard Hinnantec3773c2011-12-01 20:21:04607 if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
Howard Hinnantbc8d3f92010-05-11 19:42:16608 break;
609 return __low;
610 }
611
Louis Dionne54238052018-07-11 23:14:33612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16613 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
614 {
615 for (; __low != __high; ++__low)
Howard Hinnantec3773c2011-12-01 20:21:04616 if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)))
Howard Hinnantbc8d3f92010-05-11 19:42:16617 break;
618 return __low;
619 }
620
Louis Dionne54238052018-07-11 23:14:33621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16622 char_type toupper(char_type __c) const
623 {
624 return do_toupper(__c);
625 }
626
Louis Dionne54238052018-07-11 23:14:33627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16628 const char_type* toupper(char_type* __low, const char_type* __high) const
629 {
630 return do_toupper(__low, __high);
631 }
632
Louis Dionne54238052018-07-11 23:14:33633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16634 char_type tolower(char_type __c) const
635 {
636 return do_tolower(__c);
637 }
638
Louis Dionne54238052018-07-11 23:14:33639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16640 const char_type* tolower(char_type* __low, const char_type* __high) const
641 {
642 return do_tolower(__low, __high);
643 }
644
Louis Dionne54238052018-07-11 23:14:33645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16646 char_type widen(char __c) const
647 {
648 return do_widen(__c);
649 }
650
Louis Dionne54238052018-07-11 23:14:33651 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16652 const char* widen(const char* __low, const char* __high, char_type* __to) const
653 {
654 return do_widen(__low, __high, __to);
655 }
656
Louis Dionne54238052018-07-11 23:14:33657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16658 char narrow(char_type __c, char __dfault) const
659 {
660 return do_narrow(__c, __dfault);
661 }
662
Louis Dionne54238052018-07-11 23:14:33663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16664 const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
665 {
666 return do_narrow(__low, __high, __dfault, __to);
667 }
668
669 static locale::id id;
670
Howard Hinnantadff4892010-05-24 17:49:41671#ifdef _CACHED_RUNES
Howard Hinnantbc8d3f92010-05-11 19:42:16672 static const size_t table_size = _CACHED_RUNES;
Howard Hinnantadff4892010-05-24 17:49:41673#else
674 static const size_t table_size = 256; // FIXME: Don't hardcode this.
675#endif
Louis Dionne54238052018-07-11 23:14:33676 _LIBCPP_INLINE_VISIBILITY const mask* table() const _NOEXCEPT {return __tab_;}
Howard Hinnantc9834542011-05-31 15:34:58677 static const mask* classic_table() _NOEXCEPT;
Vasileios Kalintiris5e00a712015-11-24 10:24:54678#if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
Sean Hunt62a6ac32011-07-09 00:56:23679 static const int* __classic_upper_table() _NOEXCEPT;
680 static const int* __classic_lower_table() _NOEXCEPT;
Sean Hunte59f7242011-07-09 01:09:31681#endif
Joerg Sonnenbergera71a9522013-05-17 21:17:34682#if defined(__NetBSD__)
683 static const short* __classic_upper_table() _NOEXCEPT;
684 static const short* __classic_lower_table() _NOEXCEPT;
685#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16686
687protected:
688 ~ctype();
689 virtual char_type do_toupper(char_type __c) const;
690 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
691 virtual char_type do_tolower(char_type __c) const;
692 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
693 virtual char_type do_widen(char __c) const;
694 virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
695 virtual char do_narrow(char_type __c, char __dfault) const;
696 virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
697};
698
699// template <class CharT> class ctype_byname;
700
Eric Fiselierc3589a82017-01-04 23:56:00701template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype_byname;
Howard Hinnantbc8d3f92010-05-11 19:42:16702
703template <>
Howard Hinnant83eade62013-03-06 23:30:19704class _LIBCPP_TYPE_VIS ctype_byname<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16705 : public ctype<char>
706{
707 locale_t __l;
708
709public:
710 explicit ctype_byname(const char*, size_t = 0);
711 explicit ctype_byname(const string&, size_t = 0);
712
713protected:
714 ~ctype_byname();
715 virtual char_type do_toupper(char_type) const;
716 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
717 virtual char_type do_tolower(char_type) const;
718 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
719};
720
721template <>
Howard Hinnant83eade62013-03-06 23:30:19722class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16723 : public ctype<wchar_t>
724{
725 locale_t __l;
726
727public:
728 explicit ctype_byname(const char*, size_t = 0);
729 explicit ctype_byname(const string&, size_t = 0);
730
731protected:
732 ~ctype_byname();
733 virtual bool do_is(mask __m, char_type __c) const;
734 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
735 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
736 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
737 virtual char_type do_toupper(char_type) const;
738 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
739 virtual char_type do_tolower(char_type) const;
740 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
741 virtual char_type do_widen(char) const;
742 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
743 virtual char do_narrow(char_type, char __dfault) const;
744 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
745};
746
747template <class _CharT>
748inline _LIBCPP_INLINE_VISIBILITY
749bool
750isspace(_CharT __c, const locale& __loc)
751{
752 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
753}
754
755template <class _CharT>
756inline _LIBCPP_INLINE_VISIBILITY
757bool
758isprint(_CharT __c, const locale& __loc)
759{
760 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
761}
762
763template <class _CharT>
764inline _LIBCPP_INLINE_VISIBILITY
765bool
766iscntrl(_CharT __c, const locale& __loc)
767{
768 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
769}
770
771template <class _CharT>
772inline _LIBCPP_INLINE_VISIBILITY
773bool
774isupper(_CharT __c, const locale& __loc)
775{
776 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
777}
778
779template <class _CharT>
780inline _LIBCPP_INLINE_VISIBILITY
781bool
782islower(_CharT __c, const locale& __loc)
783{
784 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
785}
786
787template <class _CharT>
788inline _LIBCPP_INLINE_VISIBILITY
789bool
790isalpha(_CharT __c, const locale& __loc)
791{
792 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
793}
794
795template <class _CharT>
796inline _LIBCPP_INLINE_VISIBILITY
797bool
798isdigit(_CharT __c, const locale& __loc)
799{
800 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
801}
802
803template <class _CharT>
804inline _LIBCPP_INLINE_VISIBILITY
805bool
806ispunct(_CharT __c, const locale& __loc)
807{
808 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
809}
810
811template <class _CharT>
812inline _LIBCPP_INLINE_VISIBILITY
813bool
814isxdigit(_CharT __c, const locale& __loc)
815{
816 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
817}
818
819template <class _CharT>
820inline _LIBCPP_INLINE_VISIBILITY
821bool
822isalnum(_CharT __c, const locale& __loc)
823{
824 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
825}
826
827template <class _CharT>
828inline _LIBCPP_INLINE_VISIBILITY
829bool
830isgraph(_CharT __c, const locale& __loc)
831{
832 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
833}
834
835template <class _CharT>
836inline _LIBCPP_INLINE_VISIBILITY
837_CharT
838toupper(_CharT __c, const locale& __loc)
839{
840 return use_facet<ctype<_CharT> >(__loc).toupper(__c);
841}
842
843template <class _CharT>
844inline _LIBCPP_INLINE_VISIBILITY
845_CharT
846tolower(_CharT __c, const locale& __loc)
847{
848 return use_facet<ctype<_CharT> >(__loc).tolower(__c);
849}
850
851// codecvt_base
852
Howard Hinnant83eade62013-03-06 23:30:19853class _LIBCPP_TYPE_VIS codecvt_base
Howard Hinnantbc8d3f92010-05-11 19:42:16854{
855public:
Louis Dionne54238052018-07-11 23:14:33856 _LIBCPP_INLINE_VISIBILITY codecvt_base() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16857 enum result {ok, partial, error, noconv};
858};
859
860// template <class internT, class externT, class stateT> class codecvt;
861
Eric Fiselierc3589a82017-01-04 23:56:00862template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TEMPLATE_VIS codecvt;
Howard Hinnantbc8d3f92010-05-11 19:42:16863
864// template <> class codecvt<char, char, mbstate_t>
865
866template <>
Howard Hinnant83eade62013-03-06 23:30:19867class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16868 : public locale::facet,
869 public codecvt_base
870{
871public:
872 typedef char intern_type;
873 typedef char extern_type;
874 typedef mbstate_t state_type;
875
Louis Dionne54238052018-07-11 23:14:33876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16877 explicit codecvt(size_t __refs = 0)
878 : locale::facet(__refs) {}
879
Louis Dionne54238052018-07-11 23:14:33880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16881 result out(state_type& __st,
882 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
883 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
884 {
885 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
886 }
887
Louis Dionne54238052018-07-11 23:14:33888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16889 result unshift(state_type& __st,
890 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
891 {
892 return do_unshift(__st, __to, __to_end, __to_nxt);
893 }
894
Louis Dionne54238052018-07-11 23:14:33895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16896 result in(state_type& __st,
897 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
898 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
899 {
900 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
901 }
902
Louis Dionne54238052018-07-11 23:14:33903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc9834542011-05-31 15:34:58904 int encoding() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16905 {
906 return do_encoding();
907 }
908
Louis Dionne54238052018-07-11 23:14:33909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc9834542011-05-31 15:34:58910 bool always_noconv() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16911 {
912 return do_always_noconv();
913 }
914
Louis Dionne54238052018-07-11 23:14:33915 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16916 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
917 {
918 return do_length(__st, __frm, __end, __mx);
919 }
920
Louis Dionne54238052018-07-11 23:14:33921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc9834542011-05-31 15:34:58922 int max_length() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16923 {
924 return do_max_length();
925 }
926
927 static locale::id id;
928
929protected:
Louis Dionne54238052018-07-11 23:14:33930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16931 explicit codecvt(const char*, size_t __refs = 0)
932 : locale::facet(__refs) {}
933
934 ~codecvt();
935
936 virtual result do_out(state_type& __st,
937 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
938 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
939 virtual result do_in(state_type& __st,
940 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
941 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
942 virtual result do_unshift(state_type& __st,
943 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnantc9834542011-05-31 15:34:58944 virtual int do_encoding() const _NOEXCEPT;
945 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16946 virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
Howard Hinnantc9834542011-05-31 15:34:58947 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16948};
949
950// template <> class codecvt<wchar_t, char, mbstate_t>
951
952template <>
Howard Hinnant83eade62013-03-06 23:30:19953class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16954 : public locale::facet,
955 public codecvt_base
956{
957 locale_t __l;
958public:
959 typedef wchar_t intern_type;
960 typedef char extern_type;
961 typedef mbstate_t state_type;
962
963 explicit codecvt(size_t __refs = 0);
964
Louis Dionne54238052018-07-11 23:14:33965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16966 result out(state_type& __st,
967 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
968 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
969 {
970 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
971 }
972
Louis Dionne54238052018-07-11 23:14:33973 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16974 result unshift(state_type& __st,
975 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
976 {
977 return do_unshift(__st, __to, __to_end, __to_nxt);
978 }
979
Louis Dionne54238052018-07-11 23:14:33980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16981 result in(state_type& __st,
982 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
983 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
984 {
985 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
986 }
987
Louis Dionne54238052018-07-11 23:14:33988 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc9834542011-05-31 15:34:58989 int encoding() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16990 {
991 return do_encoding();
992 }
993
Louis Dionne54238052018-07-11 23:14:33994 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc9834542011-05-31 15:34:58995 bool always_noconv() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16996 {
997 return do_always_noconv();
998 }
999
Louis Dionne54238052018-07-11 23:14:331000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161001 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1002 {
1003 return do_length(__st, __frm, __end, __mx);
1004 }
1005
Louis Dionne54238052018-07-11 23:14:331006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc9834542011-05-31 15:34:581007 int max_length() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161008 {
1009 return do_max_length();
1010 }
1011
1012 static locale::id id;
1013
1014protected:
1015 explicit codecvt(const char*, size_t __refs = 0);
1016
1017 ~codecvt();
1018
1019 virtual result do_out(state_type& __st,
1020 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1021 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1022 virtual result do_in(state_type& __st,
1023 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1024 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1025 virtual result do_unshift(state_type& __st,
1026 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnantc9834542011-05-31 15:34:581027 virtual int do_encoding() const _NOEXCEPT;
1028 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161029 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
Howard Hinnantc9834542011-05-31 15:34:581030 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161031};
1032
1033// template <> class codecvt<char16_t, char, mbstate_t>
1034
1035template <>
Howard Hinnant83eade62013-03-06 23:30:191036class _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
Howard Hinnantbc8d3f92010-05-11 19:42:161037 : public locale::facet,
1038 public codecvt_base
1039{
1040public:
1041 typedef char16_t intern_type;
1042 typedef char extern_type;
1043 typedef mbstate_t state_type;
1044
Louis Dionne54238052018-07-11 23:14:331045 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161046 explicit codecvt(size_t __refs = 0)
1047 : locale::facet(__refs) {}
1048
Louis Dionne54238052018-07-11 23:14:331049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161050 result out(state_type& __st,
1051 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1052 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1053 {
1054 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1055 }
1056
Louis Dionne54238052018-07-11 23:14:331057 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161058 result unshift(state_type& __st,
1059 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1060 {
1061 return do_unshift(__st, __to, __to_end, __to_nxt);
1062 }
1063
Louis Dionne54238052018-07-11 23:14:331064 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161065 result in(state_type& __st,
1066 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1067 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1068 {
1069 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1070 }
1071
Louis Dionne54238052018-07-11 23:14:331072 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc9834542011-05-31 15:34:581073 int encoding() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161074 {
1075 return do_encoding();
1076 }
1077
Louis Dionne54238052018-07-11 23:14:331078 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc9834542011-05-31 15:34:581079 bool always_noconv() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161080 {
1081 return do_always_noconv();
1082 }
1083
Louis Dionne54238052018-07-11 23:14:331084 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161085 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1086 {
1087 return do_length(__st, __frm, __end, __mx);
1088 }
1089
Louis Dionne54238052018-07-11 23:14:331090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc9834542011-05-31 15:34:581091 int max_length() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161092 {
1093 return do_max_length();
1094 }
1095
1096 static locale::id id;
1097
1098protected:
Louis Dionne54238052018-07-11 23:14:331099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161100 explicit codecvt(const char*, size_t __refs = 0)
1101 : locale::facet(__refs) {}
1102
1103 ~codecvt();
1104
1105 virtual result do_out(state_type& __st,
1106 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1107 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1108 virtual result do_in(state_type& __st,
1109 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1110 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1111 virtual result do_unshift(state_type& __st,
1112 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnantc9834542011-05-31 15:34:581113 virtual int do_encoding() const _NOEXCEPT;
1114 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161115 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
Howard Hinnantc9834542011-05-31 15:34:581116 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161117};
1118
1119// template <> class codecvt<char32_t, char, mbstate_t>
1120
1121template <>
Howard Hinnant83eade62013-03-06 23:30:191122class _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
Howard Hinnantbc8d3f92010-05-11 19:42:161123 : public locale::facet,
1124 public codecvt_base
1125{
1126public:
1127 typedef char32_t intern_type;
1128 typedef char extern_type;
1129 typedef mbstate_t state_type;
1130
Louis Dionne54238052018-07-11 23:14:331131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161132 explicit codecvt(size_t __refs = 0)
1133 : locale::facet(__refs) {}
1134
Louis Dionne54238052018-07-11 23:14:331135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161136 result out(state_type& __st,
1137 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1138 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1139 {
1140 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1141 }
1142
Louis Dionne54238052018-07-11 23:14:331143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161144 result unshift(state_type& __st,
1145 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1146 {
1147 return do_unshift(__st, __to, __to_end, __to_nxt);
1148 }
1149
Louis Dionne54238052018-07-11 23:14:331150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161151 result in(state_type& __st,
1152 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1153 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1154 {
1155 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1156 }
1157
Louis Dionne54238052018-07-11 23:14:331158 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc9834542011-05-31 15:34:581159 int encoding() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161160 {
1161 return do_encoding();
1162 }
1163
Louis Dionne54238052018-07-11 23:14:331164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc9834542011-05-31 15:34:581165 bool always_noconv() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161166 {
1167 return do_always_noconv();
1168 }
1169
Louis Dionne54238052018-07-11 23:14:331170 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161171 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1172 {
1173 return do_length(__st, __frm, __end, __mx);
1174 }
1175
Louis Dionne54238052018-07-11 23:14:331176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc9834542011-05-31 15:34:581177 int max_length() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161178 {
1179 return do_max_length();
1180 }
1181
1182 static locale::id id;
1183
1184protected:
Louis Dionne54238052018-07-11 23:14:331185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161186 explicit codecvt(const char*, size_t __refs = 0)
1187 : locale::facet(__refs) {}
1188
1189 ~codecvt();
1190
1191 virtual result do_out(state_type& __st,
1192 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1193 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1194 virtual result do_in(state_type& __st,
1195 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1196 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1197 virtual result do_unshift(state_type& __st,
1198 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnantc9834542011-05-31 15:34:581199 virtual int do_encoding() const _NOEXCEPT;
1200 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161201 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
Howard Hinnantc9834542011-05-31 15:34:581202 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161203};
1204
Howard Hinnantbc8d3f92010-05-11 19:42:161205// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
1206
1207template <class _InternT, class _ExternT, class _StateT>
Eric Fiselierc3589a82017-01-04 23:56:001208class _LIBCPP_TEMPLATE_VIS codecvt_byname
Howard Hinnantbc8d3f92010-05-11 19:42:161209 : public codecvt<_InternT, _ExternT, _StateT>
1210{
1211public:
Louis Dionne54238052018-07-11 23:14:331212 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161213 explicit codecvt_byname(const char* __nm, size_t __refs = 0)
1214 : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
Louis Dionne54238052018-07-11 23:14:331215 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161216 explicit codecvt_byname(const string& __nm, size_t __refs = 0)
1217 : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
1218protected:
1219 ~codecvt_byname();
1220};
1221
1222template <class _InternT, class _ExternT, class _StateT>
1223codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
1224{
1225}
1226
Eric Fiselier833d6442016-09-15 22:27:071227_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>)
1228_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>)
1229_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>)
1230_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>)
Howard Hinnantbc8d3f92010-05-11 19:42:161231
Aditya Kumar5db67372016-08-27 02:26:421232_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
1233
Howard Hinnant99968442011-11-29 18:15:501234template <size_t _Np>
Howard Hinnantbc8d3f92010-05-11 19:42:161235struct __narrow_to_utf8
1236{
1237 template <class _OutputIterator, class _CharT>
1238 _OutputIterator
1239 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
1240};
1241
1242template <>
1243struct __narrow_to_utf8<8>
1244{
1245 template <class _OutputIterator, class _CharT>
Louis Dionne54238052018-07-11 23:14:331246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161247 _OutputIterator
1248 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1249 {
1250 for (; __wb < __we; ++__wb, ++__s)
1251 *__s = *__wb;
1252 return __s;
1253 }
1254};
1255
1256template <>
Louis Dionne07f95bd2018-10-25 12:13:431257struct _LIBCPP_TEMPLATE_VIS __narrow_to_utf8<16>
Howard Hinnantbc8d3f92010-05-11 19:42:161258 : public codecvt<char16_t, char, mbstate_t>
1259{
Louis Dionne54238052018-07-11 23:14:331260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161261 __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1262
Louis Dionne07f95bd2018-10-25 12:13:431263 _LIBCPP_EXPORTED_FROM_ABI ~__narrow_to_utf8();
Howard Hinnantbc8d3f92010-05-11 19:42:161264
1265 template <class _OutputIterator, class _CharT>
Louis Dionne54238052018-07-11 23:14:331266 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161267 _OutputIterator
1268 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1269 {
1270 result __r = ok;
1271 mbstate_t __mb;
1272 while (__wb < __we && __r != error)
1273 {
1274 const int __sz = 32;
1275 char __buf[__sz];
1276 char* __bn;
1277 const char16_t* __wn = (const char16_t*)__wb;
1278 __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
1279 __buf, __buf+__sz, __bn);
1280 if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
1281 __throw_runtime_error("locale not supported");
1282 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1283 *__s = *__p;
1284 __wb = (const _CharT*)__wn;
1285 }
1286 return __s;
1287 }
1288};
1289
1290template <>
Louis Dionne07f95bd2018-10-25 12:13:431291struct _LIBCPP_TEMPLATE_VIS __narrow_to_utf8<32>
Howard Hinnantbc8d3f92010-05-11 19:42:161292 : public codecvt<char32_t, char, mbstate_t>
1293{
Louis Dionne54238052018-07-11 23:14:331294 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161295 __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1296
Louis Dionne07f95bd2018-10-25 12:13:431297 _LIBCPP_EXPORTED_FROM_ABI ~__narrow_to_utf8();
Howard Hinnantbc8d3f92010-05-11 19:42:161298
1299 template <class _OutputIterator, class _CharT>
Louis Dionne54238052018-07-11 23:14:331300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161301 _OutputIterator
1302 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1303 {
1304 result __r = ok;
1305 mbstate_t __mb;
1306 while (__wb < __we && __r != error)
1307 {
1308 const int __sz = 32;
1309 char __buf[__sz];
1310 char* __bn;
1311 const char32_t* __wn = (const char32_t*)__wb;
1312 __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
1313 __buf, __buf+__sz, __bn);
1314 if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
1315 __throw_runtime_error("locale not supported");
1316 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1317 *__s = *__p;
1318 __wb = (const _CharT*)__wn;
1319 }
1320 return __s;
1321 }
1322};
1323
Howard Hinnant99968442011-11-29 18:15:501324template <size_t _Np>
Howard Hinnantbc8d3f92010-05-11 19:42:161325struct __widen_from_utf8
1326{
1327 template <class _OutputIterator>
1328 _OutputIterator
1329 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
1330};
1331
1332template <>
1333struct __widen_from_utf8<8>
1334{
1335 template <class _OutputIterator>
Louis Dionne54238052018-07-11 23:14:331336 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161337 _OutputIterator
1338 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1339 {
1340 for (; __nb < __ne; ++__nb, ++__s)
1341 *__s = *__nb;
1342 return __s;
1343 }
1344};
1345
1346template <>
Louis Dionne07f95bd2018-10-25 12:13:431347struct _LIBCPP_TEMPLATE_VIS __widen_from_utf8<16>
Howard Hinnantbc8d3f92010-05-11 19:42:161348 : public codecvt<char16_t, char, mbstate_t>
1349{
Louis Dionne54238052018-07-11 23:14:331350 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161351 __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1352
Louis Dionne07f95bd2018-10-25 12:13:431353 _LIBCPP_EXPORTED_FROM_ABI ~__widen_from_utf8();
Howard Hinnantbc8d3f92010-05-11 19:42:161354
1355 template <class _OutputIterator>
Louis Dionne54238052018-07-11 23:14:331356 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161357 _OutputIterator
1358 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1359 {
1360 result __r = ok;
1361 mbstate_t __mb;
1362 while (__nb < __ne && __r != error)
1363 {
1364 const int __sz = 32;
1365 char16_t __buf[__sz];
1366 char16_t* __bn;
1367 const char* __nn = __nb;
1368 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1369 __buf, __buf+__sz, __bn);
1370 if (__r == codecvt_base::error || __nn == __nb)
1371 __throw_runtime_error("locale not supported");
1372 for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
1373 *__s = (wchar_t)*__p;
1374 __nb = __nn;
1375 }
1376 return __s;
1377 }
1378};
1379
1380template <>
Louis Dionne07f95bd2018-10-25 12:13:431381struct _LIBCPP_TEMPLATE_VIS __widen_from_utf8<32>
Howard Hinnantbc8d3f92010-05-11 19:42:161382 : public codecvt<char32_t, char, mbstate_t>
1383{
Louis Dionne54238052018-07-11 23:14:331384 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161385 __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1386
Louis Dionne07f95bd2018-10-25 12:13:431387 _LIBCPP_EXPORTED_FROM_ABI ~__widen_from_utf8();
Howard Hinnantbc8d3f92010-05-11 19:42:161388
1389 template <class _OutputIterator>
Louis Dionne54238052018-07-11 23:14:331390 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161391 _OutputIterator
1392 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1393 {
1394 result __r = ok;
1395 mbstate_t __mb;
1396 while (__nb < __ne && __r != error)
1397 {
1398 const int __sz = 32;
1399 char32_t __buf[__sz];
1400 char32_t* __bn;
1401 const char* __nn = __nb;
1402 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1403 __buf, __buf+__sz, __bn);
1404 if (__r == codecvt_base::error || __nn == __nb)
1405 __throw_runtime_error("locale not supported");
1406 for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
1407 *__s = (wchar_t)*__p;
1408 __nb = __nn;
1409 }
1410 return __s;
1411 }
1412};
1413
1414// template <class charT> class numpunct
1415
Eric Fiselierc3589a82017-01-04 23:56:001416template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct;
Howard Hinnantbc8d3f92010-05-11 19:42:161417
1418template <>
Howard Hinnant83eade62013-03-06 23:30:191419class _LIBCPP_TYPE_VIS numpunct<char>
Howard Hinnantbc8d3f92010-05-11 19:42:161420 : public locale::facet
1421{
1422public:
1423 typedef char char_type;
1424 typedef basic_string<char_type> string_type;
1425
1426 explicit numpunct(size_t __refs = 0);
1427
Louis Dionne54238052018-07-11 23:14:331428 _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
1429 _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
1430 _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();}
1431 _LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();}
1432 _LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();}
Howard Hinnantbc8d3f92010-05-11 19:42:161433
1434 static locale::id id;
1435
1436protected:
1437 ~numpunct();
1438 virtual char_type do_decimal_point() const;
1439 virtual char_type do_thousands_sep() const;
1440 virtual string do_grouping() const;
1441 virtual string_type do_truename() const;
1442 virtual string_type do_falsename() const;
1443
1444 char_type __decimal_point_;
1445 char_type __thousands_sep_;
1446 string __grouping_;
1447};
1448
1449template <>
Howard Hinnant83eade62013-03-06 23:30:191450class _LIBCPP_TYPE_VIS numpunct<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:161451 : public locale::facet
1452{
1453public:
1454 typedef wchar_t char_type;
1455 typedef basic_string<char_type> string_type;
1456
1457 explicit numpunct(size_t __refs = 0);
1458
Louis Dionne54238052018-07-11 23:14:331459 _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
1460 _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
1461 _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();}
1462 _LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();}
1463 _LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();}
Howard Hinnantbc8d3f92010-05-11 19:42:161464
1465 static locale::id id;
1466
1467protected:
1468 ~numpunct();
1469 virtual char_type do_decimal_point() const;
1470 virtual char_type do_thousands_sep() const;
1471 virtual string do_grouping() const;
1472 virtual string_type do_truename() const;
1473 virtual string_type do_falsename() const;
1474
1475 char_type __decimal_point_;
1476 char_type __thousands_sep_;
1477 string __grouping_;
1478};
1479
1480// template <class charT> class numpunct_byname
1481
Eric Fiselierc3589a82017-01-04 23:56:001482template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct_byname;
Howard Hinnantbc8d3f92010-05-11 19:42:161483
1484template <>
Howard Hinnant83eade62013-03-06 23:30:191485class _LIBCPP_TYPE_VIS numpunct_byname<char>
Howard Hinnantbc8d3f92010-05-11 19:42:161486: public numpunct<char>
1487{
1488public:
1489 typedef char char_type;
1490 typedef basic_string<char_type> string_type;
1491
1492 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1493 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1494
1495protected:
1496 ~numpunct_byname();
1497
1498private:
1499 void __init(const char*);
1500};
1501
1502template <>
Howard Hinnant83eade62013-03-06 23:30:191503class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:161504: public numpunct<wchar_t>
1505{
1506public:
1507 typedef wchar_t char_type;
1508 typedef basic_string<char_type> string_type;
1509
1510 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1511 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1512
1513protected:
1514 ~numpunct_byname();
1515
1516private:
1517 void __init(const char*);
1518};
1519
1520_LIBCPP_END_NAMESPACE_STD
1521
1522#endif // _LIBCPP___LOCALE