12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481 |
- // -*- C++ -*-
- //===----------------------------------------------------------------------===//
- //
- // The LLVM Compiler Infrastructure
- //
- // This file is dual licensed under the MIT and the University of Illinois Open
- // Source Licenses. See LICENSE.TXT for details.
- //
- //===----------------------------------------------------------------------===//
- #ifndef _LIBCPP___LOCALE
- #define _LIBCPP___LOCALE
- // Not supported in SGX.
- #include <__config>
- #if !defined(_LIBCPP_SGX_CONFIG)
- #include <string>
- #include <memory>
- #include <utility>
- #include <mutex>
- #include <cstdint>
- #include <cctype>
- #include <locale.h>
- #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
- # include <support/win32/locale_win32.h>
- #elif defined(_AIX)
- # include <support/ibm/xlocale.h>
- #elif defined(__ANDROID__)
- // Android gained the locale aware functions in L (API level 21)
- # include <android/api-level.h>
- # if __ANDROID_API__ <= 20
- # include <support/android/locale_bionic.h>
- # endif
- #elif defined(__sun__)
- # include <xlocale.h>
- # include <support/solaris/xlocale.h>
- #elif defined(_NEWLIB_VERSION)
- # include <support/newlib/xlocale.h>
- #elif (defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) \
- || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
- # include <xlocale.h>
- #elif defined(_LIBCPP_HAS_MUSL_LIBC)
- # include <support/musl/xlocale.h>
- #endif // __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__
- #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
- #pragma GCC system_header
- #endif
- _LIBCPP_BEGIN_NAMESPACE_STD
- class _LIBCPP_TYPE_VIS locale;
- template <class _Facet>
- _LIBCPP_INLINE_VISIBILITY
- bool
- has_facet(const locale&) _NOEXCEPT;
- template <class _Facet>
- _LIBCPP_INLINE_VISIBILITY
- const _Facet&
- use_facet(const locale&);
- class _LIBCPP_TYPE_VIS locale
- {
- public:
- // types:
- class _LIBCPP_TYPE_VIS facet;
- class _LIBCPP_TYPE_VIS id;
- typedef int category;
- static const category // values assigned here are for exposition only
- none = 0,
- collate = LC_COLLATE_MASK,
- ctype = LC_CTYPE_MASK,
- monetary = LC_MONETARY_MASK,
- numeric = LC_NUMERIC_MASK,
- time = LC_TIME_MASK,
- messages = LC_MESSAGES_MASK,
- all = collate | ctype | monetary | numeric | time | messages;
- // construct/copy/destroy:
- locale() _NOEXCEPT;
- locale(const locale&) _NOEXCEPT;
- explicit locale(const char*);
- explicit locale(const string&);
- locale(const locale&, const char*, category);
- locale(const locale&, const string&, category);
- template <class _Facet>
- _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
- locale(const locale&, const locale&, category);
- ~locale();
- const locale& operator=(const locale&) _NOEXCEPT;
- template <class _Facet> locale combine(const locale&) const;
- // locale operations:
- string name() const;
- bool operator==(const locale&) const;
- bool operator!=(const locale& __y) const {return !(*this == __y);}
- template <class _CharT, class _Traits, class _Allocator>
- bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
- const basic_string<_CharT, _Traits, _Allocator>&) const;
- // global locale objects:
- static locale global(const locale&);
- static const locale& classic();
- private:
- class __imp;
- __imp* __locale_;
- void __install_ctor(const locale&, facet*, long);
- static locale& __global();
- bool has_facet(id&) const;
- const facet* use_facet(id&) const;
- template <class _Facet> friend bool has_facet(const locale&) _NOEXCEPT;
- template <class _Facet> friend const _Facet& use_facet(const locale&);
- };
- class _LIBCPP_TYPE_VIS locale::facet
- : public __shared_count
- {
- protected:
- _LIBCPP_INLINE_VISIBILITY
- explicit facet(size_t __refs = 0)
- : __shared_count(static_cast<long>(__refs)-1) {}
- virtual ~facet();
- // facet(const facet&) = delete; // effectively done in __shared_count
- // void operator=(const facet&) = delete;
- private:
- virtual void __on_zero_shared() _NOEXCEPT;
- };
- class _LIBCPP_TYPE_VIS locale::id
- {
- once_flag __flag_;
- int32_t __id_;
- static int32_t __next_id;
- public:
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
- private:
- void __init();
- void operator=(const id&); // = delete;
- id(const id&); // = delete;
- public: // only needed for tests
- long __get();
- friend class locale;
- friend class locale::__imp;
- };
- template <class _Facet>
- inline _LIBCPP_INLINE_VISIBILITY
- locale::locale(const locale& __other, _Facet* __f)
- {
- __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
- }
- template <class _Facet>
- locale
- locale::combine(const locale& __other) const
- {
- #ifndef _LIBCPP_NO_EXCEPTIONS
- if (!_VSTD::has_facet<_Facet>(__other))
- throw runtime_error("locale::combine: locale missing facet");
- #endif // _LIBCPP_NO_EXCEPTIONS
- return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
- }
- template <class _Facet>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- has_facet(const locale& __l) _NOEXCEPT
- {
- return __l.has_facet(_Facet::id);
- }
- template <class _Facet>
- inline _LIBCPP_INLINE_VISIBILITY
- const _Facet&
- use_facet(const locale& __l)
- {
- return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
- }
- // template <class _CharT> class collate;
- template <class _CharT>
- class _LIBCPP_TYPE_VIS_ONLY collate
- : public locale::facet
- {
- public:
- typedef _CharT char_type;
- typedef basic_string<char_type> string_type;
- _LIBCPP_INLINE_VISIBILITY
- explicit collate(size_t __refs = 0)
- : locale::facet(__refs) {}
- _LIBCPP_INLINE_VISIBILITY
- int compare(const char_type* __lo1, const char_type* __hi1,
- const char_type* __lo2, const char_type* __hi2) const
- {
- return do_compare(__lo1, __hi1, __lo2, __hi2);
- }
- _LIBCPP_INLINE_VISIBILITY
- string_type transform(const char_type* __lo, const char_type* __hi) const
- {
- return do_transform(__lo, __hi);
- }
- _LIBCPP_INLINE_VISIBILITY
- long hash(const char_type* __lo, const char_type* __hi) const
- {
- return do_hash(__lo, __hi);
- }
- static locale::id id;
- protected:
- ~collate();
- virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
- const char_type* __lo2, const char_type* __hi2) const;
- virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
- {return string_type(__lo, __hi);}
- virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
- };
- template <class _CharT> locale::id collate<_CharT>::id;
- template <class _CharT>
- collate<_CharT>::~collate()
- {
- }
- template <class _CharT>
- int
- collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
- const char_type* __lo2, const char_type* __hi2) const
- {
- for (; __lo2 != __hi2; ++__lo1, ++__lo2)
- {
- if (__lo1 == __hi1 || *__lo1 < *__lo2)
- return -1;
- if (*__lo2 < *__lo1)
- return 1;
- }
- return __lo1 != __hi1;
- }
- template <class _CharT>
- long
- collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
- {
- size_t __h = 0;
- const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
- const size_t __mask = size_t(0xF) << (__sr + 4);
- for(const char_type* __p = __lo; __p != __hi; ++__p)
- {
- __h = (__h << 4) + static_cast<size_t>(*__p);
- size_t __g = __h & __mask;
- __h ^= __g | (__g >> __sr);
- }
- return static_cast<long>(__h);
- }
- _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS collate<char>)
- _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS collate<wchar_t>)
- // template <class CharT> class collate_byname;
- template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY collate_byname;
- template <>
- class _LIBCPP_TYPE_VIS collate_byname<char>
- : public collate<char>
- {
- locale_t __l;
- public:
- typedef char char_type;
- typedef basic_string<char_type> string_type;
- explicit collate_byname(const char* __n, size_t __refs = 0);
- explicit collate_byname(const string& __n, size_t __refs = 0);
- protected:
- ~collate_byname();
- virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
- const char_type* __lo2, const char_type* __hi2) const;
- virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
- };
- template <>
- class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
- : public collate<wchar_t>
- {
- locale_t __l;
- public:
- typedef wchar_t char_type;
- typedef basic_string<char_type> string_type;
- explicit collate_byname(const char* __n, size_t __refs = 0);
- explicit collate_byname(const string& __n, size_t __refs = 0);
- protected:
- ~collate_byname();
- virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
- const char_type* __lo2, const char_type* __hi2) const;
- virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
- };
- template <class _CharT, class _Traits, class _Allocator>
- bool
- locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
- const basic_string<_CharT, _Traits, _Allocator>& __y) const
- {
- return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
- __x.data(), __x.data() + __x.size(),
- __y.data(), __y.data() + __y.size()) < 0;
- }
- // template <class charT> class ctype
- class _LIBCPP_TYPE_VIS ctype_base
- {
- public:
- #if defined(__GLIBC__)
- typedef unsigned short mask;
- static const mask space = _ISspace;
- static const mask print = _ISprint;
- static const mask cntrl = _IScntrl;
- static const mask upper = _ISupper;
- static const mask lower = _ISlower;
- static const mask alpha = _ISalpha;
- static const mask digit = _ISdigit;
- static const mask punct = _ISpunct;
- static const mask xdigit = _ISxdigit;
- static const mask blank = _ISblank;
- #elif defined(_WIN32)
- typedef unsigned short mask;
- static const mask space = _SPACE;
- static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT;
- static const mask cntrl = _CONTROL;
- static const mask upper = _UPPER;
- static const mask lower = _LOWER;
- static const mask alpha = _ALPHA;
- static const mask digit = _DIGIT;
- static const mask punct = _PUNCT;
- static const mask xdigit = _HEX;
- static const mask blank = _BLANK;
- # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
- #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
- # ifdef __APPLE__
- typedef __uint32_t mask;
- # elif defined(__FreeBSD__)
- typedef unsigned long mask;
- # elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
- typedef unsigned short mask;
- # endif
- static const mask space = _CTYPE_S;
- static const mask print = _CTYPE_R;
- static const mask cntrl = _CTYPE_C;
- static const mask upper = _CTYPE_U;
- static const mask lower = _CTYPE_L;
- static const mask alpha = _CTYPE_A;
- static const mask digit = _CTYPE_D;
- static const mask punct = _CTYPE_P;
- static const mask xdigit = _CTYPE_X;
- # if defined(__NetBSD__)
- static const mask blank = _CTYPE_BL;
- # else
- static const mask blank = _CTYPE_B;
- # endif
- #elif defined(__sun__) || defined(_AIX)
- typedef unsigned int mask;
- static const mask space = _ISSPACE;
- static const mask print = _ISPRINT;
- static const mask cntrl = _ISCNTRL;
- static const mask upper = _ISUPPER;
- static const mask lower = _ISLOWER;
- static const mask alpha = _ISALPHA;
- static const mask digit = _ISDIGIT;
- static const mask punct = _ISPUNCT;
- static const mask xdigit = _ISXDIGIT;
- static const mask blank = _ISBLANK;
- #elif defined(_NEWLIB_VERSION)
- // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
- typedef char mask;
- static const mask space = _S;
- static const mask print = _P | _U | _L | _N | _B;
- static const mask cntrl = _C;
- static const mask upper = _U;
- static const mask lower = _L;
- static const mask alpha = _U | _L;
- static const mask digit = _N;
- static const mask punct = _P;
- static const mask xdigit = _X | _N;
- static const mask blank = _B;
- # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
- # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
- # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
- #else
- typedef unsigned long mask;
- static const mask space = 1<<0;
- static const mask print = 1<<1;
- static const mask cntrl = 1<<2;
- static const mask upper = 1<<3;
- static const mask lower = 1<<4;
- static const mask alpha = 1<<5;
- static const mask digit = 1<<6;
- static const mask punct = 1<<7;
- static const mask xdigit = 1<<8;
- static const mask blank = 1<<9;
- #endif
- static const mask alnum = alpha | digit;
- static const mask graph = alnum | punct;
- _LIBCPP_ALWAYS_INLINE ctype_base() {}
- };
- template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY ctype;
- template <>
- class _LIBCPP_TYPE_VIS ctype<wchar_t>
- : public locale::facet,
- public ctype_base
- {
- public:
- typedef wchar_t char_type;
- _LIBCPP_ALWAYS_INLINE
- explicit ctype(size_t __refs = 0)
- : locale::facet(__refs) {}
- _LIBCPP_ALWAYS_INLINE
- bool is(mask __m, char_type __c) const
- {
- return do_is(__m, __c);
- }
- _LIBCPP_ALWAYS_INLINE
- const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
- {
- return do_is(__low, __high, __vec);
- }
- _LIBCPP_ALWAYS_INLINE
- const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
- {
- return do_scan_is(__m, __low, __high);
- }
- _LIBCPP_ALWAYS_INLINE
- const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
- {
- return do_scan_not(__m, __low, __high);
- }
- _LIBCPP_ALWAYS_INLINE
- char_type toupper(char_type __c) const
- {
- return do_toupper(__c);
- }
- _LIBCPP_ALWAYS_INLINE
- const char_type* toupper(char_type* __low, const char_type* __high) const
- {
- return do_toupper(__low, __high);
- }
- _LIBCPP_ALWAYS_INLINE
- char_type tolower(char_type __c) const
- {
- return do_tolower(__c);
- }
- _LIBCPP_ALWAYS_INLINE
- const char_type* tolower(char_type* __low, const char_type* __high) const
- {
- return do_tolower(__low, __high);
- }
- _LIBCPP_ALWAYS_INLINE
- char_type widen(char __c) const
- {
- return do_widen(__c);
- }
- _LIBCPP_ALWAYS_INLINE
- const char* widen(const char* __low, const char* __high, char_type* __to) const
- {
- return do_widen(__low, __high, __to);
- }
- _LIBCPP_ALWAYS_INLINE
- char narrow(char_type __c, char __dfault) const
- {
- return do_narrow(__c, __dfault);
- }
- _LIBCPP_ALWAYS_INLINE
- const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
- {
- return do_narrow(__low, __high, __dfault, __to);
- }
- static locale::id id;
- protected:
- ~ctype();
- virtual bool do_is(mask __m, char_type __c) const;
- virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
- virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
- virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
- virtual char_type do_toupper(char_type) const;
- virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
- virtual char_type do_tolower(char_type) const;
- virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
- virtual char_type do_widen(char) const;
- virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
- virtual char do_narrow(char_type, char __dfault) const;
- virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
- };
- template <>
- class _LIBCPP_TYPE_VIS ctype<char>
- : public locale::facet, public ctype_base
- {
- const mask* __tab_;
- bool __del_;
- public:
- typedef char char_type;
- explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
- _LIBCPP_ALWAYS_INLINE
- bool is(mask __m, char_type __c) const
- {
- return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false;
- }
- _LIBCPP_ALWAYS_INLINE
- const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
- {
- for (; __low != __high; ++__low, ++__vec)
- *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
- return __low;
- }
- _LIBCPP_ALWAYS_INLINE
- const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
- {
- for (; __low != __high; ++__low)
- if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
- break;
- return __low;
- }
- _LIBCPP_ALWAYS_INLINE
- const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
- {
- for (; __low != __high; ++__low)
- if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)))
- break;
- return __low;
- }
- _LIBCPP_ALWAYS_INLINE
- char_type toupper(char_type __c) const
- {
- return do_toupper(__c);
- }
- _LIBCPP_ALWAYS_INLINE
- const char_type* toupper(char_type* __low, const char_type* __high) const
- {
- return do_toupper(__low, __high);
- }
- _LIBCPP_ALWAYS_INLINE
- char_type tolower(char_type __c) const
- {
- return do_tolower(__c);
- }
- _LIBCPP_ALWAYS_INLINE
- const char_type* tolower(char_type* __low, const char_type* __high) const
- {
- return do_tolower(__low, __high);
- }
- _LIBCPP_ALWAYS_INLINE
- char_type widen(char __c) const
- {
- return do_widen(__c);
- }
- _LIBCPP_ALWAYS_INLINE
- const char* widen(const char* __low, const char* __high, char_type* __to) const
- {
- return do_widen(__low, __high, __to);
- }
- _LIBCPP_ALWAYS_INLINE
- char narrow(char_type __c, char __dfault) const
- {
- return do_narrow(__c, __dfault);
- }
- _LIBCPP_ALWAYS_INLINE
- const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
- {
- return do_narrow(__low, __high, __dfault, __to);
- }
- static locale::id id;
- #ifdef _CACHED_RUNES
- static const size_t table_size = _CACHED_RUNES;
- #else
- static const size_t table_size = 256; // FIXME: Don't hardcode this.
- #endif
- _LIBCPP_ALWAYS_INLINE const mask* table() const _NOEXCEPT {return __tab_;}
- static const mask* classic_table() _NOEXCEPT;
- #if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
- static const int* __classic_upper_table() _NOEXCEPT;
- static const int* __classic_lower_table() _NOEXCEPT;
- #endif
- #if defined(__NetBSD__)
- static const short* __classic_upper_table() _NOEXCEPT;
- static const short* __classic_lower_table() _NOEXCEPT;
- #endif
- protected:
- ~ctype();
- virtual char_type do_toupper(char_type __c) const;
- virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
- virtual char_type do_tolower(char_type __c) const;
- virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
- virtual char_type do_widen(char __c) const;
- virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
- virtual char do_narrow(char_type __c, char __dfault) const;
- virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
- };
- // template <class CharT> class ctype_byname;
- template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY ctype_byname;
- template <>
- class _LIBCPP_TYPE_VIS ctype_byname<char>
- : public ctype<char>
- {
- locale_t __l;
- public:
- explicit ctype_byname(const char*, size_t = 0);
- explicit ctype_byname(const string&, size_t = 0);
- protected:
- ~ctype_byname();
- virtual char_type do_toupper(char_type) const;
- virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
- virtual char_type do_tolower(char_type) const;
- virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
- };
- template <>
- class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
- : public ctype<wchar_t>
- {
- locale_t __l;
- public:
- explicit ctype_byname(const char*, size_t = 0);
- explicit ctype_byname(const string&, size_t = 0);
- protected:
- ~ctype_byname();
- virtual bool do_is(mask __m, char_type __c) const;
- virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
- virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
- virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
- virtual char_type do_toupper(char_type) const;
- virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
- virtual char_type do_tolower(char_type) const;
- virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
- virtual char_type do_widen(char) const;
- virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
- virtual char do_narrow(char_type, char __dfault) const;
- virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
- };
- template <class _CharT>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- isspace(_CharT __c, const locale& __loc)
- {
- return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
- }
- template <class _CharT>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- isprint(_CharT __c, const locale& __loc)
- {
- return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
- }
- template <class _CharT>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- iscntrl(_CharT __c, const locale& __loc)
- {
- return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
- }
- template <class _CharT>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- isupper(_CharT __c, const locale& __loc)
- {
- return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
- }
- template <class _CharT>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- islower(_CharT __c, const locale& __loc)
- {
- return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
- }
- template <class _CharT>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- isalpha(_CharT __c, const locale& __loc)
- {
- return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
- }
- template <class _CharT>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- isdigit(_CharT __c, const locale& __loc)
- {
- return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
- }
- template <class _CharT>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- ispunct(_CharT __c, const locale& __loc)
- {
- return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
- }
- template <class _CharT>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- isxdigit(_CharT __c, const locale& __loc)
- {
- return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
- }
- template <class _CharT>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- isalnum(_CharT __c, const locale& __loc)
- {
- return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
- }
- template <class _CharT>
- inline _LIBCPP_INLINE_VISIBILITY
- bool
- isgraph(_CharT __c, const locale& __loc)
- {
- return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
- }
- template <class _CharT>
- inline _LIBCPP_INLINE_VISIBILITY
- _CharT
- toupper(_CharT __c, const locale& __loc)
- {
- return use_facet<ctype<_CharT> >(__loc).toupper(__c);
- }
- template <class _CharT>
- inline _LIBCPP_INLINE_VISIBILITY
- _CharT
- tolower(_CharT __c, const locale& __loc)
- {
- return use_facet<ctype<_CharT> >(__loc).tolower(__c);
- }
- // codecvt_base
- class _LIBCPP_TYPE_VIS codecvt_base
- {
- public:
- _LIBCPP_ALWAYS_INLINE codecvt_base() {}
- enum result {ok, partial, error, noconv};
- };
- // template <class internT, class externT, class stateT> class codecvt;
- template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TYPE_VIS_ONLY codecvt;
- // template <> class codecvt<char, char, mbstate_t>
- template <>
- class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
- : public locale::facet,
- public codecvt_base
- {
- public:
- typedef char intern_type;
- typedef char extern_type;
- typedef mbstate_t state_type;
- _LIBCPP_ALWAYS_INLINE
- explicit codecvt(size_t __refs = 0)
- : locale::facet(__refs) {}
- _LIBCPP_ALWAYS_INLINE
- result out(state_type& __st,
- const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
- {
- return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
- }
- _LIBCPP_ALWAYS_INLINE
- result unshift(state_type& __st,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
- {
- return do_unshift(__st, __to, __to_end, __to_nxt);
- }
- _LIBCPP_ALWAYS_INLINE
- result in(state_type& __st,
- const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
- intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
- {
- return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
- }
- _LIBCPP_ALWAYS_INLINE
- int encoding() const _NOEXCEPT
- {
- return do_encoding();
- }
- _LIBCPP_ALWAYS_INLINE
- bool always_noconv() const _NOEXCEPT
- {
- return do_always_noconv();
- }
- _LIBCPP_ALWAYS_INLINE
- int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
- {
- return do_length(__st, __frm, __end, __mx);
- }
- _LIBCPP_ALWAYS_INLINE
- int max_length() const _NOEXCEPT
- {
- return do_max_length();
- }
- static locale::id id;
- protected:
- _LIBCPP_ALWAYS_INLINE
- explicit codecvt(const char*, size_t __refs = 0)
- : locale::facet(__refs) {}
- ~codecvt();
- virtual result do_out(state_type& __st,
- const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
- virtual result do_in(state_type& __st,
- const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
- intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
- virtual result do_unshift(state_type& __st,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
- virtual int do_encoding() const _NOEXCEPT;
- virtual bool do_always_noconv() const _NOEXCEPT;
- virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
- virtual int do_max_length() const _NOEXCEPT;
- };
- // template <> class codecvt<wchar_t, char, mbstate_t>
- template <>
- class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
- : public locale::facet,
- public codecvt_base
- {
- locale_t __l;
- public:
- typedef wchar_t intern_type;
- typedef char extern_type;
- typedef mbstate_t state_type;
- explicit codecvt(size_t __refs = 0);
- _LIBCPP_ALWAYS_INLINE
- result out(state_type& __st,
- const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
- {
- return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
- }
- _LIBCPP_ALWAYS_INLINE
- result unshift(state_type& __st,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
- {
- return do_unshift(__st, __to, __to_end, __to_nxt);
- }
- _LIBCPP_ALWAYS_INLINE
- result in(state_type& __st,
- const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
- intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
- {
- return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
- }
- _LIBCPP_ALWAYS_INLINE
- int encoding() const _NOEXCEPT
- {
- return do_encoding();
- }
- _LIBCPP_ALWAYS_INLINE
- bool always_noconv() const _NOEXCEPT
- {
- return do_always_noconv();
- }
- _LIBCPP_ALWAYS_INLINE
- int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
- {
- return do_length(__st, __frm, __end, __mx);
- }
- _LIBCPP_ALWAYS_INLINE
- int max_length() const _NOEXCEPT
- {
- return do_max_length();
- }
- static locale::id id;
- protected:
- explicit codecvt(const char*, size_t __refs = 0);
- ~codecvt();
- virtual result do_out(state_type& __st,
- const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
- virtual result do_in(state_type& __st,
- const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
- intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
- virtual result do_unshift(state_type& __st,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
- virtual int do_encoding() const _NOEXCEPT;
- virtual bool do_always_noconv() const _NOEXCEPT;
- virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
- virtual int do_max_length() const _NOEXCEPT;
- };
- // template <> class codecvt<char16_t, char, mbstate_t>
- template <>
- class _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
- : public locale::facet,
- public codecvt_base
- {
- public:
- typedef char16_t intern_type;
- typedef char extern_type;
- typedef mbstate_t state_type;
- _LIBCPP_ALWAYS_INLINE
- explicit codecvt(size_t __refs = 0)
- : locale::facet(__refs) {}
- _LIBCPP_ALWAYS_INLINE
- result out(state_type& __st,
- const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
- {
- return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
- }
- _LIBCPP_ALWAYS_INLINE
- result unshift(state_type& __st,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
- {
- return do_unshift(__st, __to, __to_end, __to_nxt);
- }
- _LIBCPP_ALWAYS_INLINE
- result in(state_type& __st,
- const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
- intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
- {
- return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
- }
- _LIBCPP_ALWAYS_INLINE
- int encoding() const _NOEXCEPT
- {
- return do_encoding();
- }
- _LIBCPP_ALWAYS_INLINE
- bool always_noconv() const _NOEXCEPT
- {
- return do_always_noconv();
- }
- _LIBCPP_ALWAYS_INLINE
- int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
- {
- return do_length(__st, __frm, __end, __mx);
- }
- _LIBCPP_ALWAYS_INLINE
- int max_length() const _NOEXCEPT
- {
- return do_max_length();
- }
- static locale::id id;
- protected:
- _LIBCPP_ALWAYS_INLINE
- explicit codecvt(const char*, size_t __refs = 0)
- : locale::facet(__refs) {}
- ~codecvt();
- virtual result do_out(state_type& __st,
- const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
- virtual result do_in(state_type& __st,
- const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
- intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
- virtual result do_unshift(state_type& __st,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
- virtual int do_encoding() const _NOEXCEPT;
- virtual bool do_always_noconv() const _NOEXCEPT;
- virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
- virtual int do_max_length() const _NOEXCEPT;
- };
- // template <> class codecvt<char32_t, char, mbstate_t>
- template <>
- class _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
- : public locale::facet,
- public codecvt_base
- {
- public:
- typedef char32_t intern_type;
- typedef char extern_type;
- typedef mbstate_t state_type;
- _LIBCPP_ALWAYS_INLINE
- explicit codecvt(size_t __refs = 0)
- : locale::facet(__refs) {}
- _LIBCPP_ALWAYS_INLINE
- result out(state_type& __st,
- const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
- {
- return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
- }
- _LIBCPP_ALWAYS_INLINE
- result unshift(state_type& __st,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
- {
- return do_unshift(__st, __to, __to_end, __to_nxt);
- }
- _LIBCPP_ALWAYS_INLINE
- result in(state_type& __st,
- const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
- intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
- {
- return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
- }
- _LIBCPP_ALWAYS_INLINE
- int encoding() const _NOEXCEPT
- {
- return do_encoding();
- }
- _LIBCPP_ALWAYS_INLINE
- bool always_noconv() const _NOEXCEPT
- {
- return do_always_noconv();
- }
- _LIBCPP_ALWAYS_INLINE
- int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
- {
- return do_length(__st, __frm, __end, __mx);
- }
- _LIBCPP_ALWAYS_INLINE
- int max_length() const _NOEXCEPT
- {
- return do_max_length();
- }
- static locale::id id;
- protected:
- _LIBCPP_ALWAYS_INLINE
- explicit codecvt(const char*, size_t __refs = 0)
- : locale::facet(__refs) {}
- ~codecvt();
- virtual result do_out(state_type& __st,
- const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
- virtual result do_in(state_type& __st,
- const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
- intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
- virtual result do_unshift(state_type& __st,
- extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
- virtual int do_encoding() const _NOEXCEPT;
- virtual bool do_always_noconv() const _NOEXCEPT;
- virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
- virtual int do_max_length() const _NOEXCEPT;
- };
- // template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
- template <class _InternT, class _ExternT, class _StateT>
- class _LIBCPP_TYPE_VIS_ONLY codecvt_byname
- : public codecvt<_InternT, _ExternT, _StateT>
- {
- public:
- _LIBCPP_ALWAYS_INLINE
- explicit codecvt_byname(const char* __nm, size_t __refs = 0)
- : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
- _LIBCPP_ALWAYS_INLINE
- explicit codecvt_byname(const string& __nm, size_t __refs = 0)
- : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
- protected:
- ~codecvt_byname();
- };
- template <class _InternT, class _ExternT, class _StateT>
- codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
- {
- }
- _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<char, char, mbstate_t>)
- _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>)
- _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>)
- _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>)
- _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
- template <size_t _Np>
- struct __narrow_to_utf8
- {
- template <class _OutputIterator, class _CharT>
- _OutputIterator
- operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
- };
- template <>
- struct __narrow_to_utf8<8>
- {
- template <class _OutputIterator, class _CharT>
- _LIBCPP_ALWAYS_INLINE
- _OutputIterator
- operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
- {
- for (; __wb < __we; ++__wb, ++__s)
- *__s = *__wb;
- return __s;
- }
- };
- template <>
- struct __narrow_to_utf8<16>
- : public codecvt<char16_t, char, mbstate_t>
- {
- _LIBCPP_ALWAYS_INLINE
- __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
- ~__narrow_to_utf8();
- template <class _OutputIterator, class _CharT>
- _LIBCPP_ALWAYS_INLINE
- _OutputIterator
- operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
- {
- result __r = ok;
- mbstate_t __mb;
- while (__wb < __we && __r != error)
- {
- const int __sz = 32;
- char __buf[__sz];
- char* __bn;
- const char16_t* __wn = (const char16_t*)__wb;
- __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
- __buf, __buf+__sz, __bn);
- if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
- __throw_runtime_error("locale not supported");
- for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
- *__s = *__p;
- __wb = (const _CharT*)__wn;
- }
- return __s;
- }
- };
- template <>
- struct __narrow_to_utf8<32>
- : public codecvt<char32_t, char, mbstate_t>
- {
- _LIBCPP_ALWAYS_INLINE
- __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
- ~__narrow_to_utf8();
- template <class _OutputIterator, class _CharT>
- _LIBCPP_ALWAYS_INLINE
- _OutputIterator
- operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
- {
- result __r = ok;
- mbstate_t __mb;
- while (__wb < __we && __r != error)
- {
- const int __sz = 32;
- char __buf[__sz];
- char* __bn;
- const char32_t* __wn = (const char32_t*)__wb;
- __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
- __buf, __buf+__sz, __bn);
- if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
- __throw_runtime_error("locale not supported");
- for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
- *__s = *__p;
- __wb = (const _CharT*)__wn;
- }
- return __s;
- }
- };
- template <size_t _Np>
- struct __widen_from_utf8
- {
- template <class _OutputIterator>
- _OutputIterator
- operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
- };
- template <>
- struct __widen_from_utf8<8>
- {
- template <class _OutputIterator>
- _LIBCPP_ALWAYS_INLINE
- _OutputIterator
- operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
- {
- for (; __nb < __ne; ++__nb, ++__s)
- *__s = *__nb;
- return __s;
- }
- };
- template <>
- struct __widen_from_utf8<16>
- : public codecvt<char16_t, char, mbstate_t>
- {
- _LIBCPP_ALWAYS_INLINE
- __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
- ~__widen_from_utf8();
- template <class _OutputIterator>
- _LIBCPP_ALWAYS_INLINE
- _OutputIterator
- operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
- {
- result __r = ok;
- mbstate_t __mb;
- while (__nb < __ne && __r != error)
- {
- const int __sz = 32;
- char16_t __buf[__sz];
- char16_t* __bn;
- const char* __nn = __nb;
- __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
- __buf, __buf+__sz, __bn);
- if (__r == codecvt_base::error || __nn == __nb)
- __throw_runtime_error("locale not supported");
- for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
- *__s = (wchar_t)*__p;
- __nb = __nn;
- }
- return __s;
- }
- };
- template <>
- struct __widen_from_utf8<32>
- : public codecvt<char32_t, char, mbstate_t>
- {
- _LIBCPP_ALWAYS_INLINE
- __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
- ~__widen_from_utf8();
- template <class _OutputIterator>
- _LIBCPP_ALWAYS_INLINE
- _OutputIterator
- operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
- {
- result __r = ok;
- mbstate_t __mb;
- while (__nb < __ne && __r != error)
- {
- const int __sz = 32;
- char32_t __buf[__sz];
- char32_t* __bn;
- const char* __nn = __nb;
- __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
- __buf, __buf+__sz, __bn);
- if (__r == codecvt_base::error || __nn == __nb)
- __throw_runtime_error("locale not supported");
- for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
- *__s = (wchar_t)*__p;
- __nb = __nn;
- }
- return __s;
- }
- };
- // template <class charT> class numpunct
- template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY numpunct;
- template <>
- class _LIBCPP_TYPE_VIS numpunct<char>
- : public locale::facet
- {
- public:
- typedef char char_type;
- typedef basic_string<char_type> string_type;
- explicit numpunct(size_t __refs = 0);
- _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
- _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
- _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();}
- _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();}
- _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();}
- static locale::id id;
- protected:
- ~numpunct();
- virtual char_type do_decimal_point() const;
- virtual char_type do_thousands_sep() const;
- virtual string do_grouping() const;
- virtual string_type do_truename() const;
- virtual string_type do_falsename() const;
- char_type __decimal_point_;
- char_type __thousands_sep_;
- string __grouping_;
- };
- template <>
- class _LIBCPP_TYPE_VIS numpunct<wchar_t>
- : public locale::facet
- {
- public:
- typedef wchar_t char_type;
- typedef basic_string<char_type> string_type;
- explicit numpunct(size_t __refs = 0);
- _LIBCPP_ALWAYS_INLINE char_type decimal_point() const {return do_decimal_point();}
- _LIBCPP_ALWAYS_INLINE char_type thousands_sep() const {return do_thousands_sep();}
- _LIBCPP_ALWAYS_INLINE string grouping() const {return do_grouping();}
- _LIBCPP_ALWAYS_INLINE string_type truename() const {return do_truename();}
- _LIBCPP_ALWAYS_INLINE string_type falsename() const {return do_falsename();}
- static locale::id id;
- protected:
- ~numpunct();
- virtual char_type do_decimal_point() const;
- virtual char_type do_thousands_sep() const;
- virtual string do_grouping() const;
- virtual string_type do_truename() const;
- virtual string_type do_falsename() const;
- char_type __decimal_point_;
- char_type __thousands_sep_;
- string __grouping_;
- };
- // template <class charT> class numpunct_byname
- template <class _CharT> class _LIBCPP_TYPE_VIS_ONLY numpunct_byname;
- template <>
- class _LIBCPP_TYPE_VIS numpunct_byname<char>
- : public numpunct<char>
- {
- public:
- typedef char char_type;
- typedef basic_string<char_type> string_type;
- explicit numpunct_byname(const char* __nm, size_t __refs = 0);
- explicit numpunct_byname(const string& __nm, size_t __refs = 0);
- protected:
- ~numpunct_byname();
- private:
- void __init(const char*);
- };
- template <>
- class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
- : public numpunct<wchar_t>
- {
- public:
- typedef wchar_t char_type;
- typedef basic_string<char_type> string_type;
- explicit numpunct_byname(const char* __nm, size_t __refs = 0);
- explicit numpunct_byname(const string& __nm, size_t __refs = 0);
- protected:
- ~numpunct_byname();
- private:
- void __init(const char*);
- };
- _LIBCPP_END_NAMESPACE_STD
- #endif // !defined(_LIBCPP_SGX_CONFIG)
- #endif // _LIBCPP___LOCALE
|