blob: 0a275c07a9abc6282239939b288c3485a71086e5 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// 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 Hinnantc51e1022010-05-11 19:42:16 +00007//
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 Hinnant155c2af2010-05-24 17:49:41 +000020#include <locale.h>
Eric Fiselierbb999f92017-05-31 22:14:05 +000021#if defined(_LIBCPP_MSVCRT_LIKE)
Howard Hinnantae0f80b2011-09-29 20:33:10 +000022# include <support/win32/locale_win32.h>
Marshall Clow2f96ec62014-03-11 17:18:47 +000023#elif defined(_AIX)
Howard Hinnantea382952013-08-14 18:00:20 +000024# include <support/ibm/xlocale.h>
Marshall Clow3477ec92014-07-10 15:20:28 +000025#elif defined(__ANDROID__)
Saleem Abdulrasoolac039f32018-04-13 18:14:57 +000026# include <support/android/locale_bionic.h>
Eric Fiselier7274c652014-11-25 21:57:41 +000027#elif defined(__sun__)
Eric Fiselier90adc202015-01-23 22:22:36 +000028# include <xlocale.h>
Eric Fiselier7274c652014-11-25 21:57:41 +000029# include <support/solaris/xlocale.h>
Sergey Dmitrouk9935bd42014-12-12 08:36:16 +000030#elif defined(_NEWLIB_VERSION)
31# include <support/newlib/xlocale.h>
Eric Fiseliercee57932017-08-03 04:28:10 +000032#elif (defined(__APPLE__) || defined(__FreeBSD__) \
Eric Fiselier7274c652014-11-25 21:57:41 +000033 || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
Howard Hinnantdd0d7022011-09-22 19:10:18 +000034# include <xlocale.h>
Petr Hosekfdb4a872017-04-13 21:29:21 +000035#elif defined(__Fuchsia__)
36# include <support/fuchsia/xlocale.h>
Vasileios Kalintiris281b4cf2015-11-09 10:21:04 +000037#elif defined(_LIBCPP_HAS_MUSL_LIBC)
38# include <support/musl/xlocale.h>
Petr Hosekfdb4a872017-04-13 21:29:21 +000039#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +000040
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000041#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +000042#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000043#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +000044
45_LIBCPP_BEGIN_NAMESPACE_STD
46
Martin Storsjo5482ac62017-11-23 10:38:18 +000047#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
Eric Fiselierebc2d2c2017-05-08 22:02:43 +000048struct __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 Storsjo5482ac62017-11-23 10:38:18 +000063#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 Fiselierebc2d2c2017-05-08 22:02:43 +000089#endif
90
91
Howard Hinnant8331b762013-03-06 23:30:19 +000092class _LIBCPP_TYPE_VIS locale;
Howard Hinnantc51e1022010-05-11 19:42:16 +000093
Howard Hinnanta54386e2012-09-14 00:39:16 +000094template <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 Hinnantc51e1022010-05-11 19:42:16 +0000103
Howard Hinnant8331b762013-03-06 23:30:19 +0000104class _LIBCPP_TYPE_VIS locale
Howard Hinnantc51e1022010-05-11 19:42:16 +0000105{
106public:
107 // types:
Howard Hinnant8331b762013-03-06 23:30:19 +0000108 class _LIBCPP_TYPE_VIS facet;
109 class _LIBCPP_TYPE_VIS id;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000110
111 typedef int category;
Mehdi Amini228053d2017-05-04 17:08:54 +0000112 _LIBCPP_AVAILABILITY_LOCALE_CATEGORY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000113 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 Hinnant7c9e5732011-05-31 15:34:58 +0000124 locale() _NOEXCEPT;
125 locale(const locale&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000126 explicit locale(const char*);
127 explicit locale(const string&);
128 locale(const locale&, const char*, category);
129 locale(const locale&, const string&, category);
Howard Hinnantcf823322010-12-17 14:46:43 +0000130 template <class _Facet>
131 _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132 locale(const locale&, const locale&, category);
133
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000134 ~locale();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000135
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000136 const locale& operator=(const locale&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000137
Shoaib Meenai55f3a462017-03-02 03:22:18 +0000138 template <class _Facet>
139 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
140 locale combine(const locale&) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000141
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 Meenai55f3a462017-03-02 03:22:18 +0000147 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000148 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 Hinnant7c9e5732011-05-31 15:34:58 +0000164 template <class _Facet> friend bool has_facet(const locale&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000165 template <class _Facet> friend const _Facet& use_facet(const locale&);
166};
167
Howard Hinnant8331b762013-03-06 23:30:19 +0000168class _LIBCPP_TYPE_VIS locale::facet
Howard Hinnantc51e1022010-05-11 19:42:16 +0000169 : public __shared_count
170{
171protected:
Howard Hinnant9833cad2010-09-21 18:58:51 +0000172 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000173 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 Hinnant719bda32011-05-28 14:41:13 +0000181 virtual void __on_zero_shared() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182};
183
Howard Hinnant8331b762013-03-06 23:30:19 +0000184class _LIBCPP_TYPE_VIS locale::id
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185{
186 once_flag __flag_;
187 int32_t __id_;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000188
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189 static int32_t __next_id;
190public:
Howard Hinnantac7d9f02012-07-26 16:14:37 +0000191 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192private:
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 Hinnantb1ad5a82011-06-30 21:18:19 +0000214 if (!_VSTD::has_facet<_Facet>(__other))
Marshall Clow8fea1612016-08-25 15:09:01 +0000215 __throw_runtime_error("locale::combine: locale missing facet");
216
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000217 return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000218}
219
220template <class _Facet>
221inline _LIBCPP_INLINE_VISIBILITY
222bool
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000223has_facet(const locale& __l) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000224{
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 Fiselierb5eb1bf2017-01-04 23:56:00 +0000239class _LIBCPP_TEMPLATE_VIS collate
Howard Hinnantc51e1022010-05-11 19:42:16 +0000240 : public locale::facet
241{
242public:
243 typedef _CharT char_type;
244 typedef basic_string<char_type> string_type;
245
Howard Hinnant9833cad2010-09-21 18:58:51 +0000246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000247 explicit collate(size_t __refs = 0)
248 : locale::facet(__refs) {}
249
Howard Hinnant9833cad2010-09-21 18:58:51 +0000250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000251 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 Hinnant9833cad2010-09-21 18:58:51 +0000257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000258 string_type transform(const char_type* __lo, const char_type* __hi) const
259 {
260 return do_transform(__lo, __hi);
261 }
262
Howard Hinnant9833cad2010-09-21 18:58:51 +0000263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264 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 Hinnant8c2bf6b2011-10-11 16:00:46 +0000304collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000305{
Howard Hinnant8c2bf6b2011-10-11 16:00:46 +0000306 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 Hinnantc51e1022010-05-11 19:42:16 +0000310 {
Howard Hinnant28b24882011-12-01 20:21:04 +0000311 __h = (__h << 4) + static_cast<size_t>(*__p);
Howard Hinnant8c2bf6b2011-10-11 16:00:46 +0000312 size_t __g = __h & __mask;
313 __h ^= __g | (__g >> __sr);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314 }
Howard Hinnant8c2bf6b2011-10-11 16:00:46 +0000315 return static_cast<long>(__h);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000316}
317
Eric Fiselier1b57fa82016-09-15 22:27:07 +0000318_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 Hinnantc51e1022010-05-11 19:42:16 +0000320
321// template <class CharT> class collate_byname;
322
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000323template <class _CharT> class _LIBCPP_TEMPLATE_VIS collate_byname;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000324
325template <>
Howard Hinnant8331b762013-03-06 23:30:19 +0000326class _LIBCPP_TYPE_VIS collate_byname<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327 : 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 Hinnant8331b762013-03-06 23:30:19 +0000345class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000346 : 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 Hinnantb1ad5a82011-06-30 21:18:19 +0000369 return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370 __x.data(), __x.data() + __x.size(),
371 __y.data(), __y.data() + __y.size()) < 0;
372}
373
374// template <class charT> class ctype
375
Howard Hinnant8331b762013-03-06 23:30:19 +0000376class _LIBCPP_TYPE_VIS ctype_base
Howard Hinnant9833cad2010-09-21 18:58:51 +0000377{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000378public:
Vasileios Kalintiris281b4cf2015-11-09 10:21:04 +0000379#if defined(__GLIBC__)
Alexis Hunt92b0c812011-07-09 00:56:23 +0000380 typedef unsigned short mask;
Howard Hinnant155c2af2010-05-24 17:49:41 +0000381 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 Fiselierbb999f92017-05-31 22:14:05 +0000391#elif defined(_LIBCPP_MSVCRT_LIKE)
Howard Hinnantd7a78632011-09-29 13:33:15 +0000392 typedef unsigned short mask;
Howard Hinnantdd0d7022011-09-22 19:10:18 +0000393 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 Roelofsae9ab252015-03-11 17:00:28 +0000403# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
Dan Albertebdf28b2015-03-11 00:51:06 +0000404#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
JF Bastien0c265d82015-02-25 22:16:46 +0000405# ifdef __APPLE__
David Chisnall1d581062011-09-21 08:39:44 +0000406 typedef __uint32_t mask;
JF Bastien0c265d82015-02-25 22:16:46 +0000407# elif defined(__FreeBSD__)
David Chisnall1d581062011-09-21 08:39:44 +0000408 typedef unsigned long mask;
Vasileios Kalintirisc5dd8942015-11-24 10:24:54 +0000409# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
Howard Hinnant942dbd22013-03-29 18:27:28 +0000410 typedef unsigned short mask;
JF Bastien0c265d82015-02-25 22:16:46 +0000411# endif
David Chisnall1d581062011-09-21 08:39:44 +0000412 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 Albert2dca4072014-07-23 19:32:03 +0000421
Joerg Sonnenberger153e4162013-05-17 21:17:34 +0000422# if defined(__NetBSD__)
423 static const mask blank = _CTYPE_BL;
424# else
David Chisnall1d581062011-09-21 08:39:44 +0000425 static const mask blank = _CTYPE_B;
Joerg Sonnenberger153e4162013-05-17 21:17:34 +0000426# endif
Howard Hinnanta47505d2013-08-30 14:42:39 +0000427#elif defined(__sun__) || defined(_AIX)
David Chisnall8074c342012-02-29 13:05:08 +0000428 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 Bastien0c265d82015-02-25 22:16:46 +0000439#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 Roelofsae9ab252015-03-11 17:00:28 +0000452# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
453# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
454# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
JF Bastien0c265d82015-02-25 22:16:46 +0000455#else
Howard Hinnant8c2bf6b2011-10-11 16:00:46 +0000456 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 Bastien0c265d82015-02-25 22:16:46 +0000467#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000468 static const mask alnum = alpha | digit;
469 static const mask graph = alnum | punct;
470
Louis Dionne16fe2952018-07-11 23:14:33 +0000471 _LIBCPP_INLINE_VISIBILITY ctype_base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000472};
473
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000474template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000475
476template <>
Howard Hinnant8331b762013-03-06 23:30:19 +0000477class _LIBCPP_TYPE_VIS ctype<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000478 : public locale::facet,
479 public ctype_base
480{
481public:
482 typedef wchar_t char_type;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000483
Louis Dionne16fe2952018-07-11 23:14:33 +0000484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485 explicit ctype(size_t __refs = 0)
486 : locale::facet(__refs) {}
487
Louis Dionne16fe2952018-07-11 23:14:33 +0000488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000489 bool is(mask __m, char_type __c) const
490 {
491 return do_is(__m, __c);
492 }
493
Louis Dionne16fe2952018-07-11 23:14:33 +0000494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000495 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 Dionne16fe2952018-07-11 23:14:33 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501 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 Dionne16fe2952018-07-11 23:14:33 +0000506 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000507 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 Dionne16fe2952018-07-11 23:14:33 +0000512 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513 char_type toupper(char_type __c) const
514 {
515 return do_toupper(__c);
516 }
517
Louis Dionne16fe2952018-07-11 23:14:33 +0000518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519 const char_type* toupper(char_type* __low, const char_type* __high) const
520 {
521 return do_toupper(__low, __high);
522 }
523
Louis Dionne16fe2952018-07-11 23:14:33 +0000524 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000525 char_type tolower(char_type __c) const
526 {
527 return do_tolower(__c);
528 }
529
Louis Dionne16fe2952018-07-11 23:14:33 +0000530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000531 const char_type* tolower(char_type* __low, const char_type* __high) const
532 {
533 return do_tolower(__low, __high);
534 }
535
Louis Dionne16fe2952018-07-11 23:14:33 +0000536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000537 char_type widen(char __c) const
538 {
539 return do_widen(__c);
540 }
541
Louis Dionne16fe2952018-07-11 23:14:33 +0000542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000543 const char* widen(const char* __low, const char* __high, char_type* __to) const
544 {
545 return do_widen(__low, __high, __to);
546 }
547
Louis Dionne16fe2952018-07-11 23:14:33 +0000548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000549 char narrow(char_type __c, char __dfault) const
550 {
551 return do_narrow(__c, __dfault);
552 }
553
Louis Dionne16fe2952018-07-11 23:14:33 +0000554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000555 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 Hinnant8331b762013-03-06 23:30:19 +0000579class _LIBCPP_TYPE_VIS ctype<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000580 : 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 Dionne16fe2952018-07-11 23:14:33 +0000589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590 bool is(mask __m, char_type __c) const
591 {
Marshall Clow11de4872013-10-21 14:41:05 +0000592 return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593 }
594
Louis Dionne16fe2952018-07-11 23:14:33 +0000595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000596 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
597 {
598 for (; __low != __high; ++__low, ++__vec)
Howard Hinnant28b24882011-12-01 20:21:04 +0000599 *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000600 return __low;
601 }
602
Louis Dionne16fe2952018-07-11 23:14:33 +0000603 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604 const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
605 {
606 for (; __low != __high; ++__low)
Howard Hinnant28b24882011-12-01 20:21:04 +0000607 if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608 break;
609 return __low;
610 }
611
Louis Dionne16fe2952018-07-11 23:14:33 +0000612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
614 {
615 for (; __low != __high; ++__low)
Howard Hinnant28b24882011-12-01 20:21:04 +0000616 if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617 break;
618 return __low;
619 }
620
Louis Dionne16fe2952018-07-11 23:14:33 +0000621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000622 char_type toupper(char_type __c) const
623 {
624 return do_toupper(__c);
625 }
626
Louis Dionne16fe2952018-07-11 23:14:33 +0000627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000628 const char_type* toupper(char_type* __low, const char_type* __high) const
629 {
630 return do_toupper(__low, __high);
631 }
632
Louis Dionne16fe2952018-07-11 23:14:33 +0000633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000634 char_type tolower(char_type __c) const
635 {
636 return do_tolower(__c);
637 }
638
Louis Dionne16fe2952018-07-11 23:14:33 +0000639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640 const char_type* tolower(char_type* __low, const char_type* __high) const
641 {
642 return do_tolower(__low, __high);
643 }
644
Louis Dionne16fe2952018-07-11 23:14:33 +0000645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000646 char_type widen(char __c) const
647 {
648 return do_widen(__c);
649 }
650
Louis Dionne16fe2952018-07-11 23:14:33 +0000651 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000652 const char* widen(const char* __low, const char* __high, char_type* __to) const
653 {
654 return do_widen(__low, __high, __to);
655 }
656
Louis Dionne16fe2952018-07-11 23:14:33 +0000657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000658 char narrow(char_type __c, char __dfault) const
659 {
660 return do_narrow(__c, __dfault);
661 }
662
Louis Dionne16fe2952018-07-11 23:14:33 +0000663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000664 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 Hinnant155c2af2010-05-24 17:49:41 +0000671#ifdef _CACHED_RUNES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672 static const size_t table_size = _CACHED_RUNES;
Howard Hinnant155c2af2010-05-24 17:49:41 +0000673#else
674 static const size_t table_size = 256; // FIXME: Don't hardcode this.
675#endif
Louis Dionne16fe2952018-07-11 23:14:33 +0000676 _LIBCPP_INLINE_VISIBILITY const mask* table() const _NOEXCEPT {return __tab_;}
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000677 static const mask* classic_table() _NOEXCEPT;
Vasileios Kalintirisc5dd8942015-11-24 10:24:54 +0000678#if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
Alexis Hunt92b0c812011-07-09 00:56:23 +0000679 static const int* __classic_upper_table() _NOEXCEPT;
680 static const int* __classic_lower_table() _NOEXCEPT;
Alexis Hunt5a4dd562011-07-09 01:09:31 +0000681#endif
Joerg Sonnenberger153e4162013-05-17 21:17:34 +0000682#if defined(__NetBSD__)
683 static const short* __classic_upper_table() _NOEXCEPT;
684 static const short* __classic_lower_table() _NOEXCEPT;
685#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000686
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 Fiselierb5eb1bf2017-01-04 23:56:00 +0000701template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype_byname;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702
703template <>
Howard Hinnant8331b762013-03-06 23:30:19 +0000704class _LIBCPP_TYPE_VIS ctype_byname<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705 : 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 Hinnant8331b762013-03-06 23:30:19 +0000722class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000723 : 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 Hinnant8331b762013-03-06 23:30:19 +0000853class _LIBCPP_TYPE_VIS codecvt_base
Howard Hinnantc51e1022010-05-11 19:42:16 +0000854{
855public:
Louis Dionne16fe2952018-07-11 23:14:33 +0000856 _LIBCPP_INLINE_VISIBILITY codecvt_base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857 enum result {ok, partial, error, noconv};
858};
859
860// template <class internT, class externT, class stateT> class codecvt;
861
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000862template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TEMPLATE_VIS codecvt;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863
864// template <> class codecvt<char, char, mbstate_t>
865
866template <>
Howard Hinnant8331b762013-03-06 23:30:19 +0000867class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868 : 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 Dionne16fe2952018-07-11 23:14:33 +0000876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000877 explicit codecvt(size_t __refs = 0)
878 : locale::facet(__refs) {}
879
Louis Dionne16fe2952018-07-11 23:14:33 +0000880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000881 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 Dionne16fe2952018-07-11 23:14:33 +0000888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000889 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 Dionne16fe2952018-07-11 23:14:33 +0000895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000896 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 Dionne16fe2952018-07-11 23:14:33 +0000903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000904 int encoding() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000905 {
906 return do_encoding();
907 }
908
Louis Dionne16fe2952018-07-11 23:14:33 +0000909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000910 bool always_noconv() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911 {
912 return do_always_noconv();
913 }
914
Louis Dionne16fe2952018-07-11 23:14:33 +0000915 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916 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 Dionne16fe2952018-07-11 23:14:33 +0000921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000922 int max_length() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000923 {
924 return do_max_length();
925 }
926
927 static locale::id id;
928
929protected:
Louis Dionne16fe2952018-07-11 23:14:33 +0000930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000931 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 Hinnant7c9e5732011-05-31 15:34:58 +0000944 virtual int do_encoding() const _NOEXCEPT;
945 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000946 virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000947 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000948};
949
950// template <> class codecvt<wchar_t, char, mbstate_t>
951
952template <>
Howard Hinnant8331b762013-03-06 23:30:19 +0000953class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000954 : 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 Dionne16fe2952018-07-11 23:14:33 +0000965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000966 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 Dionne16fe2952018-07-11 23:14:33 +0000973 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000974 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 Dionne16fe2952018-07-11 23:14:33 +0000980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000981 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 Dionne16fe2952018-07-11 23:14:33 +0000988 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000989 int encoding() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000990 {
991 return do_encoding();
992 }
993
Louis Dionne16fe2952018-07-11 23:14:33 +0000994 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000995 bool always_noconv() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996 {
997 return do_always_noconv();
998 }
999
Louis Dionne16fe2952018-07-11 23:14:33 +00001000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001001 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 Dionne16fe2952018-07-11 23:14:33 +00001006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001007 int max_length() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001008 {
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 Hinnant7c9e5732011-05-31 15:34:58 +00001027 virtual int do_encoding() const _NOEXCEPT;
1028 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001030 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001031};
1032
1033// template <> class codecvt<char16_t, char, mbstate_t>
1034
1035template <>
Howard Hinnant8331b762013-03-06 23:30:19 +00001036class _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001037 : 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 Dionne16fe2952018-07-11 23:14:33 +00001045 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001046 explicit codecvt(size_t __refs = 0)
1047 : locale::facet(__refs) {}
1048
Louis Dionne16fe2952018-07-11 23:14:33 +00001049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050 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 Dionne16fe2952018-07-11 23:14:33 +00001057 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001058 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 Dionne16fe2952018-07-11 23:14:33 +00001064 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001065 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 Dionne16fe2952018-07-11 23:14:33 +00001072 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001073 int encoding() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001074 {
1075 return do_encoding();
1076 }
1077
Louis Dionne16fe2952018-07-11 23:14:33 +00001078 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001079 bool always_noconv() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080 {
1081 return do_always_noconv();
1082 }
1083
Louis Dionne16fe2952018-07-11 23:14:33 +00001084 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085 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 Dionne16fe2952018-07-11 23:14:33 +00001090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001091 int max_length() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001092 {
1093 return do_max_length();
1094 }
1095
1096 static locale::id id;
1097
1098protected:
Louis Dionne16fe2952018-07-11 23:14:33 +00001099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001100 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 Hinnant7c9e5732011-05-31 15:34:58 +00001113 virtual int do_encoding() const _NOEXCEPT;
1114 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001116 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001117};
1118
1119// template <> class codecvt<char32_t, char, mbstate_t>
1120
1121template <>
Howard Hinnant8331b762013-03-06 23:30:19 +00001122class _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001123 : 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 Dionne16fe2952018-07-11 23:14:33 +00001131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001132 explicit codecvt(size_t __refs = 0)
1133 : locale::facet(__refs) {}
1134
Louis Dionne16fe2952018-07-11 23:14:33 +00001135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001136 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 Dionne16fe2952018-07-11 23:14:33 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144 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 Dionne16fe2952018-07-11 23:14:33 +00001150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001151 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 Dionne16fe2952018-07-11 23:14:33 +00001158 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001159 int encoding() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001160 {
1161 return do_encoding();
1162 }
1163
Louis Dionne16fe2952018-07-11 23:14:33 +00001164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001165 bool always_noconv() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001166 {
1167 return do_always_noconv();
1168 }
1169
Louis Dionne16fe2952018-07-11 23:14:33 +00001170 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001171 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 Dionne16fe2952018-07-11 23:14:33 +00001176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001177 int max_length() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001178 {
1179 return do_max_length();
1180 }
1181
1182 static locale::id id;
1183
1184protected:
Louis Dionne16fe2952018-07-11 23:14:33 +00001185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001186 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 Hinnant7c9e5732011-05-31 15:34:58 +00001199 virtual int do_encoding() const _NOEXCEPT;
1200 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001201 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001202 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001203};
1204
Howard Hinnantc51e1022010-05-11 19:42:16 +00001205// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
1206
1207template <class _InternT, class _ExternT, class _StateT>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001208class _LIBCPP_TEMPLATE_VIS codecvt_byname
Howard Hinnantc51e1022010-05-11 19:42:16 +00001209 : public codecvt<_InternT, _ExternT, _StateT>
1210{
1211public:
Louis Dionne16fe2952018-07-11 23:14:33 +00001212 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001213 explicit codecvt_byname(const char* __nm, size_t __refs = 0)
1214 : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
Louis Dionne16fe2952018-07-11 23:14:33 +00001215 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001216 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 Fiselier1b57fa82016-09-15 22:27:07 +00001227_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 Hinnantc51e1022010-05-11 19:42:16 +00001231
Howard Hinnantc834c512011-11-29 18:15:50 +00001232template <size_t _Np>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001233struct __narrow_to_utf8
1234{
1235 template <class _OutputIterator, class _CharT>
1236 _OutputIterator
1237 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
1238};
1239
1240template <>
1241struct __narrow_to_utf8<8>
1242{
1243 template <class _OutputIterator, class _CharT>
Louis Dionne16fe2952018-07-11 23:14:33 +00001244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001245 _OutputIterator
1246 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1247 {
1248 for (; __wb < __we; ++__wb, ++__s)
1249 *__s = *__wb;
1250 return __s;
1251 }
1252};
1253
1254template <>
Louis Dionne5254b372018-10-25 12:13:43 +00001255struct _LIBCPP_TEMPLATE_VIS __narrow_to_utf8<16>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001256 : public codecvt<char16_t, char, mbstate_t>
1257{
Louis Dionne16fe2952018-07-11 23:14:33 +00001258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001259 __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1260
Louis Dionne5254b372018-10-25 12:13:43 +00001261 _LIBCPP_EXPORTED_FROM_ABI ~__narrow_to_utf8();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262
1263 template <class _OutputIterator, class _CharT>
Louis Dionne16fe2952018-07-11 23:14:33 +00001264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001265 _OutputIterator
1266 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1267 {
1268 result __r = ok;
1269 mbstate_t __mb;
1270 while (__wb < __we && __r != error)
1271 {
1272 const int __sz = 32;
1273 char __buf[__sz];
1274 char* __bn;
1275 const char16_t* __wn = (const char16_t*)__wb;
1276 __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
1277 __buf, __buf+__sz, __bn);
1278 if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
1279 __throw_runtime_error("locale not supported");
1280 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1281 *__s = *__p;
1282 __wb = (const _CharT*)__wn;
1283 }
1284 return __s;
1285 }
1286};
1287
1288template <>
Louis Dionne5254b372018-10-25 12:13:43 +00001289struct _LIBCPP_TEMPLATE_VIS __narrow_to_utf8<32>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001290 : public codecvt<char32_t, char, mbstate_t>
1291{
Louis Dionne16fe2952018-07-11 23:14:33 +00001292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293 __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1294
Louis Dionne5254b372018-10-25 12:13:43 +00001295 _LIBCPP_EXPORTED_FROM_ABI ~__narrow_to_utf8();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001296
1297 template <class _OutputIterator, class _CharT>
Louis Dionne16fe2952018-07-11 23:14:33 +00001298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001299 _OutputIterator
1300 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1301 {
1302 result __r = ok;
1303 mbstate_t __mb;
1304 while (__wb < __we && __r != error)
1305 {
1306 const int __sz = 32;
1307 char __buf[__sz];
1308 char* __bn;
1309 const char32_t* __wn = (const char32_t*)__wb;
1310 __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
1311 __buf, __buf+__sz, __bn);
1312 if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
1313 __throw_runtime_error("locale not supported");
1314 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1315 *__s = *__p;
1316 __wb = (const _CharT*)__wn;
1317 }
1318 return __s;
1319 }
1320};
1321
Howard Hinnantc834c512011-11-29 18:15:50 +00001322template <size_t _Np>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001323struct __widen_from_utf8
1324{
1325 template <class _OutputIterator>
1326 _OutputIterator
1327 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
1328};
1329
1330template <>
1331struct __widen_from_utf8<8>
1332{
1333 template <class _OutputIterator>
Louis Dionne16fe2952018-07-11 23:14:33 +00001334 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001335 _OutputIterator
1336 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1337 {
1338 for (; __nb < __ne; ++__nb, ++__s)
1339 *__s = *__nb;
1340 return __s;
1341 }
1342};
1343
1344template <>
Louis Dionne5254b372018-10-25 12:13:43 +00001345struct _LIBCPP_TEMPLATE_VIS __widen_from_utf8<16>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001346 : public codecvt<char16_t, char, mbstate_t>
1347{
Louis Dionne16fe2952018-07-11 23:14:33 +00001348 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001349 __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1350
Louis Dionne5254b372018-10-25 12:13:43 +00001351 _LIBCPP_EXPORTED_FROM_ABI ~__widen_from_utf8();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001352
1353 template <class _OutputIterator>
Louis Dionne16fe2952018-07-11 23:14:33 +00001354 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001355 _OutputIterator
1356 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1357 {
1358 result __r = ok;
1359 mbstate_t __mb;
1360 while (__nb < __ne && __r != error)
1361 {
1362 const int __sz = 32;
1363 char16_t __buf[__sz];
1364 char16_t* __bn;
1365 const char* __nn = __nb;
1366 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1367 __buf, __buf+__sz, __bn);
1368 if (__r == codecvt_base::error || __nn == __nb)
1369 __throw_runtime_error("locale not supported");
1370 for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
1371 *__s = (wchar_t)*__p;
1372 __nb = __nn;
1373 }
1374 return __s;
1375 }
1376};
1377
1378template <>
Louis Dionne5254b372018-10-25 12:13:43 +00001379struct _LIBCPP_TEMPLATE_VIS __widen_from_utf8<32>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380 : public codecvt<char32_t, char, mbstate_t>
1381{
Louis Dionne16fe2952018-07-11 23:14:33 +00001382 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001383 __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1384
Louis Dionne5254b372018-10-25 12:13:43 +00001385 _LIBCPP_EXPORTED_FROM_ABI ~__widen_from_utf8();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001386
1387 template <class _OutputIterator>
Louis Dionne16fe2952018-07-11 23:14:33 +00001388 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001389 _OutputIterator
1390 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1391 {
1392 result __r = ok;
1393 mbstate_t __mb;
1394 while (__nb < __ne && __r != error)
1395 {
1396 const int __sz = 32;
1397 char32_t __buf[__sz];
1398 char32_t* __bn;
1399 const char* __nn = __nb;
1400 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1401 __buf, __buf+__sz, __bn);
1402 if (__r == codecvt_base::error || __nn == __nb)
1403 __throw_runtime_error("locale not supported");
1404 for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
1405 *__s = (wchar_t)*__p;
1406 __nb = __nn;
1407 }
1408 return __s;
1409 }
1410};
1411
1412// template <class charT> class numpunct
1413
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001414template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001415
1416template <>
Howard Hinnant8331b762013-03-06 23:30:19 +00001417class _LIBCPP_TYPE_VIS numpunct<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001418 : public locale::facet
1419{
1420public:
1421 typedef char char_type;
1422 typedef basic_string<char_type> string_type;
1423
1424 explicit numpunct(size_t __refs = 0);
1425
Louis Dionne16fe2952018-07-11 23:14:33 +00001426 _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
1427 _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
1428 _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();}
1429 _LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();}
1430 _LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001431
1432 static locale::id id;
1433
1434protected:
1435 ~numpunct();
1436 virtual char_type do_decimal_point() const;
1437 virtual char_type do_thousands_sep() const;
1438 virtual string do_grouping() const;
1439 virtual string_type do_truename() const;
1440 virtual string_type do_falsename() const;
1441
1442 char_type __decimal_point_;
1443 char_type __thousands_sep_;
1444 string __grouping_;
1445};
1446
1447template <>
Howard Hinnant8331b762013-03-06 23:30:19 +00001448class _LIBCPP_TYPE_VIS numpunct<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001449 : public locale::facet
1450{
1451public:
1452 typedef wchar_t char_type;
1453 typedef basic_string<char_type> string_type;
1454
1455 explicit numpunct(size_t __refs = 0);
1456
Louis Dionne16fe2952018-07-11 23:14:33 +00001457 _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
1458 _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
1459 _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();}
1460 _LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();}
1461 _LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001462
1463 static locale::id id;
1464
1465protected:
1466 ~numpunct();
1467 virtual char_type do_decimal_point() const;
1468 virtual char_type do_thousands_sep() const;
1469 virtual string do_grouping() const;
1470 virtual string_type do_truename() const;
1471 virtual string_type do_falsename() const;
1472
1473 char_type __decimal_point_;
1474 char_type __thousands_sep_;
1475 string __grouping_;
1476};
1477
1478// template <class charT> class numpunct_byname
1479
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001480template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct_byname;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001481
1482template <>
Howard Hinnant8331b762013-03-06 23:30:19 +00001483class _LIBCPP_TYPE_VIS numpunct_byname<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001484: public numpunct<char>
1485{
1486public:
1487 typedef char char_type;
1488 typedef basic_string<char_type> string_type;
1489
1490 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1491 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1492
1493protected:
1494 ~numpunct_byname();
1495
1496private:
1497 void __init(const char*);
1498};
1499
1500template <>
Howard Hinnant8331b762013-03-06 23:30:19 +00001501class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001502: public numpunct<wchar_t>
1503{
1504public:
1505 typedef wchar_t char_type;
1506 typedef basic_string<char_type> string_type;
1507
1508 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1509 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1510
1511protected:
1512 ~numpunct_byname();
1513
1514private:
1515 void __init(const char*);
1516};
1517
1518_LIBCPP_END_NAMESPACE_STD
1519
1520#endif // _LIBCPP___LOCALE