blob: 19895582cac87160f0be6939d0636fc121a5455f [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP___LOCALE
12#define _LIBCPP___LOCALE
13
14#include <__config>
15#include <string>
16#include <memory>
17#include <utility>
18#include <mutex>
19#include <cstdint>
20#include <cctype>
Howard Hinnantadff4892010-05-24 17:49:41 +000021#include <locale.h>
Howard Hinnantef5aa932013-09-17 01:34:47 +000022#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
Howard Hinnant14fa9f92011-09-29 20:33:10 +000023# include <support/win32/locale_win32.h>
Marshall Clowbe3d1172014-03-11 17:18:47 +000024#elif defined(_AIX)
Howard Hinnant7f764502013-08-14 18:00:20 +000025# include <support/ibm/xlocale.h>
Marshall Clowa6439262014-07-10 15:20:28 +000026#elif defined(__ANDROID__)
27// Android gained the locale aware functions in L (API level 21)
28# include <android/api-level.h>
29# if __ANDROID_API__ <= 20
30# include <support/android/locale_bionic.h>
31# endif
Eric Fiselier6cb69ff2014-11-25 21:57:41 +000032#elif defined(__sun__)
Eric Fiselierf51d6762015-01-23 22:22:36 +000033# include <xlocale.h>
Eric Fiselier6cb69ff2014-11-25 21:57:41 +000034# include <support/solaris/xlocale.h>
Sergey Dmitrouk984f8f62014-12-12 08:36:16 +000035#elif defined(_NEWLIB_VERSION)
36# include <support/newlib/xlocale.h>
Marshall Clowa6439262014-07-10 15:20:28 +000037#elif (defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) \
Eric Fiselier6cb69ff2014-11-25 21:57:41 +000038 || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
Howard Hinnant92a07002011-09-22 19:10:18 +000039# include <xlocale.h>
Marshall Clowa6439262014-07-10 15:20:28 +000040#endif // __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000041
Howard Hinnant08e17472011-10-17 20:05:10 +000042#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000043#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +000044#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000045
46_LIBCPP_BEGIN_NAMESPACE_STD
47
Howard Hinnant83eade62013-03-06 23:30:19 +000048class _LIBCPP_TYPE_VIS locale;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000049
Howard Hinnant33be35e2012-09-14 00:39:16 +000050template <class _Facet>
51_LIBCPP_INLINE_VISIBILITY
52bool
53has_facet(const locale&) _NOEXCEPT;
54
55template <class _Facet>
56_LIBCPP_INLINE_VISIBILITY
57const _Facet&
58use_facet(const locale&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000059
Howard Hinnant83eade62013-03-06 23:30:19 +000060class _LIBCPP_TYPE_VIS locale
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000061{
62public:
63 // types:
Howard Hinnant83eade62013-03-06 23:30:19 +000064 class _LIBCPP_TYPE_VIS facet;
65 class _LIBCPP_TYPE_VIS id;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000066
67 typedef int category;
68 static const category // values assigned here are for exposition only
69 none = 0,
70 collate = LC_COLLATE_MASK,
71 ctype = LC_CTYPE_MASK,
72 monetary = LC_MONETARY_MASK,
73 numeric = LC_NUMERIC_MASK,
74 time = LC_TIME_MASK,
75 messages = LC_MESSAGES_MASK,
76 all = collate | ctype | monetary | numeric | time | messages;
77
78 // construct/copy/destroy:
Howard Hinnantc9834542011-05-31 15:34:58 +000079 locale() _NOEXCEPT;
80 locale(const locale&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000081 explicit locale(const char*);
82 explicit locale(const string&);
83 locale(const locale&, const char*, category);
84 locale(const locale&, const string&, category);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +000085 template <class _Facet>
86 _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000087 locale(const locale&, const locale&, category);
88
Howard Hinnantc9834542011-05-31 15:34:58 +000089 ~locale();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000090
Howard Hinnantc9834542011-05-31 15:34:58 +000091 const locale& operator=(const locale&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000092
93 template <class _Facet> locale combine(const locale&) const;
94
95 // locale operations:
96 string name() const;
97 bool operator==(const locale&) const;
98 bool operator!=(const locale& __y) const {return !(*this == __y);}
99 template <class _CharT, class _Traits, class _Allocator>
100 bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
101 const basic_string<_CharT, _Traits, _Allocator>&) const;
102
103 // global locale objects:
104 static locale global(const locale&);
105 static const locale& classic();
106
107private:
108 class __imp;
109 __imp* __locale_;
110
111 void __install_ctor(const locale&, facet*, long);
112 static locale& __global();
113 bool has_facet(id&) const;
114 const facet* use_facet(id&) const;
115
Howard Hinnantc9834542011-05-31 15:34:58 +0000116 template <class _Facet> friend bool has_facet(const locale&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000117 template <class _Facet> friend const _Facet& use_facet(const locale&);
118};
119
Howard Hinnant83eade62013-03-06 23:30:19 +0000120class _LIBCPP_TYPE_VIS locale::facet
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000121 : public __shared_count
122{
123protected:
Howard Hinnantb0be42b2010-09-21 18:58:51 +0000124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000125 explicit facet(size_t __refs = 0)
126 : __shared_count(static_cast<long>(__refs)-1) {}
127
128 virtual ~facet();
129
130// facet(const facet&) = delete; // effectively done in __shared_count
131// void operator=(const facet&) = delete;
132private:
Howard Hinnant1694d232011-05-28 14:41:13 +0000133 virtual void __on_zero_shared() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000134};
135
Howard Hinnant83eade62013-03-06 23:30:19 +0000136class _LIBCPP_TYPE_VIS locale::id
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000137{
138 once_flag __flag_;
139 int32_t __id_;
Howard Hinnant324bb032010-08-22 00:02:43 +0000140
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000141 static int32_t __next_id;
142public:
Howard Hinnantf3d62ea2012-07-26 16:14:37 +0000143 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144private:
145 void __init();
146 void operator=(const id&); // = delete;
147 id(const id&); // = delete;
148public: // only needed for tests
149 long __get();
150
151 friend class locale;
152 friend class locale::__imp;
153};
154
155template <class _Facet>
156inline _LIBCPP_INLINE_VISIBILITY
157locale::locale(const locale& __other, _Facet* __f)
158{
159 __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
160}
161
162template <class _Facet>
163locale
164locale::combine(const locale& __other) const
165{
Howard Hinnantd4444702010-08-11 17:04:31 +0000166#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0949eed2011-06-30 21:18:19 +0000167 if (!_VSTD::has_facet<_Facet>(__other))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000168 throw runtime_error("locale::combine: locale missing facet");
Howard Hinnant324bb032010-08-22 00:02:43 +0000169#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0949eed2011-06-30 21:18:19 +0000170 return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000171}
172
173template <class _Facet>
174inline _LIBCPP_INLINE_VISIBILITY
175bool
Howard Hinnantc9834542011-05-31 15:34:58 +0000176has_facet(const locale& __l) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000177{
178 return __l.has_facet(_Facet::id);
179}
180
181template <class _Facet>
182inline _LIBCPP_INLINE_VISIBILITY
183const _Facet&
184use_facet(const locale& __l)
185{
186 return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
187}
188
189// template <class _CharT> class collate;
190
191template <class _CharT>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000192class _LIBCPP_TYPE_VIS_ONLY collate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000193 : public locale::facet
194{
195public:
196 typedef _CharT char_type;
197 typedef basic_string<char_type> string_type;
198
Howard Hinnantb0be42b2010-09-21 18:58:51 +0000199 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000200 explicit collate(size_t __refs = 0)
201 : locale::facet(__refs) {}
202
Howard Hinnantb0be42b2010-09-21 18:58:51 +0000203 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000204 int compare(const char_type* __lo1, const char_type* __hi1,
205 const char_type* __lo2, const char_type* __hi2) const
206 {
207 return do_compare(__lo1, __hi1, __lo2, __hi2);
208 }
209
Howard Hinnantb0be42b2010-09-21 18:58:51 +0000210 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000211 string_type transform(const char_type* __lo, const char_type* __hi) const
212 {
213 return do_transform(__lo, __hi);
214 }
215
Howard Hinnantb0be42b2010-09-21 18:58:51 +0000216 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000217 long hash(const char_type* __lo, const char_type* __hi) const
218 {
219 return do_hash(__lo, __hi);
220 }
221
222 static locale::id id;
223
224protected:
225 ~collate();
226 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
227 const char_type* __lo2, const char_type* __hi2) const;
228 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
229 {return string_type(__lo, __hi);}
230 virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
231};
232
233template <class _CharT> locale::id collate<_CharT>::id;
234
235template <class _CharT>
236collate<_CharT>::~collate()
237{
238}
239
240template <class _CharT>
241int
242collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
243 const char_type* __lo2, const char_type* __hi2) const
244{
245 for (; __lo2 != __hi2; ++__lo1, ++__lo2)
246 {
247 if (__lo1 == __hi1 || *__lo1 < *__lo2)
248 return -1;
249 if (*__lo2 < *__lo1)
250 return 1;
251 }
252 return __lo1 != __hi1;
253}
254
255template <class _CharT>
256long
Howard Hinnant11624452011-10-11 16:00:46 +0000257collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258{
Howard Hinnant11624452011-10-11 16:00:46 +0000259 size_t __h = 0;
260 const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
261 const size_t __mask = size_t(0xF) << (__sr + 4);
262 for(const char_type* __p = __lo; __p != __hi; ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000263 {
Howard Hinnantec3773c2011-12-01 20:21:04 +0000264 __h = (__h << 4) + static_cast<size_t>(*__p);
Howard Hinnant11624452011-10-11 16:00:46 +0000265 size_t __g = __h & __mask;
266 __h ^= __g | (__g >> __sr);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000267 }
Howard Hinnant11624452011-10-11 16:00:46 +0000268 return static_cast<long>(__h);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000269}
270
Howard Hinnant499cea12013-08-23 17:37:05 +0000271_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS collate<char>)
272_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS collate<wchar_t>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000273
274// template <class CharT> class collate_byname;
275
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000276template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY collate_byname;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000277
278template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000279class _LIBCPP_TYPE_VIS collate_byname<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000280 : public collate<char>
281{
282 locale_t __l;
283public:
284 typedef char char_type;
285 typedef basic_string<char_type> string_type;
286
287 explicit collate_byname(const char* __n, size_t __refs = 0);
288 explicit collate_byname(const string& __n, size_t __refs = 0);
289
290protected:
291 ~collate_byname();
292 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
293 const char_type* __lo2, const char_type* __hi2) const;
294 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
295};
296
297template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000298class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000299 : public collate<wchar_t>
300{
301 locale_t __l;
302public:
303 typedef wchar_t char_type;
304 typedef basic_string<char_type> string_type;
305
306 explicit collate_byname(const char* __n, size_t __refs = 0);
307 explicit collate_byname(const string& __n, size_t __refs = 0);
308
309protected:
310 ~collate_byname();
311
312 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
313 const char_type* __lo2, const char_type* __hi2) const;
314 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
315};
316
317template <class _CharT, class _Traits, class _Allocator>
318bool
319locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
320 const basic_string<_CharT, _Traits, _Allocator>& __y) const
321{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000322 return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000323 __x.data(), __x.data() + __x.size(),
324 __y.data(), __y.data() + __y.size()) < 0;
325}
326
327// template <class charT> class ctype
328
Howard Hinnant83eade62013-03-06 23:30:19 +0000329class _LIBCPP_TYPE_VIS ctype_base
Howard Hinnantb0be42b2010-09-21 18:58:51 +0000330{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000331public:
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700332#ifdef __GLIBC__
Sean Hunt62a6ac32011-07-09 00:56:23 +0000333 typedef unsigned short mask;
Howard Hinnantadff4892010-05-24 17:49:41 +0000334 static const mask space = _ISspace;
335 static const mask print = _ISprint;
336 static const mask cntrl = _IScntrl;
337 static const mask upper = _ISupper;
338 static const mask lower = _ISlower;
339 static const mask alpha = _ISalpha;
340 static const mask digit = _ISdigit;
341 static const mask punct = _ISpunct;
342 static const mask xdigit = _ISxdigit;
343 static const mask blank = _ISblank;
Marshall Clowa22d2ad2013-03-18 17:04:29 +0000344#elif defined(_WIN32)
Howard Hinnant3c466fc2011-09-29 13:33:15 +0000345 typedef unsigned short mask;
Howard Hinnant92a07002011-09-22 19:10:18 +0000346 static const mask space = _SPACE;
347 static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT;
348 static const mask cntrl = _CONTROL;
349 static const mask upper = _UPPER;
350 static const mask lower = _LOWER;
351 static const mask alpha = _ALPHA;
352 static const mask digit = _DIGIT;
353 static const mask punct = _PUNCT;
354 static const mask xdigit = _HEX;
355 static const mask blank = _BLANK;
Jonathan Roelofs6fb33ea2015-03-11 17:00:28 +0000356# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
Dan Albert6272ae52015-03-11 00:51:06 +0000357#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
JF Bastiena14f7cb2015-02-25 22:16:46 +0000358# ifdef __APPLE__
David Chisnallc512df12011-09-21 08:39:44 +0000359 typedef __uint32_t mask;
JF Bastiena14f7cb2015-02-25 22:16:46 +0000360# elif defined(__FreeBSD__)
David Chisnallc512df12011-09-21 08:39:44 +0000361 typedef unsigned long mask;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700362# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
Howard Hinnantfc2f0212013-03-29 18:27:28 +0000363 typedef unsigned short mask;
JF Bastiena14f7cb2015-02-25 22:16:46 +0000364# endif
David Chisnallc512df12011-09-21 08:39:44 +0000365 static const mask space = _CTYPE_S;
366 static const mask print = _CTYPE_R;
367 static const mask cntrl = _CTYPE_C;
368 static const mask upper = _CTYPE_U;
369 static const mask lower = _CTYPE_L;
370 static const mask alpha = _CTYPE_A;
371 static const mask digit = _CTYPE_D;
372 static const mask punct = _CTYPE_P;
373 static const mask xdigit = _CTYPE_X;
Dan Albert2a52a322014-07-23 19:32:03 +0000374
Joerg Sonnenbergera71a9522013-05-17 21:17:34 +0000375# if defined(__NetBSD__)
376 static const mask blank = _CTYPE_BL;
377# else
David Chisnallc512df12011-09-21 08:39:44 +0000378 static const mask blank = _CTYPE_B;
Joerg Sonnenbergera71a9522013-05-17 21:17:34 +0000379# endif
Howard Hinnantcb0e6b62013-08-30 14:42:39 +0000380#elif defined(__sun__) || defined(_AIX)
David Chisnall997e4542012-02-29 13:05:08 +0000381 typedef unsigned int mask;
382 static const mask space = _ISSPACE;
383 static const mask print = _ISPRINT;
384 static const mask cntrl = _ISCNTRL;
385 static const mask upper = _ISUPPER;
386 static const mask lower = _ISLOWER;
387 static const mask alpha = _ISALPHA;
388 static const mask digit = _ISDIGIT;
389 static const mask punct = _ISPUNCT;
390 static const mask xdigit = _ISXDIGIT;
391 static const mask blank = _ISBLANK;
JF Bastiena14f7cb2015-02-25 22:16:46 +0000392#elif defined(_NEWLIB_VERSION)
393 // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
394 typedef char mask;
395 static const mask space = _S;
396 static const mask print = _P | _U | _L | _N | _B;
397 static const mask cntrl = _C;
398 static const mask upper = _U;
399 static const mask lower = _L;
400 static const mask alpha = _U | _L;
401 static const mask digit = _N;
402 static const mask punct = _P;
403 static const mask xdigit = _X | _N;
404 static const mask blank = _B;
Jonathan Roelofs6fb33ea2015-03-11 17:00:28 +0000405# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
406# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
407# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
JF Bastiena14f7cb2015-02-25 22:16:46 +0000408#else
Howard Hinnant11624452011-10-11 16:00:46 +0000409 typedef unsigned long mask;
410 static const mask space = 1<<0;
411 static const mask print = 1<<1;
412 static const mask cntrl = 1<<2;
413 static const mask upper = 1<<3;
414 static const mask lower = 1<<4;
415 static const mask alpha = 1<<5;
416 static const mask digit = 1<<6;
417 static const mask punct = 1<<7;
418 static const mask xdigit = 1<<8;
419 static const mask blank = 1<<9;
JF Bastiena14f7cb2015-02-25 22:16:46 +0000420#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000421 static const mask alnum = alpha | digit;
422 static const mask graph = alnum | punct;
423
424 _LIBCPP_ALWAYS_INLINE ctype_base() {}
425};
426
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000427template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY ctype;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428
429template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000430class _LIBCPP_TYPE_VIS ctype<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000431 : public locale::facet,
432 public ctype_base
433{
434public:
435 typedef wchar_t char_type;
Howard Hinnant324bb032010-08-22 00:02:43 +0000436
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000437 _LIBCPP_ALWAYS_INLINE
438 explicit ctype(size_t __refs = 0)
439 : locale::facet(__refs) {}
440
441 _LIBCPP_ALWAYS_INLINE
442 bool is(mask __m, char_type __c) const
443 {
444 return do_is(__m, __c);
445 }
446
447 _LIBCPP_ALWAYS_INLINE
448 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
449 {
450 return do_is(__low, __high, __vec);
451 }
452
453 _LIBCPP_ALWAYS_INLINE
454 const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
455 {
456 return do_scan_is(__m, __low, __high);
457 }
458
459 _LIBCPP_ALWAYS_INLINE
460 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
461 {
462 return do_scan_not(__m, __low, __high);
463 }
464
465 _LIBCPP_ALWAYS_INLINE
466 char_type toupper(char_type __c) const
467 {
468 return do_toupper(__c);
469 }
470
471 _LIBCPP_ALWAYS_INLINE
472 const char_type* toupper(char_type* __low, const char_type* __high) const
473 {
474 return do_toupper(__low, __high);
475 }
476
477 _LIBCPP_ALWAYS_INLINE
478 char_type tolower(char_type __c) const
479 {
480 return do_tolower(__c);
481 }
482
483 _LIBCPP_ALWAYS_INLINE
484 const char_type* tolower(char_type* __low, const char_type* __high) const
485 {
486 return do_tolower(__low, __high);
487 }
488
489 _LIBCPP_ALWAYS_INLINE
490 char_type widen(char __c) const
491 {
492 return do_widen(__c);
493 }
494
495 _LIBCPP_ALWAYS_INLINE
496 const char* widen(const char* __low, const char* __high, char_type* __to) const
497 {
498 return do_widen(__low, __high, __to);
499 }
500
501 _LIBCPP_ALWAYS_INLINE
502 char narrow(char_type __c, char __dfault) const
503 {
504 return do_narrow(__c, __dfault);
505 }
506
507 _LIBCPP_ALWAYS_INLINE
508 const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
509 {
510 return do_narrow(__low, __high, __dfault, __to);
511 }
512
513 static locale::id id;
514
515protected:
516 ~ctype();
517 virtual bool do_is(mask __m, char_type __c) const;
518 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
519 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
520 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
521 virtual char_type do_toupper(char_type) const;
522 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
523 virtual char_type do_tolower(char_type) const;
524 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
525 virtual char_type do_widen(char) const;
526 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
527 virtual char do_narrow(char_type, char __dfault) const;
528 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
529};
530
531template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000532class _LIBCPP_TYPE_VIS ctype<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533 : public locale::facet, public ctype_base
534{
535 const mask* __tab_;
536 bool __del_;
537public:
538 typedef char char_type;
539
540 explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
541
542 _LIBCPP_ALWAYS_INLINE
543 bool is(mask __m, char_type __c) const
544 {
Marshall Clow8a43fca2013-10-21 14:41:05 +0000545 return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000546 }
547
548 _LIBCPP_ALWAYS_INLINE
549 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
550 {
551 for (; __low != __high; ++__low, ++__vec)
Howard Hinnantec3773c2011-12-01 20:21:04 +0000552 *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000553 return __low;
554 }
555
556 _LIBCPP_ALWAYS_INLINE
557 const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
558 {
559 for (; __low != __high; ++__low)
Howard Hinnantec3773c2011-12-01 20:21:04 +0000560 if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000561 break;
562 return __low;
563 }
564
565 _LIBCPP_ALWAYS_INLINE
566 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
567 {
568 for (; __low != __high; ++__low)
Howard Hinnantec3773c2011-12-01 20:21:04 +0000569 if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000570 break;
571 return __low;
572 }
573
574 _LIBCPP_ALWAYS_INLINE
575 char_type toupper(char_type __c) const
576 {
577 return do_toupper(__c);
578 }
579
580 _LIBCPP_ALWAYS_INLINE
581 const char_type* toupper(char_type* __low, const char_type* __high) const
582 {
583 return do_toupper(__low, __high);
584 }
585
586 _LIBCPP_ALWAYS_INLINE
587 char_type tolower(char_type __c) const
588 {
589 return do_tolower(__c);
590 }
591
592 _LIBCPP_ALWAYS_INLINE
593 const char_type* tolower(char_type* __low, const char_type* __high) const
594 {
595 return do_tolower(__low, __high);
596 }
597
598 _LIBCPP_ALWAYS_INLINE
599 char_type widen(char __c) const
600 {
601 return do_widen(__c);
602 }
603
604 _LIBCPP_ALWAYS_INLINE
605 const char* widen(const char* __low, const char* __high, char_type* __to) const
606 {
607 return do_widen(__low, __high, __to);
608 }
609
610 _LIBCPP_ALWAYS_INLINE
611 char narrow(char_type __c, char __dfault) const
612 {
613 return do_narrow(__c, __dfault);
614 }
615
616 _LIBCPP_ALWAYS_INLINE
617 const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
618 {
619 return do_narrow(__low, __high, __dfault, __to);
620 }
621
622 static locale::id id;
623
Howard Hinnantadff4892010-05-24 17:49:41 +0000624#ifdef _CACHED_RUNES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000625 static const size_t table_size = _CACHED_RUNES;
Howard Hinnantadff4892010-05-24 17:49:41 +0000626#else
627 static const size_t table_size = 256; // FIXME: Don't hardcode this.
628#endif
Howard Hinnantc9834542011-05-31 15:34:58 +0000629 _LIBCPP_ALWAYS_INLINE const mask* table() const _NOEXCEPT {return __tab_;}
630 static const mask* classic_table() _NOEXCEPT;
Vasileios Kalintiris5e00a712015-11-24 10:24:54 +0000631#if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
Sean Hunt62a6ac32011-07-09 00:56:23 +0000632 static const int* __classic_upper_table() _NOEXCEPT;
633 static const int* __classic_lower_table() _NOEXCEPT;
Sean Hunte59f7242011-07-09 01:09:31 +0000634#endif
Joerg Sonnenbergera71a9522013-05-17 21:17:34 +0000635#if defined(__NetBSD__)
636 static const short* __classic_upper_table() _NOEXCEPT;
637 static const short* __classic_lower_table() _NOEXCEPT;
638#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000639
640protected:
641 ~ctype();
642 virtual char_type do_toupper(char_type __c) const;
643 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
644 virtual char_type do_tolower(char_type __c) const;
645 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
646 virtual char_type do_widen(char __c) const;
647 virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
648 virtual char do_narrow(char_type __c, char __dfault) const;
649 virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
650};
651
652// template <class CharT> class ctype_byname;
653
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000654template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY ctype_byname;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000655
656template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000657class _LIBCPP_TYPE_VIS ctype_byname<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000658 : public ctype<char>
659{
660 locale_t __l;
661
662public:
663 explicit ctype_byname(const char*, size_t = 0);
664 explicit ctype_byname(const string&, size_t = 0);
665
666protected:
667 ~ctype_byname();
668 virtual char_type do_toupper(char_type) const;
669 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
670 virtual char_type do_tolower(char_type) const;
671 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
672};
673
674template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000675class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000676 : public ctype<wchar_t>
677{
678 locale_t __l;
679
680public:
681 explicit ctype_byname(const char*, size_t = 0);
682 explicit ctype_byname(const string&, size_t = 0);
683
684protected:
685 ~ctype_byname();
686 virtual bool do_is(mask __m, char_type __c) const;
687 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
688 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
689 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
690 virtual char_type do_toupper(char_type) const;
691 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
692 virtual char_type do_tolower(char_type) const;
693 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
694 virtual char_type do_widen(char) const;
695 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
696 virtual char do_narrow(char_type, char __dfault) const;
697 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
698};
699
700template <class _CharT>
701inline _LIBCPP_INLINE_VISIBILITY
702bool
703isspace(_CharT __c, const locale& __loc)
704{
705 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
706}
707
708template <class _CharT>
709inline _LIBCPP_INLINE_VISIBILITY
710bool
711isprint(_CharT __c, const locale& __loc)
712{
713 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
714}
715
716template <class _CharT>
717inline _LIBCPP_INLINE_VISIBILITY
718bool
719iscntrl(_CharT __c, const locale& __loc)
720{
721 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
722}
723
724template <class _CharT>
725inline _LIBCPP_INLINE_VISIBILITY
726bool
727isupper(_CharT __c, const locale& __loc)
728{
729 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
730}
731
732template <class _CharT>
733inline _LIBCPP_INLINE_VISIBILITY
734bool
735islower(_CharT __c, const locale& __loc)
736{
737 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
738}
739
740template <class _CharT>
741inline _LIBCPP_INLINE_VISIBILITY
742bool
743isalpha(_CharT __c, const locale& __loc)
744{
745 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
746}
747
748template <class _CharT>
749inline _LIBCPP_INLINE_VISIBILITY
750bool
751isdigit(_CharT __c, const locale& __loc)
752{
753 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
754}
755
756template <class _CharT>
757inline _LIBCPP_INLINE_VISIBILITY
758bool
759ispunct(_CharT __c, const locale& __loc)
760{
761 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
762}
763
764template <class _CharT>
765inline _LIBCPP_INLINE_VISIBILITY
766bool
767isxdigit(_CharT __c, const locale& __loc)
768{
769 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
770}
771
772template <class _CharT>
773inline _LIBCPP_INLINE_VISIBILITY
774bool
775isalnum(_CharT __c, const locale& __loc)
776{
777 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
778}
779
780template <class _CharT>
781inline _LIBCPP_INLINE_VISIBILITY
782bool
783isgraph(_CharT __c, const locale& __loc)
784{
785 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
786}
787
788template <class _CharT>
789inline _LIBCPP_INLINE_VISIBILITY
790_CharT
791toupper(_CharT __c, const locale& __loc)
792{
793 return use_facet<ctype<_CharT> >(__loc).toupper(__c);
794}
795
796template <class _CharT>
797inline _LIBCPP_INLINE_VISIBILITY
798_CharT
799tolower(_CharT __c, const locale& __loc)
800{
801 return use_facet<ctype<_CharT> >(__loc).tolower(__c);
802}
803
804// codecvt_base
805
Howard Hinnant83eade62013-03-06 23:30:19 +0000806class _LIBCPP_TYPE_VIS codecvt_base
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000807{
808public:
809 _LIBCPP_ALWAYS_INLINE codecvt_base() {}
810 enum result {ok, partial, error, noconv};
811};
812
813// template <class internT, class externT, class stateT> class codecvt;
814
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000815template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TYPE_VIS_ONLY codecvt;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000816
817// template <> class codecvt<char, char, mbstate_t>
818
819template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000820class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000821 : public locale::facet,
822 public codecvt_base
823{
824public:
825 typedef char intern_type;
826 typedef char extern_type;
827 typedef mbstate_t state_type;
828
829 _LIBCPP_ALWAYS_INLINE
830 explicit codecvt(size_t __refs = 0)
831 : locale::facet(__refs) {}
832
833 _LIBCPP_ALWAYS_INLINE
834 result out(state_type& __st,
835 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
836 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
837 {
838 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
839 }
840
841 _LIBCPP_ALWAYS_INLINE
842 result unshift(state_type& __st,
843 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
844 {
845 return do_unshift(__st, __to, __to_end, __to_nxt);
846 }
847
848 _LIBCPP_ALWAYS_INLINE
849 result in(state_type& __st,
850 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
851 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
852 {
853 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
854 }
855
856 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc9834542011-05-31 15:34:58 +0000857 int encoding() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000858 {
859 return do_encoding();
860 }
861
862 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc9834542011-05-31 15:34:58 +0000863 bool always_noconv() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000864 {
865 return do_always_noconv();
866 }
867
868 _LIBCPP_ALWAYS_INLINE
869 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
870 {
871 return do_length(__st, __frm, __end, __mx);
872 }
873
874 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc9834542011-05-31 15:34:58 +0000875 int max_length() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000876 {
877 return do_max_length();
878 }
879
880 static locale::id id;
881
882protected:
883 _LIBCPP_ALWAYS_INLINE
884 explicit codecvt(const char*, size_t __refs = 0)
885 : locale::facet(__refs) {}
886
887 ~codecvt();
888
889 virtual result do_out(state_type& __st,
890 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
891 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
892 virtual result do_in(state_type& __st,
893 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
894 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
895 virtual result do_unshift(state_type& __st,
896 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnantc9834542011-05-31 15:34:58 +0000897 virtual int do_encoding() const _NOEXCEPT;
898 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
Howard Hinnantc9834542011-05-31 15:34:58 +0000900 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901};
902
903// template <> class codecvt<wchar_t, char, mbstate_t>
904
905template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000906class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000907 : public locale::facet,
908 public codecvt_base
909{
910 locale_t __l;
911public:
912 typedef wchar_t intern_type;
913 typedef char extern_type;
914 typedef mbstate_t state_type;
915
916 explicit codecvt(size_t __refs = 0);
917
918 _LIBCPP_ALWAYS_INLINE
919 result out(state_type& __st,
920 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
921 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
922 {
923 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
924 }
925
926 _LIBCPP_ALWAYS_INLINE
927 result unshift(state_type& __st,
928 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
929 {
930 return do_unshift(__st, __to, __to_end, __to_nxt);
931 }
932
933 _LIBCPP_ALWAYS_INLINE
934 result in(state_type& __st,
935 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
936 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
937 {
938 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
939 }
940
941 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc9834542011-05-31 15:34:58 +0000942 int encoding() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000943 {
944 return do_encoding();
945 }
946
947 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc9834542011-05-31 15:34:58 +0000948 bool always_noconv() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000949 {
950 return do_always_noconv();
951 }
952
953 _LIBCPP_ALWAYS_INLINE
954 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
955 {
956 return do_length(__st, __frm, __end, __mx);
957 }
958
959 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc9834542011-05-31 15:34:58 +0000960 int max_length() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000961 {
962 return do_max_length();
963 }
964
965 static locale::id id;
966
967protected:
968 explicit codecvt(const char*, size_t __refs = 0);
969
970 ~codecvt();
971
972 virtual result do_out(state_type& __st,
973 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
974 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
975 virtual result do_in(state_type& __st,
976 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
977 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
978 virtual result do_unshift(state_type& __st,
979 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnantc9834542011-05-31 15:34:58 +0000980 virtual int do_encoding() const _NOEXCEPT;
981 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000982 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
Howard Hinnantc9834542011-05-31 15:34:58 +0000983 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000984};
985
986// template <> class codecvt<char16_t, char, mbstate_t>
987
988template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000989class _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000990 : public locale::facet,
991 public codecvt_base
992{
993public:
994 typedef char16_t intern_type;
995 typedef char extern_type;
996 typedef mbstate_t state_type;
997
998 _LIBCPP_ALWAYS_INLINE
999 explicit codecvt(size_t __refs = 0)
1000 : locale::facet(__refs) {}
1001
1002 _LIBCPP_ALWAYS_INLINE
1003 result out(state_type& __st,
1004 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1005 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1006 {
1007 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1008 }
1009
1010 _LIBCPP_ALWAYS_INLINE
1011 result unshift(state_type& __st,
1012 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1013 {
1014 return do_unshift(__st, __to, __to_end, __to_nxt);
1015 }
1016
1017 _LIBCPP_ALWAYS_INLINE
1018 result in(state_type& __st,
1019 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1020 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1021 {
1022 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1023 }
1024
1025 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc9834542011-05-31 15:34:58 +00001026 int encoding() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001027 {
1028 return do_encoding();
1029 }
1030
1031 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc9834542011-05-31 15:34:58 +00001032 bool always_noconv() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001033 {
1034 return do_always_noconv();
1035 }
1036
1037 _LIBCPP_ALWAYS_INLINE
1038 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1039 {
1040 return do_length(__st, __frm, __end, __mx);
1041 }
1042
1043 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc9834542011-05-31 15:34:58 +00001044 int max_length() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001045 {
1046 return do_max_length();
1047 }
1048
1049 static locale::id id;
1050
1051protected:
1052 _LIBCPP_ALWAYS_INLINE
1053 explicit codecvt(const char*, size_t __refs = 0)
1054 : locale::facet(__refs) {}
1055
1056 ~codecvt();
1057
1058 virtual result do_out(state_type& __st,
1059 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1060 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1061 virtual result do_in(state_type& __st,
1062 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1063 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1064 virtual result do_unshift(state_type& __st,
1065 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnantc9834542011-05-31 15:34:58 +00001066 virtual int do_encoding() const _NOEXCEPT;
1067 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001068 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
Howard Hinnantc9834542011-05-31 15:34:58 +00001069 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070};
1071
1072// template <> class codecvt<char32_t, char, mbstate_t>
1073
1074template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00001075class _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001076 : public locale::facet,
1077 public codecvt_base
1078{
1079public:
1080 typedef char32_t intern_type;
1081 typedef char extern_type;
1082 typedef mbstate_t state_type;
1083
1084 _LIBCPP_ALWAYS_INLINE
1085 explicit codecvt(size_t __refs = 0)
1086 : locale::facet(__refs) {}
1087
1088 _LIBCPP_ALWAYS_INLINE
1089 result out(state_type& __st,
1090 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1091 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1092 {
1093 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1094 }
1095
1096 _LIBCPP_ALWAYS_INLINE
1097 result unshift(state_type& __st,
1098 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1099 {
1100 return do_unshift(__st, __to, __to_end, __to_nxt);
1101 }
1102
1103 _LIBCPP_ALWAYS_INLINE
1104 result in(state_type& __st,
1105 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1106 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1107 {
1108 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1109 }
1110
1111 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc9834542011-05-31 15:34:58 +00001112 int encoding() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001113 {
1114 return do_encoding();
1115 }
1116
1117 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc9834542011-05-31 15:34:58 +00001118 bool always_noconv() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001119 {
1120 return do_always_noconv();
1121 }
1122
1123 _LIBCPP_ALWAYS_INLINE
1124 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1125 {
1126 return do_length(__st, __frm, __end, __mx);
1127 }
1128
1129 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc9834542011-05-31 15:34:58 +00001130 int max_length() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001131 {
1132 return do_max_length();
1133 }
1134
1135 static locale::id id;
1136
1137protected:
1138 _LIBCPP_ALWAYS_INLINE
1139 explicit codecvt(const char*, size_t __refs = 0)
1140 : locale::facet(__refs) {}
1141
1142 ~codecvt();
1143
1144 virtual result do_out(state_type& __st,
1145 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1146 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1147 virtual result do_in(state_type& __st,
1148 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1149 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1150 virtual result do_unshift(state_type& __st,
1151 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnantc9834542011-05-31 15:34:58 +00001152 virtual int do_encoding() const _NOEXCEPT;
1153 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
Howard Hinnantc9834542011-05-31 15:34:58 +00001155 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001156};
1157
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001158// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
1159
1160template <class _InternT, class _ExternT, class _StateT>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001161class _LIBCPP_TYPE_VIS_ONLY codecvt_byname
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001162 : public codecvt<_InternT, _ExternT, _StateT>
1163{
1164public:
Howard Hinnantb0be42b2010-09-21 18:58:51 +00001165 _LIBCPP_ALWAYS_INLINE
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001166 explicit codecvt_byname(const char* __nm, size_t __refs = 0)
1167 : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
Howard Hinnantb0be42b2010-09-21 18:58:51 +00001168 _LIBCPP_ALWAYS_INLINE
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001169 explicit codecvt_byname(const string& __nm, size_t __refs = 0)
1170 : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
1171protected:
1172 ~codecvt_byname();
1173};
1174
1175template <class _InternT, class _ExternT, class _StateT>
1176codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
1177{
1178}
1179
Howard Hinnant499cea12013-08-23 17:37:05 +00001180_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<char, char, mbstate_t>)
1181_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>)
1182_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>)
1183_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001184
Howard Hinnant83eade62013-03-06 23:30:19 +00001185_LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001186
Howard Hinnant99968442011-11-29 18:15:50 +00001187template <size_t _Np>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001188struct __narrow_to_utf8
1189{
1190 template <class _OutputIterator, class _CharT>
1191 _OutputIterator
1192 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
1193};
1194
1195template <>
1196struct __narrow_to_utf8<8>
1197{
1198 template <class _OutputIterator, class _CharT>
1199 _LIBCPP_ALWAYS_INLINE
1200 _OutputIterator
1201 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1202 {
1203 for (; __wb < __we; ++__wb, ++__s)
1204 *__s = *__wb;
1205 return __s;
1206 }
1207};
1208
1209template <>
1210struct __narrow_to_utf8<16>
1211 : public codecvt<char16_t, char, mbstate_t>
1212{
1213 _LIBCPP_ALWAYS_INLINE
1214 __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1215
1216 ~__narrow_to_utf8();
1217
1218 template <class _OutputIterator, class _CharT>
1219 _LIBCPP_ALWAYS_INLINE
1220 _OutputIterator
1221 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1222 {
1223 result __r = ok;
1224 mbstate_t __mb;
1225 while (__wb < __we && __r != error)
1226 {
1227 const int __sz = 32;
1228 char __buf[__sz];
1229 char* __bn;
1230 const char16_t* __wn = (const char16_t*)__wb;
1231 __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
1232 __buf, __buf+__sz, __bn);
1233 if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
1234 __throw_runtime_error("locale not supported");
1235 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1236 *__s = *__p;
1237 __wb = (const _CharT*)__wn;
1238 }
1239 return __s;
1240 }
1241};
1242
1243template <>
1244struct __narrow_to_utf8<32>
1245 : public codecvt<char32_t, char, mbstate_t>
1246{
1247 _LIBCPP_ALWAYS_INLINE
1248 __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1249
1250 ~__narrow_to_utf8();
1251
1252 template <class _OutputIterator, class _CharT>
1253 _LIBCPP_ALWAYS_INLINE
1254 _OutputIterator
1255 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1256 {
1257 result __r = ok;
1258 mbstate_t __mb;
1259 while (__wb < __we && __r != error)
1260 {
1261 const int __sz = 32;
1262 char __buf[__sz];
1263 char* __bn;
1264 const char32_t* __wn = (const char32_t*)__wb;
1265 __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
1266 __buf, __buf+__sz, __bn);
1267 if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
1268 __throw_runtime_error("locale not supported");
1269 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1270 *__s = *__p;
1271 __wb = (const _CharT*)__wn;
1272 }
1273 return __s;
1274 }
1275};
1276
Howard Hinnant99968442011-11-29 18:15:50 +00001277template <size_t _Np>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001278struct __widen_from_utf8
1279{
1280 template <class _OutputIterator>
1281 _OutputIterator
1282 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
1283};
1284
1285template <>
1286struct __widen_from_utf8<8>
1287{
1288 template <class _OutputIterator>
1289 _LIBCPP_ALWAYS_INLINE
1290 _OutputIterator
1291 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1292 {
1293 for (; __nb < __ne; ++__nb, ++__s)
1294 *__s = *__nb;
1295 return __s;
1296 }
1297};
1298
1299template <>
1300struct __widen_from_utf8<16>
1301 : public codecvt<char16_t, char, mbstate_t>
1302{
1303 _LIBCPP_ALWAYS_INLINE
1304 __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1305
1306 ~__widen_from_utf8();
1307
1308 template <class _OutputIterator>
1309 _LIBCPP_ALWAYS_INLINE
1310 _OutputIterator
1311 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1312 {
1313 result __r = ok;
1314 mbstate_t __mb;
1315 while (__nb < __ne && __r != error)
1316 {
1317 const int __sz = 32;
1318 char16_t __buf[__sz];
1319 char16_t* __bn;
1320 const char* __nn = __nb;
1321 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1322 __buf, __buf+__sz, __bn);
1323 if (__r == codecvt_base::error || __nn == __nb)
1324 __throw_runtime_error("locale not supported");
1325 for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
1326 *__s = (wchar_t)*__p;
1327 __nb = __nn;
1328 }
1329 return __s;
1330 }
1331};
1332
1333template <>
1334struct __widen_from_utf8<32>
1335 : public codecvt<char32_t, char, mbstate_t>
1336{
1337 _LIBCPP_ALWAYS_INLINE
1338 __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1339
1340 ~__widen_from_utf8();
1341
1342 template <class _OutputIterator>
1343 _LIBCPP_ALWAYS_INLINE
1344 _OutputIterator
1345 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1346 {
1347 result __r = ok;
1348 mbstate_t __mb;
1349 while (__nb < __ne && __r != error)
1350 {
1351 const int __sz = 32;
1352 char32_t __buf[__sz];
1353 char32_t* __bn;
1354 const char* __nn = __nb;
1355 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1356 __buf, __buf+__sz, __bn);
1357 if (__r == codecvt_base::error || __nn == __nb)
1358 __throw_runtime_error("locale not supported");
1359 for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
1360 *__s = (wchar_t)*__p;
1361 __nb = __nn;
1362 }
1363 return __s;
1364 }
1365};
1366
1367// template <class charT> class numpunct
1368
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001369template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY numpunct;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001370
1371template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00001372class _LIBCPP_TYPE_VIS numpunct<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001373 : public locale::facet
1374{
1375public:
1376 typedef char char_type;
1377 typedef basic_string<char_type> string_type;
1378
1379 explicit numpunct(size_t __refs = 0);
1380
1381 _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
1382 _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
1383 _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();}
1384 _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();}
1385 _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();}
1386
1387 static locale::id id;
1388
1389protected:
1390 ~numpunct();
1391 virtual char_type do_decimal_point() const;
1392 virtual char_type do_thousands_sep() const;
1393 virtual string do_grouping() const;
1394 virtual string_type do_truename() const;
1395 virtual string_type do_falsename() const;
1396
1397 char_type __decimal_point_;
1398 char_type __thousands_sep_;
1399 string __grouping_;
1400};
1401
1402template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00001403class _LIBCPP_TYPE_VIS numpunct<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001404 : public locale::facet
1405{
1406public:
1407 typedef wchar_t char_type;
1408 typedef basic_string<char_type> string_type;
1409
1410 explicit numpunct(size_t __refs = 0);
1411
1412 _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
1413 _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
1414 _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();}
1415 _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();}
1416 _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();}
1417
1418 static locale::id id;
1419
1420protected:
1421 ~numpunct();
1422 virtual char_type do_decimal_point() const;
1423 virtual char_type do_thousands_sep() const;
1424 virtual string do_grouping() const;
1425 virtual string_type do_truename() const;
1426 virtual string_type do_falsename() const;
1427
1428 char_type __decimal_point_;
1429 char_type __thousands_sep_;
1430 string __grouping_;
1431};
1432
1433// template <class charT> class numpunct_byname
1434
Marshall Clowe4220212015-01-11 06:15:59 +00001435template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY numpunct_byname;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001436
1437template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00001438class _LIBCPP_TYPE_VIS numpunct_byname<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001439: public numpunct<char>
1440{
1441public:
1442 typedef char char_type;
1443 typedef basic_string<char_type> string_type;
1444
1445 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1446 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1447
1448protected:
1449 ~numpunct_byname();
1450
1451private:
1452 void __init(const char*);
1453};
1454
1455template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00001456class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001457: public numpunct<wchar_t>
1458{
1459public:
1460 typedef wchar_t char_type;
1461 typedef basic_string<char_type> string_type;
1462
1463 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1464 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1465
1466protected:
1467 ~numpunct_byname();
1468
1469private:
1470 void __init(const char*);
1471};
1472
1473_LIBCPP_END_NAMESPACE_STD
1474
1475#endif // _LIBCPP___LOCALE