summaryrefslogtreecommitdiffstats
path: root/contrib/libc++/include/iomanip
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libc++/include/iomanip')
-rw-r--r--contrib/libc++/include/iomanip149
1 files changed, 149 insertions, 0 deletions
diff --git a/contrib/libc++/include/iomanip b/contrib/libc++/include/iomanip
index 0c58e19..e334c7d 100644
--- a/contrib/libc++/include/iomanip
+++ b/contrib/libc++/include/iomanip
@@ -14,6 +14,8 @@
/*
iomanip synopsis
+namespace std {
+
// types T1, T2, ... are unspecified implementation types
T1 resetiosflags(ios_base::fmtflags mask);
T2 setiosflags (ios_base::fmtflags mask);
@@ -26,6 +28,17 @@ template <class charT, class moneyT> T8 put_money(const moneyT& mon, bool intl =
template <class charT> T9 get_time(struct tm* tmb, const charT* fmt);
template <class charT> T10 put_time(const struct tm* tmb, const charT* fmt);
+template <class charT>
+ T11 quoted(const charT* s, charT delim=charT('"'), charT escape=charT('\\')); // C++14
+
+template <class charT, class traits, class Allocator>
+ T12 quoted(const basic_string<charT, traits, Allocator>& s,
+ charT delim=charT('"'), charT escape=charT('\\')); // C++14
+
+template <class charT, class traits, class Allocator>
+ T13 quoted(basic_string<charT, traits, Allocator>& s,
+ charT delim=charT('"'), charT escape=charT('\\')); // C++14
+
} // std
*/
@@ -499,6 +512,142 @@ put_time(const tm* __tm, const _CharT* __fmt)
return __iom_t10<_CharT>(__tm, __fmt);
}
+#if _LIBCPP_STD_VER > 11
+
+template <class _CharT, class _Traits, class _ForwardIterator>
+std::basic_ostream<_CharT, _Traits> &
+__quoted_output ( basic_ostream<_CharT, _Traits> &__os,
+ _ForwardIterator __first, _ForwardIterator __last, _CharT __delim, _CharT __escape )
+{
+ __os << __delim;
+ for ( ; __first != __last; ++ __first )
+ {
+ if (_Traits::eq (*__first, __escape) || _Traits::eq (*__first, __delim))
+ __os << __escape;
+ __os << *__first;
+ }
+ __os << __delim;
+ return __os;
+}
+
+template <class _CharT, class _Traits, class _String>
+basic_istream<_CharT, _Traits> &
+__quoted_input ( basic_istream<_CharT, _Traits> &__is, _String & __string, _CharT __delim, _CharT __escape )
+{
+ __string.clear ();
+ _CharT __c;
+ __is >> __c;
+ if ( __is.fail ())
+ return __is;
+
+ if (!_Traits::eq (__c, __delim)) // no delimiter, read the whole string
+ {
+ __is.unget ();
+ __is >> __string;
+ return __is;
+ }
+
+ __save_flags<_CharT, _Traits> sf(__is);
+ noskipws (__is);
+ while (true)
+ {
+ __is >> __c;
+ if ( __is.fail ())
+ break;
+ if (_Traits::eq (__c, __escape))
+ {
+ __is >> __c;
+ if ( __is.fail ())
+ break;
+ }
+ else if (_Traits::eq (__c, __delim))
+ break;
+ __string.push_back ( __c );
+ }
+ return __is;
+}
+
+
+template <class _CharT, class _Iter, class _Traits=char_traits<_CharT>>
+struct __quoted_output_proxy
+{
+ _Iter __first;
+ _Iter __last;
+ _CharT __delim;
+ _CharT __escape;
+
+ __quoted_output_proxy(_Iter __f, _Iter __l, _CharT __d, _CharT __e)
+ : __first(__f), __last(__l), __delim(__d), __escape(__e) {}
+ // This would be a nice place for a string_ref
+};
+
+template <class _CharT, class _Traits, class _Iter>
+basic_ostream<_CharT, _Traits>& operator<<(
+ basic_ostream<_CharT, _Traits>& __os,
+ const __quoted_output_proxy<_CharT, _Iter, _Traits> & __proxy)
+{
+ return __quoted_output (__os, __proxy.__first, __proxy.__last, __proxy.__delim, __proxy.__escape);
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+struct __quoted_proxy
+{
+ basic_string<_CharT, _Traits, _Allocator> &__string;
+ _CharT __delim;
+ _CharT __escape;
+
+ __quoted_proxy(basic_string<_CharT, _Traits, _Allocator> &__s, _CharT __d, _CharT __e)
+ : __string(__s), __delim(__d), __escape(__e) {}
+};
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY
+basic_ostream<_CharT, _Traits>& operator<<(
+ basic_ostream<_CharT, _Traits>& __os,
+ const __quoted_proxy<_CharT, _Traits, _Allocator> & __proxy)
+{
+ return __quoted_output (__os, __proxy.__string.cbegin (), __proxy.__string.cend (), __proxy.__delim, __proxy.__escape);
+}
+
+// extractor for non-const basic_string& proxies
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY
+basic_istream<_CharT, _Traits>& operator>>(
+ basic_istream<_CharT, _Traits>& __is,
+ const __quoted_proxy<_CharT, _Traits, _Allocator> & __proxy)
+{
+ return __quoted_input ( __is, __proxy.__string, __proxy.__delim, __proxy.__escape );
+}
+
+
+template <class _CharT>
+_LIBCPP_INLINE_VISIBILITY
+__quoted_output_proxy<_CharT, const _CharT *>
+quoted ( const _CharT *__s, _CharT __delim = _CharT('"'), _CharT __escape =_CharT('\\'))
+{
+ const _CharT *__end = __s;
+ while ( *__end ) ++__end;
+ return __quoted_output_proxy<_CharT, const _CharT *> ( __s, __end, __delim, __escape );
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+_LIBCPP_INLINE_VISIBILITY
+__quoted_output_proxy<_CharT, typename basic_string <_CharT, _Traits, _Allocator>::const_iterator>
+quoted ( const basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
+{
+ return __quoted_output_proxy<_CharT,
+ typename basic_string <_CharT, _Traits, _Allocator>::const_iterator>
+ ( __s.cbegin(), __s.cend (), __delim, __escape );
+}
+
+template <class _CharT, class _Traits, class _Allocator>
+__quoted_proxy<_CharT, _Traits, _Allocator>
+quoted ( basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
+{
+ return __quoted_proxy<_CharT, _Traits, _Allocator>( __s, __delim, __escape );
+}
+#endif
+
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_IOMANIP
OpenPOWER on IntegriCloud