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