xref: /freebsd-12.1/contrib/libc++/include/iomanip (revision b5893f02)
17a984708SDavid Chisnall// -*- C++ -*-
27a984708SDavid Chisnall//===--------------------------- iomanip ----------------------------------===//
37a984708SDavid Chisnall//
47a984708SDavid Chisnall//                     The LLVM Compiler Infrastructure
57a984708SDavid Chisnall//
67a984708SDavid Chisnall// This file is dual licensed under the MIT and the University of Illinois Open
77a984708SDavid Chisnall// Source Licenses. See LICENSE.TXT for details.
87a984708SDavid Chisnall//
97a984708SDavid Chisnall//===----------------------------------------------------------------------===//
107a984708SDavid Chisnall
117a984708SDavid Chisnall#ifndef _LIBCPP_IOMANIP
127a984708SDavid Chisnall#define _LIBCPP_IOMANIP
137a984708SDavid Chisnall
147a984708SDavid Chisnall/*
157a984708SDavid Chisnall    iomanip synopsis
167a984708SDavid Chisnall
174f7ab58eSDimitry Andricnamespace std {
184f7ab58eSDimitry Andric
197a984708SDavid Chisnall// types T1, T2, ... are unspecified implementation types
207a984708SDavid ChisnallT1 resetiosflags(ios_base::fmtflags mask);
217a984708SDavid ChisnallT2 setiosflags (ios_base::fmtflags mask);
227a984708SDavid ChisnallT3 setbase(int base);
237a984708SDavid Chisnalltemplate<charT> T4 setfill(charT c);
247a984708SDavid ChisnallT5 setprecision(int n);
257a984708SDavid ChisnallT6 setw(int n);
267a984708SDavid Chisnalltemplate <class moneyT> T7 get_money(moneyT& mon, bool intl = false);
277a984708SDavid Chisnalltemplate <class charT, class moneyT> T8 put_money(const moneyT& mon, bool intl = false);
287a984708SDavid Chisnalltemplate <class charT> T9 get_time(struct tm* tmb, const charT* fmt);
297a984708SDavid Chisnalltemplate <class charT> T10 put_time(const struct tm* tmb, const charT* fmt);
307a984708SDavid Chisnall
314f7ab58eSDimitry Andrictemplate <class charT>
324f7ab58eSDimitry Andric  T11 quoted(const charT* s, charT delim=charT('"'), charT escape=charT('\\')); // C++14
334f7ab58eSDimitry Andric
344f7ab58eSDimitry Andrictemplate <class charT, class traits, class Allocator>
354f7ab58eSDimitry Andric  T12 quoted(const basic_string<charT, traits, Allocator>& s,
364f7ab58eSDimitry Andric             charT delim=charT('"'), charT escape=charT('\\')); // C++14
374f7ab58eSDimitry Andric
384f7ab58eSDimitry Andrictemplate <class charT, class traits, class Allocator>
394f7ab58eSDimitry Andric  T13 quoted(basic_string<charT, traits, Allocator>& s,
404f7ab58eSDimitry Andric             charT delim=charT('"'), charT escape=charT('\\')); // C++14
414f7ab58eSDimitry Andric
427a984708SDavid Chisnall}  // std
437a984708SDavid Chisnall
447a984708SDavid Chisnall*/
457a984708SDavid Chisnall
467a984708SDavid Chisnall#include <__config>
47aed8d94eSDimitry Andric#include <__string>
487a984708SDavid Chisnall#include <istream>
49*b5893f02SDimitry Andric#include <version>
507a984708SDavid Chisnall
517a984708SDavid Chisnall#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
527a984708SDavid Chisnall#pragma GCC system_header
537a984708SDavid Chisnall#endif
547a984708SDavid Chisnall
557a984708SDavid Chisnall_LIBCPP_BEGIN_NAMESPACE_STD
567a984708SDavid Chisnall
577a984708SDavid Chisnall// resetiosflags
587a984708SDavid Chisnall
597a984708SDavid Chisnallclass __iom_t1
607a984708SDavid Chisnall{
617a984708SDavid Chisnall    ios_base::fmtflags __mask_;
627a984708SDavid Chisnallpublic:
637a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
647a984708SDavid Chisnall    explicit __iom_t1(ios_base::fmtflags __m) : __mask_(__m) {}
657a984708SDavid Chisnall
667a984708SDavid Chisnall    template <class _CharT, class _Traits>
677a984708SDavid Chisnall    friend
687a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
697a984708SDavid Chisnall    basic_istream<_CharT, _Traits>&
707a984708SDavid Chisnall    operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t1& __x)
717a984708SDavid Chisnall    {
727a984708SDavid Chisnall        __is.unsetf(__x.__mask_);
737a984708SDavid Chisnall        return __is;
747a984708SDavid Chisnall    }
757a984708SDavid Chisnall
767a984708SDavid Chisnall    template <class _CharT, class _Traits>
777a984708SDavid Chisnall    friend
787a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
797a984708SDavid Chisnall    basic_ostream<_CharT, _Traits>&
807a984708SDavid Chisnall    operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t1& __x)
817a984708SDavid Chisnall    {
827a984708SDavid Chisnall        __os.unsetf(__x.__mask_);
837a984708SDavid Chisnall        return __os;
847a984708SDavid Chisnall    }
857a984708SDavid Chisnall};
867a984708SDavid Chisnall
877a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
887a984708SDavid Chisnall__iom_t1
897a984708SDavid Chisnallresetiosflags(ios_base::fmtflags __mask)
907a984708SDavid Chisnall{
917a984708SDavid Chisnall    return __iom_t1(__mask);
927a984708SDavid Chisnall}
937a984708SDavid Chisnall
947a984708SDavid Chisnall// setiosflags
957a984708SDavid Chisnall
967a984708SDavid Chisnallclass __iom_t2
977a984708SDavid Chisnall{
987a984708SDavid Chisnall    ios_base::fmtflags __mask_;
997a984708SDavid Chisnallpublic:
1007a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
1017a984708SDavid Chisnall    explicit __iom_t2(ios_base::fmtflags __m) : __mask_(__m) {}
1027a984708SDavid Chisnall
1037a984708SDavid Chisnall    template <class _CharT, class _Traits>
1047a984708SDavid Chisnall    friend
1057a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
1067a984708SDavid Chisnall    basic_istream<_CharT, _Traits>&
1077a984708SDavid Chisnall    operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t2& __x)
1087a984708SDavid Chisnall    {
1097a984708SDavid Chisnall        __is.setf(__x.__mask_);
1107a984708SDavid Chisnall        return __is;
1117a984708SDavid Chisnall    }
1127a984708SDavid Chisnall
1137a984708SDavid Chisnall    template <class _CharT, class _Traits>
1147a984708SDavid Chisnall    friend
1157a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
1167a984708SDavid Chisnall    basic_ostream<_CharT, _Traits>&
1177a984708SDavid Chisnall    operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t2& __x)
1187a984708SDavid Chisnall    {
1197a984708SDavid Chisnall        __os.setf(__x.__mask_);
1207a984708SDavid Chisnall        return __os;
1217a984708SDavid Chisnall    }
1227a984708SDavid Chisnall};
1237a984708SDavid Chisnall
1247a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1257a984708SDavid Chisnall__iom_t2
1267a984708SDavid Chisnallsetiosflags(ios_base::fmtflags __mask)
1277a984708SDavid Chisnall{
1287a984708SDavid Chisnall    return __iom_t2(__mask);
1297a984708SDavid Chisnall}
1307a984708SDavid Chisnall
1317a984708SDavid Chisnall// setbase
1327a984708SDavid Chisnall
1337a984708SDavid Chisnallclass __iom_t3
1347a984708SDavid Chisnall{
1357a984708SDavid Chisnall    int __base_;
1367a984708SDavid Chisnallpublic:
1377a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
1387a984708SDavid Chisnall    explicit __iom_t3(int __b) : __base_(__b) {}
1397a984708SDavid Chisnall
1407a984708SDavid Chisnall    template <class _CharT, class _Traits>
1417a984708SDavid Chisnall    friend
1427a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
1437a984708SDavid Chisnall    basic_istream<_CharT, _Traits>&
1447a984708SDavid Chisnall    operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t3& __x)
1457a984708SDavid Chisnall    {
1467a984708SDavid Chisnall        __is.setf(__x.__base_ == 8  ? ios_base::oct :
1477a984708SDavid Chisnall                  __x.__base_ == 10 ? ios_base::dec :
1487a984708SDavid Chisnall                  __x.__base_ == 16 ? ios_base::hex :
1497a984708SDavid Chisnall                  ios_base::fmtflags(0), ios_base::basefield);
1507a984708SDavid Chisnall        return __is;
1517a984708SDavid Chisnall    }
1527a984708SDavid Chisnall
1537a984708SDavid Chisnall    template <class _CharT, class _Traits>
1547a984708SDavid Chisnall    friend
1557a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
1567a984708SDavid Chisnall    basic_ostream<_CharT, _Traits>&
1577a984708SDavid Chisnall    operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t3& __x)
1587a984708SDavid Chisnall    {
1597a984708SDavid Chisnall        __os.setf(__x.__base_ == 8  ? ios_base::oct :
1607a984708SDavid Chisnall                  __x.__base_ == 10 ? ios_base::dec :
1617a984708SDavid Chisnall                  __x.__base_ == 16 ? ios_base::hex :
1627a984708SDavid Chisnall                  ios_base::fmtflags(0), ios_base::basefield);
1637a984708SDavid Chisnall        return __os;
1647a984708SDavid Chisnall    }
1657a984708SDavid Chisnall};
1667a984708SDavid Chisnall
1677a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1687a984708SDavid Chisnall__iom_t3
1697a984708SDavid Chisnallsetbase(int __base)
1707a984708SDavid Chisnall{
1717a984708SDavid Chisnall    return __iom_t3(__base);
1727a984708SDavid Chisnall}
1737a984708SDavid Chisnall
1747a984708SDavid Chisnall// setfill
1757a984708SDavid Chisnall
1767a984708SDavid Chisnalltemplate<class _CharT>
1777a984708SDavid Chisnallclass __iom_t4
1787a984708SDavid Chisnall{
1797a984708SDavid Chisnall    _CharT __fill_;
1807a984708SDavid Chisnallpublic:
1817a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
1827a984708SDavid Chisnall    explicit __iom_t4(_CharT __c) : __fill_(__c) {}
1837a984708SDavid Chisnall
1847a984708SDavid Chisnall    template <class _Traits>
1857a984708SDavid Chisnall    friend
1867a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
1877a984708SDavid Chisnall    basic_ostream<_CharT, _Traits>&
1887a984708SDavid Chisnall    operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t4& __x)
1897a984708SDavid Chisnall    {
1907a984708SDavid Chisnall        __os.fill(__x.__fill_);
1917a984708SDavid Chisnall        return __os;
1927a984708SDavid Chisnall    }
1937a984708SDavid Chisnall};
1947a984708SDavid Chisnall
1957a984708SDavid Chisnalltemplate<class _CharT>
1967a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1977a984708SDavid Chisnall__iom_t4<_CharT>
1987a984708SDavid Chisnallsetfill(_CharT __c)
1997a984708SDavid Chisnall{
2007a984708SDavid Chisnall    return __iom_t4<_CharT>(__c);
2017a984708SDavid Chisnall}
2027a984708SDavid Chisnall
2037a984708SDavid Chisnall// setprecision
2047a984708SDavid Chisnall
2057a984708SDavid Chisnallclass __iom_t5
2067a984708SDavid Chisnall{
2077a984708SDavid Chisnall    int __n_;
2087a984708SDavid Chisnallpublic:
2097a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2107a984708SDavid Chisnall    explicit __iom_t5(int __n) : __n_(__n) {}
2117a984708SDavid Chisnall
2127a984708SDavid Chisnall    template <class _CharT, class _Traits>
2137a984708SDavid Chisnall    friend
2147a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2157a984708SDavid Chisnall    basic_istream<_CharT, _Traits>&
2167a984708SDavid Chisnall    operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t5& __x)
2177a984708SDavid Chisnall    {
2187a984708SDavid Chisnall        __is.precision(__x.__n_);
2197a984708SDavid Chisnall        return __is;
2207a984708SDavid Chisnall    }
2217a984708SDavid Chisnall
2227a984708SDavid Chisnall    template <class _CharT, class _Traits>
2237a984708SDavid Chisnall    friend
2247a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2257a984708SDavid Chisnall    basic_ostream<_CharT, _Traits>&
2267a984708SDavid Chisnall    operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t5& __x)
2277a984708SDavid Chisnall    {
2287a984708SDavid Chisnall        __os.precision(__x.__n_);
2297a984708SDavid Chisnall        return __os;
2307a984708SDavid Chisnall    }
2317a984708SDavid Chisnall};
2327a984708SDavid Chisnall
2337a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
2347a984708SDavid Chisnall__iom_t5
2357a984708SDavid Chisnallsetprecision(int __n)
2367a984708SDavid Chisnall{
2377a984708SDavid Chisnall    return __iom_t5(__n);
2387a984708SDavid Chisnall}
2397a984708SDavid Chisnall
2407a984708SDavid Chisnall// setw
2417a984708SDavid Chisnall
2427a984708SDavid Chisnallclass __iom_t6
2437a984708SDavid Chisnall{
2447a984708SDavid Chisnall    int __n_;
2457a984708SDavid Chisnallpublic:
2467a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2477a984708SDavid Chisnall    explicit __iom_t6(int __n) : __n_(__n) {}
2487a984708SDavid Chisnall
2497a984708SDavid Chisnall    template <class _CharT, class _Traits>
2507a984708SDavid Chisnall    friend
2517a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2527a984708SDavid Chisnall    basic_istream<_CharT, _Traits>&
2537a984708SDavid Chisnall    operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t6& __x)
2547a984708SDavid Chisnall    {
2557a984708SDavid Chisnall        __is.width(__x.__n_);
2567a984708SDavid Chisnall        return __is;
2577a984708SDavid Chisnall    }
2587a984708SDavid Chisnall
2597a984708SDavid Chisnall    template <class _CharT, class _Traits>
2607a984708SDavid Chisnall    friend
2617a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2627a984708SDavid Chisnall    basic_ostream<_CharT, _Traits>&
2637a984708SDavid Chisnall    operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t6& __x)
2647a984708SDavid Chisnall    {
2657a984708SDavid Chisnall        __os.width(__x.__n_);
2667a984708SDavid Chisnall        return __os;
2677a984708SDavid Chisnall    }
2687a984708SDavid Chisnall};
2697a984708SDavid Chisnall
2707a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
2717a984708SDavid Chisnall__iom_t6
2727a984708SDavid Chisnallsetw(int __n)
2737a984708SDavid Chisnall{
2747a984708SDavid Chisnall    return __iom_t6(__n);
2757a984708SDavid Chisnall}
2767a984708SDavid Chisnall
2777a984708SDavid Chisnall// get_money
2787a984708SDavid Chisnall
2797a984708SDavid Chisnalltemplate <class _MoneyT> class __iom_t7;
2807a984708SDavid Chisnall
2817a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _MoneyT>
2827a984708SDavid Chisnallbasic_istream<_CharT, _Traits>&
2837a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x);
2847a984708SDavid Chisnall
2857a984708SDavid Chisnalltemplate <class _MoneyT>
2867a984708SDavid Chisnallclass __iom_t7
2877a984708SDavid Chisnall{
2887a984708SDavid Chisnall    _MoneyT& __mon_;
2897a984708SDavid Chisnall    bool __intl_;
2907a984708SDavid Chisnallpublic:
2917a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
2927a984708SDavid Chisnall    __iom_t7(_MoneyT& __mon, bool __intl)
2937a984708SDavid Chisnall        : __mon_(__mon), __intl_(__intl) {}
2947a984708SDavid Chisnall
29594e3ee44SDavid Chisnall    template <class _CharT, class _Traits, class _Mp>
2967a984708SDavid Chisnall    friend
2977a984708SDavid Chisnall    basic_istream<_CharT, _Traits>&
29894e3ee44SDavid Chisnall    operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_Mp>& __x);
2997a984708SDavid Chisnall};
3007a984708SDavid Chisnall
3017a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _MoneyT>
3027a984708SDavid Chisnallbasic_istream<_CharT, _Traits>&
3037a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x)
3047a984708SDavid Chisnall{
3057a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
3067a984708SDavid Chisnall    try
3077a984708SDavid Chisnall    {
3087a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
3097a984708SDavid Chisnall        typename basic_istream<_CharT, _Traits>::sentry __s(__is);
3107a984708SDavid Chisnall        if (__s)
3117a984708SDavid Chisnall        {
31294e3ee44SDavid Chisnall            typedef istreambuf_iterator<_CharT, _Traits> _Ip;
31394e3ee44SDavid Chisnall            typedef money_get<_CharT, _Ip> _Fp;
3147a984708SDavid Chisnall            ios_base::iostate __err = ios_base::goodbit;
31594e3ee44SDavid Chisnall            const _Fp& __mf = use_facet<_Fp>(__is.getloc());
31694e3ee44SDavid Chisnall            __mf.get(_Ip(__is), _Ip(), __x.__intl_, __is, __err, __x.__mon_);
3177a984708SDavid Chisnall            __is.setstate(__err);
3187a984708SDavid Chisnall        }
3197a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
3207a984708SDavid Chisnall    }
3217a984708SDavid Chisnall    catch (...)
3227a984708SDavid Chisnall    {
3237a984708SDavid Chisnall        __is.__set_badbit_and_consider_rethrow();
3247a984708SDavid Chisnall    }
3257a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
3267a984708SDavid Chisnall    return __is;
3277a984708SDavid Chisnall}
3287a984708SDavid Chisnall
3297a984708SDavid Chisnalltemplate <class _MoneyT>
3307a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
3317a984708SDavid Chisnall__iom_t7<_MoneyT>
3327a984708SDavid Chisnallget_money(_MoneyT& __mon, bool __intl = false)
3337a984708SDavid Chisnall{
3347a984708SDavid Chisnall    return __iom_t7<_MoneyT>(__mon, __intl);
3357a984708SDavid Chisnall}
3367a984708SDavid Chisnall
3377a984708SDavid Chisnall// put_money
3387a984708SDavid Chisnall
3397a984708SDavid Chisnalltemplate <class _MoneyT> class __iom_t8;
3407a984708SDavid Chisnall
3417a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _MoneyT>
3427a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>&
3437a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x);
3447a984708SDavid Chisnall
3457a984708SDavid Chisnalltemplate <class _MoneyT>
3467a984708SDavid Chisnallclass __iom_t8
3477a984708SDavid Chisnall{
3487a984708SDavid Chisnall    const _MoneyT& __mon_;
3497a984708SDavid Chisnall    bool __intl_;
3507a984708SDavid Chisnallpublic:
3517a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
3527a984708SDavid Chisnall    __iom_t8(const _MoneyT& __mon, bool __intl)
3537a984708SDavid Chisnall        : __mon_(__mon), __intl_(__intl) {}
3547a984708SDavid Chisnall
35594e3ee44SDavid Chisnall    template <class _CharT, class _Traits, class _Mp>
3567a984708SDavid Chisnall    friend
3577a984708SDavid Chisnall    basic_ostream<_CharT, _Traits>&
35894e3ee44SDavid Chisnall    operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_Mp>& __x);
3597a984708SDavid Chisnall};
3607a984708SDavid Chisnall
3617a984708SDavid Chisnalltemplate <class _CharT, class _Traits, class _MoneyT>
3627a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>&
3637a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x)
3647a984708SDavid Chisnall{
3657a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
3667a984708SDavid Chisnall    try
3677a984708SDavid Chisnall    {
3687a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
3697a984708SDavid Chisnall        typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
3707a984708SDavid Chisnall        if (__s)
3717a984708SDavid Chisnall        {
37294e3ee44SDavid Chisnall            typedef ostreambuf_iterator<_CharT, _Traits> _Op;
37394e3ee44SDavid Chisnall            typedef money_put<_CharT, _Op> _Fp;
37494e3ee44SDavid Chisnall            const _Fp& __mf = use_facet<_Fp>(__os.getloc());
37594e3ee44SDavid Chisnall            if (__mf.put(_Op(__os), __x.__intl_, __os, __os.fill(), __x.__mon_).failed())
3767a984708SDavid Chisnall                __os.setstate(ios_base::badbit);
3777a984708SDavid Chisnall        }
3787a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
3797a984708SDavid Chisnall    }
3807a984708SDavid Chisnall    catch (...)
3817a984708SDavid Chisnall    {
3827a984708SDavid Chisnall        __os.__set_badbit_and_consider_rethrow();
3837a984708SDavid Chisnall    }
3847a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
3857a984708SDavid Chisnall    return __os;
3867a984708SDavid Chisnall}
3877a984708SDavid Chisnall
3887a984708SDavid Chisnalltemplate <class _MoneyT>
3897a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
3907a984708SDavid Chisnall__iom_t8<_MoneyT>
3917a984708SDavid Chisnallput_money(const _MoneyT& __mon, bool __intl = false)
3927a984708SDavid Chisnall{
3937a984708SDavid Chisnall    return __iom_t8<_MoneyT>(__mon, __intl);
3947a984708SDavid Chisnall}
3957a984708SDavid Chisnall
3967a984708SDavid Chisnall// get_time
3977a984708SDavid Chisnall
3987a984708SDavid Chisnalltemplate <class _CharT> class __iom_t9;
3997a984708SDavid Chisnall
4007a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
4017a984708SDavid Chisnallbasic_istream<_CharT, _Traits>&
4027a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x);
4037a984708SDavid Chisnall
4047a984708SDavid Chisnalltemplate <class _CharT>
4057a984708SDavid Chisnallclass __iom_t9
4067a984708SDavid Chisnall{
4077a984708SDavid Chisnall    tm* __tm_;
4087a984708SDavid Chisnall    const _CharT* __fmt_;
4097a984708SDavid Chisnallpublic:
4107a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4117a984708SDavid Chisnall    __iom_t9(tm* __tm, const _CharT* __fmt)
4127a984708SDavid Chisnall        : __tm_(__tm), __fmt_(__fmt) {}
4137a984708SDavid Chisnall
41494e3ee44SDavid Chisnall    template <class _Cp, class _Traits>
4157a984708SDavid Chisnall    friend
41694e3ee44SDavid Chisnall    basic_istream<_Cp, _Traits>&
41794e3ee44SDavid Chisnall    operator>>(basic_istream<_Cp, _Traits>& __is, const __iom_t9<_Cp>& __x);
4187a984708SDavid Chisnall};
4197a984708SDavid Chisnall
4207a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
4217a984708SDavid Chisnallbasic_istream<_CharT, _Traits>&
4227a984708SDavid Chisnalloperator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x)
4237a984708SDavid Chisnall{
4247a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
4257a984708SDavid Chisnall    try
4267a984708SDavid Chisnall    {
4277a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
4287a984708SDavid Chisnall        typename basic_istream<_CharT, _Traits>::sentry __s(__is);
4297a984708SDavid Chisnall        if (__s)
4307a984708SDavid Chisnall        {
43194e3ee44SDavid Chisnall            typedef istreambuf_iterator<_CharT, _Traits> _Ip;
43294e3ee44SDavid Chisnall            typedef time_get<_CharT, _Ip> _Fp;
4337a984708SDavid Chisnall            ios_base::iostate __err = ios_base::goodbit;
43494e3ee44SDavid Chisnall            const _Fp& __tf = use_facet<_Fp>(__is.getloc());
43594e3ee44SDavid Chisnall            __tf.get(_Ip(__is), _Ip(), __is, __err, __x.__tm_,
4367a984708SDavid Chisnall                     __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_));
4377a984708SDavid Chisnall            __is.setstate(__err);
4387a984708SDavid Chisnall        }
4397a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
4407a984708SDavid Chisnall    }
4417a984708SDavid Chisnall    catch (...)
4427a984708SDavid Chisnall    {
4437a984708SDavid Chisnall        __is.__set_badbit_and_consider_rethrow();
4447a984708SDavid Chisnall    }
4457a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
4467a984708SDavid Chisnall    return __is;
4477a984708SDavid Chisnall}
4487a984708SDavid Chisnall
4497a984708SDavid Chisnalltemplate <class _CharT>
4507a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
4517a984708SDavid Chisnall__iom_t9<_CharT>
4527a984708SDavid Chisnallget_time(tm* __tm, const _CharT* __fmt)
4537a984708SDavid Chisnall{
4547a984708SDavid Chisnall    return __iom_t9<_CharT>(__tm, __fmt);
4557a984708SDavid Chisnall}
4567a984708SDavid Chisnall
4577a984708SDavid Chisnall// put_time
4587a984708SDavid Chisnall
4597a984708SDavid Chisnalltemplate <class _CharT> class __iom_t10;
4607a984708SDavid Chisnall
4617a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
4627a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>&
4637a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x);
4647a984708SDavid Chisnall
4657a984708SDavid Chisnalltemplate <class _CharT>
4667a984708SDavid Chisnallclass __iom_t10
4677a984708SDavid Chisnall{
4687a984708SDavid Chisnall    const tm* __tm_;
4697a984708SDavid Chisnall    const _CharT* __fmt_;
4707a984708SDavid Chisnallpublic:
4717a984708SDavid Chisnall    _LIBCPP_INLINE_VISIBILITY
4727a984708SDavid Chisnall    __iom_t10(const tm* __tm, const _CharT* __fmt)
4737a984708SDavid Chisnall        : __tm_(__tm), __fmt_(__fmt) {}
4747a984708SDavid Chisnall
47594e3ee44SDavid Chisnall    template <class _Cp, class _Traits>
4767a984708SDavid Chisnall    friend
47794e3ee44SDavid Chisnall    basic_ostream<_Cp, _Traits>&
47894e3ee44SDavid Chisnall    operator<<(basic_ostream<_Cp, _Traits>& __os, const __iom_t10<_Cp>& __x);
4797a984708SDavid Chisnall};
4807a984708SDavid Chisnall
4817a984708SDavid Chisnalltemplate <class _CharT, class _Traits>
4827a984708SDavid Chisnallbasic_ostream<_CharT, _Traits>&
4837a984708SDavid Chisnalloperator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x)
4847a984708SDavid Chisnall{
4857a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
4867a984708SDavid Chisnall    try
4877a984708SDavid Chisnall    {
4887a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
4897a984708SDavid Chisnall        typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
4907a984708SDavid Chisnall        if (__s)
4917a984708SDavid Chisnall        {
49294e3ee44SDavid Chisnall            typedef ostreambuf_iterator<_CharT, _Traits> _Op;
49394e3ee44SDavid Chisnall            typedef time_put<_CharT, _Op> _Fp;
49494e3ee44SDavid Chisnall            const _Fp& __tf = use_facet<_Fp>(__os.getloc());
49594e3ee44SDavid Chisnall            if (__tf.put(_Op(__os), __os, __os.fill(), __x.__tm_,
4967a984708SDavid Chisnall                         __x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_)).failed())
4977a984708SDavid Chisnall                __os.setstate(ios_base::badbit);
4987a984708SDavid Chisnall        }
4997a984708SDavid Chisnall#ifndef _LIBCPP_NO_EXCEPTIONS
5007a984708SDavid Chisnall    }
5017a984708SDavid Chisnall    catch (...)
5027a984708SDavid Chisnall    {
5037a984708SDavid Chisnall        __os.__set_badbit_and_consider_rethrow();
5047a984708SDavid Chisnall    }
5057a984708SDavid Chisnall#endif  // _LIBCPP_NO_EXCEPTIONS
5067a984708SDavid Chisnall    return __os;
5077a984708SDavid Chisnall}
5087a984708SDavid Chisnall
5097a984708SDavid Chisnalltemplate <class _CharT>
5107a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
5117a984708SDavid Chisnall__iom_t10<_CharT>
5127a984708SDavid Chisnallput_time(const tm* __tm, const _CharT* __fmt)
5137a984708SDavid Chisnall{
5147a984708SDavid Chisnall    return __iom_t10<_CharT>(__tm, __fmt);
5157a984708SDavid Chisnall}
5167a984708SDavid Chisnall
5174f7ab58eSDimitry Andrictemplate <class _CharT, class _Traits, class _ForwardIterator>
5184f7ab58eSDimitry Andricstd::basic_ostream<_CharT, _Traits> &
5194f7ab58eSDimitry Andric__quoted_output ( basic_ostream<_CharT, _Traits> &__os,
5204f7ab58eSDimitry Andric        _ForwardIterator __first, _ForwardIterator __last, _CharT __delim, _CharT __escape )
5214f7ab58eSDimitry Andric{
522d72607e9SDimitry Andric    _VSTD::basic_string<_CharT, _Traits> __str;
523d72607e9SDimitry Andric    __str.push_back(__delim);
5244f7ab58eSDimitry Andric    for ( ; __first != __last; ++ __first )
5254f7ab58eSDimitry Andric    {
5264f7ab58eSDimitry Andric        if (_Traits::eq (*__first, __escape) || _Traits::eq (*__first, __delim))
527d72607e9SDimitry Andric            __str.push_back(__escape);
528d72607e9SDimitry Andric        __str.push_back(*__first);
5294f7ab58eSDimitry Andric    }
530d72607e9SDimitry Andric    __str.push_back(__delim);
531d72607e9SDimitry Andric    return __put_character_sequence(__os, __str.data(), __str.size());
5324f7ab58eSDimitry Andric}
5334f7ab58eSDimitry Andric
5344f7ab58eSDimitry Andrictemplate <class _CharT, class _Traits, class _String>
5354f7ab58eSDimitry Andricbasic_istream<_CharT, _Traits> &
5364f7ab58eSDimitry Andric__quoted_input ( basic_istream<_CharT, _Traits> &__is, _String & __string, _CharT __delim, _CharT __escape )
5374f7ab58eSDimitry Andric{
5384f7ab58eSDimitry Andric    __string.clear ();
5394f7ab58eSDimitry Andric    _CharT __c;
5404f7ab58eSDimitry Andric    __is >> __c;
5414f7ab58eSDimitry Andric    if ( __is.fail ())
5424f7ab58eSDimitry Andric        return __is;
5434f7ab58eSDimitry Andric
5444f7ab58eSDimitry Andric    if (!_Traits::eq (__c, __delim))    // no delimiter, read the whole string
5454f7ab58eSDimitry Andric    {
5464f7ab58eSDimitry Andric        __is.unget ();
5474f7ab58eSDimitry Andric        __is >> __string;
5484f7ab58eSDimitry Andric        return __is;
5494f7ab58eSDimitry Andric    }
5504f7ab58eSDimitry Andric
5514f7ab58eSDimitry Andric    __save_flags<_CharT, _Traits> sf(__is);
5524f7ab58eSDimitry Andric    noskipws (__is);
5534f7ab58eSDimitry Andric    while (true)
5544f7ab58eSDimitry Andric        {
5554f7ab58eSDimitry Andric        __is >> __c;
5564f7ab58eSDimitry Andric        if ( __is.fail ())
5574f7ab58eSDimitry Andric            break;
5584f7ab58eSDimitry Andric        if (_Traits::eq (__c, __escape))
5594f7ab58eSDimitry Andric        {
5604f7ab58eSDimitry Andric            __is >> __c;
5614f7ab58eSDimitry Andric            if ( __is.fail ())
5624f7ab58eSDimitry Andric                break;
5634f7ab58eSDimitry Andric        }
5644f7ab58eSDimitry Andric        else if (_Traits::eq (__c, __delim))
5654f7ab58eSDimitry Andric            break;
5664f7ab58eSDimitry Andric        __string.push_back ( __c );
5674f7ab58eSDimitry Andric        }
5684f7ab58eSDimitry Andric    return __is;
5694f7ab58eSDimitry Andric}
5704f7ab58eSDimitry Andric
5714f7ab58eSDimitry Andric
5724f7ab58eSDimitry Andrictemplate <class _CharT, class _Traits, class _Iter>
5734f7ab58eSDimitry Andricbasic_ostream<_CharT, _Traits>& operator<<(
5744f7ab58eSDimitry Andric         basic_ostream<_CharT, _Traits>& __os,
5754f7ab58eSDimitry Andric         const __quoted_output_proxy<_CharT, _Iter, _Traits> & __proxy)
5764f7ab58eSDimitry Andric{
5774f7ab58eSDimitry Andric    return __quoted_output (__os, __proxy.__first, __proxy.__last, __proxy.__delim, __proxy.__escape);
5784f7ab58eSDimitry Andric}
5794f7ab58eSDimitry Andric
5804f7ab58eSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
5814f7ab58eSDimitry Andricstruct __quoted_proxy
5824f7ab58eSDimitry Andric{
5834f7ab58eSDimitry Andric    basic_string<_CharT, _Traits, _Allocator> &__string;
5844f7ab58eSDimitry Andric    _CharT  __delim;
5854f7ab58eSDimitry Andric    _CharT  __escape;
5864f7ab58eSDimitry Andric
5874f7ab58eSDimitry Andric    __quoted_proxy(basic_string<_CharT, _Traits, _Allocator> &__s, _CharT __d, _CharT __e)
5884f7ab58eSDimitry Andric    : __string(__s), __delim(__d), __escape(__e) {}
5894f7ab58eSDimitry Andric};
5904f7ab58eSDimitry Andric
5914f7ab58eSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
5924f7ab58eSDimitry Andric_LIBCPP_INLINE_VISIBILITY
5934f7ab58eSDimitry Andricbasic_ostream<_CharT, _Traits>& operator<<(
5944f7ab58eSDimitry Andric        basic_ostream<_CharT, _Traits>& __os,
5954f7ab58eSDimitry Andric        const __quoted_proxy<_CharT, _Traits, _Allocator> & __proxy)
5964f7ab58eSDimitry Andric{
5974f7ab58eSDimitry Andric    return __quoted_output (__os, __proxy.__string.cbegin (), __proxy.__string.cend (), __proxy.__delim, __proxy.__escape);
5984f7ab58eSDimitry Andric}
5994f7ab58eSDimitry Andric
6004f7ab58eSDimitry Andric//  extractor for non-const basic_string& proxies
6014f7ab58eSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
6024f7ab58eSDimitry Andric_LIBCPP_INLINE_VISIBILITY
6034f7ab58eSDimitry Andricbasic_istream<_CharT, _Traits>& operator>>(
6044f7ab58eSDimitry Andric        basic_istream<_CharT, _Traits>& __is,
6054f7ab58eSDimitry Andric        const __quoted_proxy<_CharT, _Traits, _Allocator> & __proxy)
6064f7ab58eSDimitry Andric{
6074f7ab58eSDimitry Andric    return __quoted_input ( __is, __proxy.__string, __proxy.__delim, __proxy.__escape );
6084f7ab58eSDimitry Andric}
6094f7ab58eSDimitry Andric
6104f7ab58eSDimitry Andric
6114f7ab58eSDimitry Andrictemplate <class _CharT>
6124f7ab58eSDimitry Andric_LIBCPP_INLINE_VISIBILITY
6134f7ab58eSDimitry Andric__quoted_output_proxy<_CharT, const _CharT *>
6144f7ab58eSDimitry Andricquoted ( const _CharT *__s, _CharT __delim = _CharT('"'), _CharT __escape =_CharT('\\'))
6154f7ab58eSDimitry Andric{
6164f7ab58eSDimitry Andric    const _CharT *__end = __s;
6174f7ab58eSDimitry Andric    while ( *__end ) ++__end;
6184f7ab58eSDimitry Andric    return __quoted_output_proxy<_CharT, const _CharT *> ( __s, __end, __delim, __escape );
6194f7ab58eSDimitry Andric}
6204f7ab58eSDimitry Andric
6217c82a1ecSDimitry Andric
6224f7ab58eSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
6234f7ab58eSDimitry Andric_LIBCPP_INLINE_VISIBILITY
6244f7ab58eSDimitry Andric__quoted_output_proxy<_CharT, typename basic_string <_CharT, _Traits, _Allocator>::const_iterator>
6257c82a1ecSDimitry Andric__quoted ( const basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
6264f7ab58eSDimitry Andric{
6274f7ab58eSDimitry Andric    return __quoted_output_proxy<_CharT,
6284f7ab58eSDimitry Andric            typename basic_string <_CharT, _Traits, _Allocator>::const_iterator>
6294f7ab58eSDimitry Andric                    ( __s.cbegin(), __s.cend (), __delim, __escape );
6304f7ab58eSDimitry Andric}
6314f7ab58eSDimitry Andric
6324f7ab58eSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
6337c82a1ecSDimitry Andric_LIBCPP_INLINE_VISIBILITY
6347c82a1ecSDimitry Andric__quoted_proxy<_CharT, _Traits, _Allocator>
6357c82a1ecSDimitry Andric__quoted ( basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
6367c82a1ecSDimitry Andric{
6377c82a1ecSDimitry Andric    return __quoted_proxy<_CharT, _Traits, _Allocator>( __s, __delim, __escape );
6387c82a1ecSDimitry Andric}
6397c82a1ecSDimitry Andric
6407c82a1ecSDimitry Andric
6417c82a1ecSDimitry Andric#if _LIBCPP_STD_VER > 11
6427c82a1ecSDimitry Andric
6437c82a1ecSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
6447c82a1ecSDimitry Andric_LIBCPP_INLINE_VISIBILITY
6457c82a1ecSDimitry Andric__quoted_output_proxy<_CharT, typename basic_string <_CharT, _Traits, _Allocator>::const_iterator>
6467c82a1ecSDimitry Andricquoted ( const basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
6477c82a1ecSDimitry Andric{
6487c82a1ecSDimitry Andric    return __quoted(__s, __delim, __escape);
6497c82a1ecSDimitry Andric}
6507c82a1ecSDimitry Andric
6517c82a1ecSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator>
6527c82a1ecSDimitry Andric_LIBCPP_INLINE_VISIBILITY
6534f7ab58eSDimitry Andric__quoted_proxy<_CharT, _Traits, _Allocator>
6544f7ab58eSDimitry Andricquoted ( basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
6554f7ab58eSDimitry Andric{
6567c82a1ecSDimitry Andric    return __quoted(__s, __delim, __escape);
6574f7ab58eSDimitry Andric}
658aed8d94eSDimitry Andric
659aed8d94eSDimitry Andrictemplate <class _CharT, class _Traits>
660aed8d94eSDimitry Andric__quoted_output_proxy<_CharT, const _CharT *, _Traits>
661aed8d94eSDimitry Andricquoted (basic_string_view <_CharT, _Traits> __sv,
662aed8d94eSDimitry Andric             _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
663aed8d94eSDimitry Andric{
664aed8d94eSDimitry Andric    return __quoted_output_proxy<_CharT, const _CharT *, _Traits>
665aed8d94eSDimitry Andric         ( __sv.data(), __sv.data() + __sv.size(), __delim, __escape );
666aed8d94eSDimitry Andric}
6674f7ab58eSDimitry Andric#endif
6684f7ab58eSDimitry Andric
6697a984708SDavid Chisnall_LIBCPP_END_NAMESPACE_STD
6707a984708SDavid Chisnall
6717a984708SDavid Chisnall#endif  // _LIBCPP_IOMANIP
672