iomanip 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  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_IOMANIP
  10. #define _LIBCPP_IOMANIP
  11. /*
  12. iomanip synopsis
  13. namespace std {
  14. // types T1, T2, ... are unspecified implementation types
  15. T1 resetiosflags(ios_base::fmtflags mask);
  16. T2 setiosflags (ios_base::fmtflags mask);
  17. T3 setbase(int base);
  18. template<charT> T4 setfill(charT c);
  19. T5 setprecision(int n);
  20. T6 setw(int n);
  21. template <class moneyT> T7 get_money(moneyT& mon, bool intl = false);
  22. template <class charT, class moneyT> T8 put_money(const moneyT& mon, bool intl = false);
  23. template <class charT> T9 get_time(struct tm* tmb, const charT* fmt);
  24. template <class charT> T10 put_time(const struct tm* tmb, const charT* fmt);
  25. template <class charT>
  26. T11 quoted(const charT* s, charT delim=charT('"'), charT escape=charT('\\')); // C++14
  27. template <class charT, class traits, class Allocator>
  28. T12 quoted(const basic_string<charT, traits, Allocator>& s,
  29. charT delim=charT('"'), charT escape=charT('\\')); // C++14
  30. template <class charT, class traits, class Allocator>
  31. T13 quoted(basic_string<charT, traits, Allocator>& s,
  32. charT delim=charT('"'), charT escape=charT('\\')); // C++14
  33. } // std
  34. */
  35. #include <__assert> // all public C++ headers provide the assertion handler
  36. #include <__config>
  37. #include <istream>
  38. #include <version>
  39. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  40. # pragma GCC system_header
  41. #endif
  42. _LIBCPP_BEGIN_NAMESPACE_STD
  43. // resetiosflags
  44. class __iom_t1
  45. {
  46. ios_base::fmtflags __mask_;
  47. public:
  48. _LIBCPP_INLINE_VISIBILITY
  49. explicit __iom_t1(ios_base::fmtflags __m) : __mask_(__m) {}
  50. template <class _CharT, class _Traits>
  51. friend
  52. _LIBCPP_INLINE_VISIBILITY
  53. basic_istream<_CharT, _Traits>&
  54. operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t1& __x)
  55. {
  56. __is.unsetf(__x.__mask_);
  57. return __is;
  58. }
  59. template <class _CharT, class _Traits>
  60. friend
  61. _LIBCPP_INLINE_VISIBILITY
  62. basic_ostream<_CharT, _Traits>&
  63. operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t1& __x)
  64. {
  65. __os.unsetf(__x.__mask_);
  66. return __os;
  67. }
  68. };
  69. inline _LIBCPP_INLINE_VISIBILITY
  70. __iom_t1
  71. resetiosflags(ios_base::fmtflags __mask)
  72. {
  73. return __iom_t1(__mask);
  74. }
  75. // setiosflags
  76. class __iom_t2
  77. {
  78. ios_base::fmtflags __mask_;
  79. public:
  80. _LIBCPP_INLINE_VISIBILITY
  81. explicit __iom_t2(ios_base::fmtflags __m) : __mask_(__m) {}
  82. template <class _CharT, class _Traits>
  83. friend
  84. _LIBCPP_INLINE_VISIBILITY
  85. basic_istream<_CharT, _Traits>&
  86. operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t2& __x)
  87. {
  88. __is.setf(__x.__mask_);
  89. return __is;
  90. }
  91. template <class _CharT, class _Traits>
  92. friend
  93. _LIBCPP_INLINE_VISIBILITY
  94. basic_ostream<_CharT, _Traits>&
  95. operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t2& __x)
  96. {
  97. __os.setf(__x.__mask_);
  98. return __os;
  99. }
  100. };
  101. inline _LIBCPP_INLINE_VISIBILITY
  102. __iom_t2
  103. setiosflags(ios_base::fmtflags __mask)
  104. {
  105. return __iom_t2(__mask);
  106. }
  107. // setbase
  108. class __iom_t3
  109. {
  110. int __base_;
  111. public:
  112. _LIBCPP_INLINE_VISIBILITY
  113. explicit __iom_t3(int __b) : __base_(__b) {}
  114. template <class _CharT, class _Traits>
  115. friend
  116. _LIBCPP_INLINE_VISIBILITY
  117. basic_istream<_CharT, _Traits>&
  118. operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t3& __x)
  119. {
  120. __is.setf(__x.__base_ == 8 ? ios_base::oct :
  121. __x.__base_ == 10 ? ios_base::dec :
  122. __x.__base_ == 16 ? ios_base::hex :
  123. ios_base::fmtflags(0), ios_base::basefield);
  124. return __is;
  125. }
  126. template <class _CharT, class _Traits>
  127. friend
  128. _LIBCPP_INLINE_VISIBILITY
  129. basic_ostream<_CharT, _Traits>&
  130. operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t3& __x)
  131. {
  132. __os.setf(__x.__base_ == 8 ? ios_base::oct :
  133. __x.__base_ == 10 ? ios_base::dec :
  134. __x.__base_ == 16 ? ios_base::hex :
  135. ios_base::fmtflags(0), ios_base::basefield);
  136. return __os;
  137. }
  138. };
  139. inline _LIBCPP_INLINE_VISIBILITY
  140. __iom_t3
  141. setbase(int __base)
  142. {
  143. return __iom_t3(__base);
  144. }
  145. // setfill
  146. template<class _CharT>
  147. class __iom_t4
  148. {
  149. _CharT __fill_;
  150. public:
  151. _LIBCPP_INLINE_VISIBILITY
  152. explicit __iom_t4(_CharT __c) : __fill_(__c) {}
  153. template <class _Traits>
  154. friend
  155. _LIBCPP_INLINE_VISIBILITY
  156. basic_ostream<_CharT, _Traits>&
  157. operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t4& __x)
  158. {
  159. __os.fill(__x.__fill_);
  160. return __os;
  161. }
  162. };
  163. template<class _CharT>
  164. inline _LIBCPP_INLINE_VISIBILITY
  165. __iom_t4<_CharT>
  166. setfill(_CharT __c)
  167. {
  168. return __iom_t4<_CharT>(__c);
  169. }
  170. // setprecision
  171. class __iom_t5
  172. {
  173. int __n_;
  174. public:
  175. _LIBCPP_INLINE_VISIBILITY
  176. explicit __iom_t5(int __n) : __n_(__n) {}
  177. template <class _CharT, class _Traits>
  178. friend
  179. _LIBCPP_INLINE_VISIBILITY
  180. basic_istream<_CharT, _Traits>&
  181. operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t5& __x)
  182. {
  183. __is.precision(__x.__n_);
  184. return __is;
  185. }
  186. template <class _CharT, class _Traits>
  187. friend
  188. _LIBCPP_INLINE_VISIBILITY
  189. basic_ostream<_CharT, _Traits>&
  190. operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t5& __x)
  191. {
  192. __os.precision(__x.__n_);
  193. return __os;
  194. }
  195. };
  196. inline _LIBCPP_INLINE_VISIBILITY
  197. __iom_t5
  198. setprecision(int __n)
  199. {
  200. return __iom_t5(__n);
  201. }
  202. // setw
  203. class __iom_t6
  204. {
  205. int __n_;
  206. public:
  207. _LIBCPP_INLINE_VISIBILITY
  208. explicit __iom_t6(int __n) : __n_(__n) {}
  209. template <class _CharT, class _Traits>
  210. friend
  211. _LIBCPP_INLINE_VISIBILITY
  212. basic_istream<_CharT, _Traits>&
  213. operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t6& __x)
  214. {
  215. __is.width(__x.__n_);
  216. return __is;
  217. }
  218. template <class _CharT, class _Traits>
  219. friend
  220. _LIBCPP_INLINE_VISIBILITY
  221. basic_ostream<_CharT, _Traits>&
  222. operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t6& __x)
  223. {
  224. __os.width(__x.__n_);
  225. return __os;
  226. }
  227. };
  228. inline _LIBCPP_INLINE_VISIBILITY
  229. __iom_t6
  230. setw(int __n)
  231. {
  232. return __iom_t6(__n);
  233. }
  234. // get_money
  235. template <class _MoneyT> class __iom_t7;
  236. template <class _CharT, class _Traits, class _MoneyT>
  237. _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
  238. operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x);
  239. template <class _MoneyT>
  240. class __iom_t7
  241. {
  242. _MoneyT& __mon_;
  243. bool __intl_;
  244. public:
  245. _LIBCPP_INLINE_VISIBILITY
  246. __iom_t7(_MoneyT& __mon, bool __intl)
  247. : __mon_(__mon), __intl_(__intl) {}
  248. template <class _CharT, class _Traits, class _Mp>
  249. friend
  250. basic_istream<_CharT, _Traits>&
  251. operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_Mp>& __x);
  252. };
  253. template <class _CharT, class _Traits, class _MoneyT>
  254. _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
  255. operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x)
  256. {
  257. #ifndef _LIBCPP_NO_EXCEPTIONS
  258. try
  259. {
  260. #endif // _LIBCPP_NO_EXCEPTIONS
  261. typename basic_istream<_CharT, _Traits>::sentry __s(__is);
  262. if (__s)
  263. {
  264. typedef istreambuf_iterator<_CharT, _Traits> _Ip;
  265. typedef money_get<_CharT, _Ip> _Fp;
  266. ios_base::iostate __err = ios_base::goodbit;
  267. const _Fp& __mf = std::use_facet<_Fp>(__is.getloc());
  268. __mf.get(_Ip(__is), _Ip(), __x.__intl_, __is, __err, __x.__mon_);
  269. __is.setstate(__err);
  270. }
  271. #ifndef _LIBCPP_NO_EXCEPTIONS
  272. }
  273. catch (...)
  274. {
  275. __is.__set_badbit_and_consider_rethrow();
  276. }
  277. #endif // _LIBCPP_NO_EXCEPTIONS
  278. return __is;
  279. }
  280. template <class _MoneyT>
  281. inline _LIBCPP_INLINE_VISIBILITY
  282. __iom_t7<_MoneyT>
  283. get_money(_MoneyT& __mon, bool __intl = false)
  284. {
  285. return __iom_t7<_MoneyT>(__mon, __intl);
  286. }
  287. // put_money
  288. template <class _MoneyT> class __iom_t8;
  289. template <class _CharT, class _Traits, class _MoneyT>
  290. _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
  291. operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x);
  292. template <class _MoneyT>
  293. class __iom_t8
  294. {
  295. const _MoneyT& __mon_;
  296. bool __intl_;
  297. public:
  298. _LIBCPP_INLINE_VISIBILITY
  299. __iom_t8(const _MoneyT& __mon, bool __intl)
  300. : __mon_(__mon), __intl_(__intl) {}
  301. template <class _CharT, class _Traits, class _Mp>
  302. friend
  303. basic_ostream<_CharT, _Traits>&
  304. operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_Mp>& __x);
  305. };
  306. template <class _CharT, class _Traits, class _MoneyT>
  307. _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
  308. operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x)
  309. {
  310. #ifndef _LIBCPP_NO_EXCEPTIONS
  311. try
  312. {
  313. #endif // _LIBCPP_NO_EXCEPTIONS
  314. typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
  315. if (__s)
  316. {
  317. typedef ostreambuf_iterator<_CharT, _Traits> _Op;
  318. typedef money_put<_CharT, _Op> _Fp;
  319. const _Fp& __mf = std::use_facet<_Fp>(__os.getloc());
  320. if (__mf.put(_Op(__os), __x.__intl_, __os, __os.fill(), __x.__mon_).failed())
  321. __os.setstate(ios_base::badbit);
  322. }
  323. #ifndef _LIBCPP_NO_EXCEPTIONS
  324. }
  325. catch (...)
  326. {
  327. __os.__set_badbit_and_consider_rethrow();
  328. }
  329. #endif // _LIBCPP_NO_EXCEPTIONS
  330. return __os;
  331. }
  332. template <class _MoneyT>
  333. inline _LIBCPP_INLINE_VISIBILITY
  334. __iom_t8<_MoneyT>
  335. put_money(const _MoneyT& __mon, bool __intl = false)
  336. {
  337. return __iom_t8<_MoneyT>(__mon, __intl);
  338. }
  339. // get_time
  340. template <class _CharT> class __iom_t9;
  341. template <class _CharT, class _Traits>
  342. _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
  343. operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x);
  344. template <class _CharT>
  345. class __iom_t9
  346. {
  347. tm* __tm_;
  348. const _CharT* __fmt_;
  349. public:
  350. _LIBCPP_INLINE_VISIBILITY
  351. __iom_t9(tm* __tm, const _CharT* __fmt)
  352. : __tm_(__tm), __fmt_(__fmt) {}
  353. template <class _Cp, class _Traits>
  354. friend
  355. basic_istream<_Cp, _Traits>&
  356. operator>>(basic_istream<_Cp, _Traits>& __is, const __iom_t9<_Cp>& __x);
  357. };
  358. template <class _CharT, class _Traits>
  359. _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
  360. operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x)
  361. {
  362. #ifndef _LIBCPP_NO_EXCEPTIONS
  363. try
  364. {
  365. #endif // _LIBCPP_NO_EXCEPTIONS
  366. typename basic_istream<_CharT, _Traits>::sentry __s(__is);
  367. if (__s)
  368. {
  369. typedef istreambuf_iterator<_CharT, _Traits> _Ip;
  370. typedef time_get<_CharT, _Ip> _Fp;
  371. ios_base::iostate __err = ios_base::goodbit;
  372. const _Fp& __tf = std::use_facet<_Fp>(__is.getloc());
  373. __tf.get(_Ip(__is), _Ip(), __is, __err, __x.__tm_,
  374. __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_));
  375. __is.setstate(__err);
  376. }
  377. #ifndef _LIBCPP_NO_EXCEPTIONS
  378. }
  379. catch (...)
  380. {
  381. __is.__set_badbit_and_consider_rethrow();
  382. }
  383. #endif // _LIBCPP_NO_EXCEPTIONS
  384. return __is;
  385. }
  386. template <class _CharT>
  387. inline _LIBCPP_INLINE_VISIBILITY
  388. __iom_t9<_CharT>
  389. get_time(tm* __tm, const _CharT* __fmt)
  390. {
  391. return __iom_t9<_CharT>(__tm, __fmt);
  392. }
  393. // put_time
  394. template <class _CharT> class __iom_t10;
  395. template <class _CharT, class _Traits>
  396. _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
  397. operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x);
  398. template <class _CharT>
  399. class __iom_t10
  400. {
  401. const tm* __tm_;
  402. const _CharT* __fmt_;
  403. public:
  404. _LIBCPP_INLINE_VISIBILITY
  405. __iom_t10(const tm* __tm, const _CharT* __fmt)
  406. : __tm_(__tm), __fmt_(__fmt) {}
  407. template <class _Cp, class _Traits>
  408. friend
  409. basic_ostream<_Cp, _Traits>&
  410. operator<<(basic_ostream<_Cp, _Traits>& __os, const __iom_t10<_Cp>& __x);
  411. };
  412. template <class _CharT, class _Traits>
  413. _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
  414. operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x)
  415. {
  416. #ifndef _LIBCPP_NO_EXCEPTIONS
  417. try
  418. {
  419. #endif // _LIBCPP_NO_EXCEPTIONS
  420. typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
  421. if (__s)
  422. {
  423. typedef ostreambuf_iterator<_CharT, _Traits> _Op;
  424. typedef time_put<_CharT, _Op> _Fp;
  425. const _Fp& __tf = std::use_facet<_Fp>(__os.getloc());
  426. if (__tf.put(_Op(__os), __os, __os.fill(), __x.__tm_,
  427. __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_)).failed())
  428. __os.setstate(ios_base::badbit);
  429. }
  430. #ifndef _LIBCPP_NO_EXCEPTIONS
  431. }
  432. catch (...)
  433. {
  434. __os.__set_badbit_and_consider_rethrow();
  435. }
  436. #endif // _LIBCPP_NO_EXCEPTIONS
  437. return __os;
  438. }
  439. template <class _CharT>
  440. inline _LIBCPP_INLINE_VISIBILITY
  441. __iom_t10<_CharT>
  442. put_time(const tm* __tm, const _CharT* __fmt)
  443. {
  444. return __iom_t10<_CharT>(__tm, __fmt);
  445. }
  446. #if _LIBCPP_STD_VER >= 11
  447. template <class _CharT, class _Traits>
  448. _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
  449. __quoted_output(basic_ostream<_CharT, _Traits>& __os,
  450. const _CharT *__first, const _CharT *__last, _CharT __delim, _CharT __escape)
  451. {
  452. basic_string<_CharT, _Traits> __str;
  453. __str.push_back(__delim);
  454. for (; __first != __last; ++__first) {
  455. if (_Traits::eq(*__first, __escape) || _Traits::eq(*__first, __delim))
  456. __str.push_back(__escape);
  457. __str.push_back(*__first);
  458. }
  459. __str.push_back(__delim);
  460. return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
  461. }
  462. template <class _CharT, class _Traits, class _String>
  463. _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
  464. __quoted_input(basic_istream<_CharT, _Traits>& __is, _String& __string, _CharT __delim, _CharT __escape)
  465. {
  466. __string.clear();
  467. _CharT __c;
  468. __is >> __c;
  469. if (__is.fail())
  470. return __is;
  471. if (!_Traits::eq(__c, __delim)) {
  472. // no delimiter, read the whole string
  473. __is.unget();
  474. __is >> __string;
  475. return __is;
  476. }
  477. __save_flags<_CharT, _Traits> __sf(__is);
  478. std::noskipws(__is);
  479. while (true) {
  480. __is >> __c;
  481. if (__is.fail())
  482. break;
  483. if (_Traits::eq(__c, __escape)) {
  484. __is >> __c;
  485. if (__is.fail())
  486. break;
  487. } else if (_Traits::eq(__c, __delim))
  488. break;
  489. __string.push_back(__c);
  490. }
  491. return __is;
  492. }
  493. template <class _CharT, class _Traits>
  494. struct _LIBCPP_HIDDEN __quoted_output_proxy
  495. {
  496. const _CharT *__first_;
  497. const _CharT *__last_;
  498. _CharT __delim_;
  499. _CharT __escape_;
  500. _LIBCPP_HIDE_FROM_ABI
  501. explicit __quoted_output_proxy(const _CharT *__f, const _CharT *__l, _CharT __d, _CharT __e)
  502. : __first_(__f), __last_(__l), __delim_(__d), __escape_(__e) {}
  503. template<class _T2, __enable_if_t<_IsSame<_Traits, void>::value || _IsSame<_Traits, _T2>::value>* = nullptr>
  504. friend _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _T2>&
  505. operator<<(basic_ostream<_CharT, _T2>& __os, const __quoted_output_proxy& __p) {
  506. return std::__quoted_output(__os, __p.__first_, __p.__last_, __p.__delim_, __p.__escape_);
  507. }
  508. };
  509. template <class _CharT, class _Traits, class _Allocator>
  510. struct _LIBCPP_HIDDEN __quoted_proxy
  511. {
  512. basic_string<_CharT, _Traits, _Allocator>& __string_;
  513. _CharT __delim_;
  514. _CharT __escape_;
  515. _LIBCPP_HIDE_FROM_ABI
  516. explicit __quoted_proxy(basic_string<_CharT, _Traits, _Allocator>& __s, _CharT __d, _CharT __e)
  517. : __string_(__s), __delim_(__d), __escape_(__e) {}
  518. friend _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
  519. operator<<(basic_ostream<_CharT, _Traits>& __os, const __quoted_proxy& __p) {
  520. return std::__quoted_output(__os, __p.__string_.data(), __p.__string_.data() + __p.__string_.size(), __p.__delim_, __p.__escape_);
  521. }
  522. friend _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
  523. operator>>(basic_istream<_CharT, _Traits>& __is, const __quoted_proxy& __p) {
  524. return std::__quoted_input(__is, __p.__string_, __p.__delim_, __p.__escape_);
  525. }
  526. };
  527. template <class _CharT, class _Traits, class _Allocator>
  528. _LIBCPP_HIDE_FROM_ABI
  529. __quoted_output_proxy<_CharT, _Traits>
  530. __quoted(const basic_string<_CharT, _Traits, _Allocator>& __s, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
  531. {
  532. return __quoted_output_proxy<_CharT, _Traits>(__s.data(), __s.data() + __s.size(), __delim, __escape);
  533. }
  534. template <class _CharT, class _Traits, class _Allocator>
  535. _LIBCPP_HIDE_FROM_ABI
  536. __quoted_proxy<_CharT, _Traits, _Allocator>
  537. __quoted(basic_string<_CharT, _Traits, _Allocator>& __s, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
  538. {
  539. return __quoted_proxy<_CharT, _Traits, _Allocator>(__s, __delim, __escape);
  540. }
  541. #endif // _LIBCPP_STD_VER >= 11
  542. #if _LIBCPP_STD_VER > 11
  543. template <class _CharT>
  544. _LIBCPP_HIDE_FROM_ABI
  545. auto quoted(const _CharT *__s, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
  546. {
  547. const _CharT *__end = __s;
  548. while (*__end) ++__end;
  549. return __quoted_output_proxy<_CharT, void>(__s, __end, __delim, __escape);
  550. }
  551. template <class _CharT, class _Traits, class _Allocator>
  552. _LIBCPP_HIDE_FROM_ABI
  553. auto quoted(const basic_string<_CharT, _Traits, _Allocator>& __s, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
  554. {
  555. return __quoted_output_proxy<_CharT, _Traits>(__s.data(), __s.data() + __s.size(), __delim, __escape);
  556. }
  557. template <class _CharT, class _Traits, class _Allocator>
  558. _LIBCPP_HIDE_FROM_ABI
  559. auto quoted(basic_string<_CharT, _Traits, _Allocator>& __s, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
  560. {
  561. return __quoted_proxy<_CharT, _Traits, _Allocator>(__s, __delim, __escape);
  562. }
  563. template <class _CharT, class _Traits>
  564. _LIBCPP_HIDE_FROM_ABI
  565. auto quoted(basic_string_view<_CharT, _Traits> __sv, _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\'))
  566. {
  567. return __quoted_output_proxy<_CharT, _Traits>(__sv.data(), __sv.data() + __sv.size(), __delim, __escape);
  568. }
  569. #endif // _LIBCPP_STD_VER > 11
  570. _LIBCPP_END_NAMESPACE_STD
  571. #endif // _LIBCPP_IOMANIP