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