xref: /freebsd/contrib/llvm-project/libcxx/include/__ostream/put_character_sequence.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric //===---------------------------------------------------------------------===//
2*700637cbSDimitry Andric //
3*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*700637cbSDimitry Andric //
7*700637cbSDimitry Andric //===---------------------------------------------------------------------===//
8*700637cbSDimitry Andric 
9*700637cbSDimitry Andric #ifndef _LIBCPP___OSTREAM_PUT_CHARACTER_SEQUENCE_H
10*700637cbSDimitry Andric #define _LIBCPP___OSTREAM_PUT_CHARACTER_SEQUENCE_H
11*700637cbSDimitry Andric 
12*700637cbSDimitry Andric #include <__config>
13*700637cbSDimitry Andric 
14*700637cbSDimitry Andric #if _LIBCPP_HAS_LOCALIZATION
15*700637cbSDimitry Andric 
16*700637cbSDimitry Andric #  include <__cstddef/size_t.h>
17*700637cbSDimitry Andric #  include <__fwd/ostream.h>
18*700637cbSDimitry Andric #  include <__iterator/ostreambuf_iterator.h>
19*700637cbSDimitry Andric #  include <__locale_dir/pad_and_output.h>
20*700637cbSDimitry Andric #  include <ios>
21*700637cbSDimitry Andric 
22*700637cbSDimitry Andric #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23*700637cbSDimitry Andric #    pragma GCC system_header
24*700637cbSDimitry Andric #  endif
25*700637cbSDimitry Andric 
26*700637cbSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
27*700637cbSDimitry Andric 
28*700637cbSDimitry Andric template <class _CharT, class _Traits>
29*700637cbSDimitry Andric _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
__put_character_sequence(basic_ostream<_CharT,_Traits> & __os,const _CharT * __str,size_t __len)30*700637cbSDimitry Andric __put_character_sequence(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str, size_t __len) {
31*700637cbSDimitry Andric #  if _LIBCPP_HAS_EXCEPTIONS
32*700637cbSDimitry Andric   try {
33*700637cbSDimitry Andric #  endif // _LIBCPP_HAS_EXCEPTIONS
34*700637cbSDimitry Andric     typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
35*700637cbSDimitry Andric     if (__s) {
36*700637cbSDimitry Andric       typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
37*700637cbSDimitry Andric       if (std::__pad_and_output(
38*700637cbSDimitry Andric               _Ip(__os),
39*700637cbSDimitry Andric               __str,
40*700637cbSDimitry Andric               (__os.flags() & ios_base::adjustfield) == ios_base::left ? __str + __len : __str,
41*700637cbSDimitry Andric               __str + __len,
42*700637cbSDimitry Andric               __os,
43*700637cbSDimitry Andric               __os.fill())
44*700637cbSDimitry Andric               .failed())
45*700637cbSDimitry Andric         __os.setstate(ios_base::badbit | ios_base::failbit);
46*700637cbSDimitry Andric     }
47*700637cbSDimitry Andric #  if _LIBCPP_HAS_EXCEPTIONS
48*700637cbSDimitry Andric   } catch (...) {
49*700637cbSDimitry Andric     __os.__set_badbit_and_consider_rethrow();
50*700637cbSDimitry Andric   }
51*700637cbSDimitry Andric #  endif // _LIBCPP_HAS_EXCEPTIONS
52*700637cbSDimitry Andric   return __os;
53*700637cbSDimitry Andric }
54*700637cbSDimitry Andric 
55*700637cbSDimitry Andric _LIBCPP_END_NAMESPACE_STD
56*700637cbSDimitry Andric 
57*700637cbSDimitry Andric #endif // _LIBCPP_HAS_LOCALIZATION
58*700637cbSDimitry Andric 
59*700637cbSDimitry Andric #endif // _LIBCPP___OSTREAM_PUT_CHARACTER_SEQUENCE_H
60