summaryrefslogtreecommitdiff
path: root/boost/utility/string_ref.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/utility/string_ref.hpp')
-rw-r--r--boost/utility/string_ref.hpp45
1 files changed, 3 insertions, 42 deletions
diff --git a/boost/utility/string_ref.hpp b/boost/utility/string_ref.hpp
index 4b36ffc0d8..999f1c3d6c 100644
--- a/boost/utility/string_ref.hpp
+++ b/boost/utility/string_ref.hpp
@@ -1,5 +1,6 @@
/*
Copyright (c) Marshall Clow 2012-2015.
+ Copyright (c) Glen Joseph Fernandes 2019 (glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,6 +18,7 @@
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
+#include <boost/utility/ostream_string.hpp>
#include <boost/utility/string_ref_fwd.hpp>
#include <boost/throw_exception.hpp>
@@ -421,52 +423,11 @@ namespace boost {
return basic_string_ref<charT, traits>(x) >= y;
}
- namespace detail {
-
- template<class charT, class traits>
- inline void sr_insert_fill_chars(std::basic_ostream<charT, traits>& os, std::size_t n) {
- enum { chunk_size = 8 };
- charT fill_chars[chunk_size];
- std::fill_n(fill_chars, static_cast< std::size_t >(chunk_size), os.fill());
- for (; n >= chunk_size && os.good(); n -= chunk_size)
- os.write(fill_chars, static_cast< std::size_t >(chunk_size));
- if (n > 0 && os.good())
- os.write(fill_chars, n);
- }
-
- template<class charT, class traits>
- void sr_insert_aligned(std::basic_ostream<charT, traits>& os, const basic_string_ref<charT,traits>& str) {
- const std::size_t size = str.size();
- const std::size_t alignment_size = static_cast< std::size_t >(os.width()) - size;
- const bool align_left = (os.flags() & std::basic_ostream<charT, traits>::adjustfield) == std::basic_ostream<charT, traits>::left;
- if (!align_left) {
- detail::sr_insert_fill_chars(os, alignment_size);
- if (os.good())
- os.write(str.data(), size);
- }
- else {
- os.write(str.data(), size);
- if (os.good())
- detail::sr_insert_fill_chars(os, alignment_size);
- }
- }
-
- } // namespace detail
-
// Inserter
template<class charT, class traits>
inline std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const basic_string_ref<charT,traits>& str) {
- if (os.good()) {
- const std::size_t size = str.size();
- const std::size_t w = static_cast< std::size_t >(os.width());
- if (w <= size)
- os.write(str.data(), size);
- else
- detail::sr_insert_aligned(os, str);
- os.width(0);
- }
- return os;
+ return boost::ostream_string(os, str.data(), str.size());
}
#if 0