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)
344 typedef __uint32_t mask;
345 #elif defined(__FreeBSD__)
346 typedef unsigned long mask;
347 #elif defined(EMSCRIPTEN)
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 static const mask blank = _CTYPE_B;
360 #elif defined(__sun__)
361 typedef unsigned int mask;
362 static const mask space = _ISSPACE;
363 static const mask print = _ISPRINT;
364 static const mask cntrl = _ISCNTRL;
365 static const mask upper = _ISUPPER;
366 static const mask lower = _ISLOWER;
367 static const mask alpha = _ISALPHA;
368 static const mask digit = _ISDIGIT;
369 static const mask punct = _ISPUNCT;
370 static const mask xdigit = _ISXDIGIT;
371 static const mask blank = _ISBLANK;
372 #else // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__ || EMSCRIPTEN || __sun__
373 typedef unsigned long mask;
374 static const mask space = 1<<0;
375 static const mask print = 1<<1;
376 static const mask cntrl = 1<<2;
377 static const mask upper = 1<<3;
378 static const mask lower = 1<<4;
379 static const mask alpha = 1<<5;
380 static const mask digit = 1<<6;
381 static const mask punct = 1<<7;
382 static const mask xdigit = 1<<8;
383 static const mask blank = 1<<9;
384 #endif // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__
385 static const mask alnum = alpha | digit;
386 static const mask graph = alnum | punct;
388 _LIBCPP_ALWAYS_INLINE ctype_base() {}
391 template <class _CharT> class _LIBCPP_TYPE_VIS ctype;
394 class _LIBCPP_TYPE_VIS ctype<wchar_t>
395 : public locale::facet,
399 typedef wchar_t char_type;
401 _LIBCPP_ALWAYS_INLINE
402 explicit ctype(size_t __refs = 0)
403 : locale::facet(__refs) {}
405 _LIBCPP_ALWAYS_INLINE
406 bool is(mask __m, char_type __c) const
408 return do_is(__m, __c);
411 _LIBCPP_ALWAYS_INLINE
412 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
414 return do_is(__low, __high, __vec);
417 _LIBCPP_ALWAYS_INLINE
418 const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
420 return do_scan_is(__m, __low, __high);
423 _LIBCPP_ALWAYS_INLINE
424 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
426 return do_scan_not(__m, __low, __high);
429 _LIBCPP_ALWAYS_INLINE
430 char_type toupper(char_type __c) const
432 return do_toupper(__c);
435 _LIBCPP_ALWAYS_INLINE
436 const char_type* toupper(char_type* __low, const char_type* __high) const
438 return do_toupper(__low, __high);
441 _LIBCPP_ALWAYS_INLINE
442 char_type tolower(char_type __c) const
444 return do_tolower(__c);
447 _LIBCPP_ALWAYS_INLINE
448 const char_type* tolower(char_type* __low, const char_type* __high) const
450 return do_tolower(__low, __high);
453 _LIBCPP_ALWAYS_INLINE
454 char_type widen(char __c) const
456 return do_widen(__c);
459 _LIBCPP_ALWAYS_INLINE
460 const char* widen(const char* __low, const char* __high, char_type* __to) const
462 return do_widen(__low, __high, __to);
465 _LIBCPP_ALWAYS_INLINE
466 char narrow(char_type __c, char __dfault) const
468 return do_narrow(__c, __dfault);
471 _LIBCPP_ALWAYS_INLINE
472 const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
474 return do_narrow(__low, __high, __dfault, __to);
477 static locale::id id;
481 virtual bool do_is(mask __m, char_type __c) const;
482 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
483 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
484 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
485 virtual char_type do_toupper(char_type) const;
486 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
487 virtual char_type do_tolower(char_type) const;
488 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
489 virtual char_type do_widen(char) const;
490 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
491 virtual char do_narrow(char_type, char __dfault) const;
492 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
496 class _LIBCPP_TYPE_VIS ctype<char>
497 : public locale::facet, public ctype_base
502 typedef char char_type;
504 explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
506 _LIBCPP_ALWAYS_INLINE
507 bool is(mask __m, char_type __c) const
509 return isascii(__c) ? __tab_[static_cast<int>(__c)] & __m : false;
512 _LIBCPP_ALWAYS_INLINE
513 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
515 for (; __low != __high; ++__low, ++__vec)
516 *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
520 _LIBCPP_ALWAYS_INLINE
521 const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
523 for (; __low != __high; ++__low)
524 if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
529 _LIBCPP_ALWAYS_INLINE
530 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
532 for (; __low != __high; ++__low)
533 if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)))
538 _LIBCPP_ALWAYS_INLINE
539 char_type toupper(char_type __c) const
541 return do_toupper(__c);
544 _LIBCPP_ALWAYS_INLINE
545 const char_type* toupper(char_type* __low, const char_type* __high) const
547 return do_toupper(__low, __high);
550 _LIBCPP_ALWAYS_INLINE
551 char_type tolower(char_type __c) const
553 return do_tolower(__c);
556 _LIBCPP_ALWAYS_INLINE
557 const char_type* tolower(char_type* __low, const char_type* __high) const
559 return do_tolower(__low, __high);
562 _LIBCPP_ALWAYS_INLINE
563 char_type widen(char __c) const
565 return do_widen(__c);
568 _LIBCPP_ALWAYS_INLINE
569 const char* widen(const char* __low, const char* __high, char_type* __to) const
571 return do_widen(__low, __high, __to);
574 _LIBCPP_ALWAYS_INLINE
575 char narrow(char_type __c, char __dfault) const
577 return do_narrow(__c, __dfault);
580 _LIBCPP_ALWAYS_INLINE
581 const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
583 return do_narrow(__low, __high, __dfault, __to);
586 static locale::id id;
589 static const size_t table_size = _CACHED_RUNES;
591 static const size_t table_size = 256; // FIXME: Don't hardcode this.
593 _LIBCPP_ALWAYS_INLINE const mask* table() const _NOEXCEPT {return __tab_;}
594 static const mask* classic_table() _NOEXCEPT;
595 #if defined(__GLIBC__) || defined(EMSCRIPTEN)
596 static const int* __classic_upper_table() _NOEXCEPT;
597 static const int* __classic_lower_table() _NOEXCEPT;
602 virtual char_type do_toupper(char_type __c) const;
603 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
604 virtual char_type do_tolower(char_type __c) const;
605 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
606 virtual char_type do_widen(char __c) const;
607 virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
608 virtual char do_narrow(char_type __c, char __dfault) const;
609 virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
612 // template <class CharT> class ctype_byname;
614 template <class _CharT> class _LIBCPP_TYPE_VIS ctype_byname;
617 class _LIBCPP_TYPE_VIS ctype_byname<char>
623 explicit ctype_byname(const char*, size_t = 0);
624 explicit ctype_byname(const string&, size_t = 0);
628 virtual char_type do_toupper(char_type) const;
629 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
630 virtual char_type do_tolower(char_type) const;
631 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
635 class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
636 : public ctype<wchar_t>
641 explicit ctype_byname(const char*, size_t = 0);
642 explicit ctype_byname(const string&, size_t = 0);
646 virtual bool do_is(mask __m, char_type __c) const;
647 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
648 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
649 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
650 virtual char_type do_toupper(char_type) const;
651 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
652 virtual char_type do_tolower(char_type) const;
653 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
654 virtual char_type do_widen(char) const;
655 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
656 virtual char do_narrow(char_type, char __dfault) const;
657 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
660 template <class _CharT>
661 inline _LIBCPP_INLINE_VISIBILITY
663 isspace(_CharT __c, const locale& __loc)
665 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
668 template <class _CharT>
669 inline _LIBCPP_INLINE_VISIBILITY
671 isprint(_CharT __c, const locale& __loc)
673 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
676 template <class _CharT>
677 inline _LIBCPP_INLINE_VISIBILITY
679 iscntrl(_CharT __c, const locale& __loc)
681 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
684 template <class _CharT>
685 inline _LIBCPP_INLINE_VISIBILITY
687 isupper(_CharT __c, const locale& __loc)
689 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
692 template <class _CharT>
693 inline _LIBCPP_INLINE_VISIBILITY
695 islower(_CharT __c, const locale& __loc)
697 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
700 template <class _CharT>
701 inline _LIBCPP_INLINE_VISIBILITY
703 isalpha(_CharT __c, const locale& __loc)
705 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
708 template <class _CharT>
709 inline _LIBCPP_INLINE_VISIBILITY
711 isdigit(_CharT __c, const locale& __loc)
713 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
716 template <class _CharT>
717 inline _LIBCPP_INLINE_VISIBILITY
719 ispunct(_CharT __c, const locale& __loc)
721 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
724 template <class _CharT>
725 inline _LIBCPP_INLINE_VISIBILITY
727 isxdigit(_CharT __c, const locale& __loc)
729 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
732 template <class _CharT>
733 inline _LIBCPP_INLINE_VISIBILITY
735 isalnum(_CharT __c, const locale& __loc)
737 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
740 template <class _CharT>
741 inline _LIBCPP_INLINE_VISIBILITY
743 isgraph(_CharT __c, const locale& __loc)
745 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
748 template <class _CharT>
749 inline _LIBCPP_INLINE_VISIBILITY
751 toupper(_CharT __c, const locale& __loc)
753 return use_facet<ctype<_CharT> >(__loc).toupper(__c);
756 template <class _CharT>
757 inline _LIBCPP_INLINE_VISIBILITY
759 tolower(_CharT __c, const locale& __loc)
761 return use_facet<ctype<_CharT> >(__loc).tolower(__c);
766 class _LIBCPP_TYPE_VIS codecvt_base
769 _LIBCPP_ALWAYS_INLINE codecvt_base() {}
770 enum result {ok, partial, error, noconv};
773 // template <class internT, class externT, class stateT> class codecvt;
775 template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TYPE_VIS codecvt;
777 // template <> class codecvt<char, char, mbstate_t>
780 class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
781 : public locale::facet,
785 typedef char intern_type;
786 typedef char extern_type;
787 typedef mbstate_t state_type;
789 _LIBCPP_ALWAYS_INLINE
790 explicit codecvt(size_t __refs = 0)
791 : locale::facet(__refs) {}
793 _LIBCPP_ALWAYS_INLINE
794 result out(state_type& __st,
795 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
796 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
798 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
801 _LIBCPP_ALWAYS_INLINE
802 result unshift(state_type& __st,
803 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
805 return do_unshift(__st, __to, __to_end, __to_nxt);
808 _LIBCPP_ALWAYS_INLINE
809 result in(state_type& __st,
810 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
811 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
813 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
816 _LIBCPP_ALWAYS_INLINE
817 int encoding() const _NOEXCEPT
819 return do_encoding();
822 _LIBCPP_ALWAYS_INLINE
823 bool always_noconv() const _NOEXCEPT
825 return do_always_noconv();
828 _LIBCPP_ALWAYS_INLINE
829 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
831 return do_length(__st, __frm, __end, __mx);
834 _LIBCPP_ALWAYS_INLINE
835 int max_length() const _NOEXCEPT
837 return do_max_length();
840 static locale::id id;
843 _LIBCPP_ALWAYS_INLINE
844 explicit codecvt(const char*, size_t __refs = 0)
845 : locale::facet(__refs) {}
849 virtual result do_out(state_type& __st,
850 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
851 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
852 virtual result do_in(state_type& __st,
853 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
854 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
855 virtual result do_unshift(state_type& __st,
856 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
857 virtual int do_encoding() const _NOEXCEPT;
858 virtual bool do_always_noconv() const _NOEXCEPT;
859 virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
860 virtual int do_max_length() const _NOEXCEPT;
863 // template <> class codecvt<wchar_t, char, mbstate_t>
866 class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
867 : public locale::facet,
872 typedef wchar_t intern_type;
873 typedef char extern_type;
874 typedef mbstate_t state_type;
876 explicit codecvt(size_t __refs = 0);
878 _LIBCPP_ALWAYS_INLINE
879 result out(state_type& __st,
880 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
881 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
883 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
886 _LIBCPP_ALWAYS_INLINE
887 result unshift(state_type& __st,
888 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
890 return do_unshift(__st, __to, __to_end, __to_nxt);
893 _LIBCPP_ALWAYS_INLINE
894 result in(state_type& __st,
895 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
896 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
898 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
901 _LIBCPP_ALWAYS_INLINE
902 int encoding() const _NOEXCEPT
904 return do_encoding();
907 _LIBCPP_ALWAYS_INLINE
908 bool always_noconv() const _NOEXCEPT
910 return do_always_noconv();
913 _LIBCPP_ALWAYS_INLINE
914 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
916 return do_length(__st, __frm, __end, __mx);
919 _LIBCPP_ALWAYS_INLINE
920 int max_length() const _NOEXCEPT
922 return do_max_length();
925 static locale::id id;
928 explicit codecvt(const char*, size_t __refs = 0);
932 virtual result do_out(state_type& __st,
933 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
934 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
935 virtual result do_in(state_type& __st,
936 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
937 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
938 virtual result do_unshift(state_type& __st,
939 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
940 virtual int do_encoding() const _NOEXCEPT;
941 virtual bool do_always_noconv() const _NOEXCEPT;
942 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
943 virtual int do_max_length() const _NOEXCEPT;
946 // template <> class codecvt<char16_t, char, mbstate_t>
949 class _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
950 : public locale::facet,
954 typedef char16_t intern_type;
955 typedef char extern_type;
956 typedef mbstate_t state_type;
958 _LIBCPP_ALWAYS_INLINE
959 explicit codecvt(size_t __refs = 0)
960 : locale::facet(__refs) {}
962 _LIBCPP_ALWAYS_INLINE
963 result out(state_type& __st,
964 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
965 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
967 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
970 _LIBCPP_ALWAYS_INLINE
971 result unshift(state_type& __st,
972 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
974 return do_unshift(__st, __to, __to_end, __to_nxt);
977 _LIBCPP_ALWAYS_INLINE
978 result in(state_type& __st,
979 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
980 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
982 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
985 _LIBCPP_ALWAYS_INLINE
986 int encoding() const _NOEXCEPT
988 return do_encoding();
991 _LIBCPP_ALWAYS_INLINE
992 bool always_noconv() const _NOEXCEPT
994 return do_always_noconv();
997 _LIBCPP_ALWAYS_INLINE
998 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1000 return do_length(__st, __frm, __end, __mx);
1003 _LIBCPP_ALWAYS_INLINE
1004 int max_length() const _NOEXCEPT
1006 return do_max_length();
1009 static locale::id id;
1012 _LIBCPP_ALWAYS_INLINE
1013 explicit codecvt(const char*, size_t __refs = 0)
1014 : locale::facet(__refs) {}
1018 virtual result do_out(state_type& __st,
1019 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1020 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1021 virtual result do_in(state_type& __st,
1022 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1023 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1024 virtual result do_unshift(state_type& __st,
1025 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1026 virtual int do_encoding() const _NOEXCEPT;
1027 virtual bool do_always_noconv() const _NOEXCEPT;
1028 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1029 virtual int do_max_length() const _NOEXCEPT;
1032 // template <> class codecvt<char32_t, char, mbstate_t>
1035 class _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
1036 : public locale::facet,
1040 typedef char32_t intern_type;
1041 typedef char extern_type;
1042 typedef mbstate_t state_type;
1044 _LIBCPP_ALWAYS_INLINE
1045 explicit codecvt(size_t __refs = 0)
1046 : locale::facet(__refs) {}
1048 _LIBCPP_ALWAYS_INLINE
1049 result out(state_type& __st,
1050 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1051 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1053 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1056 _LIBCPP_ALWAYS_INLINE
1057 result unshift(state_type& __st,
1058 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1060 return do_unshift(__st, __to, __to_end, __to_nxt);
1063 _LIBCPP_ALWAYS_INLINE
1064 result in(state_type& __st,
1065 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1066 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1068 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1071 _LIBCPP_ALWAYS_INLINE
1072 int encoding() const _NOEXCEPT
1074 return do_encoding();
1077 _LIBCPP_ALWAYS_INLINE
1078 bool always_noconv() const _NOEXCEPT
1080 return do_always_noconv();
1083 _LIBCPP_ALWAYS_INLINE
1084 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1086 return do_length(__st, __frm, __end, __mx);
1089 _LIBCPP_ALWAYS_INLINE
1090 int max_length() const _NOEXCEPT
1092 return do_max_length();
1095 static locale::id id;
1098 _LIBCPP_ALWAYS_INLINE
1099 explicit codecvt(const char*, size_t __refs = 0)
1100 : locale::facet(__refs) {}
1104 virtual result do_out(state_type& __st,
1105 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1106 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1107 virtual result do_in(state_type& __st,
1108 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1109 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1110 virtual result do_unshift(state_type& __st,
1111 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1112 virtual int do_encoding() const _NOEXCEPT;
1113 virtual bool do_always_noconv() const _NOEXCEPT;
1114 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1115 virtual int do_max_length() const _NOEXCEPT;
1118 // template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
1120 template <class _InternT, class _ExternT, class _StateT>
1121 class _LIBCPP_TYPE_VIS codecvt_byname
1122 : public codecvt<_InternT, _ExternT, _StateT>
1125 _LIBCPP_ALWAYS_INLINE
1126 explicit codecvt_byname(const char* __nm, size_t __refs = 0)
1127 : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
1128 _LIBCPP_ALWAYS_INLINE
1129 explicit codecvt_byname(const string& __nm, size_t __refs = 0)
1130 : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
1135 template <class _InternT, class _ExternT, class _StateT>
1136 codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
1140 _LIBCPP_EXTERN_TEMPLATE(class codecvt_byname<char, char, mbstate_t>)
1141 _LIBCPP_EXTERN_TEMPLATE(class codecvt_byname<wchar_t, char, mbstate_t>)
1142 _LIBCPP_EXTERN_TEMPLATE(class codecvt_byname<char16_t, char, mbstate_t>)
1143 _LIBCPP_EXTERN_TEMPLATE(class codecvt_byname<char32_t, char, mbstate_t>)
1145 _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
1147 template <size_t _Np>
1148 struct __narrow_to_utf8
1150 template <class _OutputIterator, class _CharT>
1152 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
1156 struct __narrow_to_utf8<8>
1158 template <class _OutputIterator, class _CharT>
1159 _LIBCPP_ALWAYS_INLINE
1161 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1163 for (; __wb < __we; ++__wb, ++__s)
1170 struct __narrow_to_utf8<16>
1171 : public codecvt<char16_t, char, mbstate_t>
1173 _LIBCPP_ALWAYS_INLINE
1174 __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1176 ~__narrow_to_utf8();
1178 template <class _OutputIterator, class _CharT>
1179 _LIBCPP_ALWAYS_INLINE
1181 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1185 while (__wb < __we && __r != error)
1187 const int __sz = 32;
1190 const char16_t* __wn = (const char16_t*)__wb;
1191 __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
1192 __buf, __buf+__sz, __bn);
1193 if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
1194 __throw_runtime_error("locale not supported");
1195 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1197 __wb = (const _CharT*)__wn;
1204 struct __narrow_to_utf8<32>
1205 : public codecvt<char32_t, char, mbstate_t>
1207 _LIBCPP_ALWAYS_INLINE
1208 __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1210 ~__narrow_to_utf8();
1212 template <class _OutputIterator, class _CharT>
1213 _LIBCPP_ALWAYS_INLINE
1215 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1219 while (__wb < __we && __r != error)
1221 const int __sz = 32;
1224 const char32_t* __wn = (const char32_t*)__wb;
1225 __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
1226 __buf, __buf+__sz, __bn);
1227 if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
1228 __throw_runtime_error("locale not supported");
1229 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1231 __wb = (const _CharT*)__wn;
1237 template <size_t _Np>
1238 struct __widen_from_utf8
1240 template <class _OutputIterator>
1242 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
1246 struct __widen_from_utf8<8>
1248 template <class _OutputIterator>
1249 _LIBCPP_ALWAYS_INLINE
1251 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1253 for (; __nb < __ne; ++__nb, ++__s)
1260 struct __widen_from_utf8<16>
1261 : public codecvt<char16_t, char, mbstate_t>
1263 _LIBCPP_ALWAYS_INLINE
1264 __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1266 ~__widen_from_utf8();
1268 template <class _OutputIterator>
1269 _LIBCPP_ALWAYS_INLINE
1271 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1275 while (__nb < __ne && __r != error)
1277 const int __sz = 32;
1278 char16_t __buf[__sz];
1280 const char* __nn = __nb;
1281 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1282 __buf, __buf+__sz, __bn);
1283 if (__r == codecvt_base::error || __nn == __nb)
1284 __throw_runtime_error("locale not supported");
1285 for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
1286 *__s = (wchar_t)*__p;
1294 struct __widen_from_utf8<32>
1295 : public codecvt<char32_t, char, mbstate_t>
1297 _LIBCPP_ALWAYS_INLINE
1298 __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1300 ~__widen_from_utf8();
1302 template <class _OutputIterator>
1303 _LIBCPP_ALWAYS_INLINE
1305 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1309 while (__nb < __ne && __r != error)
1311 const int __sz = 32;
1312 char32_t __buf[__sz];
1314 const char* __nn = __nb;
1315 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1316 __buf, __buf+__sz, __bn);
1317 if (__r == codecvt_base::error || __nn == __nb)
1318 __throw_runtime_error("locale not supported");
1319 for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
1320 *__s = (wchar_t)*__p;
1327 // template <class charT> class numpunct
1329 template <class _CharT> class _LIBCPP_TYPE_VIS numpunct;
1332 class _LIBCPP_TYPE_VIS numpunct<char>
1333 : public locale::facet
1336 typedef char char_type;
1337 typedef basic_string<char_type> string_type;
1339 explicit numpunct(size_t __refs = 0);
1341 _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
1342 _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
1343 _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();}
1344 _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();}
1345 _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();}
1347 static locale::id id;
1351 virtual char_type do_decimal_point() const;
1352 virtual char_type do_thousands_sep() const;
1353 virtual string do_grouping() const;
1354 virtual string_type do_truename() const;
1355 virtual string_type do_falsename() const;
1357 char_type __decimal_point_;
1358 char_type __thousands_sep_;
1363 class _LIBCPP_TYPE_VIS numpunct<wchar_t>
1364 : public locale::facet
1367 typedef wchar_t char_type;
1368 typedef basic_string<char_type> string_type;
1370 explicit numpunct(size_t __refs = 0);
1372 _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
1373 _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
1374 _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();}
1375 _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();}
1376 _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();}
1378 static locale::id id;
1382 virtual char_type do_decimal_point() const;
1383 virtual char_type do_thousands_sep() const;
1384 virtual string do_grouping() const;
1385 virtual string_type do_truename() const;
1386 virtual string_type do_falsename() const;
1388 char_type __decimal_point_;
1389 char_type __thousands_sep_;
1393 // template <class charT> class numpunct_byname
1395 template <class charT> class _LIBCPP_TYPE_VIS numpunct_byname;
1398 class _LIBCPP_TYPE_VIS numpunct_byname<char>
1399 : public numpunct<char>
1402 typedef char char_type;
1403 typedef basic_string<char_type> string_type;
1405 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1406 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1412 void __init(const char*);
1416 class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
1417 : public numpunct<wchar_t>
1420 typedef wchar_t char_type;
1421 typedef basic_string<char_type> string_type;
1423 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1424 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1430 void __init(const char*);
1433 _LIBCPP_END_NAMESPACE_STD
1435 #endif // _LIBCPP___LOCALE