__locale 57 KB

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