codecvt 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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_CODECVT
  10. #define _LIBCPP_CODECVT
  11. /*
  12. codecvt synopsis
  13. namespace std
  14. {
  15. enum codecvt_mode
  16. {
  17. consume_header = 4,
  18. generate_header = 2,
  19. little_endian = 1
  20. };
  21. template <class Elem, unsigned long Maxcode = 0x10ffff,
  22. codecvt_mode Mode = (codecvt_mode)0>
  23. class codecvt_utf8
  24. : public codecvt<Elem, char, mbstate_t>
  25. {
  26. explicit codecvt_utf8(size_t refs = 0);
  27. ~codecvt_utf8();
  28. };
  29. template <class Elem, unsigned long Maxcode = 0x10ffff,
  30. codecvt_mode Mode = (codecvt_mode)0>
  31. class codecvt_utf16
  32. : public codecvt<Elem, char, mbstate_t>
  33. {
  34. explicit codecvt_utf16(size_t refs = 0);
  35. ~codecvt_utf16();
  36. };
  37. template <class Elem, unsigned long Maxcode = 0x10ffff,
  38. codecvt_mode Mode = (codecvt_mode)0>
  39. class codecvt_utf8_utf16
  40. : public codecvt<Elem, char, mbstate_t>
  41. {
  42. explicit codecvt_utf8_utf16(size_t refs = 0);
  43. ~codecvt_utf8_utf16();
  44. };
  45. } // std
  46. */
  47. #include <__assert> // all public C++ headers provide the assertion handler
  48. #include <__config>
  49. #include <__locale>
  50. #include <version>
  51. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  52. # pragma GCC system_header
  53. #endif
  54. _LIBCPP_BEGIN_NAMESPACE_STD
  55. enum _LIBCPP_DEPRECATED_IN_CXX17 codecvt_mode
  56. {
  57. consume_header = 4,
  58. generate_header = 2,
  59. little_endian = 1
  60. };
  61. // codecvt_utf8
  62. template <class _Elem> class __codecvt_utf8;
  63. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  64. template <>
  65. class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8<wchar_t>
  66. : public codecvt<wchar_t, char, mbstate_t>
  67. {
  68. unsigned long __maxcode_;
  69. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  70. codecvt_mode __mode_;
  71. _LIBCPP_SUPPRESS_DEPRECATED_POP
  72. public:
  73. typedef wchar_t intern_type;
  74. typedef char extern_type;
  75. typedef mbstate_t state_type;
  76. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  77. _LIBCPP_INLINE_VISIBILITY
  78. explicit __codecvt_utf8(size_t __refs, unsigned long __maxcode,
  79. codecvt_mode __mode)
  80. : codecvt<wchar_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
  81. __mode_(__mode) {}
  82. _LIBCPP_SUPPRESS_DEPRECATED_POP
  83. protected:
  84. result do_out(state_type& __st,
  85. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  86. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  87. result do_in(state_type& __st,
  88. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  89. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
  90. result do_unshift(state_type& __st,
  91. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  92. int do_encoding() const _NOEXCEPT override;
  93. bool do_always_noconv() const _NOEXCEPT override;
  94. int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
  95. int do_max_length() const _NOEXCEPT override;
  96. };
  97. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  98. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  99. template <>
  100. class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8<char16_t>
  101. : public codecvt<char16_t, char, mbstate_t>
  102. {
  103. unsigned long __maxcode_;
  104. codecvt_mode __mode_;
  105. public:
  106. typedef char16_t intern_type;
  107. typedef char extern_type;
  108. typedef mbstate_t state_type;
  109. _LIBCPP_INLINE_VISIBILITY
  110. explicit __codecvt_utf8(size_t __refs, unsigned long __maxcode,
  111. codecvt_mode __mode)
  112. : codecvt<char16_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
  113. __mode_(__mode) {}
  114. _LIBCPP_SUPPRESS_DEPRECATED_POP
  115. protected:
  116. result do_out(state_type& __st,
  117. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  118. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  119. result do_in(state_type& __st,
  120. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  121. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
  122. result do_unshift(state_type& __st,
  123. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  124. int do_encoding() const _NOEXCEPT override;
  125. bool do_always_noconv() const _NOEXCEPT override;
  126. int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
  127. int do_max_length() const _NOEXCEPT override;
  128. };
  129. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  130. template <>
  131. class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8<char32_t>
  132. : public codecvt<char32_t, char, mbstate_t>
  133. {
  134. unsigned long __maxcode_;
  135. codecvt_mode __mode_;
  136. public:
  137. typedef char32_t intern_type;
  138. typedef char extern_type;
  139. typedef mbstate_t state_type;
  140. _LIBCPP_INLINE_VISIBILITY
  141. explicit __codecvt_utf8(size_t __refs, unsigned long __maxcode,
  142. codecvt_mode __mode)
  143. : codecvt<char32_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
  144. __mode_(__mode) {}
  145. _LIBCPP_SUPPRESS_DEPRECATED_POP
  146. protected:
  147. result do_out(state_type& __st,
  148. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  149. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  150. result do_in(state_type& __st,
  151. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  152. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
  153. result do_unshift(state_type& __st,
  154. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  155. int do_encoding() const _NOEXCEPT override;
  156. bool do_always_noconv() const _NOEXCEPT override;
  157. int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
  158. int do_max_length() const _NOEXCEPT override;
  159. };
  160. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  161. template <class _Elem, unsigned long _Maxcode = 0x10ffff,
  162. codecvt_mode _Mode = (codecvt_mode)0>
  163. class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 codecvt_utf8
  164. : public __codecvt_utf8<_Elem>
  165. {
  166. public:
  167. _LIBCPP_INLINE_VISIBILITY
  168. explicit codecvt_utf8(size_t __refs = 0)
  169. : __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) {}
  170. _LIBCPP_INLINE_VISIBILITY
  171. ~codecvt_utf8() {}
  172. };
  173. _LIBCPP_SUPPRESS_DEPRECATED_POP
  174. // codecvt_utf16
  175. template <class _Elem, bool _LittleEndian> class __codecvt_utf16;
  176. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  177. template <>
  178. class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf16<wchar_t, false>
  179. : public codecvt<wchar_t, char, mbstate_t>
  180. {
  181. unsigned long __maxcode_;
  182. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  183. codecvt_mode __mode_;
  184. _LIBCPP_SUPPRESS_DEPRECATED_POP
  185. public:
  186. typedef wchar_t intern_type;
  187. typedef char extern_type;
  188. typedef mbstate_t state_type;
  189. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  190. _LIBCPP_INLINE_VISIBILITY
  191. explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
  192. codecvt_mode __mode)
  193. : codecvt<wchar_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
  194. __mode_(__mode) {}
  195. _LIBCPP_SUPPRESS_DEPRECATED_POP
  196. protected:
  197. result do_out(state_type& __st,
  198. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  199. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  200. result do_in(state_type& __st,
  201. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  202. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
  203. result do_unshift(state_type& __st,
  204. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  205. int do_encoding() const _NOEXCEPT override;
  206. bool do_always_noconv() const _NOEXCEPT override;
  207. int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
  208. size_t __mx) const override;
  209. int do_max_length() const _NOEXCEPT override;
  210. };
  211. template <>
  212. class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf16<wchar_t, true>
  213. : public codecvt<wchar_t, char, mbstate_t>
  214. {
  215. unsigned long __maxcode_;
  216. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  217. codecvt_mode __mode_;
  218. _LIBCPP_SUPPRESS_DEPRECATED_POP
  219. public:
  220. typedef wchar_t intern_type;
  221. typedef char extern_type;
  222. typedef mbstate_t state_type;
  223. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  224. _LIBCPP_INLINE_VISIBILITY
  225. explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
  226. codecvt_mode __mode)
  227. : codecvt<wchar_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
  228. __mode_(__mode) {}
  229. _LIBCPP_SUPPRESS_DEPRECATED_POP
  230. protected:
  231. result do_out(state_type& __st,
  232. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  233. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  234. result do_in(state_type& __st,
  235. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  236. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
  237. result do_unshift(state_type& __st,
  238. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  239. int do_encoding() const _NOEXCEPT override;
  240. bool do_always_noconv() const _NOEXCEPT override;
  241. int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
  242. int do_max_length() const _NOEXCEPT override;
  243. };
  244. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  245. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  246. template <>
  247. class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf16<char16_t, false>
  248. : public codecvt<char16_t, char, mbstate_t>
  249. {
  250. unsigned long __maxcode_;
  251. codecvt_mode __mode_;
  252. public:
  253. typedef char16_t intern_type;
  254. typedef char extern_type;
  255. typedef mbstate_t state_type;
  256. _LIBCPP_INLINE_VISIBILITY
  257. explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
  258. codecvt_mode __mode)
  259. : codecvt<char16_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
  260. __mode_(__mode) {}
  261. _LIBCPP_SUPPRESS_DEPRECATED_POP
  262. protected:
  263. result do_out(state_type& __st,
  264. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  265. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  266. result do_in(state_type& __st,
  267. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  268. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
  269. result do_unshift(state_type& __st,
  270. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  271. int do_encoding() const _NOEXCEPT override;
  272. bool do_always_noconv() const _NOEXCEPT override;
  273. int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
  274. int do_max_length() const _NOEXCEPT override;
  275. };
  276. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  277. template <>
  278. class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf16<char16_t, true>
  279. : public codecvt<char16_t, char, mbstate_t>
  280. {
  281. unsigned long __maxcode_;
  282. codecvt_mode __mode_;
  283. public:
  284. typedef char16_t intern_type;
  285. typedef char extern_type;
  286. typedef mbstate_t state_type;
  287. _LIBCPP_INLINE_VISIBILITY
  288. explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
  289. codecvt_mode __mode)
  290. : codecvt<char16_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
  291. __mode_(__mode) {}
  292. _LIBCPP_SUPPRESS_DEPRECATED_POP
  293. protected:
  294. result do_out(state_type& __st,
  295. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  296. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  297. result do_in(state_type& __st,
  298. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  299. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
  300. result do_unshift(state_type& __st,
  301. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  302. int do_encoding() const _NOEXCEPT override;
  303. bool do_always_noconv() const _NOEXCEPT override;
  304. int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
  305. int do_max_length() const _NOEXCEPT override;
  306. };
  307. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  308. template <>
  309. class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf16<char32_t, false>
  310. : public codecvt<char32_t, char, mbstate_t>
  311. {
  312. unsigned long __maxcode_;
  313. codecvt_mode __mode_;
  314. public:
  315. typedef char32_t intern_type;
  316. typedef char extern_type;
  317. typedef mbstate_t state_type;
  318. _LIBCPP_INLINE_VISIBILITY
  319. explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
  320. codecvt_mode __mode)
  321. : codecvt<char32_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
  322. __mode_(__mode) {}
  323. _LIBCPP_SUPPRESS_DEPRECATED_POP
  324. protected:
  325. result do_out(state_type& __st,
  326. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  327. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  328. result do_in(state_type& __st,
  329. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  330. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
  331. result do_unshift(state_type& __st,
  332. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  333. int do_encoding() const _NOEXCEPT override;
  334. bool do_always_noconv() const _NOEXCEPT override;
  335. int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
  336. int do_max_length() const _NOEXCEPT override;
  337. };
  338. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  339. template <>
  340. class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf16<char32_t, true>
  341. : public codecvt<char32_t, char, mbstate_t>
  342. {
  343. unsigned long __maxcode_;
  344. codecvt_mode __mode_;
  345. public:
  346. typedef char32_t intern_type;
  347. typedef char extern_type;
  348. typedef mbstate_t state_type;
  349. _LIBCPP_INLINE_VISIBILITY
  350. explicit __codecvt_utf16(size_t __refs, unsigned long __maxcode,
  351. codecvt_mode __mode)
  352. : codecvt<char32_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
  353. __mode_(__mode) {}
  354. _LIBCPP_SUPPRESS_DEPRECATED_POP
  355. protected:
  356. result do_out(state_type& __st,
  357. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  358. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  359. result do_in(state_type& __st,
  360. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  361. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
  362. result do_unshift(state_type& __st,
  363. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  364. int do_encoding() const _NOEXCEPT override;
  365. bool do_always_noconv() const _NOEXCEPT override;
  366. int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
  367. int do_max_length() const _NOEXCEPT override;
  368. };
  369. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  370. template <class _Elem, unsigned long _Maxcode = 0x10ffff,
  371. codecvt_mode _Mode = (codecvt_mode)0>
  372. class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 codecvt_utf16
  373. : public __codecvt_utf16<_Elem, _Mode & little_endian>
  374. {
  375. public:
  376. _LIBCPP_INLINE_VISIBILITY
  377. explicit codecvt_utf16(size_t __refs = 0)
  378. : __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) {}
  379. _LIBCPP_INLINE_VISIBILITY
  380. ~codecvt_utf16() {}
  381. };
  382. _LIBCPP_SUPPRESS_DEPRECATED_POP
  383. // codecvt_utf8_utf16
  384. template <class _Elem> class __codecvt_utf8_utf16;
  385. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  386. template <>
  387. class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8_utf16<wchar_t>
  388. : public codecvt<wchar_t, char, mbstate_t>
  389. {
  390. unsigned long __maxcode_;
  391. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  392. codecvt_mode __mode_;
  393. _LIBCPP_SUPPRESS_DEPRECATED_POP
  394. public:
  395. typedef wchar_t intern_type;
  396. typedef char extern_type;
  397. typedef mbstate_t state_type;
  398. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  399. _LIBCPP_INLINE_VISIBILITY
  400. explicit __codecvt_utf8_utf16(size_t __refs, unsigned long __maxcode,
  401. codecvt_mode __mode)
  402. : codecvt<wchar_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
  403. __mode_(__mode) {}
  404. _LIBCPP_SUPPRESS_DEPRECATED_POP
  405. protected:
  406. result do_out(state_type& __st,
  407. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  408. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  409. result do_in(state_type& __st,
  410. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  411. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
  412. result do_unshift(state_type& __st,
  413. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  414. int do_encoding() const _NOEXCEPT override;
  415. bool do_always_noconv() const _NOEXCEPT override;
  416. int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
  417. int do_max_length() const _NOEXCEPT override;
  418. };
  419. #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
  420. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  421. template <>
  422. class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8_utf16<char32_t>
  423. : public codecvt<char32_t, char, mbstate_t>
  424. {
  425. unsigned long __maxcode_;
  426. codecvt_mode __mode_;
  427. public:
  428. typedef char32_t intern_type;
  429. typedef char extern_type;
  430. typedef mbstate_t state_type;
  431. _LIBCPP_INLINE_VISIBILITY
  432. explicit __codecvt_utf8_utf16(size_t __refs, unsigned long __maxcode,
  433. codecvt_mode __mode)
  434. : codecvt<char32_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
  435. __mode_(__mode) {}
  436. _LIBCPP_SUPPRESS_DEPRECATED_POP
  437. protected:
  438. result do_out(state_type& __st,
  439. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  440. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  441. result do_in(state_type& __st,
  442. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  443. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
  444. result do_unshift(state_type& __st,
  445. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  446. int do_encoding() const _NOEXCEPT override;
  447. bool do_always_noconv() const _NOEXCEPT override;
  448. int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
  449. int do_max_length() const _NOEXCEPT override;
  450. };
  451. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  452. template <>
  453. class _LIBCPP_EXPORTED_FROM_ABI __codecvt_utf8_utf16<char16_t>
  454. : public codecvt<char16_t, char, mbstate_t>
  455. {
  456. unsigned long __maxcode_;
  457. codecvt_mode __mode_;
  458. public:
  459. typedef char16_t intern_type;
  460. typedef char extern_type;
  461. typedef mbstate_t state_type;
  462. _LIBCPP_INLINE_VISIBILITY
  463. explicit __codecvt_utf8_utf16(size_t __refs, unsigned long __maxcode,
  464. codecvt_mode __mode)
  465. : codecvt<char16_t, char, mbstate_t>(__refs), __maxcode_(__maxcode),
  466. __mode_(__mode) {}
  467. _LIBCPP_SUPPRESS_DEPRECATED_POP
  468. protected:
  469. result do_out(state_type& __st,
  470. const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
  471. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  472. result do_in(state_type& __st,
  473. const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
  474. intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const override;
  475. result do_unshift(state_type& __st,
  476. extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const override;
  477. int do_encoding() const _NOEXCEPT override;
  478. bool do_always_noconv() const _NOEXCEPT override;
  479. int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const override;
  480. int do_max_length() const _NOEXCEPT override;
  481. };
  482. _LIBCPP_SUPPRESS_DEPRECATED_PUSH
  483. template <class _Elem, unsigned long _Maxcode = 0x10ffff,
  484. codecvt_mode _Mode = (codecvt_mode)0>
  485. class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 codecvt_utf8_utf16
  486. : public __codecvt_utf8_utf16<_Elem>
  487. {
  488. public:
  489. _LIBCPP_INLINE_VISIBILITY
  490. explicit codecvt_utf8_utf16(size_t __refs = 0)
  491. : __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) {}
  492. _LIBCPP_INLINE_VISIBILITY
  493. ~codecvt_utf8_utf16() {}
  494. };
  495. _LIBCPP_SUPPRESS_DEPRECATED_POP
  496. _LIBCPP_END_NAMESPACE_STD
  497. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  498. # include <atomic>
  499. # include <concepts>
  500. # include <cstddef>
  501. # include <cstdlib>
  502. # include <cstring>
  503. # include <initializer_list>
  504. # include <iosfwd>
  505. # include <limits>
  506. # include <mutex>
  507. # include <new>
  508. # include <stdexcept>
  509. # include <type_traits>
  510. # include <typeinfo>
  511. #endif
  512. #endif // _LIBCPP_CODECVT