|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r84609 - trunk/boost/utility
From: andrey.semashev_at_[hidden]
Date: 2013-06-02 14:15:54
Author: andysem
Date: 2013-06-02 14:15:53 EDT (Sun, 02 Jun 2013)
New Revision: 84609
URL: http://svn.boost.org/trac/boost/changeset/84609
Log:
Modifications according to the review.
Text files modified:
trunk/boost/utility/string_ref.hpp | 53 ++++++++++++++++++++++++++-------------
1 files changed, 35 insertions(+), 18 deletions(-)
Modified: trunk/boost/utility/string_ref.hpp
==============================================================================
--- trunk/boost/utility/string_ref.hpp (original)
+++ trunk/boost/utility/string_ref.hpp 2013-06-02 14:15:53 EDT (Sun, 02 Jun 2013)
@@ -402,6 +402,37 @@
return basic_string_ref<charT, traits>(x) >= y;
}
+ namespace detail {
+
+ template<class charT, class traits>
+ inline void insert_fill_chars(std::basic_ostream<charT, traits>& os, std::size_t n) {
+ charT fill_chars[8];
+ std::fill_n(fill_chars, 8, os.fill());
+ for (std::size_t m = n / 8u; m > 0 && os.good(); --m)
+ os.write(fill_chars, 8);
+ n &= 7u;
+ if (n > 0 && os.good())
+ os.write(fill_chars, static_cast< std::streamsize >(n));
+ }
+
+ template<class charT, class traits>
+ void 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::ios_base::adjustfield) == std::ios_base::left;
+ if (!align_left) {
+ detail::insert_fill_chars(os, alignment_size);
+ if (os.good())
+ os.write(str.data(), static_cast< std::streamsize >(size));
+ }
+ else {
+ os.write(str.data(), static_cast< std::streamsize >(size));
+ detail::insert_fill_chars(os, alignment_size);
+ }
+ }
+
+ } // namespace detail
+
// Inserter
template<class charT, class traits>
inline std::basic_ostream<charT, traits>&
@@ -409,25 +440,11 @@
if (os.good()) {
const std::size_t size = str.size();
const std::size_t w = static_cast< std::size_t >(os.width());
- os.width(0);
if (w <= size)
- os.write(str.data(), size);
- else {
- const bool align_left = (os.flags() & std::basic_ostream<charT, traits>::adjustfield) == std::basic_ostream<charT, traits>::left;
- const std::size_t alignment_size = w - size;
- if (!align_left) {
- const charT fill_char = os.fill();
- for (std::size_t i = 0; i < alignment_size && os.good(); ++i)
- os.put(fill_char);
- }
- if (os.good())
- os.write(str.data(), size);
- if (align_left && os.good()) {
- const charT fill_char = os.fill();
- for (std::size_t i = 0; i < alignment_size && os.good(); ++i)
- os.put(fill_char);
- }
- }
+ os.write(str.data(), static_cast< std::streamsize >(size));
+ else
+ detail::insert_aligned(os, str);
+ os.width(0);
}
return os;
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk