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(__ANDROID__)
27 // Android gained the locale aware functions in L (API level 21)
28 # include <android/api-level.h>
29 # if __ANDROID_API__ <= 20
30 # include <support/android/locale_bionic.h>
32 #elif defined(__sun__)
33 # include <support/solaris/xlocale.h>
34 #elif defined(_NEWLIB_VERSION)
35 # include <support/newlib/xlocale.h>
36 #elif (defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) \
37 || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
39 #endif // __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
41 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
42 #pragma GCC system_header
45 _LIBCPP_BEGIN_NAMESPACE_STD
47 class _LIBCPP_TYPE_VIS locale;
49 template <class _Facet>
50 _LIBCPP_INLINE_VISIBILITY
52 has_facet(const locale&) _NOEXCEPT;
54 template <class _Facet>
55 _LIBCPP_INLINE_VISIBILITY
57 use_facet(const locale&);
59 class _LIBCPP_TYPE_VIS locale
63 class _LIBCPP_TYPE_VIS facet;
64 class _LIBCPP_TYPE_VIS id;
67 static const category // values assigned here are for exposition only
69 collate = LC_COLLATE_MASK,
70 ctype = LC_CTYPE_MASK,
71 monetary = LC_MONETARY_MASK,
72 numeric = LC_NUMERIC_MASK,
74 messages = LC_MESSAGES_MASK,
75 all = collate | ctype | monetary | numeric | time | messages;
77 // construct/copy/destroy:
79 locale(const locale&) _NOEXCEPT;
80 explicit locale(const char*);
81 explicit locale(const string&);
82 locale(const locale&, const char*, category);
83 locale(const locale&, const string&, category);
84 template <class _Facet>
85 _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
86 locale(const locale&, const locale&, category);
90 const locale& operator=(const locale&) _NOEXCEPT;
92 template <class _Facet> locale combine(const locale&) const;
96 bool operator==(const locale&) const;
97 bool operator!=(const locale& __y) const {return !(*this == __y);}
98 template <class _CharT, class _Traits, class _Allocator>
99 bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
100 const basic_string<_CharT, _Traits, _Allocator>&) const;
102 // global locale objects:
103 static locale global(const locale&);
104 static const locale& classic();
110 void __install_ctor(const locale&, facet*, long);
111 static locale& __global();
112 bool has_facet(id&) const;
113 const facet* use_facet(id&) const;
115 template <class _Facet> friend bool has_facet(const locale&) _NOEXCEPT;
116 template <class _Facet> friend const _Facet& use_facet(const locale&);
119 class _LIBCPP_TYPE_VIS locale::facet
120 : public __shared_count
123 _LIBCPP_INLINE_VISIBILITY
124 explicit facet(size_t __refs = 0)
125 : __shared_count(static_cast<long>(__refs)-1) {}
129 // facet(const facet&) = delete; // effectively done in __shared_count
130 // void operator=(const facet&) = delete;
132 virtual void __on_zero_shared() _NOEXCEPT;
135 class _LIBCPP_TYPE_VIS locale::id
140 static int32_t __next_id;
142 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
145 void operator=(const id&); // = delete;
146 id(const id&); // = delete;
147 public: // only needed for tests
151 friend class locale::__imp;
154 template <class _Facet>
155 inline _LIBCPP_INLINE_VISIBILITY
156 locale::locale(const locale& __other, _Facet* __f)
158 __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
161 template <class _Facet>
163 locale::combine(const locale& __other) const
165 #ifndef _LIBCPP_NO_EXCEPTIONS
166 if (!_VSTD::has_facet<_Facet>(__other))
167 throw runtime_error("locale::combine: locale missing facet");
168 #endif // _LIBCPP_NO_EXCEPTIONS
169 return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
172 template <class _Facet>
173 inline _LIBCPP_INLINE_VISIBILITY
175 has_facet(const locale& __l) _NOEXCEPT
177 return __l.has_facet(_Facet::id);
180 template <class _Facet>
181 inline _LIBCPP_INLINE_VISIBILITY
183 use_facet(const locale& __l)
185 return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
188 // template <class _CharT> class collate;
190 template <class _CharT>
191 class _LIBCPP_TYPE_VIS_ONLY collate
192 : public locale::facet
195 typedef _CharT char_type;
196 typedef basic_string<char_type> string_type;
198 _LIBCPP_INLINE_VISIBILITY
199 explicit collate(size_t __refs = 0)
200 : locale::facet(__refs) {}
202 _LIBCPP_INLINE_VISIBILITY
203 int compare(const char_type* __lo1, const char_type* __hi1,
204 const char_type* __lo2, const char_type* __hi2) const
206 return do_compare(__lo1, __hi1, __lo2, __hi2);
209 _LIBCPP_INLINE_VISIBILITY
210 string_type transform(const char_type* __lo, const char_type* __hi) const
212 return do_transform(__lo, __hi);
215 _LIBCPP_INLINE_VISIBILITY
216 long hash(const char_type* __lo, const char_type* __hi) const
218 return do_hash(__lo, __hi);
221 static locale::id id;
225 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
226 const char_type* __lo2, const char_type* __hi2) const;
227 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
228 {return string_type(__lo, __hi);}
229 virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
232 template <class _CharT> locale::id collate<_CharT>::id;
234 template <class _CharT>
235 collate<_CharT>::~collate()
239 template <class _CharT>
241 collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
242 const char_type* __lo2, const char_type* __hi2) const
244 for (; __lo2 != __hi2; ++__lo1, ++__lo2)
246 if (__lo1 == __hi1 || *__lo1 < *__lo2)
251 return __lo1 != __hi1;
254 template <class _CharT>
256 collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
259 const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
260 const size_t __mask = size_t(0xF) << (__sr + 4);
261 for(const char_type* __p = __lo; __p != __hi; ++__p)
263 __h = (__h << 4) + static_cast<size_t>(*__p);
264 size_t __g = __h & __mask;
265 __h ^= __g | (__g >> __sr);
267 return static_cast<long>(__h);
270 _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS collate<char>)
271 _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS collate<wchar_t>)
273 // template <class CharT> class collate_byname;
275 template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY collate_byname;
278 class _LIBCPP_TYPE_VIS collate_byname<char>
279 : public collate<char>
283 typedef char char_type;
284 typedef basic_string<char_type> string_type;
286 explicit collate_byname(const char* __n, size_t __refs = 0);
287 explicit collate_byname(const string& __n, size_t __refs = 0);
291 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
292 const char_type* __lo2, const char_type* __hi2) const;
293 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
297 class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
298 : public collate<wchar_t>
302 typedef wchar_t char_type;
303 typedef basic_string<char_type> string_type;
305 explicit collate_byname(const char* __n, size_t __refs = 0);
306 explicit collate_byname(const string& __n, size_t __refs = 0);
311 virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
312 const char_type* __lo2, const char_type* __hi2) const;
313 virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
316 template <class _CharT, class _Traits, class _Allocator>
318 locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
319 const basic_string<_CharT, _Traits, _Allocator>& __y) const
321 return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
322 __x.data(), __x.data() + __x.size(),
323 __y.data(), __y.data() + __y.size()) < 0;
326 // template <class charT> class ctype
328 class _LIBCPP_TYPE_VIS ctype_base
332 typedef unsigned short mask;
333 static const mask space = _ISspace;
334 static const mask print = _ISprint;
335 static const mask cntrl = _IScntrl;
336 static const mask upper = _ISupper;
337 static const mask lower = _ISlower;
338 static const mask alpha = _ISalpha;
339 static const mask digit = _ISdigit;
340 static const mask punct = _ISpunct;
341 static const mask xdigit = _ISxdigit;
342 static const mask blank = _ISblank;
343 #elif defined(_WIN32)
344 typedef unsigned short mask;
345 static const mask space = _SPACE;
346 static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT;
347 static const mask cntrl = _CONTROL;
348 static const mask upper = _UPPER;
349 static const mask lower = _LOWER;
350 static const mask alpha = _ALPHA;
351 static const mask digit = _DIGIT;
352 static const mask punct = _PUNCT;
353 static const mask xdigit = _HEX;
354 static const mask blank = _BLANK;
355 #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__ANDROID__)
357 typedef __uint32_t mask;
358 #elif defined(__FreeBSD__)
359 typedef unsigned long mask;
360 #elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
361 typedef unsigned short mask;
362 #elif defined(__ANDROID__)
363 typedef unsigned char mask;
365 static const mask space = _CTYPE_S;
366 static const mask print = _CTYPE_R;
367 static const mask cntrl = _CTYPE_C;
368 static const mask upper = _CTYPE_U;
369 static const mask lower = _CTYPE_L;
370 static const mask alpha = _CTYPE_A;
371 static const mask digit = _CTYPE_D;
372 static const mask punct = _CTYPE_P;
373 # if defined(__ANDROID__)
374 static const mask xdigit = _CTYPE_X | _CTYPE_D;
376 static const mask xdigit = _CTYPE_X;
379 # if defined(__NetBSD__)
380 static const mask blank = _CTYPE_BL;
382 static const mask blank = _CTYPE_B;
384 #elif defined(__sun__) || defined(_AIX)
385 typedef unsigned int mask;
386 static const mask space = _ISSPACE;
387 static const mask print = _ISPRINT;
388 static const mask cntrl = _ISCNTRL;
389 static const mask upper = _ISUPPER;
390 static const mask lower = _ISLOWER;
391 static const mask alpha = _ISALPHA;
392 static const mask digit = _ISDIGIT;
393 static const mask punct = _ISPUNCT;
394 static const mask xdigit = _ISXDIGIT;
395 static const mask blank = _ISBLANK;
396 #else // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__ || __EMSCRIPTEN__ || __sun__
397 typedef unsigned long mask;
398 static const mask space = 1<<0;
399 static const mask print = 1<<1;
400 static const mask cntrl = 1<<2;
401 static const mask upper = 1<<3;
402 static const mask lower = 1<<4;
403 static const mask alpha = 1<<5;
404 static const mask digit = 1<<6;
405 static const mask punct = 1<<7;
406 static const mask xdigit = 1<<8;
407 static const mask blank = 1<<9;
408 #endif // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__
409 static const mask alnum = alpha | digit;
410 static const mask graph = alnum | punct;
412 _LIBCPP_ALWAYS_INLINE ctype_base() {}
415 template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY ctype;
418 class _LIBCPP_TYPE_VIS ctype<wchar_t>
419 : public locale::facet,
423 typedef wchar_t char_type;
425 _LIBCPP_ALWAYS_INLINE
426 explicit ctype(size_t __refs = 0)
427 : locale::facet(__refs) {}
429 _LIBCPP_ALWAYS_INLINE
430 bool is(mask __m, char_type __c) const
432 return do_is(__m, __c);
435 _LIBCPP_ALWAYS_INLINE
436 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
438 return do_is(__low, __high, __vec);
441 _LIBCPP_ALWAYS_INLINE
442 const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
444 return do_scan_is(__m, __low, __high);
447 _LIBCPP_ALWAYS_INLINE
448 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
450 return do_scan_not(__m, __low, __high);
453 _LIBCPP_ALWAYS_INLINE
454 char_type toupper(char_type __c) const
456 return do_toupper(__c);
459 _LIBCPP_ALWAYS_INLINE
460 const char_type* toupper(char_type* __low, const char_type* __high) const
462 return do_toupper(__low, __high);
465 _LIBCPP_ALWAYS_INLINE
466 char_type tolower(char_type __c) const
468 return do_tolower(__c);
471 _LIBCPP_ALWAYS_INLINE
472 const char_type* tolower(char_type* __low, const char_type* __high) const
474 return do_tolower(__low, __high);
477 _LIBCPP_ALWAYS_INLINE
478 char_type widen(char __c) const
480 return do_widen(__c);
483 _LIBCPP_ALWAYS_INLINE
484 const char* widen(const char* __low, const char* __high, char_type* __to) const
486 return do_widen(__low, __high, __to);
489 _LIBCPP_ALWAYS_INLINE
490 char narrow(char_type __c, char __dfault) const
492 return do_narrow(__c, __dfault);
495 _LIBCPP_ALWAYS_INLINE
496 const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
498 return do_narrow(__low, __high, __dfault, __to);
501 static locale::id id;
505 virtual bool do_is(mask __m, char_type __c) const;
506 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
507 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
508 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
509 virtual char_type do_toupper(char_type) const;
510 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
511 virtual char_type do_tolower(char_type) const;
512 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
513 virtual char_type do_widen(char) const;
514 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
515 virtual char do_narrow(char_type, char __dfault) const;
516 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
520 class _LIBCPP_TYPE_VIS ctype<char>
521 : public locale::facet, public ctype_base
526 typedef char char_type;
528 explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
530 _LIBCPP_ALWAYS_INLINE
531 bool is(mask __m, char_type __c) const
533 return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false;
536 _LIBCPP_ALWAYS_INLINE
537 const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
539 for (; __low != __high; ++__low, ++__vec)
540 *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
544 _LIBCPP_ALWAYS_INLINE
545 const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
547 for (; __low != __high; ++__low)
548 if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
553 _LIBCPP_ALWAYS_INLINE
554 const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
556 for (; __low != __high; ++__low)
557 if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)))
562 _LIBCPP_ALWAYS_INLINE
563 char_type toupper(char_type __c) const
565 return do_toupper(__c);
568 _LIBCPP_ALWAYS_INLINE
569 const char_type* toupper(char_type* __low, const char_type* __high) const
571 return do_toupper(__low, __high);
574 _LIBCPP_ALWAYS_INLINE
575 char_type tolower(char_type __c) const
577 return do_tolower(__c);
580 _LIBCPP_ALWAYS_INLINE
581 const char_type* tolower(char_type* __low, const char_type* __high) const
583 return do_tolower(__low, __high);
586 _LIBCPP_ALWAYS_INLINE
587 char_type widen(char __c) const
589 return do_widen(__c);
592 _LIBCPP_ALWAYS_INLINE
593 const char* widen(const char* __low, const char* __high, char_type* __to) const
595 return do_widen(__low, __high, __to);
598 _LIBCPP_ALWAYS_INLINE
599 char narrow(char_type __c, char __dfault) const
601 return do_narrow(__c, __dfault);
604 _LIBCPP_ALWAYS_INLINE
605 const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
607 return do_narrow(__low, __high, __dfault, __to);
610 static locale::id id;
613 static const size_t table_size = _CACHED_RUNES;
615 static const size_t table_size = 256; // FIXME: Don't hardcode this.
617 _LIBCPP_ALWAYS_INLINE const mask* table() const _NOEXCEPT {return __tab_;}
618 static const mask* classic_table() _NOEXCEPT;
619 #if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
620 static const int* __classic_upper_table() _NOEXCEPT;
621 static const int* __classic_lower_table() _NOEXCEPT;
623 #if defined(__NetBSD__)
624 static const short* __classic_upper_table() _NOEXCEPT;
625 static const short* __classic_lower_table() _NOEXCEPT;
630 virtual char_type do_toupper(char_type __c) const;
631 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
632 virtual char_type do_tolower(char_type __c) const;
633 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
634 virtual char_type do_widen(char __c) const;
635 virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
636 virtual char do_narrow(char_type __c, char __dfault) const;
637 virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
640 // template <class CharT> class ctype_byname;
642 template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY ctype_byname;
645 class _LIBCPP_TYPE_VIS ctype_byname<char>
651 explicit ctype_byname(const char*, size_t = 0);
652 explicit ctype_byname(const string&, size_t = 0);
656 virtual char_type do_toupper(char_type) const;
657 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
658 virtual char_type do_tolower(char_type) const;
659 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
663 class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
664 : public ctype<wchar_t>
669 explicit ctype_byname(const char*, size_t = 0);
670 explicit ctype_byname(const string&, size_t = 0);
674 virtual bool do_is(mask __m, char_type __c) const;
675 virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
676 virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
677 virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
678 virtual char_type do_toupper(char_type) const;
679 virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
680 virtual char_type do_tolower(char_type) const;
681 virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
682 virtual char_type do_widen(char) const;
683 virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
684 virtual char do_narrow(char_type, char __dfault) const;
685 virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
688 template <class _CharT>
689 inline _LIBCPP_INLINE_VISIBILITY
691 isspace(_CharT __c, const locale& __loc)
693 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
696 template <class _CharT>
697 inline _LIBCPP_INLINE_VISIBILITY
699 isprint(_CharT __c, const locale& __loc)
701 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
704 template <class _CharT>
705 inline _LIBCPP_INLINE_VISIBILITY
707 iscntrl(_CharT __c, const locale& __loc)
709 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
712 template <class _CharT>
713 inline _LIBCPP_INLINE_VISIBILITY
715 isupper(_CharT __c, const locale& __loc)
717 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
720 template <class _CharT>
721 inline _LIBCPP_INLINE_VISIBILITY
723 islower(_CharT __c, const locale& __loc)
725 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
728 template <class _CharT>
729 inline _LIBCPP_INLINE_VISIBILITY
731 isalpha(_CharT __c, const locale& __loc)
733 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
736 template <class _CharT>
737 inline _LIBCPP_INLINE_VISIBILITY
739 isdigit(_CharT __c, const locale& __loc)
741 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
744 template <class _CharT>
745 inline _LIBCPP_INLINE_VISIBILITY
747 ispunct(_CharT __c, const locale& __loc)
749 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
752 template <class _CharT>
753 inline _LIBCPP_INLINE_VISIBILITY
755 isxdigit(_CharT __c, const locale& __loc)
757 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
760 template <class _CharT>
761 inline _LIBCPP_INLINE_VISIBILITY
763 isalnum(_CharT __c, const locale& __loc)
765 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
768 template <class _CharT>
769 inline _LIBCPP_INLINE_VISIBILITY
771 isgraph(_CharT __c, const locale& __loc)
773 return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
776 template <class _CharT>
777 inline _LIBCPP_INLINE_VISIBILITY
779 toupper(_CharT __c, const locale& __loc)
781 return use_facet<ctype<_CharT> >(__loc).toupper(__c);
784 template <class _CharT>
785 inline _LIBCPP_INLINE_VISIBILITY
787 tolower(_CharT __c, const locale& __loc)
789 return use_facet<ctype<_CharT> >(__loc).tolower(__c);
794 class _LIBCPP_TYPE_VIS codecvt_base
797 _LIBCPP_ALWAYS_INLINE codecvt_base() {}
798 enum result {ok, partial, error, noconv};
801 // template <class internT, class externT, class stateT> class codecvt;
803 template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TYPE_VIS_ONLY codecvt;
805 // template <> class codecvt<char, char, mbstate_t>
808 class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
809 : public locale::facet,
813 typedef char intern_type;
814 typedef char extern_type;
815 typedef mbstate_t state_type;
817 _LIBCPP_ALWAYS_INLINE
818 explicit codecvt(size_t __refs = 0)
819 : locale::facet(__refs) {}
821 _LIBCPP_ALWAYS_INLINE
822 result out(state_type& __st,
823 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
824 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
826 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
829 _LIBCPP_ALWAYS_INLINE
830 result unshift(state_type& __st,
831 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
833 return do_unshift(__st, __to, __to_end, __to_nxt);
836 _LIBCPP_ALWAYS_INLINE
837 result in(state_type& __st,
838 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
839 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
841 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
844 _LIBCPP_ALWAYS_INLINE
845 int encoding() const _NOEXCEPT
847 return do_encoding();
850 _LIBCPP_ALWAYS_INLINE
851 bool always_noconv() const _NOEXCEPT
853 return do_always_noconv();
856 _LIBCPP_ALWAYS_INLINE
857 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
859 return do_length(__st, __frm, __end, __mx);
862 _LIBCPP_ALWAYS_INLINE
863 int max_length() const _NOEXCEPT
865 return do_max_length();
868 static locale::id id;
871 _LIBCPP_ALWAYS_INLINE
872 explicit codecvt(const char*, size_t __refs = 0)
873 : locale::facet(__refs) {}
877 virtual result do_out(state_type& __st,
878 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
879 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
880 virtual result do_in(state_type& __st,
881 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
882 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
883 virtual result do_unshift(state_type& __st,
884 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
885 virtual int do_encoding() const _NOEXCEPT;
886 virtual bool do_always_noconv() const _NOEXCEPT;
887 virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
888 virtual int do_max_length() const _NOEXCEPT;
891 // template <> class codecvt<wchar_t, char, mbstate_t>
894 class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
895 : public locale::facet,
900 typedef wchar_t intern_type;
901 typedef char extern_type;
902 typedef mbstate_t state_type;
904 explicit codecvt(size_t __refs = 0);
906 _LIBCPP_ALWAYS_INLINE
907 result out(state_type& __st,
908 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
909 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
911 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
914 _LIBCPP_ALWAYS_INLINE
915 result unshift(state_type& __st,
916 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
918 return do_unshift(__st, __to, __to_end, __to_nxt);
921 _LIBCPP_ALWAYS_INLINE
922 result in(state_type& __st,
923 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
924 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
926 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
929 _LIBCPP_ALWAYS_INLINE
930 int encoding() const _NOEXCEPT
932 return do_encoding();
935 _LIBCPP_ALWAYS_INLINE
936 bool always_noconv() const _NOEXCEPT
938 return do_always_noconv();
941 _LIBCPP_ALWAYS_INLINE
942 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
944 return do_length(__st, __frm, __end, __mx);
947 _LIBCPP_ALWAYS_INLINE
948 int max_length() const _NOEXCEPT
950 return do_max_length();
953 static locale::id id;
956 explicit codecvt(const char*, size_t __refs = 0);
960 virtual result do_out(state_type& __st,
961 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
962 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
963 virtual result do_in(state_type& __st,
964 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
965 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
966 virtual result do_unshift(state_type& __st,
967 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
968 virtual int do_encoding() const _NOEXCEPT;
969 virtual bool do_always_noconv() const _NOEXCEPT;
970 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
971 virtual int do_max_length() const _NOEXCEPT;
974 // template <> class codecvt<char16_t, char, mbstate_t>
977 class _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
978 : public locale::facet,
982 typedef char16_t intern_type;
983 typedef char extern_type;
984 typedef mbstate_t state_type;
986 _LIBCPP_ALWAYS_INLINE
987 explicit codecvt(size_t __refs = 0)
988 : locale::facet(__refs) {}
990 _LIBCPP_ALWAYS_INLINE
991 result out(state_type& __st,
992 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
993 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
995 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
998 _LIBCPP_ALWAYS_INLINE
999 result unshift(state_type& __st,
1000 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1002 return do_unshift(__st, __to, __to_end, __to_nxt);
1005 _LIBCPP_ALWAYS_INLINE
1006 result in(state_type& __st,
1007 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1008 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1010 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1013 _LIBCPP_ALWAYS_INLINE
1014 int encoding() const _NOEXCEPT
1016 return do_encoding();
1019 _LIBCPP_ALWAYS_INLINE
1020 bool always_noconv() const _NOEXCEPT
1022 return do_always_noconv();
1025 _LIBCPP_ALWAYS_INLINE
1026 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1028 return do_length(__st, __frm, __end, __mx);
1031 _LIBCPP_ALWAYS_INLINE
1032 int max_length() const _NOEXCEPT
1034 return do_max_length();
1037 static locale::id id;
1040 _LIBCPP_ALWAYS_INLINE
1041 explicit codecvt(const char*, size_t __refs = 0)
1042 : locale::facet(__refs) {}
1046 virtual result do_out(state_type& __st,
1047 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1048 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1049 virtual result do_in(state_type& __st,
1050 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1051 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1052 virtual result do_unshift(state_type& __st,
1053 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1054 virtual int do_encoding() const _NOEXCEPT;
1055 virtual bool do_always_noconv() const _NOEXCEPT;
1056 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1057 virtual int do_max_length() const _NOEXCEPT;
1060 // template <> class codecvt<char32_t, char, mbstate_t>
1063 class _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
1064 : public locale::facet,
1068 typedef char32_t intern_type;
1069 typedef char extern_type;
1070 typedef mbstate_t state_type;
1072 _LIBCPP_ALWAYS_INLINE
1073 explicit codecvt(size_t __refs = 0)
1074 : locale::facet(__refs) {}
1076 _LIBCPP_ALWAYS_INLINE
1077 result out(state_type& __st,
1078 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1079 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1081 return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1084 _LIBCPP_ALWAYS_INLINE
1085 result unshift(state_type& __st,
1086 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
1088 return do_unshift(__st, __to, __to_end, __to_nxt);
1091 _LIBCPP_ALWAYS_INLINE
1092 result in(state_type& __st,
1093 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1094 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
1096 return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
1099 _LIBCPP_ALWAYS_INLINE
1100 int encoding() const _NOEXCEPT
1102 return do_encoding();
1105 _LIBCPP_ALWAYS_INLINE
1106 bool always_noconv() const _NOEXCEPT
1108 return do_always_noconv();
1111 _LIBCPP_ALWAYS_INLINE
1112 int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
1114 return do_length(__st, __frm, __end, __mx);
1117 _LIBCPP_ALWAYS_INLINE
1118 int max_length() const _NOEXCEPT
1120 return do_max_length();
1123 static locale::id id;
1126 _LIBCPP_ALWAYS_INLINE
1127 explicit codecvt(const char*, size_t __refs = 0)
1128 : locale::facet(__refs) {}
1132 virtual result do_out(state_type& __st,
1133 const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
1134 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1135 virtual result do_in(state_type& __st,
1136 const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
1137 intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
1138 virtual result do_unshift(state_type& __st,
1139 extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
1140 virtual int do_encoding() const _NOEXCEPT;
1141 virtual bool do_always_noconv() const _NOEXCEPT;
1142 virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
1143 virtual int do_max_length() const _NOEXCEPT;
1146 // template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
1148 template <class _InternT, class _ExternT, class _StateT>
1149 class _LIBCPP_TYPE_VIS_ONLY codecvt_byname
1150 : public codecvt<_InternT, _ExternT, _StateT>
1153 _LIBCPP_ALWAYS_INLINE
1154 explicit codecvt_byname(const char* __nm, size_t __refs = 0)
1155 : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
1156 _LIBCPP_ALWAYS_INLINE
1157 explicit codecvt_byname(const string& __nm, size_t __refs = 0)
1158 : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
1163 template <class _InternT, class _ExternT, class _StateT>
1164 codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
1168 _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<char, char, mbstate_t>)
1169 _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>)
1170 _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>)
1171 _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>)
1173 _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
1175 template <size_t _Np>
1176 struct __narrow_to_utf8
1178 template <class _OutputIterator, class _CharT>
1180 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
1184 struct __narrow_to_utf8<8>
1186 template <class _OutputIterator, class _CharT>
1187 _LIBCPP_ALWAYS_INLINE
1189 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1191 for (; __wb < __we; ++__wb, ++__s)
1198 struct __narrow_to_utf8<16>
1199 : public codecvt<char16_t, char, mbstate_t>
1201 _LIBCPP_ALWAYS_INLINE
1202 __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1204 ~__narrow_to_utf8();
1206 template <class _OutputIterator, class _CharT>
1207 _LIBCPP_ALWAYS_INLINE
1209 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1213 while (__wb < __we && __r != error)
1215 const int __sz = 32;
1218 const char16_t* __wn = (const char16_t*)__wb;
1219 __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
1220 __buf, __buf+__sz, __bn);
1221 if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
1222 __throw_runtime_error("locale not supported");
1223 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1225 __wb = (const _CharT*)__wn;
1232 struct __narrow_to_utf8<32>
1233 : public codecvt<char32_t, char, mbstate_t>
1235 _LIBCPP_ALWAYS_INLINE
1236 __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1238 ~__narrow_to_utf8();
1240 template <class _OutputIterator, class _CharT>
1241 _LIBCPP_ALWAYS_INLINE
1243 operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
1247 while (__wb < __we && __r != error)
1249 const int __sz = 32;
1252 const char32_t* __wn = (const char32_t*)__wb;
1253 __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
1254 __buf, __buf+__sz, __bn);
1255 if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
1256 __throw_runtime_error("locale not supported");
1257 for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
1259 __wb = (const _CharT*)__wn;
1265 template <size_t _Np>
1266 struct __widen_from_utf8
1268 template <class _OutputIterator>
1270 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
1274 struct __widen_from_utf8<8>
1276 template <class _OutputIterator>
1277 _LIBCPP_ALWAYS_INLINE
1279 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1281 for (; __nb < __ne; ++__nb, ++__s)
1288 struct __widen_from_utf8<16>
1289 : public codecvt<char16_t, char, mbstate_t>
1291 _LIBCPP_ALWAYS_INLINE
1292 __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
1294 ~__widen_from_utf8();
1296 template <class _OutputIterator>
1297 _LIBCPP_ALWAYS_INLINE
1299 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1303 while (__nb < __ne && __r != error)
1305 const int __sz = 32;
1306 char16_t __buf[__sz];
1308 const char* __nn = __nb;
1309 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1310 __buf, __buf+__sz, __bn);
1311 if (__r == codecvt_base::error || __nn == __nb)
1312 __throw_runtime_error("locale not supported");
1313 for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
1314 *__s = (wchar_t)*__p;
1322 struct __widen_from_utf8<32>
1323 : public codecvt<char32_t, char, mbstate_t>
1325 _LIBCPP_ALWAYS_INLINE
1326 __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
1328 ~__widen_from_utf8();
1330 template <class _OutputIterator>
1331 _LIBCPP_ALWAYS_INLINE
1333 operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
1337 while (__nb < __ne && __r != error)
1339 const int __sz = 32;
1340 char32_t __buf[__sz];
1342 const char* __nn = __nb;
1343 __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
1344 __buf, __buf+__sz, __bn);
1345 if (__r == codecvt_base::error || __nn == __nb)
1346 __throw_runtime_error("locale not supported");
1347 for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
1348 *__s = (wchar_t)*__p;
1355 // template <class charT> class numpunct
1357 template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY numpunct;
1360 class _LIBCPP_TYPE_VIS numpunct<char>
1361 : public locale::facet
1364 typedef char char_type;
1365 typedef basic_string<char_type> string_type;
1367 explicit numpunct(size_t __refs = 0);
1369 _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
1370 _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
1371 _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();}
1372 _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();}
1373 _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();}
1375 static locale::id id;
1379 virtual char_type do_decimal_point() const;
1380 virtual char_type do_thousands_sep() const;
1381 virtual string do_grouping() const;
1382 virtual string_type do_truename() const;
1383 virtual string_type do_falsename() const;
1385 char_type __decimal_point_;
1386 char_type __thousands_sep_;
1391 class _LIBCPP_TYPE_VIS numpunct<wchar_t>
1392 : public locale::facet
1395 typedef wchar_t char_type;
1396 typedef basic_string<char_type> string_type;
1398 explicit numpunct(size_t __refs = 0);
1400 _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
1401 _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
1402 _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();}
1403 _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();}
1404 _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();}
1406 static locale::id id;
1410 virtual char_type do_decimal_point() const;
1411 virtual char_type do_thousands_sep() const;
1412 virtual string do_grouping() const;
1413 virtual string_type do_truename() const;
1414 virtual string_type do_falsename() const;
1416 char_type __decimal_point_;
1417 char_type __thousands_sep_;
1421 // template <class charT> class numpunct_byname
1423 template <class charT> class _LIBCPP_TYPE_VIS_ONLY numpunct_byname;
1426 class _LIBCPP_TYPE_VIS numpunct_byname<char>
1427 : public numpunct<char>
1430 typedef char 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*);
1444 class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
1445 : public numpunct<wchar_t>
1448 typedef wchar_t char_type;
1449 typedef basic_string<char_type> string_type;
1451 explicit numpunct_byname(const char* __nm, size_t __refs = 0);
1452 explicit numpunct_byname(const string& __nm, size_t __refs = 0);
1458 void __init(const char*);
1461 _LIBCPP_END_NAMESPACE_STD
1463 #endif // _LIBCPP___LOCALE