blob: 4296adbbd8e927ce5b807c55562c31deb29d01cd [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
Louis Dionne73912b22020-11-04 15:01:25 -050013#include <__availability>
Arthur O'Dwyeref181602021-05-19 11:57:04 -040014#include <__config>
Howard Hinnantc51e1022010-05-11 19:42:16 +000015#include <string>
16#include <memory>
17#include <utility>
18#include <mutex>
19#include <cstdint>
20#include <cctype>
Howard Hinnant155c2af2010-05-24 17:49:41 +000021#include <locale.h>
Eric Fiselierbb999f92017-05-31 22:14:05 +000022#if defined(_LIBCPP_MSVCRT_LIKE)
Thomas Anderson094acbc2019-03-27 18:09:30 +000023# include <cstring>
Louis Dionne90a04492021-02-02 16:58:38 -050024# include <__support/win32/locale_win32.h>
Muiez Ahmedaf108fb2020-11-10 09:54:03 -050025#elif defined(_AIX) || defined(__MVS__)
Louis Dionne90a04492021-02-02 16:58:38 -050026# include <__support/ibm/xlocale.h>
Marshall Clow3477ec92014-07-10 15:20:28 +000027#elif defined(__ANDROID__)
Louis Dionne90a04492021-02-02 16:58:38 -050028# include <__support/android/locale_bionic.h>
Eric Fiselier7274c652014-11-25 21:57:41 +000029#elif defined(__sun__)
Eric Fiselier90adc202015-01-23 22:22:36 +000030# include <xlocale.h>
Louis Dionne90a04492021-02-02 16:58:38 -050031# include <__support/solaris/xlocale.h>
Sergey Dmitrouk9935bd42014-12-12 08:36:16 +000032#elif defined(_NEWLIB_VERSION)
Louis Dionne90a04492021-02-02 16:58:38 -050033# include <__support/newlib/xlocale.h>
Brad Smithf6f55092021-01-12 14:16:15 -050034#elif defined(__OpenBSD__)
Louis Dionne90a04492021-02-02 16:58:38 -050035# include <__support/openbsd/xlocale.h>
Eric Fiseliercee57932017-08-03 04:28:10 +000036#elif (defined(__APPLE__) || defined(__FreeBSD__) \
Eric Fiselier7274c652014-11-25 21:57:41 +000037 || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
Howard Hinnantdd0d7022011-09-22 19:10:18 +000038# include <xlocale.h>
Petr Hosekfdb4a872017-04-13 21:29:21 +000039#elif defined(__Fuchsia__)
Louis Dionne90a04492021-02-02 16:58:38 -050040# include <__support/fuchsia/xlocale.h>
Dan Gohman280fd6b2019-05-01 16:47:30 +000041#elif defined(__wasi__)
42// WASI libc uses musl's locales support.
Louis Dionne90a04492021-02-02 16:58:38 -050043# include <__support/musl/xlocale.h>
Vasileios Kalintiris281b4cf2015-11-09 10:21:04 +000044#elif defined(_LIBCPP_HAS_MUSL_LIBC)
Louis Dionne90a04492021-02-02 16:58:38 -050045# include <__support/musl/xlocale.h>
Petr Hosekfdb4a872017-04-13 21:29:21 +000046#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +000047
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000048#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +000049#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000050#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +000051
52_LIBCPP_BEGIN_NAMESPACE_STD
53
Martin Storsjo5482ac62017-11-23 10:38:18 +000054#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
Eric Fiselierebc2d2c2017-05-08 22:02:43 +000055struct __libcpp_locale_guard {
56 _LIBCPP_INLINE_VISIBILITY
57 __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
58
59 _LIBCPP_INLINE_VISIBILITY
60 ~__libcpp_locale_guard() {
61 if (__old_loc_)
62 uselocale(__old_loc_);
63 }
64
65 locale_t __old_loc_;
66private:
67 __libcpp_locale_guard(__libcpp_locale_guard const&);
68 __libcpp_locale_guard& operator=(__libcpp_locale_guard const&);
69};
Martin Storsjo5482ac62017-11-23 10:38:18 +000070#elif defined(_LIBCPP_MSVCRT_LIKE)
71struct __libcpp_locale_guard {
72 __libcpp_locale_guard(locale_t __l) :
Thomas Anderson094acbc2019-03-27 18:09:30 +000073 __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) {
74 // Setting the locale can be expensive even when the locale given is
75 // already the current locale, so do an explicit check to see if the
76 // current locale is already the one we want.
77 const char* __lc = __setlocale(nullptr);
78 // If every category is the same, the locale string will simply be the
79 // locale name, otherwise it will be a semicolon-separated string listing
80 // each category. In the second case, we know at least one category won't
81 // be what we want, so we only have to check the first case.
Arthur O'Dwyer22236632020-12-07 21:50:15 -050082 if (_VSTD::strcmp(__l.__get_locale(), __lc) != 0) {
Thomas Anderson094acbc2019-03-27 18:09:30 +000083 __locale_all = _strdup(__lc);
84 if (__locale_all == nullptr)
85 __throw_bad_alloc();
86 __setlocale(__l.__get_locale());
87 }
88 }
Martin Storsjo5482ac62017-11-23 10:38:18 +000089 ~__libcpp_locale_guard() {
Thomas Anderson094acbc2019-03-27 18:09:30 +000090 // The CRT documentation doesn't explicitly say, but setlocale() does the
91 // right thing when given a semicolon-separated list of locale settings
92 // for the different categories in the same format as returned by
93 // setlocale(LC_ALL, nullptr).
94 if (__locale_all != nullptr) {
95 __setlocale(__locale_all);
96 free(__locale_all);
97 }
98 _configthreadlocale(__status);
99 }
100 static const char* __setlocale(const char* __locale) {
101 const char* __new_locale = setlocale(LC_ALL, __locale);
102 if (__new_locale == nullptr)
103 __throw_bad_alloc();
104 return __new_locale;
Martin Storsjo5482ac62017-11-23 10:38:18 +0000105 }
106 int __status;
Thomas Anderson094acbc2019-03-27 18:09:30 +0000107 char* __locale_all = nullptr;
Martin Storsjo5482ac62017-11-23 10:38:18 +0000108};
Eric Fiselierebc2d2c2017-05-08 22:02:43 +0000109#endif
110
Howard Hinnant8331b762013-03-06 23:30:19 +0000111class _LIBCPP_TYPE_VIS locale;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000112
Howard Hinnanta54386e2012-09-14 00:39:16 +0000113template <class _Facet>
114_LIBCPP_INLINE_VISIBILITY
115bool
116has_facet(const locale&) _NOEXCEPT;
117
118template <class _Facet>
119_LIBCPP_INLINE_VISIBILITY
120const _Facet&
121use_facet(const locale&);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000122
Howard Hinnant8331b762013-03-06 23:30:19 +0000123class _LIBCPP_TYPE_VIS locale
Howard Hinnantc51e1022010-05-11 19:42:16 +0000124{
125public:
126 // types:
Howard Hinnant8331b762013-03-06 23:30:19 +0000127 class _LIBCPP_TYPE_VIS facet;
128 class _LIBCPP_TYPE_VIS id;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000129
130 typedef int category;
Mehdi Amini228053d2017-05-04 17:08:54 +0000131 _LIBCPP_AVAILABILITY_LOCALE_CATEGORY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132 static const category // values assigned here are for exposition only
133 none = 0,
134 collate = LC_COLLATE_MASK,
135 ctype = LC_CTYPE_MASK,
136 monetary = LC_MONETARY_MASK,
137 numeric = LC_NUMERIC_MASK,
138 time = LC_TIME_MASK,
139 messages = LC_MESSAGES_MASK,
140 all = collate | ctype | monetary | numeric | time | messages;
141
142 // construct/copy/destroy:
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000143 locale() _NOEXCEPT;
144 locale(const locale&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000145 explicit locale(const char*);
146 explicit locale(const string&);
147 locale(const locale&, const char*, category);
148 locale(const locale&, const string&, category);
Howard Hinnantcf823322010-12-17 14:46:43 +0000149 template <class _Facet>
150 _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000151 locale(const locale&, const locale&, category);
152
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000153 ~locale();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000154
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000155 const locale& operator=(const locale&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000156
Shoaib Meenai55f3a462017-03-02 03:22:18 +0000157 template <class _Facet>
158 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
159 locale combine(const locale&) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000160
161 // locale operations:
162 string name() const;
163 bool operator==(const locale&) const;
164 bool operator!=(const locale& __y) const {return !(*this == __y);}
165 template <class _CharT, class _Traits, class _Allocator>
Shoaib Meenai55f3a462017-03-02 03:22:18 +0000166 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000167 bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
168 const basic_string<_CharT, _Traits, _Allocator>&) const;
169
170 // global locale objects:
171 static locale global(const locale&);
172 static const locale& classic();
173
174private:
175 class __imp;
176 __imp* __locale_;
177
178 void __install_ctor(const locale&, facet*, long);
179 static locale& __global();
180 bool has_facet(id&) const;
181 const facet* use_facet(id&) const;
182
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000183 template <class _Facet> friend bool has_facet(const locale&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000184 template <class _Facet> friend const _Facet& use_facet(const locale&);
185};
186
Howard Hinnant8331b762013-03-06 23:30:19 +0000187class _LIBCPP_TYPE_VIS locale::facet
Howard Hinnantc51e1022010-05-11 19:42:16 +0000188 : public __shared_count
189{
190protected:
Howard Hinnant9833cad2010-09-21 18:58:51 +0000191 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192 explicit facet(size_t __refs = 0)
193 : __shared_count(static_cast<long>(__refs)-1) {}
194
195 virtual ~facet();
196
197// facet(const facet&) = delete; // effectively done in __shared_count
198// void operator=(const facet&) = delete;
199private:
Howard Hinnant719bda32011-05-28 14:41:13 +0000200 virtual void __on_zero_shared() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000201};
202
Howard Hinnant8331b762013-03-06 23:30:19 +0000203class _LIBCPP_TYPE_VIS locale::id
Howard Hinnantc51e1022010-05-11 19:42:16 +0000204{
205 once_flag __flag_;
206 int32_t __id_;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000207
Howard Hinnantc51e1022010-05-11 19:42:16 +0000208 static int32_t __next_id;
209public:
Howard Hinnantac7d9f02012-07-26 16:14:37 +0000210 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000211private:
212 void __init();
213 void operator=(const id&); // = delete;
214 id(const id&); // = delete;
215public: // only needed for tests
216 long __get();
217
218 friend class locale;
219 friend class locale::__imp;
220};
221
222template <class _Facet>
223inline _LIBCPP_INLINE_VISIBILITY
224locale::locale(const locale& __other, _Facet* __f)
225{
226 __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
227}
228
229template <class _Facet>
230locale
231locale::combine(const locale& __other) const
232{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000233 if (!_VSTD::has_facet<_Facet>(__other))
Marshall Clow8fea1612016-08-25 15:09:01 +0000234 __throw_runtime_error("locale::combine: locale missing facet");
235
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000236 return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000237}
238
239template <class _Facet>
240inline _LIBCPP_INLINE_VISIBILITY
241bool
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000242has_facet(const locale& __l) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000243{
244 return __l.has_facet(_Facet::id);
245}
246
247template <class _Facet>
248inline _LIBCPP_INLINE_VISIBILITY
249const _Facet&
250use_facet(const locale& __l)
251{
252 return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
253}
254
255// template <class _CharT> class collate;
256
257template <class _CharT>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000258class _LIBCPP_TEMPLATE_VIS collate
Howard Hinnantc51e1022010-05-11 19:42:16 +0000259 : public locale::facet
260{
261public:
262 typedef _CharT char_type;
263 typedef basic_string<char_type> string_type;
264
Howard Hinnant9833cad2010-09-21 18:58:51 +0000265 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000266 explicit collate(size_t __refs = 0)
267 : locale::facet(__refs) {}
268
Howard Hinnant9833cad2010-09-21 18:58:51 +0000269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270 int compare(const char_type* __lo1, const char_type* __hi1,
271 const char_type* __lo2, const char_type* __hi2) const
272 {
273 return do_compare(__lo1, __hi1, __lo2, __hi2);
274 }
275
Eric Fiselier39b86ea2019-03-08 23:59:29 +0000276 // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work
277 // around a dllimport bug that expects an external instantiation.
Howard Hinnant9833cad2010-09-21 18:58:51 +0000278 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier39b86ea2019-03-08 23:59:29 +0000279 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc51e1022010-05-11 19:42:16 +0000280 string_type transform(const char_type* __lo, const char_type* __hi) const
281 {
282 return do_transform(__lo, __hi);
283 }
284
Howard Hinnant9833cad2010-09-21 18:58:51 +0000285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000286 long hash(const char_type* __lo, const char_type* __hi) const
287 {
288 return do_hash(__lo, __hi);
289 }
290
291 static locale::id id;
292
293protected:
294 ~collate();
295 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
296 const char_type* __lo2, const char_type* __hi2) const;
297 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
298 {return string_type(__lo, __hi);}
299 virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
300};
301
302template <class _CharT> locale::id collate<_CharT>::id;
303
304template <class _CharT>
305collate<_CharT>::~collate()
306{
307}
308
309template <class _CharT>
310int
311collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
312 const char_type* __lo2, const char_type* __hi2) const
313{
314 for (; __lo2 != __hi2; ++__lo1, ++__lo2)
315 {
316 if (__lo1 == __hi1 || *__lo1 < *__lo2)
317 return -1;
318 if (*__lo2 < *__lo1)
319 return 1;
320 }
321 return __lo1 != __hi1;
322}
323
324template <class _CharT>
325long
Howard Hinnant8c2bf6b2011-10-11 16:00:46 +0000326collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327{
Howard Hinnant8c2bf6b2011-10-11 16:00:46 +0000328 size_t __h = 0;
329 const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
330 const size_t __mask = size_t(0xF) << (__sr + 4);
331 for(const char_type* __p = __lo; __p != __hi; ++__p)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000332 {
Howard Hinnant28b24882011-12-01 20:21:04 +0000333 __h = (__h << 4) + static_cast<size_t>(*__p);
Howard Hinnant8c2bf6b2011-10-11 16:00:46 +0000334 size_t __g = __h & __mask;
335 __h ^= __g | (__g >> __sr);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000336 }
Howard Hinnant8c2bf6b2011-10-11 16:00:46 +0000337 return static_cast<long>(__h);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000338}
339
Louis Dionne9de5a672021-01-14 16:27:53 -0500340_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>)
Louis Dionne89258142021-08-23 15:32:36 -0400341#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Louis Dionne9de5a672021-01-14 16:27:53 -0500342_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>)
Louis Dionne89258142021-08-23 15:32:36 -0400343#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000344
345// template <class CharT> class collate_byname;
346
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000347template <class _CharT> class _LIBCPP_TEMPLATE_VIS collate_byname;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000348
349template <>
Howard Hinnant8331b762013-03-06 23:30:19 +0000350class _LIBCPP_TYPE_VIS collate_byname<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000351 : public collate<char>
352{
353 locale_t __l;
354public:
355 typedef char char_type;
356 typedef basic_string<char_type> string_type;
357
358 explicit collate_byname(const char* __n, size_t __refs = 0);
359 explicit collate_byname(const string& __n, size_t __refs = 0);
360
361protected:
362 ~collate_byname();
363 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
364 const char_type* __lo2, const char_type* __hi2) const;
365 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
366};
367
Louis Dionne89258142021-08-23 15:32:36 -0400368#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000369template <>
Howard Hinnant8331b762013-03-06 23:30:19 +0000370class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000371 : public collate<wchar_t>
372{
373 locale_t __l;
374public:
375 typedef wchar_t char_type;
376 typedef basic_string<char_type> string_type;
377
378 explicit collate_byname(const char* __n, size_t __refs = 0);
379 explicit collate_byname(const string& __n, size_t __refs = 0);
380
381protected:
382 ~collate_byname();
383
384 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
385 const char_type* __lo2, const char_type* __hi2) const;
386 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
387};
Louis Dionne89258142021-08-23 15:32:36 -0400388#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000389
390template <class _CharT, class _Traits, class _Allocator>
391bool
392locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
393 const basic_string<_CharT, _Traits, _Allocator>& __y) const
394{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000395 return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
Howard Hinnantc51e1022010-05-11 19:42:16 +0000396 __x.data(), __x.data() + __x.size(),
397 __y.data(), __y.data() + __y.size()) < 0;
398}
399
400// template <class charT> class ctype
401
Howard Hinnant8331b762013-03-06 23:30:19 +0000402class _LIBCPP_TYPE_VIS ctype_base
Howard Hinnant9833cad2010-09-21 18:58:51 +0000403{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404public:
Xiang Xiaoa0562e92020-11-11 15:30:21 -0500405#if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE)
406 typedef unsigned long mask;
407 static const mask space = 1<<0;
408 static const mask print = 1<<1;
409 static const mask cntrl = 1<<2;
410 static const mask upper = 1<<3;
411 static const mask lower = 1<<4;
412 static const mask alpha = 1<<5;
413 static const mask digit = 1<<6;
414 static const mask punct = 1<<7;
415 static const mask xdigit = 1<<8;
416 static const mask blank = 1<<9;
417#if defined(__BIONIC__)
418 // Historically this was a part of regex_traits rather than ctype_base. The
419 // historical value of the constant is preserved for ABI compatibility.
420 static const mask __regex_word = 0x8000;
421#else
422 static const mask __regex_word = 1<<10;
423#endif // defined(__BIONIC__)
424#elif defined(__GLIBC__)
Alexis Hunt92b0c812011-07-09 00:56:23 +0000425 typedef unsigned short mask;
Howard Hinnant155c2af2010-05-24 17:49:41 +0000426 static const mask space = _ISspace;
427 static const mask print = _ISprint;
428 static const mask cntrl = _IScntrl;
429 static const mask upper = _ISupper;
430 static const mask lower = _ISlower;
431 static const mask alpha = _ISalpha;
432 static const mask digit = _ISdigit;
433 static const mask punct = _ISpunct;
434 static const mask xdigit = _ISxdigit;
435 static const mask blank = _ISblank;
Mikhail Maltsev014ed062019-06-14 09:04:16 +0000436#if defined(__mips__)
Mikhail Maltsev12eb5af2019-08-20 10:19:55 +0000437 static const mask __regex_word = static_cast<mask>(_ISbit(15));
Mikhail Maltsev014ed062019-06-14 09:04:16 +0000438#else
439 static const mask __regex_word = 0x80;
440#endif
Eric Fiselierbb999f92017-05-31 22:14:05 +0000441#elif defined(_LIBCPP_MSVCRT_LIKE)
Howard Hinnantd7a78632011-09-29 13:33:15 +0000442 typedef unsigned short mask;
Howard Hinnantdd0d7022011-09-22 19:10:18 +0000443 static const mask space = _SPACE;
444 static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT;
445 static const mask cntrl = _CONTROL;
446 static const mask upper = _UPPER;
447 static const mask lower = _LOWER;
448 static const mask alpha = _ALPHA;
449 static const mask digit = _DIGIT;
450 static const mask punct = _PUNCT;
451 static const mask xdigit = _HEX;
452 static const mask blank = _BLANK;
Mikhail Maltsev014ed062019-06-14 09:04:16 +0000453 static const mask __regex_word = 0x80;
Jonathan Roelofsae9ab252015-03-11 17:00:28 +0000454# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
Dan Albertebdf28b2015-03-11 00:51:06 +0000455#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
JF Bastien0c265d82015-02-25 22:16:46 +0000456# ifdef __APPLE__
David Chisnall1d581062011-09-21 08:39:44 +0000457 typedef __uint32_t mask;
JF Bastien0c265d82015-02-25 22:16:46 +0000458# elif defined(__FreeBSD__)
David Chisnall1d581062011-09-21 08:39:44 +0000459 typedef unsigned long mask;
Vasileios Kalintirisc5dd8942015-11-24 10:24:54 +0000460# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
Howard Hinnant942dbd22013-03-29 18:27:28 +0000461 typedef unsigned short mask;
JF Bastien0c265d82015-02-25 22:16:46 +0000462# endif
David Chisnall1d581062011-09-21 08:39:44 +0000463 static const mask space = _CTYPE_S;
464 static const mask print = _CTYPE_R;
465 static const mask cntrl = _CTYPE_C;
466 static const mask upper = _CTYPE_U;
467 static const mask lower = _CTYPE_L;
468 static const mask alpha = _CTYPE_A;
469 static const mask digit = _CTYPE_D;
470 static const mask punct = _CTYPE_P;
471 static const mask xdigit = _CTYPE_X;
Dan Albert2dca4072014-07-23 19:32:03 +0000472
Joerg Sonnenberger153e4162013-05-17 21:17:34 +0000473# if defined(__NetBSD__)
474 static const mask blank = _CTYPE_BL;
Mikhail Maltsev014ed062019-06-14 09:04:16 +0000475 // NetBSD defines classes up to 0x2000
476 // see sys/ctype_bits.h, _CTYPE_Q
477 static const mask __regex_word = 0x8000;
Joerg Sonnenberger153e4162013-05-17 21:17:34 +0000478# else
David Chisnall1d581062011-09-21 08:39:44 +0000479 static const mask blank = _CTYPE_B;
Mikhail Maltsev014ed062019-06-14 09:04:16 +0000480 static const mask __regex_word = 0x80;
Joerg Sonnenberger153e4162013-05-17 21:17:34 +0000481# endif
Howard Hinnanta47505d2013-08-30 14:42:39 +0000482#elif defined(__sun__) || defined(_AIX)
David Chisnall8074c342012-02-29 13:05:08 +0000483 typedef unsigned int mask;
484 static const mask space = _ISSPACE;
485 static const mask print = _ISPRINT;
486 static const mask cntrl = _ISCNTRL;
487 static const mask upper = _ISUPPER;
488 static const mask lower = _ISLOWER;
489 static const mask alpha = _ISALPHA;
490 static const mask digit = _ISDIGIT;
491 static const mask punct = _ISPUNCT;
492 static const mask xdigit = _ISXDIGIT;
493 static const mask blank = _ISBLANK;
Mikhail Maltsev014ed062019-06-14 09:04:16 +0000494 static const mask __regex_word = 0x80;
JF Bastien0c265d82015-02-25 22:16:46 +0000495#elif defined(_NEWLIB_VERSION)
496 // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
497 typedef char mask;
498 static const mask space = _S;
499 static const mask print = _P | _U | _L | _N | _B;
500 static const mask cntrl = _C;
501 static const mask upper = _U;
502 static const mask lower = _L;
503 static const mask alpha = _U | _L;
504 static const mask digit = _N;
505 static const mask punct = _P;
506 static const mask xdigit = _X | _N;
507 static const mask blank = _B;
Mikhail Maltsev014ed062019-06-14 09:04:16 +0000508 static const mask __regex_word = 0x80;
Jonathan Roelofsae9ab252015-03-11 17:00:28 +0000509# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
510# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
511# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
JF Bastien0c265d82015-02-25 22:16:46 +0000512#else
Xiang Xiaoa0562e92020-11-11 15:30:21 -0500513# error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?
JF Bastien0c265d82015-02-25 22:16:46 +0000514#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000515 static const mask alnum = alpha | digit;
516 static const mask graph = alnum | punct;
517
Louis Dionne16fe2952018-07-11 23:14:33 +0000518 _LIBCPP_INLINE_VISIBILITY ctype_base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519};
520
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000521template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000522
Louis Dionne89258142021-08-23 15:32:36 -0400523#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000524template <>
Howard Hinnant8331b762013-03-06 23:30:19 +0000525class _LIBCPP_TYPE_VIS ctype<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000526 : public locale::facet,
527 public ctype_base
528{
529public:
530 typedef wchar_t char_type;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000531
Louis Dionne16fe2952018-07-11 23:14:33 +0000532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533 explicit ctype(size_t __refs = 0)
534 : locale::facet(__refs) {}
535
Louis Dionne16fe2952018-07-11 23:14:33 +0000536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000537 bool is(mask __m, char_type __c) const
538 {
539 return do_is(__m, __c);
540 }
541
Louis Dionne16fe2952018-07-11 23:14:33 +0000542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000543 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
544 {
545 return do_is(__low, __high, __vec);
546 }
547
Louis Dionne16fe2952018-07-11 23:14:33 +0000548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000549 const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
550 {
551 return do_scan_is(__m, __low, __high);
552 }
553
Louis Dionne16fe2952018-07-11 23:14:33 +0000554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000555 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
556 {
557 return do_scan_not(__m, __low, __high);
558 }
559
Louis Dionne16fe2952018-07-11 23:14:33 +0000560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561 char_type toupper(char_type __c) const
562 {
563 return do_toupper(__c);
564 }
565
Louis Dionne16fe2952018-07-11 23:14:33 +0000566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567 const char_type* toupper(char_type* __low, const char_type* __high) const
568 {
569 return do_toupper(__low, __high);
570 }
571
Louis Dionne16fe2952018-07-11 23:14:33 +0000572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000573 char_type tolower(char_type __c) const
574 {
575 return do_tolower(__c);
576 }
577
Louis Dionne16fe2952018-07-11 23:14:33 +0000578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000579 const char_type* tolower(char_type* __low, const char_type* __high) const
580 {
581 return do_tolower(__low, __high);
582 }
583
Louis Dionne16fe2952018-07-11 23:14:33 +0000584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000585 char_type widen(char __c) const
586 {
587 return do_widen(__c);
588 }
589
Louis Dionne16fe2952018-07-11 23:14:33 +0000590 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000591 const char* widen(const char* __low, const char* __high, char_type* __to) const
592 {
593 return do_widen(__low, __high, __to);
594 }
595
Louis Dionne16fe2952018-07-11 23:14:33 +0000596 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000597 char narrow(char_type __c, char __dfault) const
598 {
599 return do_narrow(__c, __dfault);
600 }
601
Louis Dionne16fe2952018-07-11 23:14:33 +0000602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000603 const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
604 {
605 return do_narrow(__low, __high, __dfault, __to);
606 }
607
608 static locale::id id;
609
610protected:
611 ~ctype();
612 virtual bool do_is(mask __m, char_type __c) const;
613 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
614 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
615 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
616 virtual char_type do_toupper(char_type) const;
617 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
618 virtual char_type do_tolower(char_type) const;
619 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
620 virtual char_type do_widen(char) const;
621 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
622 virtual char do_narrow(char_type, char __dfault) const;
623 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
624};
Louis Dionne89258142021-08-23 15:32:36 -0400625#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626
627template <>
Howard Hinnant8331b762013-03-06 23:30:19 +0000628class _LIBCPP_TYPE_VIS ctype<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629 : public locale::facet, public ctype_base
630{
631 const mask* __tab_;
632 bool __del_;
633public:
634 typedef char char_type;
635
Bruce Mitchener170d8972020-11-24 12:53:53 -0500636 explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000637
Louis Dionne16fe2952018-07-11 23:14:33 +0000638 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000639 bool is(mask __m, char_type __c) const
640 {
Marshall Clow11de4872013-10-21 14:41:05 +0000641 return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642 }
643
Louis Dionne16fe2952018-07-11 23:14:33 +0000644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
646 {
647 for (; __low != __high; ++__low, ++__vec)
Howard Hinnant28b24882011-12-01 20:21:04 +0000648 *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000649 return __low;
650 }
651
Louis Dionne16fe2952018-07-11 23:14:33 +0000652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000653 const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
654 {
655 for (; __low != __high; ++__low)
Howard Hinnant28b24882011-12-01 20:21:04 +0000656 if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000657 break;
658 return __low;
659 }
660
Louis Dionne16fe2952018-07-11 23:14:33 +0000661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000662 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
663 {
664 for (; __low != __high; ++__low)
Howard Hinnant28b24882011-12-01 20:21:04 +0000665 if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666 break;
667 return __low;
668 }
669
Louis Dionne16fe2952018-07-11 23:14:33 +0000670 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671 char_type toupper(char_type __c) const
672 {
673 return do_toupper(__c);
674 }
675
Louis Dionne16fe2952018-07-11 23:14:33 +0000676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000677 const char_type* toupper(char_type* __low, const char_type* __high) const
678 {
679 return do_toupper(__low, __high);
680 }
681
Louis Dionne16fe2952018-07-11 23:14:33 +0000682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000683 char_type tolower(char_type __c) const
684 {
685 return do_tolower(__c);
686 }
687
Louis Dionne16fe2952018-07-11 23:14:33 +0000688 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000689 const char_type* tolower(char_type* __low, const char_type* __high) const
690 {
691 return do_tolower(__low, __high);
692 }
693
Louis Dionne16fe2952018-07-11 23:14:33 +0000694 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695 char_type widen(char __c) const
696 {
697 return do_widen(__c);
698 }
699
Louis Dionne16fe2952018-07-11 23:14:33 +0000700 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701 const char* widen(const char* __low, const char* __high, char_type* __to) const
702 {
703 return do_widen(__low, __high, __to);
704 }
705
Louis Dionne16fe2952018-07-11 23:14:33 +0000706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000707 char narrow(char_type __c, char __dfault) const
708 {
709 return do_narrow(__c, __dfault);
710 }
711
Louis Dionne16fe2952018-07-11 23:14:33 +0000712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000713 const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
714 {
715 return do_narrow(__low, __high, __dfault, __to);
716 }
717
718 static locale::id id;
719
Howard Hinnant155c2af2010-05-24 17:49:41 +0000720#ifdef _CACHED_RUNES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000721 static const size_t table_size = _CACHED_RUNES;
Howard Hinnant155c2af2010-05-24 17:49:41 +0000722#else
723 static const size_t table_size = 256; // FIXME: Don't hardcode this.
724#endif
Louis Dionne16fe2952018-07-11 23:14:33 +0000725 _LIBCPP_INLINE_VISIBILITY const mask* table() const _NOEXCEPT {return __tab_;}
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000726 static const mask* classic_table() _NOEXCEPT;
Vasileios Kalintirisc5dd8942015-11-24 10:24:54 +0000727#if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
Alexis Hunt92b0c812011-07-09 00:56:23 +0000728 static const int* __classic_upper_table() _NOEXCEPT;
729 static const int* __classic_lower_table() _NOEXCEPT;
Alexis Hunt5a4dd562011-07-09 01:09:31 +0000730#endif
Joerg Sonnenberger153e4162013-05-17 21:17:34 +0000731#if defined(__NetBSD__)
732 static const short* __classic_upper_table() _NOEXCEPT;
733 static const short* __classic_lower_table() _NOEXCEPT;
734#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000735
736protected:
737 ~ctype();
738 virtual char_type do_toupper(char_type __c) const;
739 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
740 virtual char_type do_tolower(char_type __c) const;
741 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
742 virtual char_type do_widen(char __c) const;
743 virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
744 virtual char do_narrow(char_type __c, char __dfault) const;
745 virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
746};
747
748// template <class CharT> class ctype_byname;
749
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000750template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype_byname;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000751
752template <>
Howard Hinnant8331b762013-03-06 23:30:19 +0000753class _LIBCPP_TYPE_VIS ctype_byname<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000754 : public ctype<char>
755{
756 locale_t __l;
757
758public:
759 explicit ctype_byname(const char*, size_t = 0);
760 explicit ctype_byname(const string&, size_t = 0);
761
762protected:
763 ~ctype_byname();
764 virtual char_type do_toupper(char_type) const;
765 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
766 virtual char_type do_tolower(char_type) const;
767 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
768};
769
Louis Dionne89258142021-08-23 15:32:36 -0400770#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000771template <>
Howard Hinnant8331b762013-03-06 23:30:19 +0000772class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000773 : public ctype<wchar_t>
774{
775 locale_t __l;
776
777public:
778 explicit ctype_byname(const char*, size_t = 0);
779 explicit ctype_byname(const string&, size_t = 0);
780
781protected:
782 ~ctype_byname();
783 virtual bool do_is(mask __m, char_type __c) const;
784 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
785 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
786 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
787 virtual char_type do_toupper(char_type) const;
788 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
789 virtual char_type do_tolower(char_type) const;
790 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
791 virtual char_type do_widen(char) const;
792 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
793 virtual char do_narrow(char_type, char __dfault) const;
794 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
795};
Louis Dionne89258142021-08-23 15:32:36 -0400796#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000797
798template <class _CharT>
799inline _LIBCPP_INLINE_VISIBILITY
800bool
801isspace(_CharT __c, const locale& __loc)
802{
803 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
804}
805
806template <class _CharT>
807inline _LIBCPP_INLINE_VISIBILITY
808bool
809isprint(_CharT __c, const locale& __loc)
810{
811 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
812}
813
814template <class _CharT>
815inline _LIBCPP_INLINE_VISIBILITY
816bool
817iscntrl(_CharT __c, const locale& __loc)
818{
819 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
820}
821
822template <class _CharT>
823inline _LIBCPP_INLINE_VISIBILITY
824bool
825isupper(_CharT __c, const locale& __loc)
826{
827 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
828}
829
830template <class _CharT>
831inline _LIBCPP_INLINE_VISIBILITY
832bool
833islower(_CharT __c, const locale& __loc)
834{
835 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
836}
837
838template <class _CharT>
839inline _LIBCPP_INLINE_VISIBILITY
840bool
841isalpha(_CharT __c, const locale& __loc)
842{
843 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
844}
845
846template <class _CharT>
847inline _LIBCPP_INLINE_VISIBILITY
848bool
849isdigit(_CharT __c, const locale& __loc)
850{
851 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
852}
853
854template <class _CharT>
855inline _LIBCPP_INLINE_VISIBILITY
856bool
857ispunct(_CharT __c, const locale& __loc)
858{
859 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
860}
861
862template <class _CharT>
863inline _LIBCPP_INLINE_VISIBILITY
864bool
865isxdigit(_CharT __c, const locale& __loc)
866{
867 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
868}
869
870template <class _CharT>
871inline _LIBCPP_INLINE_VISIBILITY
872bool
873isalnum(_CharT __c, const locale& __loc)
874{
875 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
876}
877
878template <class _CharT>
879inline _LIBCPP_INLINE_VISIBILITY
880bool
881isgraph(_CharT __c, const locale& __loc)
882{
883 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
884}
885
886template <class _CharT>
887inline _LIBCPP_INLINE_VISIBILITY
888_CharT
889toupper(_CharT __c, const locale& __loc)
890{
891 return use_facet<ctype<_CharT> >(__loc).toupper(__c);
892}
893
894template <class _CharT>
895inline _LIBCPP_INLINE_VISIBILITY
896_CharT
897tolower(_CharT __c, const locale& __loc)
898{
899 return use_facet<ctype<_CharT> >(__loc).tolower(__c);
900}
901
902// codecvt_base
903
Howard Hinnant8331b762013-03-06 23:30:19 +0000904class _LIBCPP_TYPE_VIS codecvt_base
Howard Hinnantc51e1022010-05-11 19:42:16 +0000905{
906public:
Louis Dionne16fe2952018-07-11 23:14:33 +0000907 _LIBCPP_INLINE_VISIBILITY codecvt_base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000908 enum result {ok, partial, error, noconv};
909};
910
911// template <class internT, class externT, class stateT> class codecvt;
912
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000913template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TEMPLATE_VIS codecvt;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914
915// template <> class codecvt<char, char, mbstate_t>
916
917template <>
Howard Hinnant8331b762013-03-06 23:30:19 +0000918class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000919 : public locale::facet,
920 public codecvt_base
921{
922public:
923 typedef char intern_type;
924 typedef char extern_type;
925 typedef mbstate_t state_type;
926
Louis Dionne16fe2952018-07-11 23:14:33 +0000927 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000928 explicit codecvt(size_t __refs = 0)
929 : locale::facet(__refs) {}
930
Louis Dionne16fe2952018-07-11 23:14:33 +0000931 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000932 result out(state_type& __st,
933 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
934 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
935 {
936 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
937 }
938
Louis Dionne16fe2952018-07-11 23:14:33 +0000939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000940 result unshift(state_type& __st,
941 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
942 {
943 return do_unshift(__st, __to, __to_end, __to_nxt);
944 }
945
Louis Dionne16fe2952018-07-11 23:14:33 +0000946 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000947 result in(state_type& __st,
948 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
949 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
950 {
951 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
952 }
953
Louis Dionne16fe2952018-07-11 23:14:33 +0000954 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000955 int encoding() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000956 {
957 return do_encoding();
958 }
959
Louis Dionne16fe2952018-07-11 23:14:33 +0000960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000961 bool always_noconv() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000962 {
963 return do_always_noconv();
964 }
965
Louis Dionne16fe2952018-07-11 23:14:33 +0000966 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000967 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
968 {
969 return do_length(__st, __frm, __end, __mx);
970 }
971
Louis Dionne16fe2952018-07-11 23:14:33 +0000972 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000973 int max_length() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000974 {
975 return do_max_length();
976 }
977
978 static locale::id id;
979
980protected:
Louis Dionne16fe2952018-07-11 23:14:33 +0000981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000982 explicit codecvt(const char*, size_t __refs = 0)
983 : locale::facet(__refs) {}
984
985 ~codecvt();
986
987 virtual result do_out(state_type& __st,
988 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
989 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
990 virtual result do_in(state_type& __st,
991 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
992 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
993 virtual result do_unshift(state_type& __st,
994 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000995 virtual int do_encoding() const _NOEXCEPT;
996 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000997 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 +0000998 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000999};
1000
1001// template <> class codecvt<wchar_t, char, mbstate_t>
1002
Louis Dionne89258142021-08-23 15:32:36 -04001003#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001004template <>
Howard Hinnant8331b762013-03-06 23:30:19 +00001005class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001006 : public locale::facet,
1007 public codecvt_base
1008{
1009 locale_t __l;
1010public:
1011 typedef wchar_t intern_type;
1012 typedef char extern_type;
1013 typedef mbstate_t state_type;
1014
1015 explicit codecvt(size_t __refs = 0);
1016
Louis Dionne16fe2952018-07-11 23:14:33 +00001017 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001018 result out(state_type& __st,
1019 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1020 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1021 {
1022 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1023 }
1024
Louis Dionne16fe2952018-07-11 23:14:33 +00001025 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001026 result unshift(state_type& __st,
1027 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1028 {
1029 return do_unshift(__st, __to, __to_end, __to_nxt);
1030 }
1031
Louis Dionne16fe2952018-07-11 23:14:33 +00001032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033 result in(state_type& __st,
1034 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1035 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1036 {
1037 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1038 }
1039
Louis Dionne16fe2952018-07-11 23:14:33 +00001040 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001041 int encoding() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001042 {
1043 return do_encoding();
1044 }
1045
Louis Dionne16fe2952018-07-11 23:14:33 +00001046 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001047 bool always_noconv() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001048 {
1049 return do_always_noconv();
1050 }
1051
Louis Dionne16fe2952018-07-11 23:14:33 +00001052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1054 {
1055 return do_length(__st, __frm, __end, __mx);
1056 }
1057
Louis Dionne16fe2952018-07-11 23:14:33 +00001058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001059 int max_length() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001060 {
1061 return do_max_length();
1062 }
1063
1064 static locale::id id;
1065
1066protected:
1067 explicit codecvt(const char*, size_t __refs = 0);
1068
1069 ~codecvt();
1070
1071 virtual result do_out(state_type& __st,
1072 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1073 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1074 virtual result do_in(state_type& __st,
1075 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1076 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1077 virtual result do_unshift(state_type& __st,
1078 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001079 virtual int do_encoding() const _NOEXCEPT;
1080 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 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 +00001082 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001083};
Louis Dionne89258142021-08-23 15:32:36 -04001084#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085
Marek Kurdej718b62c2020-12-02 08:57:02 +01001086// template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087
1088template <>
Reid Klecknerbc2a2ce2021-01-15 08:56:34 -08001089class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001090 : public locale::facet,
1091 public codecvt_base
1092{
1093public:
1094 typedef char16_t intern_type;
1095 typedef char extern_type;
1096 typedef mbstate_t state_type;
1097
Louis Dionne16fe2952018-07-11 23:14:33 +00001098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099 explicit codecvt(size_t __refs = 0)
1100 : locale::facet(__refs) {}
1101
Louis Dionne16fe2952018-07-11 23:14:33 +00001102 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001103 result out(state_type& __st,
1104 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1105 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1106 {
1107 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1108 }
1109
Louis Dionne16fe2952018-07-11 23:14:33 +00001110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001111 result unshift(state_type& __st,
1112 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1113 {
1114 return do_unshift(__st, __to, __to_end, __to_nxt);
1115 }
1116
Louis Dionne16fe2952018-07-11 23:14:33 +00001117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001118 result in(state_type& __st,
1119 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1120 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1121 {
1122 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1123 }
1124
Louis Dionne16fe2952018-07-11 23:14:33 +00001125 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001126 int encoding() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001127 {
1128 return do_encoding();
1129 }
1130
Louis Dionne16fe2952018-07-11 23:14:33 +00001131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001132 bool always_noconv() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001133 {
1134 return do_always_noconv();
1135 }
1136
Louis Dionne16fe2952018-07-11 23:14:33 +00001137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001138 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1139 {
1140 return do_length(__st, __frm, __end, __mx);
1141 }
1142
Louis Dionne16fe2952018-07-11 23:14:33 +00001143 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001144 int max_length() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001145 {
1146 return do_max_length();
1147 }
1148
1149 static locale::id id;
1150
1151protected:
Louis Dionne16fe2952018-07-11 23:14:33 +00001152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001153 explicit codecvt(const char*, size_t __refs = 0)
1154 : locale::facet(__refs) {}
1155
1156 ~codecvt();
1157
1158 virtual result do_out(state_type& __st,
1159 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1160 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1161 virtual result do_in(state_type& __st,
1162 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1163 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1164 virtual result do_unshift(state_type& __st,
1165 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001166 virtual int do_encoding() const _NOEXCEPT;
1167 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001168 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 +00001169 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170};
1171
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -04001172#ifndef _LIBCPP_HAS_NO_CHAR8_T
Marek Kurdej718b62c2020-12-02 08:57:02 +01001173
1174// template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001175
1176template <>
Marek Kurdej718b62c2020-12-02 08:57:02 +01001177class _LIBCPP_TYPE_VIS codecvt<char16_t, char8_t, mbstate_t>
1178 : public locale::facet,
1179 public codecvt_base
1180{
1181public:
1182 typedef char16_t intern_type;
1183 typedef char8_t extern_type;
1184 typedef mbstate_t state_type;
1185
1186 _LIBCPP_INLINE_VISIBILITY
1187 explicit codecvt(size_t __refs = 0)
1188 : locale::facet(__refs) {}
1189
1190 _LIBCPP_INLINE_VISIBILITY
1191 result 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 {
1195 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1196 }
1197
1198 _LIBCPP_INLINE_VISIBILITY
1199 result unshift(state_type& __st,
1200 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1201 {
1202 return do_unshift(__st, __to, __to_end, __to_nxt);
1203 }
1204
1205 _LIBCPP_INLINE_VISIBILITY
1206 result in(state_type& __st,
1207 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1208 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1209 {
1210 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1211 }
1212
1213 _LIBCPP_INLINE_VISIBILITY
1214 int encoding() const _NOEXCEPT
1215 {
1216 return do_encoding();
1217 }
1218
1219 _LIBCPP_INLINE_VISIBILITY
1220 bool always_noconv() const _NOEXCEPT
1221 {
1222 return do_always_noconv();
1223 }
1224
1225 _LIBCPP_INLINE_VISIBILITY
1226 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1227 {
1228 return do_length(__st, __frm, __end, __mx);
1229 }
1230
1231 _LIBCPP_INLINE_VISIBILITY
1232 int max_length() const _NOEXCEPT
1233 {
1234 return do_max_length();
1235 }
1236
1237 static locale::id id;
1238
1239protected:
1240 _LIBCPP_INLINE_VISIBILITY
1241 explicit codecvt(const char*, size_t __refs = 0)
1242 : locale::facet(__refs) {}
1243
1244 ~codecvt();
1245
1246 virtual result do_out(state_type& __st,
1247 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1248 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1249 virtual result do_in(state_type& __st,
1250 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1251 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1252 virtual result do_unshift(state_type& __st,
1253 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1254 virtual int do_encoding() const _NOEXCEPT;
1255 virtual bool do_always_noconv() const _NOEXCEPT;
1256 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1257 virtual int do_max_length() const _NOEXCEPT;
1258};
1259
1260#endif
1261
1262// template <> class codecvt<char32_t, char, mbstate_t> // deprecated in C++20
1263
1264template <>
Reid Klecknerbc2a2ce2021-01-15 08:56:34 -08001265class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001266 : public locale::facet,
1267 public codecvt_base
1268{
1269public:
1270 typedef char32_t intern_type;
1271 typedef char extern_type;
1272 typedef mbstate_t state_type;
1273
Louis Dionne16fe2952018-07-11 23:14:33 +00001274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001275 explicit codecvt(size_t __refs = 0)
1276 : locale::facet(__refs) {}
1277
Louis Dionne16fe2952018-07-11 23:14:33 +00001278 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001279 result out(state_type& __st,
1280 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1281 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1282 {
1283 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1284 }
1285
Louis Dionne16fe2952018-07-11 23:14:33 +00001286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001287 result unshift(state_type& __st,
1288 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1289 {
1290 return do_unshift(__st, __to, __to_end, __to_nxt);
1291 }
1292
Louis Dionne16fe2952018-07-11 23:14:33 +00001293 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001294 result in(state_type& __st,
1295 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1296 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1297 {
1298 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1299 }
1300
Louis Dionne16fe2952018-07-11 23:14:33 +00001301 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001302 int encoding() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001303 {
1304 return do_encoding();
1305 }
1306
Louis Dionne16fe2952018-07-11 23:14:33 +00001307 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001308 bool always_noconv() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001309 {
1310 return do_always_noconv();
1311 }
1312
Louis Dionne16fe2952018-07-11 23:14:33 +00001313 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001314 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1315 {
1316 return do_length(__st, __frm, __end, __mx);
1317 }
1318
Louis Dionne16fe2952018-07-11 23:14:33 +00001319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001320 int max_length() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001321 {
1322 return do_max_length();
1323 }
1324
1325 static locale::id id;
1326
1327protected:
Louis Dionne16fe2952018-07-11 23:14:33 +00001328 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329 explicit codecvt(const char*, size_t __refs = 0)
1330 : locale::facet(__refs) {}
1331
1332 ~codecvt();
1333
1334 virtual result do_out(state_type& __st,
1335 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1336 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1337 virtual result do_in(state_type& __st,
1338 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1339 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1340 virtual result do_unshift(state_type& __st,
1341 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001342 virtual int do_encoding() const _NOEXCEPT;
1343 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001344 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 +00001345 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001346};
1347
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -04001348#ifndef _LIBCPP_HAS_NO_CHAR8_T
Marek Kurdej718b62c2020-12-02 08:57:02 +01001349
1350// template <> class codecvt<char32_t, char8_t, mbstate_t> // C++20
1351
1352template <>
1353class _LIBCPP_TYPE_VIS codecvt<char32_t, char8_t, mbstate_t>
1354 : public locale::facet,
1355 public codecvt_base
1356{
1357public:
1358 typedef char32_t intern_type;
1359 typedef char8_t extern_type;
1360 typedef mbstate_t state_type;
1361
1362 _LIBCPP_INLINE_VISIBILITY
1363 explicit codecvt(size_t __refs = 0)
1364 : locale::facet(__refs) {}
1365
1366 _LIBCPP_INLINE_VISIBILITY
1367 result out(state_type& __st,
1368 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1369 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1370 {
1371 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1372 }
1373
1374 _LIBCPP_INLINE_VISIBILITY
1375 result unshift(state_type& __st,
1376 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1377 {
1378 return do_unshift(__st, __to, __to_end, __to_nxt);
1379 }
1380
1381 _LIBCPP_INLINE_VISIBILITY
1382 result in(state_type& __st,
1383 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1384 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1385 {
1386 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1387 }
1388
1389 _LIBCPP_INLINE_VISIBILITY
1390 int encoding() const _NOEXCEPT
1391 {
1392 return do_encoding();
1393 }
1394
1395 _LIBCPP_INLINE_VISIBILITY
1396 bool always_noconv() const _NOEXCEPT
1397 {
1398 return do_always_noconv();
1399 }
1400
1401 _LIBCPP_INLINE_VISIBILITY
1402 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1403 {
1404 return do_length(__st, __frm, __end, __mx);
1405 }
1406
1407 _LIBCPP_INLINE_VISIBILITY
1408 int max_length() const _NOEXCEPT
1409 {
1410 return do_max_length();
1411 }
1412
1413 static locale::id id;
1414
1415protected:
1416 _LIBCPP_INLINE_VISIBILITY
1417 explicit codecvt(const char*, size_t __refs = 0)
1418 : locale::facet(__refs) {}
1419
1420 ~codecvt();
1421
1422 virtual result do_out(state_type& __st,
1423 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1424 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1425 virtual result do_in(state_type& __st,
1426 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1427 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1428 virtual result do_unshift(state_type& __st,
1429 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1430 virtual int do_encoding() const _NOEXCEPT;
1431 virtual bool do_always_noconv() const _NOEXCEPT;
1432 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1433 virtual int do_max_length() const _NOEXCEPT;
1434};
1435
1436#endif
1437
Howard Hinnantc51e1022010-05-11 19:42:16 +00001438// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
1439
1440template <class _InternT, class _ExternT, class _StateT>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001441class _LIBCPP_TEMPLATE_VIS codecvt_byname
Howard Hinnantc51e1022010-05-11 19:42:16 +00001442 : public codecvt<_InternT, _ExternT, _StateT>
1443{
1444public:
Louis Dionne16fe2952018-07-11 23:14:33 +00001445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001446 explicit codecvt_byname(const char* __nm, size_t __refs = 0)
1447 : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
Louis Dionne16fe2952018-07-11 23:14:33 +00001448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001449 explicit codecvt_byname(const string& __nm, size_t __refs = 0)
1450 : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
1451protected:
1452 ~codecvt_byname();
1453};
1454
Marek Kurdej718b62c2020-12-02 08:57:02 +01001455_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456template <class _InternT, class _ExternT, class _StateT>
1457codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
1458{
1459}
Marek Kurdej718b62c2020-12-02 08:57:02 +01001460_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +00001461
Louis Dionne9de5a672021-01-14 16:27:53 -05001462_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>)
Louis Dionne89258142021-08-23 15:32:36 -04001463#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Louis Dionne9de5a672021-01-14 16:27:53 -05001464_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>)
Louis Dionne89258142021-08-23 15:32:36 -04001465#endif
Louis Dionne9de5a672021-01-14 16:27:53 -05001466_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>) // deprecated in C++20
1467_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>) // deprecated in C++20
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -04001468#ifndef _LIBCPP_HAS_NO_CHAR8_T
Louis Dionne9de5a672021-01-14 16:27:53 -05001469_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>) // C++20
1470_LIBCPP_EXTERN_TEMPLATE_EVEN_IN_DEBUG_MODE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>) // C++20
Marek Kurdej718b62c2020-12-02 08:57:02 +01001471#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001472
Howard Hinnantc834c512011-11-29 18:15:50 +00001473template <size_t _Np>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001474struct __narrow_to_utf8
1475{
1476 template <class _OutputIterator, class _CharT>
1477 _OutputIterator
1478 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
1479};
1480
1481template <>
1482struct __narrow_to_utf8<8>
1483{
1484 template <class _OutputIterator, class _CharT>
Louis Dionne16fe2952018-07-11 23:14:33 +00001485 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001486 _OutputIterator
1487 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1488 {
1489 for (; __wb < __we; ++__wb, ++__s)
1490 *__s = *__wb;
1491 return __s;
1492 }
1493};
1494
Marek Kurdej718b62c2020-12-02 08:57:02 +01001495_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +00001496template <>
Martin Storsjö3b02e512021-05-18 14:45:08 +00001497struct _LIBCPP_TYPE_VIS __narrow_to_utf8<16>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001498 : public codecvt<char16_t, char, mbstate_t>
1499{
Louis Dionne16fe2952018-07-11 23:14:33 +00001500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001501 __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +01001502_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +00001503
Martin Storsjö3b02e512021-05-18 14:45:08 +00001504 ~__narrow_to_utf8();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001505
1506 template <class _OutputIterator, class _CharT>
Louis Dionne16fe2952018-07-11 23:14:33 +00001507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001508 _OutputIterator
1509 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1510 {
1511 result __r = ok;
1512 mbstate_t __mb;
1513 while (__wb < __we && __r != error)
1514 {
1515 const int __sz = 32;
1516 char __buf[__sz];
1517 char* __bn;
1518 const char16_t* __wn = (const char16_t*)__wb;
1519 __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
1520 __buf, __buf+__sz, __bn);
1521 if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
1522 __throw_runtime_error("locale not supported");
1523 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1524 *__s = *__p;
1525 __wb = (const _CharT*)__wn;
1526 }
1527 return __s;
1528 }
1529};
1530
Marek Kurdej718b62c2020-12-02 08:57:02 +01001531_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +00001532template <>
Martin Storsjö3b02e512021-05-18 14:45:08 +00001533struct _LIBCPP_TYPE_VIS __narrow_to_utf8<32>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001534 : public codecvt<char32_t, char, mbstate_t>
1535{
Louis Dionne16fe2952018-07-11 23:14:33 +00001536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001537 __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +01001538_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +00001539
Martin Storsjö3b02e512021-05-18 14:45:08 +00001540 ~__narrow_to_utf8();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001541
1542 template <class _OutputIterator, class _CharT>
Louis Dionne16fe2952018-07-11 23:14:33 +00001543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001544 _OutputIterator
1545 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1546 {
1547 result __r = ok;
1548 mbstate_t __mb;
1549 while (__wb < __we && __r != error)
1550 {
1551 const int __sz = 32;
1552 char __buf[__sz];
1553 char* __bn;
1554 const char32_t* __wn = (const char32_t*)__wb;
1555 __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
1556 __buf, __buf+__sz, __bn);
1557 if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
1558 __throw_runtime_error("locale not supported");
1559 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1560 *__s = *__p;
1561 __wb = (const _CharT*)__wn;
1562 }
1563 return __s;
1564 }
1565};
1566
Howard Hinnantc834c512011-11-29 18:15:50 +00001567template <size_t _Np>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001568struct __widen_from_utf8
1569{
1570 template <class _OutputIterator>
1571 _OutputIterator
1572 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
1573};
1574
1575template <>
1576struct __widen_from_utf8<8>
1577{
1578 template <class _OutputIterator>
Louis Dionne16fe2952018-07-11 23:14:33 +00001579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001580 _OutputIterator
1581 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1582 {
1583 for (; __nb < __ne; ++__nb, ++__s)
1584 *__s = *__nb;
1585 return __s;
1586 }
1587};
1588
Marek Kurdej718b62c2020-12-02 08:57:02 +01001589_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +00001590template <>
Martin Storsjö3b02e512021-05-18 14:45:08 +00001591struct _LIBCPP_TYPE_VIS __widen_from_utf8<16>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001592 : public codecvt<char16_t, char, mbstate_t>
1593{
Louis Dionne16fe2952018-07-11 23:14:33 +00001594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001595 __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +01001596_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +00001597
Martin Storsjö3b02e512021-05-18 14:45:08 +00001598 ~__widen_from_utf8();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001599
1600 template <class _OutputIterator>
Louis Dionne16fe2952018-07-11 23:14:33 +00001601 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001602 _OutputIterator
1603 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1604 {
1605 result __r = ok;
1606 mbstate_t __mb;
1607 while (__nb < __ne && __r != error)
1608 {
1609 const int __sz = 32;
1610 char16_t __buf[__sz];
1611 char16_t* __bn;
1612 const char* __nn = __nb;
1613 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1614 __buf, __buf+__sz, __bn);
1615 if (__r == codecvt_base::error || __nn == __nb)
1616 __throw_runtime_error("locale not supported");
1617 for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
Martin Storsjö971fc1c2020-10-27 13:01:54 +02001618 *__s = *__p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001619 __nb = __nn;
1620 }
1621 return __s;
1622 }
1623};
1624
Marek Kurdej718b62c2020-12-02 08:57:02 +01001625_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Howard Hinnantc51e1022010-05-11 19:42:16 +00001626template <>
Martin Storsjö3b02e512021-05-18 14:45:08 +00001627struct _LIBCPP_TYPE_VIS __widen_from_utf8<32>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001628 : public codecvt<char32_t, char, mbstate_t>
1629{
Louis Dionne16fe2952018-07-11 23:14:33 +00001630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001631 __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
Marek Kurdej718b62c2020-12-02 08:57:02 +01001632_LIBCPP_SUPPRESS_DEPRECATED_POP
Howard Hinnantc51e1022010-05-11 19:42:16 +00001633
Martin Storsjö3b02e512021-05-18 14:45:08 +00001634 ~__widen_from_utf8();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001635
1636 template <class _OutputIterator>
Louis Dionne16fe2952018-07-11 23:14:33 +00001637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001638 _OutputIterator
1639 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1640 {
1641 result __r = ok;
1642 mbstate_t __mb;
1643 while (__nb < __ne && __r != error)
1644 {
1645 const int __sz = 32;
1646 char32_t __buf[__sz];
1647 char32_t* __bn;
1648 const char* __nn = __nb;
1649 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1650 __buf, __buf+__sz, __bn);
1651 if (__r == codecvt_base::error || __nn == __nb)
1652 __throw_runtime_error("locale not supported");
1653 for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
Martin Storsjö971fc1c2020-10-27 13:01:54 +02001654 *__s = *__p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001655 __nb = __nn;
1656 }
1657 return __s;
1658 }
1659};
1660
1661// template <class charT> class numpunct
1662
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001663template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001664
1665template <>
Howard Hinnant8331b762013-03-06 23:30:19 +00001666class _LIBCPP_TYPE_VIS numpunct<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001667 : public locale::facet
1668{
1669public:
1670 typedef char char_type;
1671 typedef basic_string<char_type> string_type;
1672
1673 explicit numpunct(size_t __refs = 0);
1674
Louis Dionne16fe2952018-07-11 23:14:33 +00001675 _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
1676 _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
1677 _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();}
1678 _LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();}
1679 _LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001680
1681 static locale::id id;
1682
1683protected:
1684 ~numpunct();
1685 virtual char_type do_decimal_point() const;
1686 virtual char_type do_thousands_sep() const;
1687 virtual string do_grouping() const;
1688 virtual string_type do_truename() const;
1689 virtual string_type do_falsename() const;
1690
1691 char_type __decimal_point_;
1692 char_type __thousands_sep_;
1693 string __grouping_;
1694};
1695
Louis Dionne89258142021-08-23 15:32:36 -04001696#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001697template <>
Howard Hinnant8331b762013-03-06 23:30:19 +00001698class _LIBCPP_TYPE_VIS numpunct<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001699 : public locale::facet
1700{
1701public:
1702 typedef wchar_t char_type;
1703 typedef basic_string<char_type> string_type;
1704
1705 explicit numpunct(size_t __refs = 0);
1706
Louis Dionne16fe2952018-07-11 23:14:33 +00001707 _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
1708 _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
1709 _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();}
1710 _LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();}
1711 _LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001712
1713 static locale::id id;
1714
1715protected:
1716 ~numpunct();
1717 virtual char_type do_decimal_point() const;
1718 virtual char_type do_thousands_sep() const;
1719 virtual string do_grouping() const;
1720 virtual string_type do_truename() const;
1721 virtual string_type do_falsename() const;
1722
1723 char_type __decimal_point_;
1724 char_type __thousands_sep_;
1725 string __grouping_;
1726};
Louis Dionne89258142021-08-23 15:32:36 -04001727#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001728
1729// template <class charT> class numpunct_byname
1730
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001731template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct_byname;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001732
1733template <>
Howard Hinnant8331b762013-03-06 23:30:19 +00001734class _LIBCPP_TYPE_VIS numpunct_byname<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001735: public numpunct<char>
1736{
1737public:
1738 typedef char char_type;
1739 typedef basic_string<char_type> string_type;
1740
1741 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1742 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1743
1744protected:
1745 ~numpunct_byname();
1746
1747private:
1748 void __init(const char*);
1749};
1750
Louis Dionne89258142021-08-23 15:32:36 -04001751#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001752template <>
Howard Hinnant8331b762013-03-06 23:30:19 +00001753class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001754: public numpunct<wchar_t>
1755{
1756public:
1757 typedef wchar_t char_type;
1758 typedef basic_string<char_type> string_type;
1759
1760 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1761 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1762
1763protected:
1764 ~numpunct_byname();
1765
1766private:
1767 void __init(const char*);
1768};
Louis Dionne89258142021-08-23 15:32:36 -04001769#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001770
1771_LIBCPP_END_NAMESPACE_STD
1772
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001773#endif // _LIBCPP___LOCALE