__locale 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP___LOCALE
  10. #define _LIBCPP___LOCALE
  11. #include <__availability>
  12. #include <__config>
  13. #include <__memory/shared_ptr.h> // __shared_count
  14. #include <__mutex/once_flag.h>
  15. #include <__type_traits/make_unsigned.h>
  16. #include <atomic>
  17. #include <cctype>
  18. #include <clocale>
  19. #include <cstdint>
  20. #include <cstdlib>
  21. #include <string>
  22. // Some platforms require more includes than others. Keep the includes on all plaforms for now.
  23. #include <cstddef>
  24. #include <cstring>
  25. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  26. # include <cwchar>
  27. #else
  28. # include <__std_mbstate_t.h>
  29. #endif
  30. #if defined(_LIBCPP_MSVCRT_LIKE)
  31. # include <__support/win32/locale_win32.h>
  32. #elif defined(_AIX) || defined(__MVS__)
  33. # include <__support/ibm/xlocale.h>
  34. #elif defined(__ANDROID__)
  35. # include <__support/android/locale_bionic.h>
  36. #elif defined(_NEWLIB_VERSION)
  37. # include <__support/newlib/xlocale.h>
  38. #elif defined(__OpenBSD__)
  39. # include <__support/openbsd/xlocale.h>
  40. #elif (defined(__APPLE__) || defined(__FreeBSD__))
  41. # include <xlocale.h>
  42. #elif defined(__Fuchsia__)
  43. # include <__support/fuchsia/xlocale.h>
  44. #elif defined(__wasi__)
  45. // WASI libc uses musl's locales support.
  46. # include <__support/musl/xlocale.h>
  47. #elif defined(_LIBCPP_HAS_MUSL_LIBC)
  48. # include <__support/musl/xlocale.h>
  49. #endif
  50. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  51. # pragma GCC system_header
  52. #endif
  53. _LIBCPP_BEGIN_NAMESPACE_STD
  54. class _LIBCPP_EXPORTED_FROM_ABI locale;
  55. template <class _Facet>
  56. _LIBCPP_INLINE_VISIBILITY
  57. bool
  58. has_facet(const locale&) _NOEXCEPT;
  59. template <class _Facet>
  60. _LIBCPP_INLINE_VISIBILITY
  61. const _Facet&
  62. use_facet(const locale&);
  63. class _LIBCPP_EXPORTED_FROM_ABI locale
  64. {
  65. public:
  66. // types:
  67. class _LIBCPP_EXPORTED_FROM_ABI facet;
  68. class _LIBCPP_EXPORTED_FROM_ABI id;
  69. typedef int category;
  70. _LIBCPP_AVAILABILITY_LOCALE_CATEGORY
  71. static const category // values assigned here are for exposition only
  72. none = 0,
  73. collate = LC_COLLATE_MASK,
  74. ctype = LC_CTYPE_MASK,
  75. monetary = LC_MONETARY_MASK,
  76. numeric = LC_NUMERIC_MASK,
  77. time = LC_TIME_MASK,
  78. messages = LC_MESSAGES_MASK,
  79. all = collate | ctype | monetary | numeric | time | messages;
  80. // construct/copy/destroy:
  81. locale() _NOEXCEPT;
  82. locale(const locale&) _NOEXCEPT;
  83. explicit locale(const char*);
  84. explicit locale(const string&);
  85. locale(const locale&, const char*, category);
  86. locale(const locale&, const string&, category);
  87. template <class _Facet>
  88. _LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
  89. locale(const locale&, const locale&, category);
  90. ~locale();
  91. const locale& operator=(const locale&) _NOEXCEPT;
  92. template <class _Facet>
  93. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  94. locale combine(const locale&) const;
  95. // locale operations:
  96. string name() const;
  97. bool operator==(const locale&) const;
  98. #if _LIBCPP_STD_VER <= 17
  99. _LIBCPP_HIDE_FROM_ABI bool operator!=(const locale& __y) const {return !(*this == __y);}
  100. #endif
  101. template <class _CharT, class _Traits, class _Allocator>
  102. _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
  103. bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
  104. const basic_string<_CharT, _Traits, _Allocator>&) const;
  105. // global locale objects:
  106. static locale global(const locale&);
  107. static const locale& classic();
  108. private:
  109. class __imp;
  110. __imp* __locale_;
  111. void __install_ctor(const locale&, facet*, long);
  112. static locale& __global();
  113. bool has_facet(id&) const;
  114. 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&);
  117. };
  118. class _LIBCPP_EXPORTED_FROM_ABI locale::facet
  119. : public __shared_count
  120. {
  121. protected:
  122. _LIBCPP_INLINE_VISIBILITY
  123. explicit facet(size_t __refs = 0)
  124. : __shared_count(static_cast<long>(__refs)-1) {}
  125. ~facet() override;
  126. // facet(const facet&) = delete; // effectively done in __shared_count
  127. // void operator=(const facet&) = delete;
  128. private:
  129. void __on_zero_shared() _NOEXCEPT override;
  130. };
  131. class _LIBCPP_EXPORTED_FROM_ABI locale::id
  132. {
  133. std::atomic<int32_t> __id_;
  134. static int32_t __next_id;
  135. public:
  136. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
  137. void operator=(const id&) = delete;
  138. id(const id&) = delete;
  139. public: // only needed for tests
  140. long __get();
  141. friend class locale;
  142. friend class locale::__imp;
  143. };
  144. template <class _Facet>
  145. inline _LIBCPP_INLINE_VISIBILITY
  146. locale::locale(const locale& __other, _Facet* __f)
  147. {
  148. __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
  149. }
  150. template <class _Facet>
  151. locale
  152. locale::combine(const locale& __other) const
  153. {
  154. if (!_VSTD::has_facet<_Facet>(__other))
  155. __throw_runtime_error("locale::combine: locale missing facet");
  156. return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
  157. }
  158. template <class _Facet>
  159. inline _LIBCPP_INLINE_VISIBILITY
  160. bool
  161. has_facet(const locale& __l) _NOEXCEPT
  162. {
  163. return __l.has_facet(_Facet::id);
  164. }
  165. template <class _Facet>
  166. inline _LIBCPP_INLINE_VISIBILITY
  167. const _Facet&
  168. use_facet(const locale& __l)
  169. {
  170. return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
  171. }
  172. // template <class _CharT> class collate;
  173. template <class _CharT>
  174. class _LIBCPP_TEMPLATE_VIS collate
  175. : public locale::facet
  176. {
  177. public:
  178. typedef _CharT char_type;
  179. typedef basic_string<char_type> string_type;
  180. _LIBCPP_INLINE_VISIBILITY
  181. explicit collate(size_t __refs = 0)
  182. : locale::facet(__refs) {}
  183. _LIBCPP_INLINE_VISIBILITY
  184. int compare(const char_type* __lo1, const char_type* __hi1,
  185. const char_type* __lo2, const char_type* __hi2) const
  186. {
  187. return do_compare(__lo1, __hi1, __lo2, __hi2);
  188. }
  189. // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work
  190. // around a dllimport bug that expects an external instantiation.
  191. _LIBCPP_INLINE_VISIBILITY
  192. _LIBCPP_ALWAYS_INLINE
  193. string_type transform(const char_type* __lo, const char_type* __hi) const
  194. {
  195. return do_transform(__lo, __hi);
  196. }
  197. _LIBCPP_INLINE_VISIBILITY
  198. long hash(const char_type* __lo, const char_type* __hi) const
  199. {
  200. return do_hash(__lo, __hi);
  201. }
  202. static locale::id id;
  203. protected:
  204. ~collate() override;
  205. virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
  206. const char_type* __lo2, const char_type* __hi2) const;
  207. virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
  208. {return string_type(__lo, __hi);}
  209. virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
  210. };
  211. template <class _CharT> locale::id collate<_CharT>::id;
  212. template <class _CharT>
  213. collate<_CharT>::~collate()
  214. {
  215. }
  216. template <class _CharT>
  217. int
  218. collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
  219. const char_type* __lo2, const char_type* __hi2) const
  220. {
  221. for (; __lo2 != __hi2; ++__lo1, ++__lo2)
  222. {
  223. if (__lo1 == __hi1 || *__lo1 < *__lo2)
  224. return -1;
  225. if (*__lo2 < *__lo1)
  226. return 1;
  227. }
  228. return __lo1 != __hi1;
  229. }
  230. template <class _CharT>
  231. long
  232. collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
  233. {
  234. size_t __h = 0;
  235. const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
  236. const size_t __mask = size_t(0xF) << (__sr + 4);
  237. for(const char_type* __p = __lo; __p != __hi; ++__p)
  238. {
  239. __h = (__h << 4) + static_cast<size_t>(*__p);
  240. size_t __g = __h & __mask;
  241. __h ^= __g | (__g >> __sr);
  242. }
  243. return static_cast<long>(__h);
  244. }
  245. extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>;
  246. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  247. extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>;
  248. #endif
  249. // template <class CharT> class collate_byname;
  250. template <class _CharT> class _LIBCPP_TEMPLATE_VIS collate_byname;
  251. template <>
  252. class _LIBCPP_EXPORTED_FROM_ABI collate_byname<char>
  253. : public collate<char>
  254. {
  255. locale_t __l_;
  256. public:
  257. typedef char char_type;
  258. typedef basic_string<char_type> string_type;
  259. explicit collate_byname(const char* __n, size_t __refs = 0);
  260. explicit collate_byname(const string& __n, size_t __refs = 0);
  261. protected:
  262. ~collate_byname() override;
  263. int do_compare(const char_type* __lo1, const char_type* __hi1,
  264. const char_type* __lo2, const char_type* __hi2) const override;
  265. string_type do_transform(const char_type* __lo, const char_type* __hi) const override;
  266. };
  267. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  268. template <>
  269. class _LIBCPP_EXPORTED_FROM_ABI collate_byname<wchar_t>
  270. : public collate<wchar_t>
  271. {
  272. locale_t __l_;
  273. public:
  274. typedef wchar_t char_type;
  275. typedef basic_string<char_type> string_type;
  276. explicit collate_byname(const char* __n, size_t __refs = 0);
  277. explicit collate_byname(const string& __n, size_t __refs = 0);
  278. protected:
  279. ~collate_byname() override;
  280. int do_compare(const char_type* __lo1, const char_type* __hi1,
  281. const char_type* __lo2, const char_type* __hi2) const override;
  282. string_type do_transform(const char_type* __lo, const char_type* __hi) const override;
  283. };
  284. #endif
  285. template <class _CharT, class _Traits, class _Allocator>
  286. bool
  287. locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
  288. const basic_string<_CharT, _Traits, _Allocator>& __y) const
  289. {
  290. return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
  291. __x.data(), __x.data() + __x.size(),
  292. __y.data(), __y.data() + __y.size()) < 0;
  293. }
  294. // template <class charT> class ctype
  295. class _LIBCPP_EXPORTED_FROM_ABI ctype_base
  296. {
  297. public:
  298. #if defined(_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE)
  299. typedef unsigned long mask;
  300. static const mask space = 1<<0;
  301. static const mask print = 1<<1;
  302. static const mask cntrl = 1<<2;
  303. static const mask upper = 1<<3;
  304. static const mask lower = 1<<4;
  305. static const mask alpha = 1<<5;
  306. static const mask digit = 1<<6;
  307. static const mask punct = 1<<7;
  308. static const mask xdigit = 1<<8;
  309. static const mask blank = 1<<9;
  310. #if defined(__BIONIC__)
  311. // Historically this was a part of regex_traits rather than ctype_base. The
  312. // historical value of the constant is preserved for ABI compatibility.
  313. static const mask __regex_word = 0x8000;
  314. #else
  315. static const mask __regex_word = 1<<10;
  316. #endif // defined(__BIONIC__)
  317. #elif defined(__GLIBC__)
  318. typedef unsigned short mask;
  319. static const mask space = _ISspace;
  320. static const mask print = _ISprint;
  321. static const mask cntrl = _IScntrl;
  322. static const mask upper = _ISupper;
  323. static const mask lower = _ISlower;
  324. static const mask alpha = _ISalpha;
  325. static const mask digit = _ISdigit;
  326. static const mask punct = _ISpunct;
  327. static const mask xdigit = _ISxdigit;
  328. static const mask blank = _ISblank;
  329. #if defined(__mips__)
  330. static const mask __regex_word = static_cast<mask>(_ISbit(15));
  331. #else
  332. static const mask __regex_word = 0x80;
  333. #endif
  334. #elif defined(_LIBCPP_MSVCRT_LIKE)
  335. typedef unsigned short mask;
  336. static const mask space = _SPACE;
  337. static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT;
  338. static const mask cntrl = _CONTROL;
  339. static const mask upper = _UPPER;
  340. static const mask lower = _LOWER;
  341. static const mask alpha = _ALPHA;
  342. static const mask digit = _DIGIT;
  343. static const mask punct = _PUNCT;
  344. static const mask xdigit = _HEX;
  345. static const mask blank = _BLANK;
  346. static const mask __regex_word = 0x4000; // 0x8000 and 0x0100 and 0x00ff are used
  347. # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
  348. # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
  349. #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
  350. # ifdef __APPLE__
  351. typedef __uint32_t mask;
  352. # elif defined(__FreeBSD__)
  353. typedef unsigned long mask;
  354. # elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
  355. typedef unsigned short mask;
  356. # endif
  357. static const mask space = _CTYPE_S;
  358. static const mask print = _CTYPE_R;
  359. static const mask cntrl = _CTYPE_C;
  360. static const mask upper = _CTYPE_U;
  361. static const mask lower = _CTYPE_L;
  362. static const mask alpha = _CTYPE_A;
  363. static const mask digit = _CTYPE_D;
  364. static const mask punct = _CTYPE_P;
  365. static const mask xdigit = _CTYPE_X;
  366. # if defined(__NetBSD__)
  367. static const mask blank = _CTYPE_BL;
  368. // NetBSD defines classes up to 0x2000
  369. // see sys/ctype_bits.h, _CTYPE_Q
  370. static const mask __regex_word = 0x8000;
  371. # else
  372. static const mask blank = _CTYPE_B;
  373. static const mask __regex_word = 0x80;
  374. # endif
  375. #elif defined(_AIX)
  376. typedef unsigned int mask;
  377. static const mask space = _ISSPACE;
  378. static const mask print = _ISPRINT;
  379. static const mask cntrl = _ISCNTRL;
  380. static const mask upper = _ISUPPER;
  381. static const mask lower = _ISLOWER;
  382. static const mask alpha = _ISALPHA;
  383. static const mask digit = _ISDIGIT;
  384. static const mask punct = _ISPUNCT;
  385. static const mask xdigit = _ISXDIGIT;
  386. static const mask blank = _ISBLANK;
  387. static const mask __regex_word = 0x8000;
  388. #elif defined(_NEWLIB_VERSION)
  389. // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
  390. typedef char mask;
  391. static const mask space = _S;
  392. static const mask print = _P | _U | _L | _N | _B;
  393. static const mask cntrl = _C;
  394. static const mask upper = _U;
  395. static const mask lower = _L;
  396. static const mask alpha = _U | _L;
  397. static const mask digit = _N;
  398. static const mask punct = _P;
  399. static const mask xdigit = _X | _N;
  400. static const mask blank = _B;
  401. // mask is already fully saturated, use a different type in regex_type_traits.
  402. static const unsigned short __regex_word = 0x100;
  403. # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
  404. # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
  405. # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
  406. #elif defined(__MVS__)
  407. # if defined(__NATIVE_ASCII_F)
  408. typedef unsigned int mask;
  409. static const mask space = _ISSPACE_A;
  410. static const mask print = _ISPRINT_A;
  411. static const mask cntrl = _ISCNTRL_A;
  412. static const mask upper = _ISUPPER_A;
  413. static const mask lower = _ISLOWER_A;
  414. static const mask alpha = _ISALPHA_A;
  415. static const mask digit = _ISDIGIT_A;
  416. static const mask punct = _ISPUNCT_A;
  417. static const mask xdigit = _ISXDIGIT_A;
  418. static const mask blank = _ISBLANK_A;
  419. # else
  420. typedef unsigned short mask;
  421. static const mask space = __ISSPACE;
  422. static const mask print = __ISPRINT;
  423. static const mask cntrl = __ISCNTRL;
  424. static const mask upper = __ISUPPER;
  425. static const mask lower = __ISLOWER;
  426. static const mask alpha = __ISALPHA;
  427. static const mask digit = __ISDIGIT;
  428. static const mask punct = __ISPUNCT;
  429. static const mask xdigit = __ISXDIGIT;
  430. static const mask blank = __ISBLANK;
  431. # endif
  432. static const mask __regex_word = 0x8000;
  433. #else
  434. # error unknown rune table for this platform -- do you mean to define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE?
  435. #endif
  436. static const mask alnum = alpha | digit;
  437. static const mask graph = alnum | punct;
  438. _LIBCPP_INLINE_VISIBILITY ctype_base() {}
  439. static_assert((__regex_word & ~(std::make_unsigned<mask>::type)(space | print | cntrl | upper | lower | alpha |
  440. digit | punct | xdigit | blank)) == __regex_word,
  441. "__regex_word can't overlap other bits");
  442. };
  443. template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
  444. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  445. template <>
  446. class _LIBCPP_EXPORTED_FROM_ABI ctype<wchar_t>
  447. : public locale::facet,
  448. public ctype_base
  449. {
  450. public:
  451. typedef wchar_t char_type;
  452. _LIBCPP_INLINE_VISIBILITY
  453. explicit ctype(size_t __refs = 0)
  454. : locale::facet(__refs) {}
  455. _LIBCPP_INLINE_VISIBILITY
  456. bool is(mask __m, char_type __c) const
  457. {
  458. return do_is(__m, __c);
  459. }
  460. _LIBCPP_INLINE_VISIBILITY
  461. const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
  462. {
  463. return do_is(__low, __high, __vec);
  464. }
  465. _LIBCPP_INLINE_VISIBILITY
  466. const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
  467. {
  468. return do_scan_is(__m, __low, __high);
  469. }
  470. _LIBCPP_INLINE_VISIBILITY
  471. const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
  472. {
  473. return do_scan_not(__m, __low, __high);
  474. }
  475. _LIBCPP_INLINE_VISIBILITY
  476. char_type toupper(char_type __c) const
  477. {
  478. return do_toupper(__c);
  479. }
  480. _LIBCPP_INLINE_VISIBILITY
  481. const char_type* toupper(char_type* __low, const char_type* __high) const
  482. {
  483. return do_toupper(__low, __high);
  484. }
  485. _LIBCPP_INLINE_VISIBILITY
  486. char_type tolower(char_type __c) const
  487. {
  488. return do_tolower(__c);
  489. }
  490. _LIBCPP_INLINE_VISIBILITY
  491. const char_type* tolower(char_type* __low, const char_type* __high) const
  492. {
  493. return do_tolower(__low, __high);
  494. }
  495. _LIBCPP_INLINE_VISIBILITY
  496. char_type widen(char __c) const
  497. {
  498. return do_widen(__c);
  499. }
  500. _LIBCPP_INLINE_VISIBILITY
  501. const char* widen(const char* __low, const char* __high, char_type* __to) const
  502. {
  503. return do_widen(__low, __high, __to);
  504. }
  505. _LIBCPP_INLINE_VISIBILITY
  506. char narrow(char_type __c, char __dfault) const
  507. {
  508. return do_narrow(__c, __dfault);
  509. }
  510. _LIBCPP_INLINE_VISIBILITY
  511. const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
  512. {
  513. return do_narrow(__low, __high, __dfault, __to);
  514. }
  515. static locale::id id;
  516. protected:
  517. ~ctype() override;
  518. virtual bool do_is(mask __m, char_type __c) const;
  519. virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
  520. virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
  521. virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
  522. virtual char_type do_toupper(char_type) const;
  523. virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
  524. virtual char_type do_tolower(char_type) const;
  525. virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
  526. virtual char_type do_widen(char) const;
  527. virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
  528. virtual char do_narrow(char_type, char __dfault) const;
  529. virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
  530. };
  531. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  532. template <>
  533. class _LIBCPP_EXPORTED_FROM_ABI ctype<char>
  534. : public locale::facet, public ctype_base
  535. {
  536. const mask* __tab_;
  537. bool __del_;
  538. public:
  539. typedef char char_type;
  540. explicit ctype(const mask* __tab = nullptr, bool __del = false, size_t __refs = 0);
  541. _LIBCPP_INLINE_VISIBILITY
  542. bool is(mask __m, char_type __c) const
  543. {
  544. return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false;
  545. }
  546. _LIBCPP_INLINE_VISIBILITY
  547. const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
  548. {
  549. for (; __low != __high; ++__low, ++__vec)
  550. *__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
  551. return __low;
  552. }
  553. _LIBCPP_INLINE_VISIBILITY
  554. const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
  555. {
  556. for (; __low != __high; ++__low)
  557. if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
  558. break;
  559. return __low;
  560. }
  561. _LIBCPP_INLINE_VISIBILITY
  562. const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
  563. {
  564. for (; __low != __high; ++__low)
  565. if (!isascii(*__low) || !(__tab_[static_cast<int>(*__low)] & __m))
  566. break;
  567. return __low;
  568. }
  569. _LIBCPP_INLINE_VISIBILITY
  570. char_type toupper(char_type __c) const
  571. {
  572. return do_toupper(__c);
  573. }
  574. _LIBCPP_INLINE_VISIBILITY
  575. const char_type* toupper(char_type* __low, const char_type* __high) const
  576. {
  577. return do_toupper(__low, __high);
  578. }
  579. _LIBCPP_INLINE_VISIBILITY
  580. char_type tolower(char_type __c) const
  581. {
  582. return do_tolower(__c);
  583. }
  584. _LIBCPP_INLINE_VISIBILITY
  585. const char_type* tolower(char_type* __low, const char_type* __high) const
  586. {
  587. return do_tolower(__low, __high);
  588. }
  589. _LIBCPP_INLINE_VISIBILITY
  590. char_type widen(char __c) const
  591. {
  592. return do_widen(__c);
  593. }
  594. _LIBCPP_INLINE_VISIBILITY
  595. const char* widen(const char* __low, const char* __high, char_type* __to) const
  596. {
  597. return do_widen(__low, __high, __to);
  598. }
  599. _LIBCPP_INLINE_VISIBILITY
  600. char narrow(char_type __c, char __dfault) const
  601. {
  602. return do_narrow(__c, __dfault);
  603. }
  604. _LIBCPP_INLINE_VISIBILITY
  605. const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
  606. {
  607. return do_narrow(__low, __high, __dfault, __to);
  608. }
  609. static locale::id id;
  610. #ifdef _CACHED_RUNES
  611. static const size_t table_size = _CACHED_RUNES;
  612. #else
  613. static const size_t table_size = 256; // FIXME: Don't hardcode this.
  614. #endif
  615. _LIBCPP_INLINE_VISIBILITY const mask* table() const _NOEXCEPT {return __tab_;}
  616. static const mask* classic_table() _NOEXCEPT;
  617. #if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
  618. static const int* __classic_upper_table() _NOEXCEPT;
  619. static const int* __classic_lower_table() _NOEXCEPT;
  620. #endif
  621. #if defined(__NetBSD__)
  622. static const short* __classic_upper_table() _NOEXCEPT;
  623. static const short* __classic_lower_table() _NOEXCEPT;
  624. #endif
  625. #if defined(__MVS__)
  626. static const unsigned short* __classic_upper_table() _NOEXCEPT;
  627. static const unsigned short* __classic_lower_table() _NOEXCEPT;
  628. #endif
  629. protected:
  630. ~ctype() override;
  631. virtual char_type do_toupper(char_type __c) const;
  632. virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
  633. virtual char_type do_tolower(char_type __c) const;
  634. virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
  635. virtual char_type do_widen(char __c) const;
  636. virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
  637. virtual char do_narrow(char_type __c, char __dfault) const;
  638. virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
  639. };
  640. // template <class CharT> class ctype_byname;
  641. template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype_byname;
  642. template <>
  643. class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<char>
  644. : public ctype<char>
  645. {
  646. locale_t __l_;
  647. public:
  648. explicit ctype_byname(const char*, size_t = 0);
  649. explicit ctype_byname(const string&, size_t = 0);
  650. protected:
  651. ~ctype_byname() override;
  652. char_type do_toupper(char_type) const override;
  653. const char_type* do_toupper(char_type* __low, const char_type* __high) const override;
  654. char_type do_tolower(char_type) const override;
  655. const char_type* do_tolower(char_type* __low, const char_type* __high) const override;
  656. };
  657. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  658. template <>
  659. class _LIBCPP_EXPORTED_FROM_ABI ctype_byname<wchar_t>
  660. : public ctype<wchar_t>
  661. {
  662. locale_t __l_;
  663. public:
  664. explicit ctype_byname(const char*, size_t = 0);
  665. explicit ctype_byname(const string&, size_t = 0);
  666. protected:
  667. ~ctype_byname() override;
  668. bool do_is(mask __m, char_type __c) const override;
  669. const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const override;
  670. const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const override;
  671. const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const override;
  672. char_type do_toupper(char_type) const override;
  673. const char_type* do_toupper(char_type* __low, const char_type* __high) const override;
  674. char_type do_tolower(char_type) const override;
  675. const char_type* do_tolower(char_type* __low, const char_type* __high) const override;
  676. char_type do_widen(char) const override;
  677. const char* do_widen(const char* __low, const char* __high, char_type* __dest) const override;
  678. char do_narrow(char_type, char __dfault) const override;
  679. const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const override;
  680. };
  681. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  682. template <class _CharT>
  683. inline _LIBCPP_INLINE_VISIBILITY
  684. bool
  685. isspace(_CharT __c, const locale& __loc)
  686. {
  687. return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
  688. }
  689. template <class _CharT>
  690. inline _LIBCPP_INLINE_VISIBILITY
  691. bool
  692. isprint(_CharT __c, const locale& __loc)
  693. {
  694. return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
  695. }
  696. template <class _CharT>
  697. inline _LIBCPP_INLINE_VISIBILITY
  698. bool
  699. iscntrl(_CharT __c, const locale& __loc)
  700. {
  701. return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
  702. }
  703. template <class _CharT>
  704. inline _LIBCPP_INLINE_VISIBILITY
  705. bool
  706. isupper(_CharT __c, const locale& __loc)
  707. {
  708. return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
  709. }
  710. template <class _CharT>
  711. inline _LIBCPP_INLINE_VISIBILITY
  712. bool
  713. islower(_CharT __c, const locale& __loc)
  714. {
  715. return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
  716. }
  717. template <class _CharT>
  718. inline _LIBCPP_INLINE_VISIBILITY
  719. bool
  720. isalpha(_CharT __c, const locale& __loc)
  721. {
  722. return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
  723. }
  724. template <class _CharT>
  725. inline _LIBCPP_INLINE_VISIBILITY
  726. bool
  727. isdigit(_CharT __c, const locale& __loc)
  728. {
  729. return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
  730. }
  731. template <class _CharT>
  732. inline _LIBCPP_INLINE_VISIBILITY
  733. bool
  734. ispunct(_CharT __c, const locale& __loc)
  735. {
  736. return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
  737. }
  738. template <class _CharT>
  739. inline _LIBCPP_INLINE_VISIBILITY
  740. bool
  741. isxdigit(_CharT __c, const locale& __loc)
  742. {
  743. return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
  744. }
  745. template <class _CharT>
  746. inline _LIBCPP_INLINE_VISIBILITY
  747. bool
  748. isalnum(_CharT __c, const locale& __loc)
  749. {
  750. return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
  751. }
  752. template <class _CharT>
  753. inline _LIBCPP_INLINE_VISIBILITY
  754. bool
  755. isgraph(_CharT __c, const locale& __loc)
  756. {
  757. return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
  758. }
  759. template <class _CharT>
  760. _LIBCPP_HIDE_FROM_ABI bool isblank(_CharT __c, const locale& __loc) {
  761. return std::use_facet<ctype<_CharT> >(__loc).is(ctype_base::blank, __c);
  762. }
  763. template <class _CharT>
  764. inline _LIBCPP_INLINE_VISIBILITY
  765. _CharT
  766. toupper(_CharT __c, const locale& __loc)
  767. {
  768. return std::use_facet<ctype<_CharT> >(__loc).toupper(__c);
  769. }
  770. template <class _CharT>
  771. inline _LIBCPP_INLINE_VISIBILITY
  772. _CharT
  773. tolower(_CharT __c, const locale& __loc)
  774. {
  775. return std::use_facet<ctype<_CharT> >(__loc).tolower(__c);
  776. }
  777. // codecvt_base
  778. class _LIBCPP_EXPORTED_FROM_ABI codecvt_base
  779. {
  780. public:
  781. _LIBCPP_INLINE_VISIBILITY codecvt_base() {}
  782. enum result {ok, partial, error, noconv};
  783. };
  784. // template <class internT, class externT, class stateT> class codecvt;
  785. template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TEMPLATE_VIS codecvt;
  786. // template <> class codecvt<char, char, mbstate_t>
  787. template <>
  788. class _LIBCPP_EXPORTED_FROM_ABI codecvt<char, char, mbstate_t>
  789. : public locale::facet,
  790. public codecvt_base
  791. {
  792. public:
  793. typedef char intern_type;
  794. typedef char extern_type;
  795. typedef mbstate_t state_type;
  796. _LIBCPP_INLINE_VISIBILITY
  797. explicit codecvt(size_t __refs = 0)
  798. : locale::facet(__refs) {}
  799. _LIBCPP_INLINE_VISIBILITY
  800. result out(state_type& __st,
  801. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  802. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
  803. {
  804. return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
  805. }
  806. _LIBCPP_INLINE_VISIBILITY
  807. result unshift(state_type& __st,
  808. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
  809. {
  810. return do_unshift(__st, __to, __to_end, __to_nxt);
  811. }
  812. _LIBCPP_INLINE_VISIBILITY
  813. result in(state_type& __st,
  814. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  815. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
  816. {
  817. return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
  818. }
  819. _LIBCPP_INLINE_VISIBILITY
  820. int encoding() const _NOEXCEPT
  821. {
  822. return do_encoding();
  823. }
  824. _LIBCPP_INLINE_VISIBILITY
  825. bool always_noconv() const _NOEXCEPT
  826. {
  827. return do_always_noconv();
  828. }
  829. _LIBCPP_INLINE_VISIBILITY
  830. int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
  831. {
  832. return do_length(__st, __frm, __end, __mx);
  833. }
  834. _LIBCPP_INLINE_VISIBILITY
  835. int max_length() const _NOEXCEPT
  836. {
  837. return do_max_length();
  838. }
  839. static locale::id id;
  840. protected:
  841. _LIBCPP_INLINE_VISIBILITY
  842. explicit codecvt(const char*, size_t __refs = 0)
  843. : locale::facet(__refs) {}
  844. ~codecvt() override;
  845. virtual result do_out(state_type& __st,
  846. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  847. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
  848. virtual result do_in(state_type& __st,
  849. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  850. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
  851. virtual result do_unshift(state_type& __st,
  852. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
  853. virtual int do_encoding() const _NOEXCEPT;
  854. virtual bool do_always_noconv() const _NOEXCEPT;
  855. virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
  856. virtual int do_max_length() const _NOEXCEPT;
  857. };
  858. // template <> class codecvt<wchar_t, char, mbstate_t>
  859. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  860. template <>
  861. class _LIBCPP_EXPORTED_FROM_ABI codecvt<wchar_t, char, mbstate_t>
  862. : public locale::facet,
  863. public codecvt_base
  864. {
  865. locale_t __l_;
  866. public:
  867. typedef wchar_t intern_type;
  868. typedef char extern_type;
  869. typedef mbstate_t state_type;
  870. explicit codecvt(size_t __refs = 0);
  871. _LIBCPP_INLINE_VISIBILITY
  872. result out(state_type& __st,
  873. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  874. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
  875. {
  876. return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
  877. }
  878. _LIBCPP_INLINE_VISIBILITY
  879. result unshift(state_type& __st,
  880. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
  881. {
  882. return do_unshift(__st, __to, __to_end, __to_nxt);
  883. }
  884. _LIBCPP_INLINE_VISIBILITY
  885. result in(state_type& __st,
  886. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  887. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
  888. {
  889. return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
  890. }
  891. _LIBCPP_INLINE_VISIBILITY
  892. int encoding() const _NOEXCEPT
  893. {
  894. return do_encoding();
  895. }
  896. _LIBCPP_INLINE_VISIBILITY
  897. bool always_noconv() const _NOEXCEPT
  898. {
  899. return do_always_noconv();
  900. }
  901. _LIBCPP_INLINE_VISIBILITY
  902. int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
  903. {
  904. return do_length(__st, __frm, __end, __mx);
  905. }
  906. _LIBCPP_INLINE_VISIBILITY
  907. int max_length() const _NOEXCEPT
  908. {
  909. return do_max_length();
  910. }
  911. static locale::id id;
  912. protected:
  913. explicit codecvt(const char*, size_t __refs = 0);
  914. ~codecvt() override;
  915. virtual result do_out(state_type& __st,
  916. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  917. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
  918. virtual result do_in(state_type& __st,
  919. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  920. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
  921. virtual result do_unshift(state_type& __st,
  922. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
  923. virtual int do_encoding() const _NOEXCEPT;
  924. virtual bool do_always_noconv() const _NOEXCEPT;
  925. virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
  926. virtual int do_max_length() const _NOEXCEPT;
  927. };
  928. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  929. // template <> class codecvt<char16_t, char, mbstate_t> // deprecated in C++20
  930. template <>
  931. class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char, mbstate_t>
  932. : public locale::facet,
  933. public codecvt_base
  934. {
  935. public:
  936. typedef char16_t intern_type;
  937. typedef char extern_type;
  938. typedef mbstate_t state_type;
  939. _LIBCPP_INLINE_VISIBILITY
  940. explicit codecvt(size_t __refs = 0)
  941. : locale::facet(__refs) {}
  942. _LIBCPP_INLINE_VISIBILITY
  943. result out(state_type& __st,
  944. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  945. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
  946. {
  947. return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
  948. }
  949. _LIBCPP_INLINE_VISIBILITY
  950. result unshift(state_type& __st,
  951. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
  952. {
  953. return do_unshift(__st, __to, __to_end, __to_nxt);
  954. }
  955. _LIBCPP_INLINE_VISIBILITY
  956. result in(state_type& __st,
  957. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  958. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
  959. {
  960. return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
  961. }
  962. _LIBCPP_INLINE_VISIBILITY
  963. int encoding() const _NOEXCEPT
  964. {
  965. return do_encoding();
  966. }
  967. _LIBCPP_INLINE_VISIBILITY
  968. bool always_noconv() const _NOEXCEPT
  969. {
  970. return do_always_noconv();
  971. }
  972. _LIBCPP_INLINE_VISIBILITY
  973. int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
  974. {
  975. return do_length(__st, __frm, __end, __mx);
  976. }
  977. _LIBCPP_INLINE_VISIBILITY
  978. int max_length() const _NOEXCEPT
  979. {
  980. return do_max_length();
  981. }
  982. static locale::id id;
  983. protected:
  984. _LIBCPP_INLINE_VISIBILITY
  985. explicit codecvt(const char*, size_t __refs = 0)
  986. : locale::facet(__refs) {}
  987. ~codecvt() override;
  988. virtual result do_out(state_type& __st,
  989. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  990. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
  991. virtual result do_in(state_type& __st,
  992. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  993. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
  994. virtual result do_unshift(state_type& __st,
  995. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
  996. virtual int do_encoding() const _NOEXCEPT;
  997. virtual bool do_always_noconv() const _NOEXCEPT;
  998. virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
  999. virtual int do_max_length() const _NOEXCEPT;
  1000. };
  1001. #ifndef _LIBCPP_HAS_NO_CHAR8_T
  1002. // template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20
  1003. template <>
  1004. class _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char8_t, mbstate_t>
  1005. : public locale::facet,
  1006. public codecvt_base
  1007. {
  1008. public:
  1009. typedef char16_t intern_type;
  1010. typedef char8_t extern_type;
  1011. typedef mbstate_t state_type;
  1012. _LIBCPP_INLINE_VISIBILITY
  1013. explicit codecvt(size_t __refs = 0)
  1014. : locale::facet(__refs) {}
  1015. _LIBCPP_INLINE_VISIBILITY
  1016. result out(state_type& __st,
  1017. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  1018. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
  1019. {
  1020. return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
  1021. }
  1022. _LIBCPP_INLINE_VISIBILITY
  1023. result unshift(state_type& __st,
  1024. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
  1025. {
  1026. return do_unshift(__st, __to, __to_end, __to_nxt);
  1027. }
  1028. _LIBCPP_INLINE_VISIBILITY
  1029. result in(state_type& __st,
  1030. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  1031. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
  1032. {
  1033. return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
  1034. }
  1035. _LIBCPP_INLINE_VISIBILITY
  1036. int encoding() const _NOEXCEPT
  1037. {
  1038. return do_encoding();
  1039. }
  1040. _LIBCPP_INLINE_VISIBILITY
  1041. bool always_noconv() const _NOEXCEPT
  1042. {
  1043. return do_always_noconv();
  1044. }
  1045. _LIBCPP_INLINE_VISIBILITY
  1046. int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
  1047. {
  1048. return do_length(__st, __frm, __end, __mx);
  1049. }
  1050. _LIBCPP_INLINE_VISIBILITY
  1051. int max_length() const _NOEXCEPT
  1052. {
  1053. return do_max_length();
  1054. }
  1055. static locale::id id;
  1056. protected:
  1057. _LIBCPP_INLINE_VISIBILITY
  1058. explicit codecvt(const char*, size_t __refs = 0)
  1059. : locale::facet(__refs) {}
  1060. ~codecvt() override;
  1061. virtual result do_out(state_type& __st,
  1062. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  1063. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
  1064. virtual result do_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;
  1067. virtual result do_unshift(state_type& __st,
  1068. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
  1069. virtual int do_encoding() const _NOEXCEPT;
  1070. virtual bool do_always_noconv() const _NOEXCEPT;
  1071. virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
  1072. virtual int do_max_length() const _NOEXCEPT;
  1073. };
  1074. #endif
  1075. // template <> class codecvt<char32_t, char, mbstate_t> // deprecated in C++20
  1076. template <>
  1077. class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char, mbstate_t>
  1078. : public locale::facet,
  1079. public codecvt_base
  1080. {
  1081. public:
  1082. typedef char32_t intern_type;
  1083. typedef char extern_type;
  1084. typedef mbstate_t state_type;
  1085. _LIBCPP_INLINE_VISIBILITY
  1086. explicit codecvt(size_t __refs = 0)
  1087. : locale::facet(__refs) {}
  1088. _LIBCPP_INLINE_VISIBILITY
  1089. result out(state_type& __st,
  1090. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  1091. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
  1092. {
  1093. return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
  1094. }
  1095. _LIBCPP_INLINE_VISIBILITY
  1096. result unshift(state_type& __st,
  1097. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
  1098. {
  1099. return do_unshift(__st, __to, __to_end, __to_nxt);
  1100. }
  1101. _LIBCPP_INLINE_VISIBILITY
  1102. result in(state_type& __st,
  1103. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  1104. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
  1105. {
  1106. return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
  1107. }
  1108. _LIBCPP_INLINE_VISIBILITY
  1109. int encoding() const _NOEXCEPT
  1110. {
  1111. return do_encoding();
  1112. }
  1113. _LIBCPP_INLINE_VISIBILITY
  1114. bool always_noconv() const _NOEXCEPT
  1115. {
  1116. return do_always_noconv();
  1117. }
  1118. _LIBCPP_INLINE_VISIBILITY
  1119. int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
  1120. {
  1121. return do_length(__st, __frm, __end, __mx);
  1122. }
  1123. _LIBCPP_INLINE_VISIBILITY
  1124. int max_length() const _NOEXCEPT
  1125. {
  1126. return do_max_length();
  1127. }
  1128. static locale::id id;
  1129. protected:
  1130. _LIBCPP_INLINE_VISIBILITY
  1131. explicit codecvt(const char*, size_t __refs = 0)
  1132. : locale::facet(__refs) {}
  1133. ~codecvt() override;
  1134. virtual result do_out(state_type& __st,
  1135. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  1136. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
  1137. virtual result do_in(state_type& __st,
  1138. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  1139. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
  1140. virtual result do_unshift(state_type& __st,
  1141. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
  1142. virtual int do_encoding() const _NOEXCEPT;
  1143. virtual bool do_always_noconv() const _NOEXCEPT;
  1144. virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
  1145. virtual int do_max_length() const _NOEXCEPT;
  1146. };
  1147. #ifndef _LIBCPP_HAS_NO_CHAR8_T
  1148. // template <> class codecvt<char32_t, char8_t, mbstate_t> // C++20
  1149. template <>
  1150. class _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char8_t, mbstate_t>
  1151. : public locale::facet,
  1152. public codecvt_base
  1153. {
  1154. public:
  1155. typedef char32_t intern_type;
  1156. typedef char8_t extern_type;
  1157. typedef mbstate_t state_type;
  1158. _LIBCPP_INLINE_VISIBILITY
  1159. explicit codecvt(size_t __refs = 0)
  1160. : locale::facet(__refs) {}
  1161. _LIBCPP_INLINE_VISIBILITY
  1162. result out(state_type& __st,
  1163. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  1164. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
  1165. {
  1166. return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
  1167. }
  1168. _LIBCPP_INLINE_VISIBILITY
  1169. result unshift(state_type& __st,
  1170. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
  1171. {
  1172. return do_unshift(__st, __to, __to_end, __to_nxt);
  1173. }
  1174. _LIBCPP_INLINE_VISIBILITY
  1175. result in(state_type& __st,
  1176. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  1177. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
  1178. {
  1179. return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
  1180. }
  1181. _LIBCPP_INLINE_VISIBILITY
  1182. int encoding() const _NOEXCEPT
  1183. {
  1184. return do_encoding();
  1185. }
  1186. _LIBCPP_INLINE_VISIBILITY
  1187. bool always_noconv() const _NOEXCEPT
  1188. {
  1189. return do_always_noconv();
  1190. }
  1191. _LIBCPP_INLINE_VISIBILITY
  1192. int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
  1193. {
  1194. return do_length(__st, __frm, __end, __mx);
  1195. }
  1196. _LIBCPP_INLINE_VISIBILITY
  1197. int max_length() const _NOEXCEPT
  1198. {
  1199. return do_max_length();
  1200. }
  1201. static locale::id id;
  1202. protected:
  1203. _LIBCPP_INLINE_VISIBILITY
  1204. explicit codecvt(const char*, size_t __refs = 0)
  1205. : locale::facet(__refs) {}
  1206. ~codecvt() override;
  1207. virtual result do_out(state_type& __st,
  1208. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  1209. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
  1210. virtual result do_in(state_type& __st,
  1211. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  1212. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
  1213. virtual result do_unshift(state_type& __st,
  1214. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
  1215. virtual int do_encoding() const _NOEXCEPT;
  1216. virtual bool do_always_noconv() const _NOEXCEPT;
  1217. virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
  1218. virtual int do_max_length() const _NOEXCEPT;
  1219. };
  1220. #endif
  1221. // template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
  1222. template <class _InternT, class _ExternT, class _StateT>
  1223. class _LIBCPP_TEMPLATE_VIS codecvt_byname
  1224. : public codecvt<_InternT, _ExternT, _StateT>
  1225. {
  1226. public:
  1227. _LIBCPP_INLINE_VISIBILITY
  1228. explicit codecvt_byname(const char* __nm, size_t __refs = 0)
  1229. : codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
  1230. _LIBCPP_INLINE_VISIBILITY
  1231. explicit codecvt_byname(const string& __nm, size_t __refs = 0)
  1232. : codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
  1233. protected:
  1234. ~codecvt_byname() override;
  1235. };
  1236. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  1237. template <class _InternT, class _ExternT, class _StateT>
  1238. codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
  1239. {
  1240. }
  1241. _LIBCPP_SUPPRESS_DEPRECATED_POP
  1242. extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>;
  1243. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1244. extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>;
  1245. #endif
  1246. extern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>; // deprecated in C++20
  1247. extern template class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>; // deprecated in C++20
  1248. #ifndef _LIBCPP_HAS_NO_CHAR8_T
  1249. extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>; // C++20
  1250. extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>; // C++20
  1251. #endif
  1252. template <size_t _Np>
  1253. struct __narrow_to_utf8
  1254. {
  1255. template <class _OutputIterator, class _CharT>
  1256. _OutputIterator
  1257. operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
  1258. };
  1259. template <>
  1260. struct __narrow_to_utf8<8>
  1261. {
  1262. template <class _OutputIterator, class _CharT>
  1263. _LIBCPP_INLINE_VISIBILITY
  1264. _OutputIterator
  1265. operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
  1266. {
  1267. for (; __wb < __we; ++__wb, ++__s)
  1268. *__s = *__wb;
  1269. return __s;
  1270. }
  1271. };
  1272. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  1273. template <>
  1274. struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<16>
  1275. : public codecvt<char16_t, char, mbstate_t>
  1276. {
  1277. _LIBCPP_INLINE_VISIBILITY
  1278. __narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
  1279. _LIBCPP_SUPPRESS_DEPRECATED_POP
  1280. ~__narrow_to_utf8() override;
  1281. template <class _OutputIterator, class _CharT>
  1282. _LIBCPP_INLINE_VISIBILITY
  1283. _OutputIterator
  1284. operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
  1285. {
  1286. result __r = ok;
  1287. mbstate_t __mb;
  1288. while (__wb < __we && __r != error)
  1289. {
  1290. const int __sz = 32;
  1291. char __buf[__sz];
  1292. char* __bn;
  1293. const char16_t* __wn = (const char16_t*)__wb;
  1294. __r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
  1295. __buf, __buf+__sz, __bn);
  1296. if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
  1297. __throw_runtime_error("locale not supported");
  1298. for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
  1299. *__s = *__p;
  1300. __wb = (const _CharT*)__wn;
  1301. }
  1302. return __s;
  1303. }
  1304. };
  1305. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  1306. template <>
  1307. struct _LIBCPP_EXPORTED_FROM_ABI __narrow_to_utf8<32>
  1308. : public codecvt<char32_t, char, mbstate_t>
  1309. {
  1310. _LIBCPP_INLINE_VISIBILITY
  1311. __narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
  1312. _LIBCPP_SUPPRESS_DEPRECATED_POP
  1313. ~__narrow_to_utf8() override;
  1314. template <class _OutputIterator, class _CharT>
  1315. _LIBCPP_INLINE_VISIBILITY
  1316. _OutputIterator
  1317. operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
  1318. {
  1319. result __r = ok;
  1320. mbstate_t __mb;
  1321. while (__wb < __we && __r != error)
  1322. {
  1323. const int __sz = 32;
  1324. char __buf[__sz];
  1325. char* __bn;
  1326. const char32_t* __wn = (const char32_t*)__wb;
  1327. __r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
  1328. __buf, __buf+__sz, __bn);
  1329. if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
  1330. __throw_runtime_error("locale not supported");
  1331. for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
  1332. *__s = *__p;
  1333. __wb = (const _CharT*)__wn;
  1334. }
  1335. return __s;
  1336. }
  1337. };
  1338. template <size_t _Np>
  1339. struct __widen_from_utf8
  1340. {
  1341. template <class _OutputIterator>
  1342. _OutputIterator
  1343. operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
  1344. };
  1345. template <>
  1346. struct __widen_from_utf8<8>
  1347. {
  1348. template <class _OutputIterator>
  1349. _LIBCPP_INLINE_VISIBILITY
  1350. _OutputIterator
  1351. operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
  1352. {
  1353. for (; __nb < __ne; ++__nb, ++__s)
  1354. *__s = *__nb;
  1355. return __s;
  1356. }
  1357. };
  1358. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  1359. template <>
  1360. struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<16>
  1361. : public codecvt<char16_t, char, mbstate_t>
  1362. {
  1363. _LIBCPP_INLINE_VISIBILITY
  1364. __widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
  1365. _LIBCPP_SUPPRESS_DEPRECATED_POP
  1366. ~__widen_from_utf8() override;
  1367. template <class _OutputIterator>
  1368. _LIBCPP_INLINE_VISIBILITY
  1369. _OutputIterator
  1370. operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
  1371. {
  1372. result __r = ok;
  1373. mbstate_t __mb;
  1374. while (__nb < __ne && __r != error)
  1375. {
  1376. const int __sz = 32;
  1377. char16_t __buf[__sz];
  1378. char16_t* __bn;
  1379. const char* __nn = __nb;
  1380. __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
  1381. __buf, __buf+__sz, __bn);
  1382. if (__r == codecvt_base::error || __nn == __nb)
  1383. __throw_runtime_error("locale not supported");
  1384. for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
  1385. *__s = *__p;
  1386. __nb = __nn;
  1387. }
  1388. return __s;
  1389. }
  1390. };
  1391. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  1392. template <>
  1393. struct _LIBCPP_EXPORTED_FROM_ABI __widen_from_utf8<32>
  1394. : public codecvt<char32_t, char, mbstate_t>
  1395. {
  1396. _LIBCPP_INLINE_VISIBILITY
  1397. __widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
  1398. _LIBCPP_SUPPRESS_DEPRECATED_POP
  1399. ~__widen_from_utf8() override;
  1400. template <class _OutputIterator>
  1401. _LIBCPP_INLINE_VISIBILITY
  1402. _OutputIterator
  1403. operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
  1404. {
  1405. result __r = ok;
  1406. mbstate_t __mb;
  1407. while (__nb < __ne && __r != error)
  1408. {
  1409. const int __sz = 32;
  1410. char32_t __buf[__sz];
  1411. char32_t* __bn;
  1412. const char* __nn = __nb;
  1413. __r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
  1414. __buf, __buf+__sz, __bn);
  1415. if (__r == codecvt_base::error || __nn == __nb)
  1416. __throw_runtime_error("locale not supported");
  1417. for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
  1418. *__s = *__p;
  1419. __nb = __nn;
  1420. }
  1421. return __s;
  1422. }
  1423. };
  1424. // template <class charT> class numpunct
  1425. template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct;
  1426. template <>
  1427. class _LIBCPP_EXPORTED_FROM_ABI numpunct<char>
  1428. : public locale::facet
  1429. {
  1430. public:
  1431. typedef char char_type;
  1432. typedef basic_string<char_type> string_type;
  1433. explicit numpunct(size_t __refs = 0);
  1434. _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
  1435. _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
  1436. _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();}
  1437. _LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();}
  1438. _LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();}
  1439. static locale::id id;
  1440. protected:
  1441. ~numpunct() override;
  1442. virtual char_type do_decimal_point() const;
  1443. virtual char_type do_thousands_sep() const;
  1444. virtual string do_grouping() const;
  1445. virtual string_type do_truename() const;
  1446. virtual string_type do_falsename() const;
  1447. char_type __decimal_point_;
  1448. char_type __thousands_sep_;
  1449. string __grouping_;
  1450. };
  1451. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1452. template <>
  1453. class _LIBCPP_EXPORTED_FROM_ABI numpunct<wchar_t>
  1454. : public locale::facet
  1455. {
  1456. public:
  1457. typedef wchar_t char_type;
  1458. typedef basic_string<char_type> string_type;
  1459. explicit numpunct(size_t __refs = 0);
  1460. _LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
  1461. _LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
  1462. _LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();}
  1463. _LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();}
  1464. _LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();}
  1465. static locale::id id;
  1466. protected:
  1467. ~numpunct() override;
  1468. virtual char_type do_decimal_point() const;
  1469. virtual char_type do_thousands_sep() const;
  1470. virtual string do_grouping() const;
  1471. virtual string_type do_truename() const;
  1472. virtual string_type do_falsename() const;
  1473. char_type __decimal_point_;
  1474. char_type __thousands_sep_;
  1475. string __grouping_;
  1476. };
  1477. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1478. // template <class charT> class numpunct_byname
  1479. template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct_byname;
  1480. template <>
  1481. class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<char>
  1482. : public numpunct<char>
  1483. {
  1484. public:
  1485. typedef char char_type;
  1486. typedef basic_string<char_type> string_type;
  1487. explicit numpunct_byname(const char* __nm, size_t __refs = 0);
  1488. explicit numpunct_byname(const string& __nm, size_t __refs = 0);
  1489. protected:
  1490. ~numpunct_byname() override;
  1491. private:
  1492. void __init(const char*);
  1493. };
  1494. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1495. template <>
  1496. class _LIBCPP_EXPORTED_FROM_ABI numpunct_byname<wchar_t>
  1497. : public numpunct<wchar_t>
  1498. {
  1499. public:
  1500. typedef wchar_t char_type;
  1501. typedef basic_string<char_type> string_type;
  1502. explicit numpunct_byname(const char* __nm, size_t __refs = 0);
  1503. explicit numpunct_byname(const string& __nm, size_t __refs = 0);
  1504. protected:
  1505. ~numpunct_byname() override;
  1506. private:
  1507. void __init(const char*);
  1508. };
  1509. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  1510. _LIBCPP_END_NAMESPACE_STD
  1511. #endif // _LIBCPP___LOCALE