2 //===----------------------------------------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP___LOCALE
12 #define _LIBCPP___LOCALE
23 # include <support/win32/locale_win32.h>
24 #elif (defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)) || defined(EMSCRIPTEN)
26 #endif // _WIN32 || __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || EMSCRIPTEN
28 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29 #pragma GCC system_header
32 _LIBCPP_BEGIN_NAMESPACE_STD
34 class _LIBCPP_TYPE_VIS locale;
36 template <class _Facet>
37 _LIBCPP_INLINE_VISIBILITY
39 has_facet(const locale&) _NOEXCEPT;
41 template <class _Facet>
42 _LIBCPP_INLINE_VISIBILITY
44 use_facet(const locale&);
46 class _LIBCPP_TYPE_VIS locale
50 class _LIBCPP_TYPE_VIS facet;
51 class _LIBCPP_TYPE_VIS id;
54 static const category // values assigned here are for exposition only
56 collate = LC_COLLATE_MASK,
57 ctype = LC_CTYPE_MASK,
58 monetary = LC_MONETARY_MASK,
59 numeric = LC_NUMERIC_MASK,
61 messages = LC_MESSAGES_MASK,
62 all = collate | ctype | monetary | numeric | time | messages;
64 // construct/copy/destroy:
66 locale(const locale&) _NOEXCEPT;
67 explicit locale(const char*);
68 explicit locale(const string&);
69 locale(const locale&, const char*, category);
70 locale(const locale&, const string&, category);
71 template <class _Facet>
72 _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
73 locale(const locale&, const locale&, category);
77 const locale& operator=(const locale&) _NOEXCEPT;
79 template <class _Facet> locale combine(const locale&) const;
83 bool operator==(const locale&) const;
84 bool operator!=(const locale& __y) const {return !(*this == __y);}
85 template <class _CharT, class _Traits, class _Allocator>
86 bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
87 const basic_string<_CharT, _Traits, _Allocator>&) const;
89 // global locale objects:
90 static locale global(const locale&);
91 static const locale& classic();
97 void __install_ctor(const locale&, facet*, long);
98 static locale& __global();
99 bool has_facet(id&) const;
100 const facet* use_facet(id&) const;
102 template <class _Facet> friend bool has_facet(const locale&) _NOEXCEPT;
103 template <class _Facet> friend const _Facet& use_facet(const locale&);
106 class _LIBCPP_TYPE_VIS locale::facet
107 : public __shared_count
110 _LIBCPP_INLINE_VISIBILITY
111 explicit facet(size_t __refs = 0)
112 : __shared_count(static_cast<long>(__refs)-1) {}
116 // facet(const facet&) = delete; // effectively done in __shared_count
117 // void operator=(const facet&) = delete;
119 virtual void __on_zero_shared() _NOEXCEPT;
122 class _LIBCPP_TYPE_VIS locale::id
127 static int32_t __next_id;
129 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
132 void operator=(const id&); // = delete;
133 id(const id&); // = delete;
134 public: // only needed for tests
138 friend class locale::__imp;
141 template <class _Facet>
142 inline _LIBCPP_INLINE_VISIBILITY
143 locale::locale(const locale& __other, _Facet* __f)
145 __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
148 template <class _Facet>
150 locale::combine(const locale& __other) const
152 #ifndef _LIBCPP_NO_EXCEPTIONS
153 if (!_VSTD::has_facet<_Facet>(__other))
154 throw runtime_error("locale::combine: locale missing facet");
155 #endif // _LIBCPP_NO_EXCEPTIONS
156 return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
159 template <class _Facet>
160 inline _LIBCPP_INLINE_VISIBILITY
162 has_facet(const locale& __l) _NOEXCEPT
164 return __l.has_facet(_Facet::id);
167 template <class _Facet>
168 inline _LIBCPP_INLINE_VISIBILITY
170 use_facet(const locale& __l)
172 return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
175 // template <class _CharT> class collate;
177 template <class _CharT>
178 class _LIBCPP_TYPE_VIS collate
179 : public locale::facet
182 typedef _CharT char_type;
183 typedef basic_string<char_type> string_type;
185 _LIBCPP_INLINE_VISIBILITY
186 explicit collate(size_t __refs = 0)
187 : locale::facet(__refs) {}
189 _LIBCPP_INLINE_VISIBILITY
190 int compare(const char_type* __lo1, const char_type* __hi1,
191 const char_type* __lo2, const char_type* __hi2) const
193 return do_compare(__lo1, __hi1, __lo2, __hi2);
196 _LIBCPP_INLINE_VISIBILITY
197 string_type transform(const char_type* __lo, const char_type* __hi) const
199 return do_transform(__lo, __hi);
202 _LIBCPP_INLINE_VISIBILITY
203 long hash(const char_type* __lo, const char_type* __hi) const
205 return do_hash(__lo, __hi);
208 static locale::id id;
212 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
213 const char_type* __lo2, const char_type* __hi2) const;
214 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
215 {return string_type(__lo, __hi);}
216 virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
219 template <class _CharT> locale::id collate<_CharT>::id;
221 template <class _CharT>
222 collate<_CharT>::~collate()
226 template <class _CharT>
228 collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
229 const char_type* __lo2, const char_type* __hi2) const
231 for (; __lo2 != __hi2; ++__lo1, ++__lo2)
233 if (__lo1 == __hi1 || *__lo1 < *__lo2)
238 return __lo1 != __hi1;
241 template <class _CharT>
243 collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
246 const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
247 const size_t __mask = size_t(0xF) << (__sr + 4);
248 for(const char_type* __p = __lo; __p != __hi; ++__p)
250 __h = (__h << 4) + static_cast<size_t>(*__p);
251 size_t __g = __h & __mask;
252 __h ^= __g | (__g >> __sr);
254 return static_cast<long>(__h);
257 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS collate<char>)
258 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS collate<wchar_t>)
260 // template <class CharT> class collate_byname;
262 template <class _CharT> class _LIBCPP_TYPE_VIS collate_byname;
265 class _LIBCPP_TYPE_VIS collate_byname<char>
266 : public collate<char>
270 typedef char char_type;
271 typedef basic_string<char_type> string_type;
273 explicit collate_byname(const char* __n, size_t __refs = 0);
274 explicit collate_byname(const string& __n, size_t __refs = 0);
278 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
279 const char_type* __lo2, const char_type* __hi2) const;
280 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
284 class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
285 : public collate<wchar_t>
289 typedef wchar_t char_type;
290 typedef basic_string<char_type> string_type;
292 explicit collate_byname(const char* __n, size_t __refs = 0);
293 explicit collate_byname(const string& __n, size_t __refs = 0);
298 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
299 const char_type* __lo2, const char_type* __hi2) const;
300 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
303 template <class _CharT, class _Traits, class _Allocator>
305 locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
306 const basic_string<_CharT, _Traits, _Allocator>& __y) const
308 return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
309 __x.data(), __x.data() + __x.size(),
310 __y.data(), __y.data() + __y.size()) < 0;
313 // template <class charT> class ctype
315 class _LIBCPP_TYPE_VIS ctype_base
319 typedef unsigned short mask;
320 static const mask space = _ISspace;
321 static const mask print = _ISprint;
322 static const mask cntrl = _IScntrl;
323 static const mask upper = _ISupper;
324 static const mask lower = _ISlower;
325 static const mask alpha = _ISalpha;
326 static const mask digit = _ISdigit;
327 static const mask punct = _ISpunct;
328 static const mask xdigit = _ISxdigit;
329 static const mask blank = _ISblank;
330 #elif defined(_WIN32)
331 typedef unsigned short mask;
332 static const mask space = _SPACE;
333 static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT;
334 static const mask cntrl = _CONTROL;
335 static const mask upper = _UPPER;
336 static const mask lower = _LOWER;
337 static const mask alpha = _ALPHA;
338 static const mask digit = _DIGIT;
339 static const mask punct = _PUNCT;
340 static const mask xdigit = _HEX;
341 static const mask blank = _BLANK;
342 #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(EMSCRIPTEN) || defined(__NetBSD__)
344 typedef __uint32_t mask;
345 #elif defined(__FreeBSD__)
346 typedef unsigned long mask;
347 #elif defined(EMSCRIPTEN) || defined(__NetBSD__)
348 typedef unsigned short mask;
350 static const mask space = _CTYPE_S;
351 static const mask print = _CTYPE_R;
352 static const mask cntrl = _CTYPE_C;
353 static const mask upper = _CTYPE_U;
354 static const mask lower = _CTYPE_L;
355 static const mask alpha = _CTYPE_A;
356 static const mask digit = _CTYPE_D;
357 static const mask punct = _CTYPE_P;
358 static const mask xdigit = _CTYPE_X;
359 # if defined(__NetBSD__)
360 static const mask blank = _CTYPE_BL;
362 static const mask blank = _CTYPE_B;
364 #elif defined(__sun__)
365 typedef unsigned int mask;
366 static const mask space = _ISSPACE;
367 static const mask print = _ISPRINT;
368 static const mask cntrl = _ISCNTRL;
369 static const mask upper = _ISUPPER;
370 static const mask lower = _ISLOWER;
371 static const mask alpha = _ISALPHA;
372 static const mask digit = _ISDIGIT;
373 static const mask punct = _ISPUNCT;
374 static const mask xdigit = _ISXDIGIT;
375 static const mask blank = _ISBLANK;
376 #else // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__ || EMSCRIPTEN || __sun__
377 typedef unsigned long mask;
378 static const mask space = 1<<0;
379 static const mask print = 1<<1;
380 static const mask cntrl = 1<<2;
381 static const mask upper = 1<<3;
382 static const mask lower = 1<<4;
383 static const mask alpha = 1<<5;
384 static const mask digit = 1<<6;
385 static const mask punct = 1<<7;
386 static const mask xdigit = 1<<8;
387 static const mask blank = 1<<9;
388 #endif // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__
389 static const mask alnum = alpha | digit;
390 static const mask graph = alnum | punct;
392 _LIBCPP_ALWAYS_INLINE ctype_base() {}
395 template <class _CharT> class _LIBCPP_TYPE_VIS ctype;
398 class _LIBCPP_TYPE_VIS ctype<wchar_t>
399 : public locale::facet,
403 typedef wchar_t char_type;
405 _LIBCPP_ALWAYS_INLINE
406 explicit ctype(size_t __refs = 0)
407 : locale::facet(__refs) {}
409 _LIBCPP_ALWAYS_INLINE
410 bool is(mask __m, char_type __c) const
412 return do_is(__m, __c);
415 _LIBCPP_ALWAYS_INLINE
416 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
418 return do_is(__low, __high, __vec);
421 _LIBCPP_ALWAYS_INLINE
422 const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
424 return do_scan_is(__m, __low, __high);
427 _LIBCPP_ALWAYS_INLINE
428 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
430 return do_scan_not(__m, __low, __high);
433 _LIBCPP_ALWAYS_INLINE
434 char_type toupper(char_type __c) const
436 return do_toupper(__c);
439 _LIBCPP_ALWAYS_INLINE
440 const char_type* toupper(char_type* __low, const char_type* __high) const
442 return do_toupper(__low, __high);
445 _LIBCPP_ALWAYS_INLINE
446 char_type tolower(char_type __c) const
448 return do_tolower(__c);
451 _LIBCPP_ALWAYS_INLINE
452 const char_type* tolower(char_type* __low, const char_type* __high) const
454 return do_tolower(__low, __high);
457 _LIBCPP_ALWAYS_INLINE
458 char_type widen(char __c) const
460 return do_widen(__c);
463 _LIBCPP_ALWAYS_INLINE
464 const char* widen(const char* __low, const char* __high, char_type* __to) const
466 return do_widen(__low, __high, __to);
469 _LIBCPP_ALWAYS_INLINE
470 char narrow(char_type __c, char __dfault) const
472 return do_narrow(__c, __dfault);
475 _LIBCPP_ALWAYS_INLINE
476 const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
478 return do_narrow(__low, __high, __dfault, __to);
481 static locale::id id;
485 virtual bool do_is(mask __m, char_type __c) const;
486 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
487 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
488 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
489 virtual char_type do_toupper(char_type) const;
490 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
491 virtual char_type do_tolower(char_type) const;
492 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
493 virtual char_type do_widen(char) const;
494 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
495 virtual char do_narrow(char_type, char __dfault) const;
496 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
500 class _LIBCPP_TYPE_VIS ctype<char>
501 : public locale::facet, public ctype_base
506 typedef char char_type;
508 explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
510 _LIBCPP_ALWAYS_INLINE
511 bool is(mask __m, char_type __c) const
513 return isascii(__c) ? __tab_[static_cast<int>(__c)] & __m : false;
516 _LIBCPP_ALWAYS_INLINE
517 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
519 for (; __low != __high; ++__low, ++__vec)
520 *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
524 _LIBCPP_ALWAYS_INLINE
525 const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
527 for (; __low != __high; ++__low)
528 if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
533 _LIBCPP_ALWAYS_INLINE
534 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
536 for (; __low != __high; ++__low)
537 if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)))
542 _LIBCPP_ALWAYS_INLINE
543 char_type toupper(char_type __c) const
545 return do_toupper(__c);
548 _LIBCPP_ALWAYS_INLINE
549 const char_type* toupper(char_type* __low, const char_type* __high) const
551 return do_toupper(__low, __high);
554 _LIBCPP_ALWAYS_INLINE
555 char_type tolower(char_type __c) const
557 return do_tolower(__c);
560 _LIBCPP_ALWAYS_INLINE
561 const char_type* tolower(char_type* __low, const char_type* __high) const
563 return do_tolower(__low, __high);
566 _LIBCPP_ALWAYS_INLINE
567 char_type widen(char __c) const
569 return do_widen(__c);
572 _LIBCPP_ALWAYS_INLINE
573 const char* widen(const char* __low, const char* __high, char_type* __to) const
575 return do_widen(__low, __high, __to);
578 _LIBCPP_ALWAYS_INLINE
579 char narrow(char_type __c, char __dfault) const
581 return do_narrow(__c, __dfault);
584 _LIBCPP_ALWAYS_INLINE
585 const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
587 return do_narrow(__low, __high, __dfault, __to);
590 static locale::id id;
593 static const size_t table_size = _CACHED_RUNES;
595 static const size_t table_size = 256; // FIXME: Don't hardcode this.
597 _LIBCPP_ALWAYS_INLINE const mask* table() const _NOEXCEPT {return __tab_;}
598 static const mask* classic_table() _NOEXCEPT;
599 #if defined(__GLIBC__) || defined(EMSCRIPTEN)
600 static const int* __classic_upper_table() _NOEXCEPT;
601 static const int* __classic_lower_table() _NOEXCEPT;
603 #if defined(__NetBSD__)
604 static const short* __classic_upper_table() _NOEXCEPT;
605 static const short* __classic_lower_table() _NOEXCEPT;
610 virtual char_type do_toupper(char_type __c) const;
611 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
612 virtual char_type do_tolower(char_type __c) const;
613 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
614 virtual char_type do_widen(char __c) const;
615 virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
616 virtual char do_narrow(char_type __c, char __dfault) const;
617 virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
620 // template <class CharT> class ctype_byname;
622 template <class _CharT> class _LIBCPP_TYPE_VIS ctype_byname;
625 class _LIBCPP_TYPE_VIS ctype_byname<char>
631 explicit ctype_byname(const char*, size_t = 0);
632 explicit ctype_byname(const string&, size_t = 0);
636 virtual char_type do_toupper(char_type) const;
637 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
638 virtual char_type do_tolower(char_type) const;
639 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
643 class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
644 : public ctype<wchar_t>
649 explicit ctype_byname(const char*, size_t = 0);
650 explicit ctype_byname(const string&, size_t = 0);
654 virtual bool do_is(mask __m, char_type __c) const;
655 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
656 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
657 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
658 virtual char_type do_toupper(char_type) const;
659 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
660 virtual char_type do_tolower(char_type) const;
661 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
662 virtual char_type do_widen(char) const;
663 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
664 virtual char do_narrow(char_type, char __dfault) const;
665 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
668 template <class _CharT>
669 inline _LIBCPP_INLINE_VISIBILITY
671 isspace(_CharT __c, const locale& __loc)
673 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
676 template <class _CharT>
677 inline _LIBCPP_INLINE_VISIBILITY
679 isprint(_CharT __c, const locale& __loc)
681 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
684 template <class _CharT>
685 inline _LIBCPP_INLINE_VISIBILITY
687 iscntrl(_CharT __c, const locale& __loc)
689 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
692 template <class _CharT>
693 inline _LIBCPP_INLINE_VISIBILITY
695 isupper(_CharT __c, const locale& __loc)
697 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
700 template <class _CharT>
701 inline _LIBCPP_INLINE_VISIBILITY
703 islower(_CharT __c, const locale& __loc)
705 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
708 template <class _CharT>
709 inline _LIBCPP_INLINE_VISIBILITY
711 isalpha(_CharT __c, const locale& __loc)
713 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
716 template <class _CharT>
717 inline _LIBCPP_INLINE_VISIBILITY
719 isdigit(_CharT __c, const locale& __loc)
721 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
724 template <class _CharT>
725 inline _LIBCPP_INLINE_VISIBILITY
727 ispunct(_CharT __c, const locale& __loc)
729 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
732 template <class _CharT>
733 inline _LIBCPP_INLINE_VISIBILITY
735 isxdigit(_CharT __c, const locale& __loc)
737 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
740 template <class _CharT>
741 inline _LIBCPP_INLINE_VISIBILITY
743 isalnum(_CharT __c, const locale& __loc)
745 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
748 template <class _CharT>
749 inline _LIBCPP_INLINE_VISIBILITY
751 isgraph(_CharT __c, const locale& __loc)
753 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
756 template <class _CharT>
757 inline _LIBCPP_INLINE_VISIBILITY
759 toupper(_CharT __c, const locale& __loc)
761 return use_facet<ctype<_CharT> >(__loc).toupper(__c);
764 template <class _CharT>
765 inline _LIBCPP_INLINE_VISIBILITY
767 tolower(_CharT __c, const locale& __loc)
769 return use_facet<ctype<_CharT> >(__loc).tolower(__c);
774 class _LIBCPP_TYPE_VIS codecvt_base
777 _LIBCPP_ALWAYS_INLINE codecvt_base() {}
778 enum result {ok, partial, error, noconv};
781 // template <class internT, class externT, class stateT> class codecvt;
783 template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TYPE_VIS codecvt;
785 // template <> class codecvt<char, char, mbstate_t>
788 class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
789 : public locale::facet,
793 typedef char intern_type;
794 typedef char extern_type;
795 typedef mbstate_t state_type;
797 _LIBCPP_ALWAYS_INLINE
798 explicit codecvt(size_t __refs = 0)
799 : locale::facet(__refs) {}
801 _LIBCPP_ALWAYS_INLINE
802 result out(state_type& __st,
803 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
804 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
806 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
809 _LIBCPP_ALWAYS_INLINE
810 result unshift(state_type& __st,
811 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
813 return do_unshift(__st, __to, __to_end, __to_nxt);
816 _LIBCPP_ALWAYS_INLINE
817 result 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
821 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
824 _LIBCPP_ALWAYS_INLINE
825 int encoding() const _NOEXCEPT
827 return do_encoding();
830 _LIBCPP_ALWAYS_INLINE
831 bool always_noconv() const _NOEXCEPT
833 return do_always_noconv();
836 _LIBCPP_ALWAYS_INLINE
837 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
839 return do_length(__st, __frm, __end, __mx);
842 _LIBCPP_ALWAYS_INLINE
843 int max_length() const _NOEXCEPT
845 return do_max_length();
848 static locale::id id;
851 _LIBCPP_ALWAYS_INLINE
852 explicit codecvt(const char*, size_t __refs = 0)
853 : locale::facet(__refs) {}
857 virtual result do_out(state_type& __st,
858 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
859 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
860 virtual result do_in(state_type& __st,
861 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
862 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
863 virtual result do_unshift(state_type& __st,
864 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
865 virtual int do_encoding() const _NOEXCEPT;
866 virtual bool do_always_noconv() const _NOEXCEPT;
867 virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
868 virtual int do_max_length() const _NOEXCEPT;
871 // template <> class codecvt<wchar_t, char, mbstate_t>
874 class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
875 : public locale::facet,
880 typedef wchar_t intern_type;
881 typedef char extern_type;
882 typedef mbstate_t state_type;
884 explicit codecvt(size_t __refs = 0);
886 _LIBCPP_ALWAYS_INLINE
887 result out(state_type& __st,
888 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
889 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
891 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
894 _LIBCPP_ALWAYS_INLINE
895 result unshift(state_type& __st,
896 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
898 return do_unshift(__st, __to, __to_end, __to_nxt);
901 _LIBCPP_ALWAYS_INLINE
902 result in(state_type& __st,
903 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
904 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
906 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
909 _LIBCPP_ALWAYS_INLINE
910 int encoding() const _NOEXCEPT
912 return do_encoding();
915 _LIBCPP_ALWAYS_INLINE
916 bool always_noconv() const _NOEXCEPT
918 return do_always_noconv();
921 _LIBCPP_ALWAYS_INLINE
922 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
924 return do_length(__st, __frm, __end, __mx);
927 _LIBCPP_ALWAYS_INLINE
928 int max_length() const _NOEXCEPT
930 return do_max_length();
933 static locale::id id;
936 explicit codecvt(const char*, size_t __refs = 0);
940 virtual result do_out(state_type& __st,
941 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
942 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
943 virtual result do_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 virtual result do_unshift(state_type& __st,
947 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
948 virtual int do_encoding() const _NOEXCEPT;
949 virtual bool do_always_noconv() const _NOEXCEPT;
950 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
951 virtual int do_max_length() const _NOEXCEPT;
954 // template <> class codecvt<char16_t, char, mbstate_t>
957 class _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
958 : public locale::facet,
962 typedef char16_t intern_type;
963 typedef char extern_type;
964 typedef mbstate_t state_type;
966 _LIBCPP_ALWAYS_INLINE
967 explicit codecvt(size_t __refs = 0)
968 : locale::facet(__refs) {}
970 _LIBCPP_ALWAYS_INLINE
971 result out(state_type& __st,
972 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
973 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
975 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
978 _LIBCPP_ALWAYS_INLINE
979 result unshift(state_type& __st,
980 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
982 return do_unshift(__st, __to, __to_end, __to_nxt);
985 _LIBCPP_ALWAYS_INLINE
986 result 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
990 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
993 _LIBCPP_ALWAYS_INLINE
994 int encoding() const _NOEXCEPT
996 return do_encoding();
999 _LIBCPP_ALWAYS_INLINE
1000 bool always_noconv() const _NOEXCEPT
1002 return do_always_noconv();
1005 _LIBCPP_ALWAYS_INLINE
1006 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1008 return do_length(__st, __frm, __end, __mx);
1011 _LIBCPP_ALWAYS_INLINE
1012 int max_length() const _NOEXCEPT
1014 return do_max_length();
1017 static locale::id id;
1020 _LIBCPP_ALWAYS_INLINE
1021 explicit codecvt(const char*, size_t __refs = 0)
1022 : locale::facet(__refs) {}
1026 virtual result do_out(state_type& __st,
1027 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1028 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1029 virtual result do_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 virtual result do_unshift(state_type& __st,
1033 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1034 virtual int do_encoding() const _NOEXCEPT;
1035 virtual bool do_always_noconv() const _NOEXCEPT;
1036 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1037 virtual int do_max_length() const _NOEXCEPT;
1040 // template <> class codecvt<char32_t, char, mbstate_t>
1043 class _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
1044 : public locale::facet,
1048 typedef char32_t intern_type;
1049 typedef char extern_type;
1050 typedef mbstate_t state_type;
1052 _LIBCPP_ALWAYS_INLINE
1053 explicit codecvt(size_t __refs = 0)
1054 : locale::facet(__refs) {}
1056 _LIBCPP_ALWAYS_INLINE
1057 result out(state_type& __st,
1058 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1059 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1061 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1064 _LIBCPP_ALWAYS_INLINE
1065 result unshift(state_type& __st,
1066 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1068 return do_unshift(__st, __to, __to_end, __to_nxt);
1071 _LIBCPP_ALWAYS_INLINE
1072 result 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
1076 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1079 _LIBCPP_ALWAYS_INLINE
1080 int encoding() const _NOEXCEPT
1082 return do_encoding();
1085 _LIBCPP_ALWAYS_INLINE
1086 bool always_noconv() const _NOEXCEPT
1088 return do_always_noconv();
1091 _LIBCPP_ALWAYS_INLINE
1092 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1094 return do_length(__st, __frm, __end, __mx);
1097 _LIBCPP_ALWAYS_INLINE
1098 int max_length() const _NOEXCEPT
1100 return do_max_length();
1103 static locale::id id;
1106 _LIBCPP_ALWAYS_INLINE
1107 explicit codecvt(const char*, size_t __refs = 0)
1108 : locale::facet(__refs) {}
1112 virtual result do_out(state_type& __st,
1113 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1114 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1115 virtual result do_in(state_type& __st,
1116 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1117 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1118 virtual result do_unshift(state_type& __st,
1119 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1120 virtual int do_encoding() const _NOEXCEPT;
1121 virtual bool do_always_noconv() const _NOEXCEPT;
1122 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1123 virtual int do_max_length() const _NOEXCEPT;
1126 // template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
1128 template <class _InternT, class _ExternT, class _StateT>
1129 class _LIBCPP_TYPE_VIS codecvt_byname
1130 : public codecvt<_InternT, _ExternT, _StateT>
1133 _LIBCPP_ALWAYS_INLINE
1134 explicit codecvt_byname(const char* __nm, size_t __refs = 0)
1135 : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
1136 _LIBCPP_ALWAYS_INLINE
1137 explicit codecvt_byname(const string& __nm, size_t __refs = 0)
1138 : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
1143 template <class _InternT, class _ExternT, class _StateT>
1144 codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
1148 _LIBCPP_EXTERN_TEMPLATE(class codecvt_byname<char, char, mbstate_t>)
1149 _LIBCPP_EXTERN_TEMPLATE(class codecvt_byname<wchar_t, char, mbstate_t>)
1150 _LIBCPP_EXTERN_TEMPLATE(class codecvt_byname<char16_t, char, mbstate_t>)
1151 _LIBCPP_EXTERN_TEMPLATE(class codecvt_byname<char32_t, char, mbstate_t>)
1153 _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
1155 template <size_t _Np>
1156 struct __narrow_to_utf8
1158 template <class _OutputIterator, class _CharT>
1160 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
1164 struct __narrow_to_utf8<8>
1166 template <class _OutputIterator, class _CharT>
1167 _LIBCPP_ALWAYS_INLINE
1169 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1171 for (; __wb < __we; ++__wb, ++__s)
1178 struct __narrow_to_utf8<16>
1179 : public codecvt<char16_t, char, mbstate_t>
1181 _LIBCPP_ALWAYS_INLINE
1182 __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1184 ~__narrow_to_utf8();
1186 template <class _OutputIterator, class _CharT>
1187 _LIBCPP_ALWAYS_INLINE
1189 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1193 while (__wb < __we && __r != error)
1195 const int __sz = 32;
1198 const char16_t* __wn = (const char16_t*)__wb;
1199 __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
1200 __buf, __buf+__sz, __bn);
1201 if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
1202 __throw_runtime_error("locale not supported");
1203 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1205 __wb = (const _CharT*)__wn;
1212 struct __narrow_to_utf8<32>
1213 : public codecvt<char32_t, char, mbstate_t>
1215 _LIBCPP_ALWAYS_INLINE
1216 __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1218 ~__narrow_to_utf8();
1220 template <class _OutputIterator, class _CharT>
1221 _LIBCPP_ALWAYS_INLINE
1223 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1227 while (__wb < __we && __r != error)
1229 const int __sz = 32;
1232 const char32_t* __wn = (const char32_t*)__wb;
1233 __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
1234 __buf, __buf+__sz, __bn);
1235 if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
1236 __throw_runtime_error("locale not supported");
1237 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1239 __wb = (const _CharT*)__wn;
1245 template <size_t _Np>
1246 struct __widen_from_utf8
1248 template <class _OutputIterator>
1250 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
1254 struct __widen_from_utf8<8>
1256 template <class _OutputIterator>
1257 _LIBCPP_ALWAYS_INLINE
1259 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1261 for (; __nb < __ne; ++__nb, ++__s)
1268 struct __widen_from_utf8<16>
1269 : public codecvt<char16_t, char, mbstate_t>
1271 _LIBCPP_ALWAYS_INLINE
1272 __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1274 ~__widen_from_utf8();
1276 template <class _OutputIterator>
1277 _LIBCPP_ALWAYS_INLINE
1279 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1283 while (__nb < __ne && __r != error)
1285 const int __sz = 32;
1286 char16_t __buf[__sz];
1288 const char* __nn = __nb;
1289 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1290 __buf, __buf+__sz, __bn);
1291 if (__r == codecvt_base::error || __nn == __nb)
1292 __throw_runtime_error("locale not supported");
1293 for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
1294 *__s = (wchar_t)*__p;
1302 struct __widen_from_utf8<32>
1303 : public codecvt<char32_t, char, mbstate_t>
1305 _LIBCPP_ALWAYS_INLINE
1306 __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1308 ~__widen_from_utf8();
1310 template <class _OutputIterator>
1311 _LIBCPP_ALWAYS_INLINE
1313 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1317 while (__nb < __ne && __r != error)
1319 const int __sz = 32;
1320 char32_t __buf[__sz];
1322 const char* __nn = __nb;
1323 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1324 __buf, __buf+__sz, __bn);
1325 if (__r == codecvt_base::error || __nn == __nb)
1326 __throw_runtime_error("locale not supported");
1327 for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
1328 *__s = (wchar_t)*__p;
1335 // template <class charT> class numpunct
1337 template <class _CharT> class _LIBCPP_TYPE_VIS numpunct;
1340 class _LIBCPP_TYPE_VIS numpunct<char>
1341 : public locale::facet
1344 typedef char char_type;
1345 typedef basic_string<char_type> string_type;
1347 explicit numpunct(size_t __refs = 0);
1349 _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
1350 _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
1351 _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();}
1352 _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();}
1353 _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();}
1355 static locale::id id;
1359 virtual char_type do_decimal_point() const;
1360 virtual char_type do_thousands_sep() const;
1361 virtual string do_grouping() const;
1362 virtual string_type do_truename() const;
1363 virtual string_type do_falsename() const;
1365 char_type __decimal_point_;
1366 char_type __thousands_sep_;
1371 class _LIBCPP_TYPE_VIS numpunct<wchar_t>
1372 : public locale::facet
1375 typedef wchar_t char_type;
1376 typedef basic_string<char_type> string_type;
1378 explicit numpunct(size_t __refs = 0);
1380 _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
1381 _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
1382 _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();}
1383 _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();}
1384 _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();}
1386 static locale::id id;
1390 virtual char_type do_decimal_point() const;
1391 virtual char_type do_thousands_sep() const;
1392 virtual string do_grouping() const;
1393 virtual string_type do_truename() const;
1394 virtual string_type do_falsename() const;
1396 char_type __decimal_point_;
1397 char_type __thousands_sep_;
1401 // template <class charT> class numpunct_byname
1403 template <class charT> class _LIBCPP_TYPE_VIS numpunct_byname;
1406 class _LIBCPP_TYPE_VIS numpunct_byname<char>
1407 : public numpunct<char>
1410 typedef char char_type;
1411 typedef basic_string<char_type> string_type;
1413 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1414 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1420 void __init(const char*);
1424 class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
1425 : public numpunct<wchar_t>
1428 typedef wchar_t char_type;
1429 typedef basic_string<char_type> string_type;
1431 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1432 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1438 void __init(const char*);
1441 _LIBCPP_END_NAMESPACE_STD
1443 #endif // _LIBCPP___LOCALE