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