codecvt.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. // Locale support (codecvt) -*- C++ -*-
  2. // Copyright (C) 2000-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file bits/codecvt.h
  21. * This is an internal header file, included by other library headers.
  22. * Do not attempt to use it directly. @headername{locale}
  23. */
  24. //
  25. // ISO C++ 14882: 22.2.1.5 Template class codecvt
  26. //
  27. // Written by Benjamin Kosnik <bkoz@redhat.com>
  28. #ifndef _CODECVT_H
  29. #define _CODECVT_H 1
  30. #pragma GCC system_header
  31. #include <bits/c++config.h>
  32. #include <bits/locale_classes.h> // locale::facet
  33. namespace std _GLIBCXX_VISIBILITY(default)
  34. {
  35. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  36. /// Empty base class for codecvt facet [22.2.1.5].
  37. class codecvt_base
  38. {
  39. public:
  40. enum result
  41. {
  42. ok,
  43. partial,
  44. error,
  45. noconv
  46. };
  47. };
  48. /**
  49. * @brief Common base for codecvt functions.
  50. *
  51. * This template class provides implementations of the public functions
  52. * that forward to the protected virtual functions.
  53. *
  54. * This template also provides abstract stubs for the protected virtual
  55. * functions.
  56. */
  57. template<typename _InternT, typename _ExternT, typename _StateT>
  58. class __codecvt_abstract_base
  59. : public locale::facet, public codecvt_base
  60. {
  61. public:
  62. // Types:
  63. typedef codecvt_base::result result;
  64. typedef _InternT intern_type;
  65. typedef _ExternT extern_type;
  66. typedef _StateT state_type;
  67. // 22.2.1.5.1 codecvt members
  68. /**
  69. * @brief Convert from internal to external character set.
  70. *
  71. * Converts input string of intern_type to output string of
  72. * extern_type. This is analogous to wcsrtombs. It does this by
  73. * calling codecvt::do_out.
  74. *
  75. * The source and destination character sets are determined by the
  76. * facet's locale, internal and external types.
  77. *
  78. * The characters in [from,from_end) are converted and written to
  79. * [to,to_end). from_next and to_next are set to point to the
  80. * character following the last successfully converted character,
  81. * respectively. If the result needed no conversion, from_next and
  82. * to_next are not affected.
  83. *
  84. * The @a state argument should be initialized if the input is at the
  85. * beginning and carried from a previous call if continuing
  86. * conversion. There are no guarantees about how @a state is used.
  87. *
  88. * The result returned is a member of codecvt_base::result. If
  89. * all the input is converted, returns codecvt_base::ok. If no
  90. * conversion is necessary, returns codecvt_base::noconv. If
  91. * the input ends early or there is insufficient space in the
  92. * output, returns codecvt_base::partial. Otherwise the
  93. * conversion failed and codecvt_base::error is returned.
  94. *
  95. * @param __state Persistent conversion state data.
  96. * @param __from Start of input.
  97. * @param __from_end End of input.
  98. * @param __from_next Returns start of unconverted data.
  99. * @param __to Start of output buffer.
  100. * @param __to_end End of output buffer.
  101. * @param __to_next Returns start of unused output area.
  102. * @return codecvt_base::result.
  103. */
  104. result
  105. out(state_type& __state, const intern_type* __from,
  106. const intern_type* __from_end, const intern_type*& __from_next,
  107. extern_type* __to, extern_type* __to_end,
  108. extern_type*& __to_next) const
  109. {
  110. return this->do_out(__state, __from, __from_end, __from_next,
  111. __to, __to_end, __to_next);
  112. }
  113. /**
  114. * @brief Reset conversion state.
  115. *
  116. * Writes characters to output that would restore @a state to initial
  117. * conditions. The idea is that if a partial conversion occurs, then
  118. * the converting the characters written by this function would leave
  119. * the state in initial conditions, rather than partial conversion
  120. * state. It does this by calling codecvt::do_unshift().
  121. *
  122. * For example, if 4 external characters always converted to 1 internal
  123. * character, and input to in() had 6 external characters with state
  124. * saved, this function would write two characters to the output and
  125. * set the state to initialized conditions.
  126. *
  127. * The source and destination character sets are determined by the
  128. * facet's locale, internal and external types.
  129. *
  130. * The result returned is a member of codecvt_base::result. If the
  131. * state could be reset and data written, returns codecvt_base::ok. If
  132. * no conversion is necessary, returns codecvt_base::noconv. If the
  133. * output has insufficient space, returns codecvt_base::partial.
  134. * Otherwise the reset failed and codecvt_base::error is returned.
  135. *
  136. * @param __state Persistent conversion state data.
  137. * @param __to Start of output buffer.
  138. * @param __to_end End of output buffer.
  139. * @param __to_next Returns start of unused output area.
  140. * @return codecvt_base::result.
  141. */
  142. result
  143. unshift(state_type& __state, extern_type* __to, extern_type* __to_end,
  144. extern_type*& __to_next) const
  145. { return this->do_unshift(__state, __to,__to_end,__to_next); }
  146. /**
  147. * @brief Convert from external to internal character set.
  148. *
  149. * Converts input string of extern_type to output string of
  150. * intern_type. This is analogous to mbsrtowcs. It does this by
  151. * calling codecvt::do_in.
  152. *
  153. * The source and destination character sets are determined by the
  154. * facet's locale, internal and external types.
  155. *
  156. * The characters in [from,from_end) are converted and written to
  157. * [to,to_end). from_next and to_next are set to point to the
  158. * character following the last successfully converted character,
  159. * respectively. If the result needed no conversion, from_next and
  160. * to_next are not affected.
  161. *
  162. * The @a state argument should be initialized if the input is at the
  163. * beginning and carried from a previous call if continuing
  164. * conversion. There are no guarantees about how @a state is used.
  165. *
  166. * The result returned is a member of codecvt_base::result. If
  167. * all the input is converted, returns codecvt_base::ok. If no
  168. * conversion is necessary, returns codecvt_base::noconv. If
  169. * the input ends early or there is insufficient space in the
  170. * output, returns codecvt_base::partial. Otherwise the
  171. * conversion failed and codecvt_base::error is returned.
  172. *
  173. * @param __state Persistent conversion state data.
  174. * @param __from Start of input.
  175. * @param __from_end End of input.
  176. * @param __from_next Returns start of unconverted data.
  177. * @param __to Start of output buffer.
  178. * @param __to_end End of output buffer.
  179. * @param __to_next Returns start of unused output area.
  180. * @return codecvt_base::result.
  181. */
  182. result
  183. in(state_type& __state, const extern_type* __from,
  184. const extern_type* __from_end, const extern_type*& __from_next,
  185. intern_type* __to, intern_type* __to_end,
  186. intern_type*& __to_next) const
  187. {
  188. return this->do_in(__state, __from, __from_end, __from_next,
  189. __to, __to_end, __to_next);
  190. }
  191. int
  192. encoding() const throw()
  193. { return this->do_encoding(); }
  194. bool
  195. always_noconv() const throw()
  196. { return this->do_always_noconv(); }
  197. int
  198. length(state_type& __state, const extern_type* __from,
  199. const extern_type* __end, size_t __max) const
  200. { return this->do_length(__state, __from, __end, __max); }
  201. int
  202. max_length() const throw()
  203. { return this->do_max_length(); }
  204. protected:
  205. explicit
  206. __codecvt_abstract_base(size_t __refs = 0) : locale::facet(__refs) { }
  207. virtual
  208. ~__codecvt_abstract_base() { }
  209. /**
  210. * @brief Convert from internal to external character set.
  211. *
  212. * Converts input string of intern_type to output string of
  213. * extern_type. This function is a hook for derived classes to change
  214. * the value returned. @see out for more information.
  215. */
  216. virtual result
  217. do_out(state_type& __state, const intern_type* __from,
  218. const intern_type* __from_end, const intern_type*& __from_next,
  219. extern_type* __to, extern_type* __to_end,
  220. extern_type*& __to_next) const = 0;
  221. virtual result
  222. do_unshift(state_type& __state, extern_type* __to,
  223. extern_type* __to_end, extern_type*& __to_next) const = 0;
  224. virtual result
  225. do_in(state_type& __state, const extern_type* __from,
  226. const extern_type* __from_end, const extern_type*& __from_next,
  227. intern_type* __to, intern_type* __to_end,
  228. intern_type*& __to_next) const = 0;
  229. virtual int
  230. do_encoding() const throw() = 0;
  231. virtual bool
  232. do_always_noconv() const throw() = 0;
  233. virtual int
  234. do_length(state_type&, const extern_type* __from,
  235. const extern_type* __end, size_t __max) const = 0;
  236. virtual int
  237. do_max_length() const throw() = 0;
  238. };
  239. /**
  240. * @brief Primary class template codecvt.
  241. * @ingroup locales
  242. *
  243. * NB: Generic, mostly useless implementation.
  244. *
  245. */
  246. template<typename _InternT, typename _ExternT, typename _StateT>
  247. class codecvt
  248. : public __codecvt_abstract_base<_InternT, _ExternT, _StateT>
  249. {
  250. public:
  251. // Types:
  252. typedef codecvt_base::result result;
  253. typedef _InternT intern_type;
  254. typedef _ExternT extern_type;
  255. typedef _StateT state_type;
  256. protected:
  257. __c_locale _M_c_locale_codecvt;
  258. public:
  259. static locale::id id;
  260. explicit
  261. codecvt(size_t __refs = 0)
  262. : __codecvt_abstract_base<_InternT, _ExternT, _StateT> (__refs),
  263. _M_c_locale_codecvt(0)
  264. { }
  265. explicit
  266. codecvt(__c_locale __cloc, size_t __refs = 0);
  267. protected:
  268. virtual
  269. ~codecvt() { }
  270. virtual result
  271. do_out(state_type& __state, const intern_type* __from,
  272. const intern_type* __from_end, const intern_type*& __from_next,
  273. extern_type* __to, extern_type* __to_end,
  274. extern_type*& __to_next) const;
  275. virtual result
  276. do_unshift(state_type& __state, extern_type* __to,
  277. extern_type* __to_end, extern_type*& __to_next) const;
  278. virtual result
  279. do_in(state_type& __state, const extern_type* __from,
  280. const extern_type* __from_end, const extern_type*& __from_next,
  281. intern_type* __to, intern_type* __to_end,
  282. intern_type*& __to_next) const;
  283. virtual int
  284. do_encoding() const throw();
  285. virtual bool
  286. do_always_noconv() const throw();
  287. virtual int
  288. do_length(state_type&, const extern_type* __from,
  289. const extern_type* __end, size_t __max) const;
  290. virtual int
  291. do_max_length() const throw();
  292. };
  293. template<typename _InternT, typename _ExternT, typename _StateT>
  294. locale::id codecvt<_InternT, _ExternT, _StateT>::id;
  295. /// class codecvt<char, char, mbstate_t> specialization.
  296. template<>
  297. class codecvt<char, char, mbstate_t>
  298. : public __codecvt_abstract_base<char, char, mbstate_t>
  299. {
  300. friend class messages<char>;
  301. public:
  302. // Types:
  303. typedef char intern_type;
  304. typedef char extern_type;
  305. typedef mbstate_t state_type;
  306. protected:
  307. __c_locale _M_c_locale_codecvt;
  308. public:
  309. static locale::id id;
  310. explicit
  311. codecvt(size_t __refs = 0);
  312. explicit
  313. codecvt(__c_locale __cloc, size_t __refs = 0);
  314. protected:
  315. virtual
  316. ~codecvt();
  317. virtual result
  318. do_out(state_type& __state, const intern_type* __from,
  319. const intern_type* __from_end, const intern_type*& __from_next,
  320. extern_type* __to, extern_type* __to_end,
  321. extern_type*& __to_next) const;
  322. virtual result
  323. do_unshift(state_type& __state, extern_type* __to,
  324. extern_type* __to_end, extern_type*& __to_next) const;
  325. virtual result
  326. do_in(state_type& __state, const extern_type* __from,
  327. const extern_type* __from_end, const extern_type*& __from_next,
  328. intern_type* __to, intern_type* __to_end,
  329. intern_type*& __to_next) const;
  330. virtual int
  331. do_encoding() const throw();
  332. virtual bool
  333. do_always_noconv() const throw();
  334. virtual int
  335. do_length(state_type&, const extern_type* __from,
  336. const extern_type* __end, size_t __max) const;
  337. virtual int
  338. do_max_length() const throw();
  339. };
  340. #ifdef _GLIBCXX_USE_WCHAR_T
  341. /** @brief Class codecvt<wchar_t, char, mbstate_t> specialization.
  342. *
  343. * Converts between narrow and wide characters in the native character set
  344. */
  345. template<>
  346. class codecvt<wchar_t, char, mbstate_t>
  347. : public __codecvt_abstract_base<wchar_t, char, mbstate_t>
  348. {
  349. friend class messages<wchar_t>;
  350. public:
  351. // Types:
  352. typedef wchar_t intern_type;
  353. typedef char extern_type;
  354. typedef mbstate_t state_type;
  355. protected:
  356. __c_locale _M_c_locale_codecvt;
  357. public:
  358. static locale::id id;
  359. explicit
  360. codecvt(size_t __refs = 0);
  361. explicit
  362. codecvt(__c_locale __cloc, size_t __refs = 0);
  363. protected:
  364. virtual
  365. ~codecvt();
  366. virtual result
  367. do_out(state_type& __state, const intern_type* __from,
  368. const intern_type* __from_end, const intern_type*& __from_next,
  369. extern_type* __to, extern_type* __to_end,
  370. extern_type*& __to_next) const;
  371. virtual result
  372. do_unshift(state_type& __state,
  373. extern_type* __to, extern_type* __to_end,
  374. extern_type*& __to_next) const;
  375. virtual result
  376. do_in(state_type& __state,
  377. const extern_type* __from, const extern_type* __from_end,
  378. const extern_type*& __from_next,
  379. intern_type* __to, intern_type* __to_end,
  380. intern_type*& __to_next) const;
  381. virtual
  382. int do_encoding() const throw();
  383. virtual
  384. bool do_always_noconv() const throw();
  385. virtual
  386. int do_length(state_type&, const extern_type* __from,
  387. const extern_type* __end, size_t __max) const;
  388. virtual int
  389. do_max_length() const throw();
  390. };
  391. #endif //_GLIBCXX_USE_WCHAR_T
  392. #if __cplusplus >= 201103L
  393. /** @brief Class codecvt<char16_t, char, mbstate_t> specialization.
  394. *
  395. * Converts between UTF-16 and UTF-8.
  396. */
  397. template<>
  398. class codecvt<char16_t, char, mbstate_t>
  399. : public __codecvt_abstract_base<char16_t, char, mbstate_t>
  400. {
  401. public:
  402. // Types:
  403. typedef char16_t intern_type;
  404. typedef char extern_type;
  405. typedef mbstate_t state_type;
  406. public:
  407. static locale::id id;
  408. explicit
  409. codecvt(size_t __refs = 0)
  410. : __codecvt_abstract_base<char16_t, char, mbstate_t>(__refs) { }
  411. protected:
  412. virtual
  413. ~codecvt();
  414. virtual result
  415. do_out(state_type& __state, const intern_type* __from,
  416. const intern_type* __from_end, const intern_type*& __from_next,
  417. extern_type* __to, extern_type* __to_end,
  418. extern_type*& __to_next) const;
  419. virtual result
  420. do_unshift(state_type& __state,
  421. extern_type* __to, extern_type* __to_end,
  422. extern_type*& __to_next) const;
  423. virtual result
  424. do_in(state_type& __state,
  425. const extern_type* __from, const extern_type* __from_end,
  426. const extern_type*& __from_next,
  427. intern_type* __to, intern_type* __to_end,
  428. intern_type*& __to_next) const;
  429. virtual
  430. int do_encoding() const throw();
  431. virtual
  432. bool do_always_noconv() const throw();
  433. virtual
  434. int do_length(state_type&, const extern_type* __from,
  435. const extern_type* __end, size_t __max) const;
  436. virtual int
  437. do_max_length() const throw();
  438. };
  439. /** @brief Class codecvt<char32_t, char, mbstate_t> specialization.
  440. *
  441. * Converts between UTF-32 and UTF-8.
  442. */
  443. template<>
  444. class codecvt<char32_t, char, mbstate_t>
  445. : public __codecvt_abstract_base<char32_t, char, mbstate_t>
  446. {
  447. public:
  448. // Types:
  449. typedef char32_t intern_type;
  450. typedef char extern_type;
  451. typedef mbstate_t state_type;
  452. public:
  453. static locale::id id;
  454. explicit
  455. codecvt(size_t __refs = 0)
  456. : __codecvt_abstract_base<char32_t, char, mbstate_t>(__refs) { }
  457. protected:
  458. virtual
  459. ~codecvt();
  460. virtual result
  461. do_out(state_type& __state, const intern_type* __from,
  462. const intern_type* __from_end, const intern_type*& __from_next,
  463. extern_type* __to, extern_type* __to_end,
  464. extern_type*& __to_next) const;
  465. virtual result
  466. do_unshift(state_type& __state,
  467. extern_type* __to, extern_type* __to_end,
  468. extern_type*& __to_next) const;
  469. virtual result
  470. do_in(state_type& __state,
  471. const extern_type* __from, const extern_type* __from_end,
  472. const extern_type*& __from_next,
  473. intern_type* __to, intern_type* __to_end,
  474. intern_type*& __to_next) const;
  475. virtual
  476. int do_encoding() const throw();
  477. virtual
  478. bool do_always_noconv() const throw();
  479. virtual
  480. int do_length(state_type&, const extern_type* __from,
  481. const extern_type* __end, size_t __max) const;
  482. virtual int
  483. do_max_length() const throw();
  484. };
  485. #ifdef _GLIBCXX_USE_CHAR8_T
  486. /** @brief Class codecvt<char16_t, char8_t, mbstate_t> specialization.
  487. *
  488. * Converts between UTF-16 and UTF-8.
  489. */
  490. template<>
  491. class codecvt<char16_t, char8_t, mbstate_t>
  492. : public __codecvt_abstract_base<char16_t, char8_t, mbstate_t>
  493. {
  494. public:
  495. // Types:
  496. typedef char16_t intern_type;
  497. typedef char8_t extern_type;
  498. typedef mbstate_t state_type;
  499. public:
  500. static locale::id id;
  501. explicit
  502. codecvt(size_t __refs = 0)
  503. : __codecvt_abstract_base<char16_t, char8_t, mbstate_t>(__refs) { }
  504. protected:
  505. virtual
  506. ~codecvt();
  507. virtual result
  508. do_out(state_type& __state, const intern_type* __from,
  509. const intern_type* __from_end, const intern_type*& __from_next,
  510. extern_type* __to, extern_type* __to_end,
  511. extern_type*& __to_next) const;
  512. virtual result
  513. do_unshift(state_type& __state,
  514. extern_type* __to, extern_type* __to_end,
  515. extern_type*& __to_next) const;
  516. virtual result
  517. do_in(state_type& __state,
  518. const extern_type* __from, const extern_type* __from_end,
  519. const extern_type*& __from_next,
  520. intern_type* __to, intern_type* __to_end,
  521. intern_type*& __to_next) const;
  522. virtual
  523. int do_encoding() const throw();
  524. virtual
  525. bool do_always_noconv() const throw();
  526. virtual
  527. int do_length(state_type&, const extern_type* __from,
  528. const extern_type* __end, size_t __max) const;
  529. virtual int
  530. do_max_length() const throw();
  531. };
  532. /** @brief Class codecvt<char32_t, char8_t, mbstate_t> specialization.
  533. *
  534. * Converts between UTF-32 and UTF-8.
  535. */
  536. template<>
  537. class codecvt<char32_t, char8_t, mbstate_t>
  538. : public __codecvt_abstract_base<char32_t, char8_t, mbstate_t>
  539. {
  540. public:
  541. // Types:
  542. typedef char32_t intern_type;
  543. typedef char8_t extern_type;
  544. typedef mbstate_t state_type;
  545. public:
  546. static locale::id id;
  547. explicit
  548. codecvt(size_t __refs = 0)
  549. : __codecvt_abstract_base<char32_t, char8_t, mbstate_t>(__refs) { }
  550. protected:
  551. virtual
  552. ~codecvt();
  553. virtual result
  554. do_out(state_type& __state, const intern_type* __from,
  555. const intern_type* __from_end, const intern_type*& __from_next,
  556. extern_type* __to, extern_type* __to_end,
  557. extern_type*& __to_next) const;
  558. virtual result
  559. do_unshift(state_type& __state,
  560. extern_type* __to, extern_type* __to_end,
  561. extern_type*& __to_next) const;
  562. virtual result
  563. do_in(state_type& __state,
  564. const extern_type* __from, const extern_type* __from_end,
  565. const extern_type*& __from_next,
  566. intern_type* __to, intern_type* __to_end,
  567. intern_type*& __to_next) const;
  568. virtual
  569. int do_encoding() const throw();
  570. virtual
  571. bool do_always_noconv() const throw();
  572. virtual
  573. int do_length(state_type&, const extern_type* __from,
  574. const extern_type* __end, size_t __max) const;
  575. virtual int
  576. do_max_length() const throw();
  577. };
  578. #endif // _GLIBCXX_USE_CHAR8_T
  579. #endif // C++11
  580. /// class codecvt_byname [22.2.1.6].
  581. template<typename _InternT, typename _ExternT, typename _StateT>
  582. class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT>
  583. {
  584. public:
  585. explicit
  586. codecvt_byname(const char* __s, size_t __refs = 0)
  587. : codecvt<_InternT, _ExternT, _StateT>(__refs)
  588. {
  589. if (__builtin_strcmp(__s, "C") != 0
  590. && __builtin_strcmp(__s, "POSIX") != 0)
  591. {
  592. this->_S_destroy_c_locale(this->_M_c_locale_codecvt);
  593. this->_S_create_c_locale(this->_M_c_locale_codecvt, __s);
  594. }
  595. }
  596. #if __cplusplus >= 201103L
  597. explicit
  598. codecvt_byname(const string& __s, size_t __refs = 0)
  599. : codecvt_byname(__s.c_str(), __refs) { }
  600. #endif
  601. protected:
  602. virtual
  603. ~codecvt_byname() { }
  604. };
  605. #if __cplusplus >= 201103L
  606. template<>
  607. class codecvt_byname<char16_t, char, mbstate_t>
  608. : public codecvt<char16_t, char, mbstate_t>
  609. {
  610. public:
  611. explicit
  612. codecvt_byname(const char*, size_t __refs = 0)
  613. : codecvt<char16_t, char, mbstate_t>(__refs) { }
  614. explicit
  615. codecvt_byname(const string& __s, size_t __refs = 0)
  616. : codecvt_byname(__s.c_str(), __refs) { }
  617. protected:
  618. virtual
  619. ~codecvt_byname() { }
  620. };
  621. template<>
  622. class codecvt_byname<char32_t, char, mbstate_t>
  623. : public codecvt<char32_t, char, mbstate_t>
  624. {
  625. public:
  626. explicit
  627. codecvt_byname(const char*, size_t __refs = 0)
  628. : codecvt<char32_t, char, mbstate_t>(__refs) { }
  629. explicit
  630. codecvt_byname(const string& __s, size_t __refs = 0)
  631. : codecvt_byname(__s.c_str(), __refs) { }
  632. protected:
  633. virtual
  634. ~codecvt_byname() { }
  635. };
  636. #if defined(_GLIBCXX_USE_CHAR8_T)
  637. template<>
  638. class codecvt_byname<char16_t, char8_t, mbstate_t>
  639. : public codecvt<char16_t, char8_t, mbstate_t>
  640. {
  641. public:
  642. explicit
  643. codecvt_byname(const char*, size_t __refs = 0)
  644. : codecvt<char16_t, char8_t, mbstate_t>(__refs) { }
  645. explicit
  646. codecvt_byname(const string& __s, size_t __refs = 0)
  647. : codecvt_byname(__s.c_str(), __refs) { }
  648. protected:
  649. virtual
  650. ~codecvt_byname() { }
  651. };
  652. template<>
  653. class codecvt_byname<char32_t, char8_t, mbstate_t>
  654. : public codecvt<char32_t, char8_t, mbstate_t>
  655. {
  656. public:
  657. explicit
  658. codecvt_byname(const char*, size_t __refs = 0)
  659. : codecvt<char32_t, char8_t, mbstate_t>(__refs) { }
  660. explicit
  661. codecvt_byname(const string& __s, size_t __refs = 0)
  662. : codecvt_byname(__s.c_str(), __refs) { }
  663. protected:
  664. virtual
  665. ~codecvt_byname() { }
  666. };
  667. #endif
  668. #endif // C++11
  669. // Inhibit implicit instantiations for required instantiations,
  670. // which are defined via explicit instantiations elsewhere.
  671. #if _GLIBCXX_EXTERN_TEMPLATE
  672. extern template class codecvt_byname<char, char, mbstate_t>;
  673. extern template
  674. const codecvt<char, char, mbstate_t>&
  675. use_facet<codecvt<char, char, mbstate_t> >(const locale&);
  676. extern template
  677. bool
  678. has_facet<codecvt<char, char, mbstate_t> >(const locale&);
  679. #ifdef _GLIBCXX_USE_WCHAR_T
  680. extern template class codecvt_byname<wchar_t, char, mbstate_t>;
  681. extern template
  682. const codecvt<wchar_t, char, mbstate_t>&
  683. use_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&);
  684. extern template
  685. bool
  686. has_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&);
  687. #endif
  688. #if __cplusplus >= 201103L
  689. extern template class codecvt_byname<char16_t, char, mbstate_t>;
  690. extern template class codecvt_byname<char32_t, char, mbstate_t>;
  691. #if defined(_GLIBCXX_USE_CHAR8_T)
  692. extern template class codecvt_byname<char16_t, char8_t, mbstate_t>;
  693. extern template class codecvt_byname<char32_t, char8_t, mbstate_t>;
  694. #endif
  695. #endif
  696. #endif
  697. _GLIBCXX_END_NAMESPACE_VERSION
  698. } // namespace std
  699. #endif // _CODECVT_H