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
22 #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
23 # include <support/win32/locale_win32.h>
25 # include <support/ibm/xlocale.h>
26 #elif (defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)) || defined(__EMSCRIPTEN__) || defined(__IBMCPP__)
28 #endif // _WIN32 || __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
30 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
31 #pragma GCC system_header
34 _LIBCPP_BEGIN_NAMESPACE_STD
36 class _LIBCPP_TYPE_VIS locale;
38 template <class _Facet>
39 _LIBCPP_INLINE_VISIBILITY
41 has_facet(const locale&) _NOEXCEPT;
43 template <class _Facet>
44 _LIBCPP_INLINE_VISIBILITY
46 use_facet(const locale&);
48 class _LIBCPP_TYPE_VIS locale
52 class _LIBCPP_TYPE_VIS facet;
53 class _LIBCPP_TYPE_VIS id;
56 static const category // values assigned here are for exposition only
58 collate = LC_COLLATE_MASK,
59 ctype = LC_CTYPE_MASK,
60 monetary = LC_MONETARY_MASK,
61 numeric = LC_NUMERIC_MASK,
63 messages = LC_MESSAGES_MASK,
64 all = collate | ctype | monetary | numeric | time | messages;
66 // construct/copy/destroy:
68 locale(const locale&) _NOEXCEPT;
69 explicit locale(const char*);
70 explicit locale(const string&);
71 locale(const locale&, const char*, category);
72 locale(const locale&, const string&, category);
73 template <class _Facet>
74 _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
75 locale(const locale&, const locale&, category);
79 const locale& operator=(const locale&) _NOEXCEPT;
81 template <class _Facet> locale combine(const locale&) const;
85 bool operator==(const locale&) const;
86 bool operator!=(const locale& __y) const {return !(*this == __y);}
87 template <class _CharT, class _Traits, class _Allocator>
88 bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
89 const basic_string<_CharT, _Traits, _Allocator>&) const;
91 // global locale objects:
92 static locale global(const locale&);
93 static const locale& classic();
99 void __install_ctor(const locale&, facet*, long);
100 static locale& __global();
101 bool has_facet(id&) const;
102 const facet* use_facet(id&) const;
104 template <class _Facet> friend bool has_facet(const locale&) _NOEXCEPT;
105 template <class _Facet> friend const _Facet& use_facet(const locale&);
108 class _LIBCPP_TYPE_VIS locale::facet
109 : public __shared_count
112 _LIBCPP_INLINE_VISIBILITY
113 explicit facet(size_t __refs = 0)
114 : __shared_count(static_cast<long>(__refs)-1) {}
118 // facet(const facet&) = delete; // effectively done in __shared_count
119 // void operator=(const facet&) = delete;
121 virtual void __on_zero_shared() _NOEXCEPT;
124 class _LIBCPP_TYPE_VIS locale::id
129 static int32_t __next_id;
131 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
134 void operator=(const id&); // = delete;
135 id(const id&); // = delete;
136 public: // only needed for tests
140 friend class locale::__imp;
143 template <class _Facet>
144 inline _LIBCPP_INLINE_VISIBILITY
145 locale::locale(const locale& __other, _Facet* __f)
147 __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
150 template <class _Facet>
152 locale::combine(const locale& __other) const
154 #ifndef _LIBCPP_NO_EXCEPTIONS
155 if (!_VSTD::has_facet<_Facet>(__other))
156 throw runtime_error("locale::combine: locale missing facet");
157 #endif // _LIBCPP_NO_EXCEPTIONS
158 return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
161 template <class _Facet>
162 inline _LIBCPP_INLINE_VISIBILITY
164 has_facet(const locale& __l) _NOEXCEPT
166 return __l.has_facet(_Facet::id);
169 template <class _Facet>
170 inline _LIBCPP_INLINE_VISIBILITY
172 use_facet(const locale& __l)
174 return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
177 // template <class _CharT> class collate;
179 template <class _CharT>
180 class _LIBCPP_TYPE_VIS_ONLY collate
181 : public locale::facet
184 typedef _CharT char_type;
185 typedef basic_string<char_type> string_type;
187 _LIBCPP_INLINE_VISIBILITY
188 explicit collate(size_t __refs = 0)
189 : locale::facet(__refs) {}
191 _LIBCPP_INLINE_VISIBILITY
192 int compare(const char_type* __lo1, const char_type* __hi1,
193 const char_type* __lo2, const char_type* __hi2) const
195 return do_compare(__lo1, __hi1, __lo2, __hi2);
198 _LIBCPP_INLINE_VISIBILITY
199 string_type transform(const char_type* __lo, const char_type* __hi) const
201 return do_transform(__lo, __hi);
204 _LIBCPP_INLINE_VISIBILITY
205 long hash(const char_type* __lo, const char_type* __hi) const
207 return do_hash(__lo, __hi);
210 static locale::id id;
214 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
215 const char_type* __lo2, const char_type* __hi2) const;
216 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
217 {return string_type(__lo, __hi);}
218 virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
221 template <class _CharT> locale::id collate<_CharT>::id;
223 template <class _CharT>
224 collate<_CharT>::~collate()
228 template <class _CharT>
230 collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
231 const char_type* __lo2, const char_type* __hi2) const
233 for (; __lo2 != __hi2; ++__lo1, ++__lo2)
235 if (__lo1 == __hi1 || *__lo1 < *__lo2)
240 return __lo1 != __hi1;
243 template <class _CharT>
245 collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
248 const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
249 const size_t __mask = size_t(0xF) << (__sr + 4);
250 for(const char_type* __p = __lo; __p != __hi; ++__p)
252 __h = (__h << 4) + static_cast<size_t>(*__p);
253 size_t __g = __h & __mask;
254 __h ^= __g | (__g >> __sr);
256 return static_cast<long>(__h);
259 _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS collate<char>)
260 _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS collate<wchar_t>)
262 // template <class CharT> class collate_byname;
264 template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY collate_byname;
267 class _LIBCPP_TYPE_VIS collate_byname<char>
268 : public collate<char>
272 typedef char char_type;
273 typedef basic_string<char_type> string_type;
275 explicit collate_byname(const char* __n, size_t __refs = 0);
276 explicit collate_byname(const string& __n, size_t __refs = 0);
280 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
281 const char_type* __lo2, const char_type* __hi2) const;
282 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
286 class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
287 : public collate<wchar_t>
291 typedef wchar_t char_type;
292 typedef basic_string<char_type> string_type;
294 explicit collate_byname(const char* __n, size_t __refs = 0);
295 explicit collate_byname(const string& __n, size_t __refs = 0);
300 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
301 const char_type* __lo2, const char_type* __hi2) const;
302 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
305 template <class _CharT, class _Traits, class _Allocator>
307 locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
308 const basic_string<_CharT, _Traits, _Allocator>& __y) const
310 return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
311 __x.data(), __x.data() + __x.size(),
312 __y.data(), __y.data() + __y.size()) < 0;
315 // template <class charT> class ctype
317 class _LIBCPP_TYPE_VIS ctype_base
321 typedef unsigned short mask;
322 static const mask space = _ISspace;
323 static const mask print = _ISprint;
324 static const mask cntrl = _IScntrl;
325 static const mask upper = _ISupper;
326 static const mask lower = _ISlower;
327 static const mask alpha = _ISalpha;
328 static const mask digit = _ISdigit;
329 static const mask punct = _ISpunct;
330 static const mask xdigit = _ISxdigit;
331 static const mask blank = _ISblank;
332 #elif defined(_WIN32)
333 typedef unsigned short mask;
334 static const mask space = _SPACE;
335 static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT;
336 static const mask cntrl = _CONTROL;
337 static const mask upper = _UPPER;
338 static const mask lower = _LOWER;
339 static const mask alpha = _ALPHA;
340 static const mask digit = _DIGIT;
341 static const mask punct = _PUNCT;
342 static const mask xdigit = _HEX;
343 static const mask blank = _BLANK;
344 #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
346 typedef __uint32_t mask;
347 #elif defined(__FreeBSD__)
348 typedef unsigned long mask;
349 #elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
350 typedef unsigned short mask;
352 static const mask space = _CTYPE_S;
353 static const mask print = _CTYPE_R;
354 static const mask cntrl = _CTYPE_C;
355 static const mask upper = _CTYPE_U;
356 static const mask lower = _CTYPE_L;
357 static const mask alpha = _CTYPE_A;
358 static const mask digit = _CTYPE_D;
359 static const mask punct = _CTYPE_P;
360 static const mask xdigit = _CTYPE_X;
361 # if defined(__NetBSD__)
362 static const mask blank = _CTYPE_BL;
364 static const mask blank = _CTYPE_B;
366 #elif defined(__sun__) || defined(_AIX)
367 typedef unsigned int mask;
368 static const mask space = _ISSPACE;
369 static const mask print = _ISPRINT;
370 static const mask cntrl = _ISCNTRL;
371 static const mask upper = _ISUPPER;
372 static const mask lower = _ISLOWER;
373 static const mask alpha = _ISALPHA;
374 static const mask digit = _ISDIGIT;
375 static const mask punct = _ISPUNCT;
376 static const mask xdigit = _ISXDIGIT;
377 static const mask blank = _ISBLANK;
378 #else // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__ || __EMSCRIPTEN__ || __sun__
379 typedef unsigned long mask;
380 static const mask space = 1<<0;
381 static const mask print = 1<<1;
382 static const mask cntrl = 1<<2;
383 static const mask upper = 1<<3;
384 static const mask lower = 1<<4;
385 static const mask alpha = 1<<5;
386 static const mask digit = 1<<6;
387 static const mask punct = 1<<7;
388 static const mask xdigit = 1<<8;
389 static const mask blank = 1<<9;
390 #endif // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__
391 static const mask alnum = alpha | digit;
392 static const mask graph = alnum | punct;
394 _LIBCPP_ALWAYS_INLINE ctype_base() {}
397 template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY ctype;
400 class _LIBCPP_TYPE_VIS ctype<wchar_t>
401 : public locale::facet,
405 typedef wchar_t char_type;
407 _LIBCPP_ALWAYS_INLINE
408 explicit ctype(size_t __refs = 0)
409 : locale::facet(__refs) {}
411 _LIBCPP_ALWAYS_INLINE
412 bool is(mask __m, char_type __c) const
414 return do_is(__m, __c);
417 _LIBCPP_ALWAYS_INLINE
418 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
420 return do_is(__low, __high, __vec);
423 _LIBCPP_ALWAYS_INLINE
424 const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
426 return do_scan_is(__m, __low, __high);
429 _LIBCPP_ALWAYS_INLINE
430 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
432 return do_scan_not(__m, __low, __high);
435 _LIBCPP_ALWAYS_INLINE
436 char_type toupper(char_type __c) const
438 return do_toupper(__c);
441 _LIBCPP_ALWAYS_INLINE
442 const char_type* toupper(char_type* __low, const char_type* __high) const
444 return do_toupper(__low, __high);
447 _LIBCPP_ALWAYS_INLINE
448 char_type tolower(char_type __c) const
450 return do_tolower(__c);
453 _LIBCPP_ALWAYS_INLINE
454 const char_type* tolower(char_type* __low, const char_type* __high) const
456 return do_tolower(__low, __high);
459 _LIBCPP_ALWAYS_INLINE
460 char_type widen(char __c) const
462 return do_widen(__c);
465 _LIBCPP_ALWAYS_INLINE
466 const char* widen(const char* __low, const char* __high, char_type* __to) const
468 return do_widen(__low, __high, __to);
471 _LIBCPP_ALWAYS_INLINE
472 char narrow(char_type __c, char __dfault) const
474 return do_narrow(__c, __dfault);
477 _LIBCPP_ALWAYS_INLINE
478 const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
480 return do_narrow(__low, __high, __dfault, __to);
483 static locale::id id;
487 virtual bool do_is(mask __m, char_type __c) const;
488 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
489 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
490 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
491 virtual char_type do_toupper(char_type) const;
492 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
493 virtual char_type do_tolower(char_type) const;
494 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
495 virtual char_type do_widen(char) const;
496 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
497 virtual char do_narrow(char_type, char __dfault) const;
498 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
502 class _LIBCPP_TYPE_VIS ctype<char>
503 : public locale::facet, public ctype_base
508 typedef char char_type;
510 explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
512 _LIBCPP_ALWAYS_INLINE
513 bool is(mask __m, char_type __c) const
515 return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false;
518 _LIBCPP_ALWAYS_INLINE
519 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
521 for (; __low != __high; ++__low, ++__vec)
522 *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
526 _LIBCPP_ALWAYS_INLINE
527 const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
529 for (; __low != __high; ++__low)
530 if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
535 _LIBCPP_ALWAYS_INLINE
536 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
538 for (; __low != __high; ++__low)
539 if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)))
544 _LIBCPP_ALWAYS_INLINE
545 char_type toupper(char_type __c) const
547 return do_toupper(__c);
550 _LIBCPP_ALWAYS_INLINE
551 const char_type* toupper(char_type* __low, const char_type* __high) const
553 return do_toupper(__low, __high);
556 _LIBCPP_ALWAYS_INLINE
557 char_type tolower(char_type __c) const
559 return do_tolower(__c);
562 _LIBCPP_ALWAYS_INLINE
563 const char_type* tolower(char_type* __low, const char_type* __high) const
565 return do_tolower(__low, __high);
568 _LIBCPP_ALWAYS_INLINE
569 char_type widen(char __c) const
571 return do_widen(__c);
574 _LIBCPP_ALWAYS_INLINE
575 const char* widen(const char* __low, const char* __high, char_type* __to) const
577 return do_widen(__low, __high, __to);
580 _LIBCPP_ALWAYS_INLINE
581 char narrow(char_type __c, char __dfault) const
583 return do_narrow(__c, __dfault);
586 _LIBCPP_ALWAYS_INLINE
587 const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
589 return do_narrow(__low, __high, __dfault, __to);
592 static locale::id id;
595 static const size_t table_size = _CACHED_RUNES;
597 static const size_t table_size = 256; // FIXME: Don't hardcode this.
599 _LIBCPP_ALWAYS_INLINE const mask* table() const _NOEXCEPT {return __tab_;}
600 static const mask* classic_table() _NOEXCEPT;
601 #if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
602 static const int* __classic_upper_table() _NOEXCEPT;
603 static const int* __classic_lower_table() _NOEXCEPT;
605 #if defined(__NetBSD__)
606 static const short* __classic_upper_table() _NOEXCEPT;
607 static const short* __classic_lower_table() _NOEXCEPT;
612 virtual char_type do_toupper(char_type __c) const;
613 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
614 virtual char_type do_tolower(char_type __c) const;
615 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
616 virtual char_type do_widen(char __c) const;
617 virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
618 virtual char do_narrow(char_type __c, char __dfault) const;
619 virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
622 // template <class CharT> class ctype_byname;
624 template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY ctype_byname;
627 class _LIBCPP_TYPE_VIS ctype_byname<char>
633 explicit ctype_byname(const char*, size_t = 0);
634 explicit ctype_byname(const string&, size_t = 0);
638 virtual char_type do_toupper(char_type) const;
639 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
640 virtual char_type do_tolower(char_type) const;
641 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
645 class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
646 : public ctype<wchar_t>
651 explicit ctype_byname(const char*, size_t = 0);
652 explicit ctype_byname(const string&, size_t = 0);
656 virtual bool do_is(mask __m, char_type __c) const;
657 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
658 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
659 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
660 virtual char_type do_toupper(char_type) const;
661 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
662 virtual char_type do_tolower(char_type) const;
663 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
664 virtual char_type do_widen(char) const;
665 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
666 virtual char do_narrow(char_type, char __dfault) const;
667 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
670 template <class _CharT>
671 inline _LIBCPP_INLINE_VISIBILITY
673 isspace(_CharT __c, const locale& __loc)
675 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
678 template <class _CharT>
679 inline _LIBCPP_INLINE_VISIBILITY
681 isprint(_CharT __c, const locale& __loc)
683 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
686 template <class _CharT>
687 inline _LIBCPP_INLINE_VISIBILITY
689 iscntrl(_CharT __c, const locale& __loc)
691 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
694 template <class _CharT>
695 inline _LIBCPP_INLINE_VISIBILITY
697 isupper(_CharT __c, const locale& __loc)
699 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
702 template <class _CharT>
703 inline _LIBCPP_INLINE_VISIBILITY
705 islower(_CharT __c, const locale& __loc)
707 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
710 template <class _CharT>
711 inline _LIBCPP_INLINE_VISIBILITY
713 isalpha(_CharT __c, const locale& __loc)
715 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
718 template <class _CharT>
719 inline _LIBCPP_INLINE_VISIBILITY
721 isdigit(_CharT __c, const locale& __loc)
723 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
726 template <class _CharT>
727 inline _LIBCPP_INLINE_VISIBILITY
729 ispunct(_CharT __c, const locale& __loc)
731 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
734 template <class _CharT>
735 inline _LIBCPP_INLINE_VISIBILITY
737 isxdigit(_CharT __c, const locale& __loc)
739 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
742 template <class _CharT>
743 inline _LIBCPP_INLINE_VISIBILITY
745 isalnum(_CharT __c, const locale& __loc)
747 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
750 template <class _CharT>
751 inline _LIBCPP_INLINE_VISIBILITY
753 isgraph(_CharT __c, const locale& __loc)
755 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
758 template <class _CharT>
759 inline _LIBCPP_INLINE_VISIBILITY
761 toupper(_CharT __c, const locale& __loc)
763 return use_facet<ctype<_CharT> >(__loc).toupper(__c);
766 template <class _CharT>
767 inline _LIBCPP_INLINE_VISIBILITY
769 tolower(_CharT __c, const locale& __loc)
771 return use_facet<ctype<_CharT> >(__loc).tolower(__c);
776 class _LIBCPP_TYPE_VIS codecvt_base
779 _LIBCPP_ALWAYS_INLINE codecvt_base() {}
780 enum result {ok, partial, error, noconv};
783 // template <class internT, class externT, class stateT> class codecvt;
785 template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TYPE_VIS_ONLY codecvt;
787 // template <> class codecvt<char, char, mbstate_t>
790 class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
791 : public locale::facet,
795 typedef char intern_type;
796 typedef char extern_type;
797 typedef mbstate_t state_type;
799 _LIBCPP_ALWAYS_INLINE
800 explicit codecvt(size_t __refs = 0)
801 : locale::facet(__refs) {}
803 _LIBCPP_ALWAYS_INLINE
804 result out(state_type& __st,
805 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
806 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
808 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
811 _LIBCPP_ALWAYS_INLINE
812 result unshift(state_type& __st,
813 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
815 return do_unshift(__st, __to, __to_end, __to_nxt);
818 _LIBCPP_ALWAYS_INLINE
819 result in(state_type& __st,
820 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
821 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
823 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
826 _LIBCPP_ALWAYS_INLINE
827 int encoding() const _NOEXCEPT
829 return do_encoding();
832 _LIBCPP_ALWAYS_INLINE
833 bool always_noconv() const _NOEXCEPT
835 return do_always_noconv();
838 _LIBCPP_ALWAYS_INLINE
839 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
841 return do_length(__st, __frm, __end, __mx);
844 _LIBCPP_ALWAYS_INLINE
845 int max_length() const _NOEXCEPT
847 return do_max_length();
850 static locale::id id;
853 _LIBCPP_ALWAYS_INLINE
854 explicit codecvt(const char*, size_t __refs = 0)
855 : locale::facet(__refs) {}
859 virtual result do_out(state_type& __st,
860 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
861 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
862 virtual result do_in(state_type& __st,
863 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
864 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
865 virtual result do_unshift(state_type& __st,
866 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
867 virtual int do_encoding() const _NOEXCEPT;
868 virtual bool do_always_noconv() const _NOEXCEPT;
869 virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
870 virtual int do_max_length() const _NOEXCEPT;
873 // template <> class codecvt<wchar_t, char, mbstate_t>
876 class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
877 : public locale::facet,
882 typedef wchar_t intern_type;
883 typedef char extern_type;
884 typedef mbstate_t state_type;
886 explicit codecvt(size_t __refs = 0);
888 _LIBCPP_ALWAYS_INLINE
889 result 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
893 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
896 _LIBCPP_ALWAYS_INLINE
897 result unshift(state_type& __st,
898 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
900 return do_unshift(__st, __to, __to_end, __to_nxt);
903 _LIBCPP_ALWAYS_INLINE
904 result in(state_type& __st,
905 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
906 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
908 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
911 _LIBCPP_ALWAYS_INLINE
912 int encoding() const _NOEXCEPT
914 return do_encoding();
917 _LIBCPP_ALWAYS_INLINE
918 bool always_noconv() const _NOEXCEPT
920 return do_always_noconv();
923 _LIBCPP_ALWAYS_INLINE
924 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
926 return do_length(__st, __frm, __end, __mx);
929 _LIBCPP_ALWAYS_INLINE
930 int max_length() const _NOEXCEPT
932 return do_max_length();
935 static locale::id id;
938 explicit codecvt(const char*, size_t __refs = 0);
942 virtual result do_out(state_type& __st,
943 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
944 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
945 virtual result do_in(state_type& __st,
946 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
947 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
948 virtual result do_unshift(state_type& __st,
949 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
950 virtual int do_encoding() const _NOEXCEPT;
951 virtual bool do_always_noconv() const _NOEXCEPT;
952 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
953 virtual int do_max_length() const _NOEXCEPT;
956 // template <> class codecvt<char16_t, char, mbstate_t>
959 class _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
960 : public locale::facet,
964 typedef char16_t intern_type;
965 typedef char extern_type;
966 typedef mbstate_t state_type;
968 _LIBCPP_ALWAYS_INLINE
969 explicit codecvt(size_t __refs = 0)
970 : locale::facet(__refs) {}
972 _LIBCPP_ALWAYS_INLINE
973 result out(state_type& __st,
974 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
975 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
977 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
980 _LIBCPP_ALWAYS_INLINE
981 result unshift(state_type& __st,
982 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
984 return do_unshift(__st, __to, __to_end, __to_nxt);
987 _LIBCPP_ALWAYS_INLINE
988 result in(state_type& __st,
989 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
990 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
992 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
995 _LIBCPP_ALWAYS_INLINE
996 int encoding() const _NOEXCEPT
998 return do_encoding();
1001 _LIBCPP_ALWAYS_INLINE
1002 bool always_noconv() const _NOEXCEPT
1004 return do_always_noconv();
1007 _LIBCPP_ALWAYS_INLINE
1008 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1010 return do_length(__st, __frm, __end, __mx);
1013 _LIBCPP_ALWAYS_INLINE
1014 int max_length() const _NOEXCEPT
1016 return do_max_length();
1019 static locale::id id;
1022 _LIBCPP_ALWAYS_INLINE
1023 explicit codecvt(const char*, size_t __refs = 0)
1024 : locale::facet(__refs) {}
1028 virtual result do_out(state_type& __st,
1029 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1030 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1031 virtual result do_in(state_type& __st,
1032 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1033 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1034 virtual result do_unshift(state_type& __st,
1035 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1036 virtual int do_encoding() const _NOEXCEPT;
1037 virtual bool do_always_noconv() const _NOEXCEPT;
1038 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1039 virtual int do_max_length() const _NOEXCEPT;
1042 // template <> class codecvt<char32_t, char, mbstate_t>
1045 class _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
1046 : public locale::facet,
1050 typedef char32_t intern_type;
1051 typedef char extern_type;
1052 typedef mbstate_t state_type;
1054 _LIBCPP_ALWAYS_INLINE
1055 explicit codecvt(size_t __refs = 0)
1056 : locale::facet(__refs) {}
1058 _LIBCPP_ALWAYS_INLINE
1059 result out(state_type& __st,
1060 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1061 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1063 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1066 _LIBCPP_ALWAYS_INLINE
1067 result unshift(state_type& __st,
1068 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1070 return do_unshift(__st, __to, __to_end, __to_nxt);
1073 _LIBCPP_ALWAYS_INLINE
1074 result in(state_type& __st,
1075 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1076 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1078 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1081 _LIBCPP_ALWAYS_INLINE
1082 int encoding() const _NOEXCEPT
1084 return do_encoding();
1087 _LIBCPP_ALWAYS_INLINE
1088 bool always_noconv() const _NOEXCEPT
1090 return do_always_noconv();
1093 _LIBCPP_ALWAYS_INLINE
1094 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1096 return do_length(__st, __frm, __end, __mx);
1099 _LIBCPP_ALWAYS_INLINE
1100 int max_length() const _NOEXCEPT
1102 return do_max_length();
1105 static locale::id id;
1108 _LIBCPP_ALWAYS_INLINE
1109 explicit codecvt(const char*, size_t __refs = 0)
1110 : locale::facet(__refs) {}
1114 virtual result do_out(state_type& __st,
1115 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1116 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1117 virtual result do_in(state_type& __st,
1118 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1119 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1120 virtual result do_unshift(state_type& __st,
1121 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1122 virtual int do_encoding() const _NOEXCEPT;
1123 virtual bool do_always_noconv() const _NOEXCEPT;
1124 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1125 virtual int do_max_length() const _NOEXCEPT;
1128 // template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
1130 template <class _InternT, class _ExternT, class _StateT>
1131 class _LIBCPP_TYPE_VIS_ONLY codecvt_byname
1132 : public codecvt<_InternT, _ExternT, _StateT>
1135 _LIBCPP_ALWAYS_INLINE
1136 explicit codecvt_byname(const char* __nm, size_t __refs = 0)
1137 : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
1138 _LIBCPP_ALWAYS_INLINE
1139 explicit codecvt_byname(const string& __nm, size_t __refs = 0)
1140 : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
1145 template <class _InternT, class _ExternT, class _StateT>
1146 codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
1150 _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<char, char, mbstate_t>)
1151 _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>)
1152 _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>)
1153 _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>)
1155 _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
1157 template <size_t _Np>
1158 struct __narrow_to_utf8
1160 template <class _OutputIterator, class _CharT>
1162 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
1166 struct __narrow_to_utf8<8>
1168 template <class _OutputIterator, class _CharT>
1169 _LIBCPP_ALWAYS_INLINE
1171 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1173 for (; __wb < __we; ++__wb, ++__s)
1180 struct __narrow_to_utf8<16>
1181 : public codecvt<char16_t, char, mbstate_t>
1183 _LIBCPP_ALWAYS_INLINE
1184 __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1186 ~__narrow_to_utf8();
1188 template <class _OutputIterator, class _CharT>
1189 _LIBCPP_ALWAYS_INLINE
1191 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1195 while (__wb < __we && __r != error)
1197 const int __sz = 32;
1200 const char16_t* __wn = (const char16_t*)__wb;
1201 __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
1202 __buf, __buf+__sz, __bn);
1203 if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
1204 __throw_runtime_error("locale not supported");
1205 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1207 __wb = (const _CharT*)__wn;
1214 struct __narrow_to_utf8<32>
1215 : public codecvt<char32_t, char, mbstate_t>
1217 _LIBCPP_ALWAYS_INLINE
1218 __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1220 ~__narrow_to_utf8();
1222 template <class _OutputIterator, class _CharT>
1223 _LIBCPP_ALWAYS_INLINE
1225 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1229 while (__wb < __we && __r != error)
1231 const int __sz = 32;
1234 const char32_t* __wn = (const char32_t*)__wb;
1235 __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
1236 __buf, __buf+__sz, __bn);
1237 if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
1238 __throw_runtime_error("locale not supported");
1239 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1241 __wb = (const _CharT*)__wn;
1247 template <size_t _Np>
1248 struct __widen_from_utf8
1250 template <class _OutputIterator>
1252 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
1256 struct __widen_from_utf8<8>
1258 template <class _OutputIterator>
1259 _LIBCPP_ALWAYS_INLINE
1261 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1263 for (; __nb < __ne; ++__nb, ++__s)
1270 struct __widen_from_utf8<16>
1271 : public codecvt<char16_t, char, mbstate_t>
1273 _LIBCPP_ALWAYS_INLINE
1274 __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1276 ~__widen_from_utf8();
1278 template <class _OutputIterator>
1279 _LIBCPP_ALWAYS_INLINE
1281 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1285 while (__nb < __ne && __r != error)
1287 const int __sz = 32;
1288 char16_t __buf[__sz];
1290 const char* __nn = __nb;
1291 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1292 __buf, __buf+__sz, __bn);
1293 if (__r == codecvt_base::error || __nn == __nb)
1294 __throw_runtime_error("locale not supported");
1295 for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
1296 *__s = (wchar_t)*__p;
1304 struct __widen_from_utf8<32>
1305 : public codecvt<char32_t, char, mbstate_t>
1307 _LIBCPP_ALWAYS_INLINE
1308 __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1310 ~__widen_from_utf8();
1312 template <class _OutputIterator>
1313 _LIBCPP_ALWAYS_INLINE
1315 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1319 while (__nb < __ne && __r != error)
1321 const int __sz = 32;
1322 char32_t __buf[__sz];
1324 const char* __nn = __nb;
1325 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1326 __buf, __buf+__sz, __bn);
1327 if (__r == codecvt_base::error || __nn == __nb)
1328 __throw_runtime_error("locale not supported");
1329 for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
1330 *__s = (wchar_t)*__p;
1337 // template <class charT> class numpunct
1339 template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY numpunct;
1342 class _LIBCPP_TYPE_VIS numpunct<char>
1343 : public locale::facet
1346 typedef char char_type;
1347 typedef basic_string<char_type> string_type;
1349 explicit numpunct(size_t __refs = 0);
1351 _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
1352 _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
1353 _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();}
1354 _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();}
1355 _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();}
1357 static locale::id id;
1361 virtual char_type do_decimal_point() const;
1362 virtual char_type do_thousands_sep() const;
1363 virtual string do_grouping() const;
1364 virtual string_type do_truename() const;
1365 virtual string_type do_falsename() const;
1367 char_type __decimal_point_;
1368 char_type __thousands_sep_;
1373 class _LIBCPP_TYPE_VIS numpunct<wchar_t>
1374 : public locale::facet
1377 typedef wchar_t char_type;
1378 typedef basic_string<char_type> string_type;
1380 explicit numpunct(size_t __refs = 0);
1382 _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
1383 _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
1384 _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();}
1385 _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();}
1386 _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();}
1388 static locale::id id;
1392 virtual char_type do_decimal_point() const;
1393 virtual char_type do_thousands_sep() const;
1394 virtual string do_grouping() const;
1395 virtual string_type do_truename() const;
1396 virtual string_type do_falsename() const;
1398 char_type __decimal_point_;
1399 char_type __thousands_sep_;
1403 // template <class charT> class numpunct_byname
1405 template <class charT> class _LIBCPP_TYPE_VIS_ONLY numpunct_byname;
1408 class _LIBCPP_TYPE_VIS numpunct_byname<char>
1409 : public numpunct<char>
1412 typedef char char_type;
1413 typedef basic_string<char_type> string_type;
1415 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1416 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1422 void __init(const char*);
1426 class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
1427 : public numpunct<wchar_t>
1430 typedef wchar_t char_type;
1431 typedef basic_string<char_type> string_type;
1433 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1434 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1440 void __init(const char*);
1443 _LIBCPP_END_NAMESPACE_STD
1445 #endif // _LIBCPP___LOCALE