blob: 42c9c5ae7f1e65e34eba4bbf03a3abbf7be61e6d [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-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 Hinnantc51e1022010-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 Hinnant155c2af2010-05-24 17:49:41 +000021#include <locale.h>
Howard Hinnantdd0d7022011-09-22 19:10:18 +000022#if _WIN32
23# include <support/win32/locale.h>
24#else // _WIN32
25# include <xlocale.h>
26#endif // _WIN32
Howard Hinnantc51e1022010-05-11 19:42:16 +000027
28#pragma GCC system_header
29
30_LIBCPP_BEGIN_NAMESPACE_STD
31
32class locale;
33
Howard Hinnant7c9e5732011-05-31 15:34:58 +000034template <class _Facet> bool has_facet(const locale&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +000035template <class _Facet> const _Facet& use_facet(const locale&);
36
Howard Hinnant9833cad2010-09-21 18:58:51 +000037class _LIBCPP_VISIBLE locale
Howard Hinnantc51e1022010-05-11 19:42:16 +000038{
39public:
40 // types:
41 class facet;
42 class id;
43
44 typedef int category;
45 static const category // values assigned here are for exposition only
46 none = 0,
47 collate = LC_COLLATE_MASK,
48 ctype = LC_CTYPE_MASK,
49 monetary = LC_MONETARY_MASK,
50 numeric = LC_NUMERIC_MASK,
51 time = LC_TIME_MASK,
52 messages = LC_MESSAGES_MASK,
53 all = collate | ctype | monetary | numeric | time | messages;
54
55 // construct/copy/destroy:
Howard Hinnant7c9e5732011-05-31 15:34:58 +000056 locale() _NOEXCEPT;
57 locale(const locale&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +000058 explicit locale(const char*);
59 explicit locale(const string&);
60 locale(const locale&, const char*, category);
61 locale(const locale&, const string&, category);
Howard Hinnantcf823322010-12-17 14:46:43 +000062 template <class _Facet>
63 _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
Howard Hinnantc51e1022010-05-11 19:42:16 +000064 locale(const locale&, const locale&, category);
65
Howard Hinnant7c9e5732011-05-31 15:34:58 +000066 ~locale();
Howard Hinnantc51e1022010-05-11 19:42:16 +000067
Howard Hinnant7c9e5732011-05-31 15:34:58 +000068 const locale& operator=(const locale&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +000069
70 template <class _Facet> locale combine(const locale&) const;
71
72 // locale operations:
73 string name() const;
74 bool operator==(const locale&) const;
75 bool operator!=(const locale& __y) const {return !(*this == __y);}
76 template <class _CharT, class _Traits, class _Allocator>
77 bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
78 const basic_string<_CharT, _Traits, _Allocator>&) const;
79
80 // global locale objects:
81 static locale global(const locale&);
82 static const locale& classic();
83
84private:
85 class __imp;
86 __imp* __locale_;
87
88 void __install_ctor(const locale&, facet*, long);
89 static locale& __global();
90 bool has_facet(id&) const;
91 const facet* use_facet(id&) const;
92
Howard Hinnant7c9e5732011-05-31 15:34:58 +000093 template <class _Facet> friend bool has_facet(const locale&) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +000094 template <class _Facet> friend const _Facet& use_facet(const locale&);
95};
96
Howard Hinnant9833cad2010-09-21 18:58:51 +000097class _LIBCPP_VISIBLE locale::facet
Howard Hinnantc51e1022010-05-11 19:42:16 +000098 : public __shared_count
99{
100protected:
Howard Hinnant9833cad2010-09-21 18:58:51 +0000101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000102 explicit facet(size_t __refs = 0)
103 : __shared_count(static_cast<long>(__refs)-1) {}
104
105 virtual ~facet();
106
107// facet(const facet&) = delete; // effectively done in __shared_count
108// void operator=(const facet&) = delete;
109private:
Howard Hinnant719bda32011-05-28 14:41:13 +0000110 virtual void __on_zero_shared() _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000111};
112
Howard Hinnant9833cad2010-09-21 18:58:51 +0000113class _LIBCPP_VISIBLE locale::id
Howard Hinnantc51e1022010-05-11 19:42:16 +0000114{
115 once_flag __flag_;
116 int32_t __id_;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000117
Howard Hinnantc51e1022010-05-11 19:42:16 +0000118 static int32_t __next_id;
119public:
Howard Hinnant9833cad2010-09-21 18:58:51 +0000120 _LIBCPP_INLINE_VISIBILITY id() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000121private:
122 void __init();
123 void operator=(const id&); // = delete;
124 id(const id&); // = delete;
125public: // only needed for tests
126 long __get();
127
128 friend class locale;
129 friend class locale::__imp;
130};
131
132template <class _Facet>
133inline _LIBCPP_INLINE_VISIBILITY
134locale::locale(const locale& __other, _Facet* __f)
135{
136 __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
137}
138
139template <class _Facet>
140locale
141locale::combine(const locale& __other) const
142{
Howard Hinnant72f73582010-08-11 17:04:31 +0000143#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000144 if (!_VSTD::has_facet<_Facet>(__other))
Howard Hinnantc51e1022010-05-11 19:42:16 +0000145 throw runtime_error("locale::combine: locale missing facet");
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000146#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000147 return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
Howard Hinnantc51e1022010-05-11 19:42:16 +0000148}
149
150template <class _Facet>
151inline _LIBCPP_INLINE_VISIBILITY
152bool
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000153has_facet(const locale& __l) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000154{
155 return __l.has_facet(_Facet::id);
156}
157
158template <class _Facet>
159inline _LIBCPP_INLINE_VISIBILITY
160const _Facet&
161use_facet(const locale& __l)
162{
163 return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
164}
165
166// template <class _CharT> class collate;
167
168template <class _CharT>
Howard Hinnant9833cad2010-09-21 18:58:51 +0000169class _LIBCPP_VISIBLE collate
Howard Hinnantc51e1022010-05-11 19:42:16 +0000170 : public locale::facet
171{
172public:
173 typedef _CharT char_type;
174 typedef basic_string<char_type> string_type;
175
Howard Hinnant9833cad2010-09-21 18:58:51 +0000176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000177 explicit collate(size_t __refs = 0)
178 : locale::facet(__refs) {}
179
Howard Hinnant9833cad2010-09-21 18:58:51 +0000180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000181 int compare(const char_type* __lo1, const char_type* __hi1,
182 const char_type* __lo2, const char_type* __hi2) const
183 {
184 return do_compare(__lo1, __hi1, __lo2, __hi2);
185 }
186
Howard Hinnant9833cad2010-09-21 18:58:51 +0000187 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000188 string_type transform(const char_type* __lo, const char_type* __hi) const
189 {
190 return do_transform(__lo, __hi);
191 }
192
Howard Hinnant9833cad2010-09-21 18:58:51 +0000193 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000194 long hash(const char_type* __lo, const char_type* __hi) const
195 {
196 return do_hash(__lo, __hi);
197 }
198
199 static locale::id id;
200
201protected:
202 ~collate();
203 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
204 const char_type* __lo2, const char_type* __hi2) const;
205 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
206 {return string_type(__lo, __hi);}
207 virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
208};
209
210template <class _CharT> locale::id collate<_CharT>::id;
211
212template <class _CharT>
213collate<_CharT>::~collate()
214{
215}
216
217template <class _CharT>
218int
219collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
220 const char_type* __lo2, const char_type* __hi2) const
221{
222 for (; __lo2 != __hi2; ++__lo1, ++__lo2)
223 {
224 if (__lo1 == __hi1 || *__lo1 < *__lo2)
225 return -1;
226 if (*__lo2 < *__lo1)
227 return 1;
228 }
229 return __lo1 != __hi1;
230}
231
232template <class _CharT>
233long
234collate<_CharT>::do_hash(const char_type* lo, const char_type* hi) const
235{
236 size_t h = 0;
237 const size_t sr = __CHAR_BIT__ * sizeof(size_t) - 8;
238 const size_t mask = size_t(0xF) << (sr + 4);
239 for(const char_type* p = lo; p != hi; ++p)
240 {
241 h = (h << 4) + *p;
242 size_t g = h & mask;
243 h ^= g | (g >> sr);
244 }
245 return static_cast<long>(h);
246}
247
Howard Hinnant9833cad2010-09-21 18:58:51 +0000248extern template class _LIBCPP_VISIBLE collate<char>;
249extern template class _LIBCPP_VISIBLE collate<wchar_t>;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000250
251// template <class CharT> class collate_byname;
252
Howard Hinnant9833cad2010-09-21 18:58:51 +0000253template <class _CharT> class _LIBCPP_VISIBLE collate_byname;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000254
255template <>
Howard Hinnant9833cad2010-09-21 18:58:51 +0000256class _LIBCPP_VISIBLE collate_byname<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000257 : public collate<char>
258{
259 locale_t __l;
260public:
261 typedef char char_type;
262 typedef basic_string<char_type> string_type;
263
264 explicit collate_byname(const char* __n, size_t __refs = 0);
265 explicit collate_byname(const string& __n, size_t __refs = 0);
266
267protected:
268 ~collate_byname();
269 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
270 const char_type* __lo2, const char_type* __hi2) const;
271 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
272};
273
274template <>
Howard Hinnant9833cad2010-09-21 18:58:51 +0000275class _LIBCPP_VISIBLE collate_byname<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000276 : public collate<wchar_t>
277{
278 locale_t __l;
279public:
280 typedef wchar_t char_type;
281 typedef basic_string<char_type> string_type;
282
283 explicit collate_byname(const char* __n, size_t __refs = 0);
284 explicit collate_byname(const string& __n, size_t __refs = 0);
285
286protected:
287 ~collate_byname();
288
289 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
290 const char_type* __lo2, const char_type* __hi2) const;
291 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
292};
293
294template <class _CharT, class _Traits, class _Allocator>
295bool
296locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
297 const basic_string<_CharT, _Traits, _Allocator>& __y) const
298{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +0000299 return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
Howard Hinnantc51e1022010-05-11 19:42:16 +0000300 __x.data(), __x.data() + __x.size(),
301 __y.data(), __y.data() + __y.size()) < 0;
302}
303
304// template <class charT> class ctype
305
Howard Hinnant9833cad2010-09-21 18:58:51 +0000306class _LIBCPP_VISIBLE ctype_base
307{
Howard Hinnantc51e1022010-05-11 19:42:16 +0000308public:
David Chisnall1d581062011-09-21 08:39:44 +0000309#if __GLIBC__
Alexis Hunt92b0c812011-07-09 00:56:23 +0000310 typedef unsigned short mask;
Howard Hinnant155c2af2010-05-24 17:49:41 +0000311 static const mask space = _ISspace;
312 static const mask print = _ISprint;
313 static const mask cntrl = _IScntrl;
314 static const mask upper = _ISupper;
315 static const mask lower = _ISlower;
316 static const mask alpha = _ISalpha;
317 static const mask digit = _ISdigit;
318 static const mask punct = _ISpunct;
319 static const mask xdigit = _ISxdigit;
320 static const mask blank = _ISblank;
Howard Hinnantdd0d7022011-09-22 19:10:18 +0000321#elif _WIN32
322 typedef unsigned __int32 mask;
323 static const mask space = _SPACE;
324 static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT;
325 static const mask cntrl = _CONTROL;
326 static const mask upper = _UPPER;
327 static const mask lower = _LOWER;
328 static const mask alpha = _ALPHA;
329 static const mask digit = _DIGIT;
330 static const mask punct = _PUNCT;
331 static const mask xdigit = _HEX;
332 static const mask blank = _BLANK;
333#else // __GLIBC__ || _WIN32
David Chisnall1d581062011-09-21 08:39:44 +0000334#if __APPLE__
335 typedef __uint32_t mask;
336#elif __FreeBSD__
337 typedef unsigned long mask;
338#endif
339 static const mask space = _CTYPE_S;
340 static const mask print = _CTYPE_R;
341 static const mask cntrl = _CTYPE_C;
342 static const mask upper = _CTYPE_U;
343 static const mask lower = _CTYPE_L;
344 static const mask alpha = _CTYPE_A;
345 static const mask digit = _CTYPE_D;
346 static const mask punct = _CTYPE_P;
347 static const mask xdigit = _CTYPE_X;
348 static const mask blank = _CTYPE_B;
Howard Hinnantdd0d7022011-09-22 19:10:18 +0000349#endif // __GLIBC__ || _WIN32
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350 static const mask alnum = alpha | digit;
351 static const mask graph = alnum | punct;
352
353 _LIBCPP_ALWAYS_INLINE ctype_base() {}
354};
355
Howard Hinnant9833cad2010-09-21 18:58:51 +0000356template <class _CharT> class _LIBCPP_VISIBLE ctype;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000357
358template <>
Howard Hinnant9833cad2010-09-21 18:58:51 +0000359class _LIBCPP_VISIBLE ctype<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360 : public locale::facet,
361 public ctype_base
362{
363public:
364 typedef wchar_t char_type;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000365
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366 _LIBCPP_ALWAYS_INLINE
367 explicit ctype(size_t __refs = 0)
368 : locale::facet(__refs) {}
369
370 _LIBCPP_ALWAYS_INLINE
371 bool is(mask __m, char_type __c) const
372 {
373 return do_is(__m, __c);
374 }
375
376 _LIBCPP_ALWAYS_INLINE
377 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
378 {
379 return do_is(__low, __high, __vec);
380 }
381
382 _LIBCPP_ALWAYS_INLINE
383 const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
384 {
385 return do_scan_is(__m, __low, __high);
386 }
387
388 _LIBCPP_ALWAYS_INLINE
389 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
390 {
391 return do_scan_not(__m, __low, __high);
392 }
393
394 _LIBCPP_ALWAYS_INLINE
395 char_type toupper(char_type __c) const
396 {
397 return do_toupper(__c);
398 }
399
400 _LIBCPP_ALWAYS_INLINE
401 const char_type* toupper(char_type* __low, const char_type* __high) const
402 {
403 return do_toupper(__low, __high);
404 }
405
406 _LIBCPP_ALWAYS_INLINE
407 char_type tolower(char_type __c) const
408 {
409 return do_tolower(__c);
410 }
411
412 _LIBCPP_ALWAYS_INLINE
413 const char_type* tolower(char_type* __low, const char_type* __high) const
414 {
415 return do_tolower(__low, __high);
416 }
417
418 _LIBCPP_ALWAYS_INLINE
419 char_type widen(char __c) const
420 {
421 return do_widen(__c);
422 }
423
424 _LIBCPP_ALWAYS_INLINE
425 const char* widen(const char* __low, const char* __high, char_type* __to) const
426 {
427 return do_widen(__low, __high, __to);
428 }
429
430 _LIBCPP_ALWAYS_INLINE
431 char narrow(char_type __c, char __dfault) const
432 {
433 return do_narrow(__c, __dfault);
434 }
435
436 _LIBCPP_ALWAYS_INLINE
437 const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
438 {
439 return do_narrow(__low, __high, __dfault, __to);
440 }
441
442 static locale::id id;
443
444protected:
445 ~ctype();
446 virtual bool do_is(mask __m, char_type __c) const;
447 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
448 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
449 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
450 virtual char_type do_toupper(char_type) const;
451 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
452 virtual char_type do_tolower(char_type) const;
453 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
454 virtual char_type do_widen(char) const;
455 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
456 virtual char do_narrow(char_type, char __dfault) const;
457 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
458};
459
460template <>
Howard Hinnant9833cad2010-09-21 18:58:51 +0000461class _LIBCPP_VISIBLE ctype<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000462 : public locale::facet, public ctype_base
463{
464 const mask* __tab_;
465 bool __del_;
466public:
467 typedef char char_type;
468
469 explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
470
471 _LIBCPP_ALWAYS_INLINE
472 bool is(mask __m, char_type __c) const
473 {
474 return isascii(__c) ? __tab_[__c] & __m : false;
475 }
476
477 _LIBCPP_ALWAYS_INLINE
478 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
479 {
480 for (; __low != __high; ++__low, ++__vec)
481 *__vec = isascii(*__low) ? __tab_[*__low] : 0;
482 return __low;
483 }
484
485 _LIBCPP_ALWAYS_INLINE
486 const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
487 {
488 for (; __low != __high; ++__low)
489 if (isascii(*__low) && (__tab_[*__low] & __m))
490 break;
491 return __low;
492 }
493
494 _LIBCPP_ALWAYS_INLINE
495 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
496 {
497 for (; __low != __high; ++__low)
498 if (!(isascii(*__low) && (__tab_[*__low] & __m)))
499 break;
500 return __low;
501 }
502
503 _LIBCPP_ALWAYS_INLINE
504 char_type toupper(char_type __c) const
505 {
506 return do_toupper(__c);
507 }
508
509 _LIBCPP_ALWAYS_INLINE
510 const char_type* toupper(char_type* __low, const char_type* __high) const
511 {
512 return do_toupper(__low, __high);
513 }
514
515 _LIBCPP_ALWAYS_INLINE
516 char_type tolower(char_type __c) const
517 {
518 return do_tolower(__c);
519 }
520
521 _LIBCPP_ALWAYS_INLINE
522 const char_type* tolower(char_type* __low, const char_type* __high) const
523 {
524 return do_tolower(__low, __high);
525 }
526
527 _LIBCPP_ALWAYS_INLINE
528 char_type widen(char __c) const
529 {
530 return do_widen(__c);
531 }
532
533 _LIBCPP_ALWAYS_INLINE
534 const char* widen(const char* __low, const char* __high, char_type* __to) const
535 {
536 return do_widen(__low, __high, __to);
537 }
538
539 _LIBCPP_ALWAYS_INLINE
540 char narrow(char_type __c, char __dfault) const
541 {
542 return do_narrow(__c, __dfault);
543 }
544
545 _LIBCPP_ALWAYS_INLINE
546 const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
547 {
548 return do_narrow(__low, __high, __dfault, __to);
549 }
550
551 static locale::id id;
552
Howard Hinnant155c2af2010-05-24 17:49:41 +0000553#ifdef _CACHED_RUNES
Howard Hinnantc51e1022010-05-11 19:42:16 +0000554 static const size_t table_size = _CACHED_RUNES;
Howard Hinnant155c2af2010-05-24 17:49:41 +0000555#else
556 static const size_t table_size = 256; // FIXME: Don't hardcode this.
557#endif
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000558 _LIBCPP_ALWAYS_INLINE const mask* table() const _NOEXCEPT {return __tab_;}
559 static const mask* classic_table() _NOEXCEPT;
Alexis Hunt5a4dd562011-07-09 01:09:31 +0000560#ifndef _LIBCPP_STABLE_APPLE_ABI
Alexis Hunt92b0c812011-07-09 00:56:23 +0000561 static const int* __classic_upper_table() _NOEXCEPT;
562 static const int* __classic_lower_table() _NOEXCEPT;
Alexis Hunt5a4dd562011-07-09 01:09:31 +0000563#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564
565protected:
566 ~ctype();
567 virtual char_type do_toupper(char_type __c) const;
568 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
569 virtual char_type do_tolower(char_type __c) const;
570 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
571 virtual char_type do_widen(char __c) const;
572 virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
573 virtual char do_narrow(char_type __c, char __dfault) const;
574 virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
575};
576
577// template <class CharT> class ctype_byname;
578
Howard Hinnant9833cad2010-09-21 18:58:51 +0000579template <class _CharT> class _LIBCPP_VISIBLE ctype_byname;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000580
581template <>
Howard Hinnant9833cad2010-09-21 18:58:51 +0000582class _LIBCPP_VISIBLE ctype_byname<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000583 : public ctype<char>
584{
585 locale_t __l;
586
587public:
588 explicit ctype_byname(const char*, size_t = 0);
589 explicit ctype_byname(const string&, size_t = 0);
590
591protected:
592 ~ctype_byname();
593 virtual char_type do_toupper(char_type) const;
594 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
595 virtual char_type do_tolower(char_type) const;
596 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
597};
598
599template <>
Howard Hinnant9833cad2010-09-21 18:58:51 +0000600class _LIBCPP_VISIBLE ctype_byname<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000601 : public ctype<wchar_t>
602{
603 locale_t __l;
604
605public:
606 explicit ctype_byname(const char*, size_t = 0);
607 explicit ctype_byname(const string&, size_t = 0);
608
609protected:
610 ~ctype_byname();
611 virtual bool do_is(mask __m, char_type __c) const;
612 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
613 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
614 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
615 virtual char_type do_toupper(char_type) const;
616 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
617 virtual char_type do_tolower(char_type) const;
618 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
619 virtual char_type do_widen(char) const;
620 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
621 virtual char do_narrow(char_type, char __dfault) const;
622 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
623};
624
625template <class _CharT>
626inline _LIBCPP_INLINE_VISIBILITY
627bool
628isspace(_CharT __c, const locale& __loc)
629{
630 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
631}
632
633template <class _CharT>
634inline _LIBCPP_INLINE_VISIBILITY
635bool
636isprint(_CharT __c, const locale& __loc)
637{
638 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
639}
640
641template <class _CharT>
642inline _LIBCPP_INLINE_VISIBILITY
643bool
644iscntrl(_CharT __c, const locale& __loc)
645{
646 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
647}
648
649template <class _CharT>
650inline _LIBCPP_INLINE_VISIBILITY
651bool
652isupper(_CharT __c, const locale& __loc)
653{
654 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
655}
656
657template <class _CharT>
658inline _LIBCPP_INLINE_VISIBILITY
659bool
660islower(_CharT __c, const locale& __loc)
661{
662 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
663}
664
665template <class _CharT>
666inline _LIBCPP_INLINE_VISIBILITY
667bool
668isalpha(_CharT __c, const locale& __loc)
669{
670 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
671}
672
673template <class _CharT>
674inline _LIBCPP_INLINE_VISIBILITY
675bool
676isdigit(_CharT __c, const locale& __loc)
677{
678 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
679}
680
681template <class _CharT>
682inline _LIBCPP_INLINE_VISIBILITY
683bool
684ispunct(_CharT __c, const locale& __loc)
685{
686 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
687}
688
689template <class _CharT>
690inline _LIBCPP_INLINE_VISIBILITY
691bool
692isxdigit(_CharT __c, const locale& __loc)
693{
694 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
695}
696
697template <class _CharT>
698inline _LIBCPP_INLINE_VISIBILITY
699bool
700isalnum(_CharT __c, const locale& __loc)
701{
702 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
703}
704
705template <class _CharT>
706inline _LIBCPP_INLINE_VISIBILITY
707bool
708isgraph(_CharT __c, const locale& __loc)
709{
710 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
711}
712
713template <class _CharT>
714inline _LIBCPP_INLINE_VISIBILITY
715_CharT
716toupper(_CharT __c, const locale& __loc)
717{
718 return use_facet<ctype<_CharT> >(__loc).toupper(__c);
719}
720
721template <class _CharT>
722inline _LIBCPP_INLINE_VISIBILITY
723_CharT
724tolower(_CharT __c, const locale& __loc)
725{
726 return use_facet<ctype<_CharT> >(__loc).tolower(__c);
727}
728
729// codecvt_base
730
Howard Hinnant9833cad2010-09-21 18:58:51 +0000731class _LIBCPP_VISIBLE codecvt_base
Howard Hinnantc51e1022010-05-11 19:42:16 +0000732{
733public:
734 _LIBCPP_ALWAYS_INLINE codecvt_base() {}
735 enum result {ok, partial, error, noconv};
736};
737
738// template <class internT, class externT, class stateT> class codecvt;
739
Howard Hinnant9833cad2010-09-21 18:58:51 +0000740template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_VISIBLE codecvt;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741
742// template <> class codecvt<char, char, mbstate_t>
743
744template <>
Howard Hinnant9833cad2010-09-21 18:58:51 +0000745class _LIBCPP_VISIBLE codecvt<char, char, mbstate_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000746 : public locale::facet,
747 public codecvt_base
748{
749public:
750 typedef char intern_type;
751 typedef char extern_type;
752 typedef mbstate_t state_type;
753
754 _LIBCPP_ALWAYS_INLINE
755 explicit codecvt(size_t __refs = 0)
756 : locale::facet(__refs) {}
757
758 _LIBCPP_ALWAYS_INLINE
759 result out(state_type& __st,
760 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
761 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
762 {
763 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
764 }
765
766 _LIBCPP_ALWAYS_INLINE
767 result unshift(state_type& __st,
768 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
769 {
770 return do_unshift(__st, __to, __to_end, __to_nxt);
771 }
772
773 _LIBCPP_ALWAYS_INLINE
774 result in(state_type& __st,
775 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
776 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
777 {
778 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
779 }
780
781 _LIBCPP_ALWAYS_INLINE
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000782 int encoding() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000783 {
784 return do_encoding();
785 }
786
787 _LIBCPP_ALWAYS_INLINE
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000788 bool always_noconv() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000789 {
790 return do_always_noconv();
791 }
792
793 _LIBCPP_ALWAYS_INLINE
794 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
795 {
796 return do_length(__st, __frm, __end, __mx);
797 }
798
799 _LIBCPP_ALWAYS_INLINE
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000800 int max_length() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000801 {
802 return do_max_length();
803 }
804
805 static locale::id id;
806
807protected:
808 _LIBCPP_ALWAYS_INLINE
809 explicit codecvt(const char*, size_t __refs = 0)
810 : locale::facet(__refs) {}
811
812 ~codecvt();
813
814 virtual result do_out(state_type& __st,
815 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
816 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
817 virtual result do_in(state_type& __st,
818 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
819 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
820 virtual result do_unshift(state_type& __st,
821 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000822 virtual int do_encoding() const _NOEXCEPT;
823 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000824 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 +0000825 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826};
827
828// template <> class codecvt<wchar_t, char, mbstate_t>
829
830template <>
Howard Hinnant9833cad2010-09-21 18:58:51 +0000831class _LIBCPP_VISIBLE codecvt<wchar_t, char, mbstate_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000832 : public locale::facet,
833 public codecvt_base
834{
835 locale_t __l;
836public:
837 typedef wchar_t intern_type;
838 typedef char extern_type;
839 typedef mbstate_t state_type;
840
841 explicit codecvt(size_t __refs = 0);
842
843 _LIBCPP_ALWAYS_INLINE
844 result out(state_type& __st,
845 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
846 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
847 {
848 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
849 }
850
851 _LIBCPP_ALWAYS_INLINE
852 result unshift(state_type& __st,
853 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
854 {
855 return do_unshift(__st, __to, __to_end, __to_nxt);
856 }
857
858 _LIBCPP_ALWAYS_INLINE
859 result in(state_type& __st,
860 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
861 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
862 {
863 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
864 }
865
866 _LIBCPP_ALWAYS_INLINE
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000867 int encoding() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868 {
869 return do_encoding();
870 }
871
872 _LIBCPP_ALWAYS_INLINE
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000873 bool always_noconv() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874 {
875 return do_always_noconv();
876 }
877
878 _LIBCPP_ALWAYS_INLINE
879 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
880 {
881 return do_length(__st, __frm, __end, __mx);
882 }
883
884 _LIBCPP_ALWAYS_INLINE
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000885 int max_length() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000886 {
887 return do_max_length();
888 }
889
890 static locale::id id;
891
892protected:
893 explicit codecvt(const char*, size_t __refs = 0);
894
895 ~codecvt();
896
897 virtual result do_out(state_type& __st,
898 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
899 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
900 virtual result do_in(state_type& __st,
901 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
902 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
903 virtual result do_unshift(state_type& __st,
904 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000905 virtual int do_encoding() const _NOEXCEPT;
906 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907 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 +0000908 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000909};
910
911// template <> class codecvt<char16_t, char, mbstate_t>
912
913template <>
Howard Hinnant9833cad2010-09-21 18:58:51 +0000914class _LIBCPP_VISIBLE codecvt<char16_t, char, mbstate_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000915 : public locale::facet,
916 public codecvt_base
917{
918public:
919 typedef char16_t intern_type;
920 typedef char extern_type;
921 typedef mbstate_t state_type;
922
923 _LIBCPP_ALWAYS_INLINE
924 explicit codecvt(size_t __refs = 0)
925 : locale::facet(__refs) {}
926
927 _LIBCPP_ALWAYS_INLINE
928 result out(state_type& __st,
929 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
930 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
931 {
932 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
933 }
934
935 _LIBCPP_ALWAYS_INLINE
936 result unshift(state_type& __st,
937 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
938 {
939 return do_unshift(__st, __to, __to_end, __to_nxt);
940 }
941
942 _LIBCPP_ALWAYS_INLINE
943 result in(state_type& __st,
944 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
945 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
946 {
947 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
948 }
949
950 _LIBCPP_ALWAYS_INLINE
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000951 int encoding() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000952 {
953 return do_encoding();
954 }
955
956 _LIBCPP_ALWAYS_INLINE
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000957 bool always_noconv() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000958 {
959 return do_always_noconv();
960 }
961
962 _LIBCPP_ALWAYS_INLINE
963 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
964 {
965 return do_length(__st, __frm, __end, __mx);
966 }
967
968 _LIBCPP_ALWAYS_INLINE
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000969 int max_length() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000970 {
971 return do_max_length();
972 }
973
974 static locale::id id;
975
976protected:
977 _LIBCPP_ALWAYS_INLINE
978 explicit codecvt(const char*, size_t __refs = 0)
979 : locale::facet(__refs) {}
980
981 ~codecvt();
982
983 virtual result do_out(state_type& __st,
984 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
985 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
986 virtual result do_in(state_type& __st,
987 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
988 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
989 virtual result do_unshift(state_type& __st,
990 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnant7c9e5732011-05-31 15:34:58 +0000991 virtual int do_encoding() const _NOEXCEPT;
992 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000993 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 +0000994 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000995};
996
997// template <> class codecvt<char32_t, char, mbstate_t>
998
999template <>
Howard Hinnant9833cad2010-09-21 18:58:51 +00001000class _LIBCPP_VISIBLE codecvt<char32_t, char, mbstate_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001001 : public locale::facet,
1002 public codecvt_base
1003{
1004public:
1005 typedef char32_t intern_type;
1006 typedef char extern_type;
1007 typedef mbstate_t state_type;
1008
1009 _LIBCPP_ALWAYS_INLINE
1010 explicit codecvt(size_t __refs = 0)
1011 : locale::facet(__refs) {}
1012
1013 _LIBCPP_ALWAYS_INLINE
1014 result out(state_type& __st,
1015 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1016 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1017 {
1018 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1019 }
1020
1021 _LIBCPP_ALWAYS_INLINE
1022 result unshift(state_type& __st,
1023 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1024 {
1025 return do_unshift(__st, __to, __to_end, __to_nxt);
1026 }
1027
1028 _LIBCPP_ALWAYS_INLINE
1029 result in(state_type& __st,
1030 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1031 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1032 {
1033 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1034 }
1035
1036 _LIBCPP_ALWAYS_INLINE
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001037 int encoding() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001038 {
1039 return do_encoding();
1040 }
1041
1042 _LIBCPP_ALWAYS_INLINE
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001043 bool always_noconv() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001044 {
1045 return do_always_noconv();
1046 }
1047
1048 _LIBCPP_ALWAYS_INLINE
1049 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1050 {
1051 return do_length(__st, __frm, __end, __mx);
1052 }
1053
1054 _LIBCPP_ALWAYS_INLINE
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001055 int max_length() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001056 {
1057 return do_max_length();
1058 }
1059
1060 static locale::id id;
1061
1062protected:
1063 _LIBCPP_ALWAYS_INLINE
1064 explicit codecvt(const char*, size_t __refs = 0)
1065 : locale::facet(__refs) {}
1066
1067 ~codecvt();
1068
1069 virtual result do_out(state_type& __st,
1070 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1071 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1072 virtual result do_in(state_type& __st,
1073 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1074 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1075 virtual result do_unshift(state_type& __st,
1076 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
Howard Hinnant7c9e5732011-05-31 15:34:58 +00001077 virtual int do_encoding() const _NOEXCEPT;
1078 virtual bool do_always_noconv() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001079 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 +00001080 virtual int do_max_length() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081};
1082
Howard Hinnantc51e1022010-05-11 19:42:16 +00001083// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
1084
1085template <class _InternT, class _ExternT, class _StateT>
Howard Hinnant9833cad2010-09-21 18:58:51 +00001086class _LIBCPP_VISIBLE codecvt_byname
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087 : public codecvt<_InternT, _ExternT, _StateT>
1088{
1089public:
Howard Hinnant9833cad2010-09-21 18:58:51 +00001090 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc51e1022010-05-11 19:42:16 +00001091 explicit codecvt_byname(const char* __nm, size_t __refs = 0)
1092 : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
Howard Hinnant9833cad2010-09-21 18:58:51 +00001093 _LIBCPP_ALWAYS_INLINE
Howard Hinnantc51e1022010-05-11 19:42:16 +00001094 explicit codecvt_byname(const string& __nm, size_t __refs = 0)
1095 : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
1096protected:
1097 ~codecvt_byname();
1098};
1099
1100template <class _InternT, class _ExternT, class _StateT>
1101codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
1102{
1103}
1104
1105extern template class codecvt_byname<char, char, mbstate_t>;
1106extern template class codecvt_byname<wchar_t, char, mbstate_t>;
1107extern template class codecvt_byname<char16_t, char, mbstate_t>;
1108extern template class codecvt_byname<char32_t, char, mbstate_t>;
1109
Howard Hinnant9833cad2010-09-21 18:58:51 +00001110_LIBCPP_VISIBLE void __throw_runtime_error(const char*);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001111
1112template <size_t _N>
1113struct __narrow_to_utf8
1114{
1115 template <class _OutputIterator, class _CharT>
1116 _OutputIterator
1117 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
1118};
1119
1120template <>
1121struct __narrow_to_utf8<8>
1122{
1123 template <class _OutputIterator, class _CharT>
1124 _LIBCPP_ALWAYS_INLINE
1125 _OutputIterator
1126 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1127 {
1128 for (; __wb < __we; ++__wb, ++__s)
1129 *__s = *__wb;
1130 return __s;
1131 }
1132};
1133
1134template <>
1135struct __narrow_to_utf8<16>
1136 : public codecvt<char16_t, char, mbstate_t>
1137{
1138 _LIBCPP_ALWAYS_INLINE
1139 __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1140
1141 ~__narrow_to_utf8();
1142
1143 template <class _OutputIterator, class _CharT>
1144 _LIBCPP_ALWAYS_INLINE
1145 _OutputIterator
1146 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1147 {
1148 result __r = ok;
1149 mbstate_t __mb;
1150 while (__wb < __we && __r != error)
1151 {
1152 const int __sz = 32;
1153 char __buf[__sz];
1154 char* __bn;
1155 const char16_t* __wn = (const char16_t*)__wb;
1156 __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
1157 __buf, __buf+__sz, __bn);
1158 if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
1159 __throw_runtime_error("locale not supported");
1160 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1161 *__s = *__p;
1162 __wb = (const _CharT*)__wn;
1163 }
1164 return __s;
1165 }
1166};
1167
1168template <>
1169struct __narrow_to_utf8<32>
1170 : public codecvt<char32_t, char, mbstate_t>
1171{
1172 _LIBCPP_ALWAYS_INLINE
1173 __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1174
1175 ~__narrow_to_utf8();
1176
1177 template <class _OutputIterator, class _CharT>
1178 _LIBCPP_ALWAYS_INLINE
1179 _OutputIterator
1180 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1181 {
1182 result __r = ok;
1183 mbstate_t __mb;
1184 while (__wb < __we && __r != error)
1185 {
1186 const int __sz = 32;
1187 char __buf[__sz];
1188 char* __bn;
1189 const char32_t* __wn = (const char32_t*)__wb;
1190 __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
1191 __buf, __buf+__sz, __bn);
1192 if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
1193 __throw_runtime_error("locale not supported");
1194 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1195 *__s = *__p;
1196 __wb = (const _CharT*)__wn;
1197 }
1198 return __s;
1199 }
1200};
1201
1202template <size_t _N>
1203struct __widen_from_utf8
1204{
1205 template <class _OutputIterator>
1206 _OutputIterator
1207 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
1208};
1209
1210template <>
1211struct __widen_from_utf8<8>
1212{
1213 template <class _OutputIterator>
1214 _LIBCPP_ALWAYS_INLINE
1215 _OutputIterator
1216 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1217 {
1218 for (; __nb < __ne; ++__nb, ++__s)
1219 *__s = *__nb;
1220 return __s;
1221 }
1222};
1223
1224template <>
1225struct __widen_from_utf8<16>
1226 : public codecvt<char16_t, char, mbstate_t>
1227{
1228 _LIBCPP_ALWAYS_INLINE
1229 __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1230
1231 ~__widen_from_utf8();
1232
1233 template <class _OutputIterator>
1234 _LIBCPP_ALWAYS_INLINE
1235 _OutputIterator
1236 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1237 {
1238 result __r = ok;
1239 mbstate_t __mb;
1240 while (__nb < __ne && __r != error)
1241 {
1242 const int __sz = 32;
1243 char16_t __buf[__sz];
1244 char16_t* __bn;
1245 const char* __nn = __nb;
1246 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1247 __buf, __buf+__sz, __bn);
1248 if (__r == codecvt_base::error || __nn == __nb)
1249 __throw_runtime_error("locale not supported");
1250 for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
1251 *__s = (wchar_t)*__p;
1252 __nb = __nn;
1253 }
1254 return __s;
1255 }
1256};
1257
1258template <>
1259struct __widen_from_utf8<32>
1260 : public codecvt<char32_t, char, mbstate_t>
1261{
1262 _LIBCPP_ALWAYS_INLINE
1263 __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1264
1265 ~__widen_from_utf8();
1266
1267 template <class _OutputIterator>
1268 _LIBCPP_ALWAYS_INLINE
1269 _OutputIterator
1270 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1271 {
1272 result __r = ok;
1273 mbstate_t __mb;
1274 while (__nb < __ne && __r != error)
1275 {
1276 const int __sz = 32;
1277 char32_t __buf[__sz];
1278 char32_t* __bn;
1279 const char* __nn = __nb;
1280 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1281 __buf, __buf+__sz, __bn);
1282 if (__r == codecvt_base::error || __nn == __nb)
1283 __throw_runtime_error("locale not supported");
1284 for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
1285 *__s = (wchar_t)*__p;
1286 __nb = __nn;
1287 }
1288 return __s;
1289 }
1290};
1291
1292// template <class charT> class numpunct
1293
Howard Hinnant9833cad2010-09-21 18:58:51 +00001294template <class _CharT> class _LIBCPP_VISIBLE numpunct;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001295
1296template <>
Howard Hinnant9833cad2010-09-21 18:58:51 +00001297class _LIBCPP_VISIBLE numpunct<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001298 : public locale::facet
1299{
1300public:
1301 typedef char char_type;
1302 typedef basic_string<char_type> string_type;
1303
1304 explicit numpunct(size_t __refs = 0);
1305
1306 _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
1307 _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
1308 _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();}
1309 _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();}
1310 _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();}
1311
1312 static locale::id id;
1313
1314protected:
1315 ~numpunct();
1316 virtual char_type do_decimal_point() const;
1317 virtual char_type do_thousands_sep() const;
1318 virtual string do_grouping() const;
1319 virtual string_type do_truename() const;
1320 virtual string_type do_falsename() const;
1321
1322 char_type __decimal_point_;
1323 char_type __thousands_sep_;
1324 string __grouping_;
1325};
1326
1327template <>
Howard Hinnant9833cad2010-09-21 18:58:51 +00001328class _LIBCPP_VISIBLE numpunct<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001329 : public locale::facet
1330{
1331public:
1332 typedef wchar_t char_type;
1333 typedef basic_string<char_type> string_type;
1334
1335 explicit numpunct(size_t __refs = 0);
1336
1337 _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
1338 _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
1339 _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();}
1340 _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();}
1341 _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();}
1342
1343 static locale::id id;
1344
1345protected:
1346 ~numpunct();
1347 virtual char_type do_decimal_point() const;
1348 virtual char_type do_thousands_sep() const;
1349 virtual string do_grouping() const;
1350 virtual string_type do_truename() const;
1351 virtual string_type do_falsename() const;
1352
1353 char_type __decimal_point_;
1354 char_type __thousands_sep_;
1355 string __grouping_;
1356};
1357
1358// template <class charT> class numpunct_byname
1359
Howard Hinnant9833cad2010-09-21 18:58:51 +00001360template <class charT> class _LIBCPP_VISIBLE numpunct_byname;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001361
1362template <>
Howard Hinnant9833cad2010-09-21 18:58:51 +00001363class _LIBCPP_VISIBLE numpunct_byname<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001364: public numpunct<char>
1365{
1366public:
1367 typedef char char_type;
1368 typedef basic_string<char_type> string_type;
1369
1370 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1371 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1372
1373protected:
1374 ~numpunct_byname();
1375
1376private:
1377 void __init(const char*);
1378};
1379
1380template <>
Howard Hinnant9833cad2010-09-21 18:58:51 +00001381class _LIBCPP_VISIBLE numpunct_byname<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001382: public numpunct<wchar_t>
1383{
1384public:
1385 typedef wchar_t char_type;
1386 typedef basic_string<char_type> string_type;
1387
1388 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1389 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1390
1391protected:
1392 ~numpunct_byname();
1393
1394private:
1395 void __init(const char*);
1396};
1397
1398_LIBCPP_END_NAMESPACE_STD
1399
1400#endif // _LIBCPP___LOCALE