mirror of
https://github.com/boostorg/utility.git
synced 2025-05-11 13:24:02 +00:00
Modifications according to the review.
[SVN r84609]
This commit is contained in:
parent
71b501a0b0
commit
f3bb2a493c
@ -402,6 +402,37 @@ namespace boost {
|
|||||||
return basic_string_ref<charT, traits>(x) >= y;
|
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
|
// Inserter
|
||||||
template<class charT, class traits>
|
template<class charT, class traits>
|
||||||
inline std::basic_ostream<charT, traits>&
|
inline std::basic_ostream<charT, traits>&
|
||||||
@ -409,25 +440,11 @@ namespace boost {
|
|||||||
if (os.good()) {
|
if (os.good()) {
|
||||||
const std::size_t size = str.size();
|
const std::size_t size = str.size();
|
||||||
const std::size_t w = static_cast< std::size_t >(os.width());
|
const std::size_t w = static_cast< std::size_t >(os.width());
|
||||||
os.width(0);
|
|
||||||
if (w <= size)
|
if (w <= size)
|
||||||
os.write(str.data(), size);
|
os.write(str.data(), static_cast< std::streamsize >(size));
|
||||||
else {
|
else
|
||||||
const bool align_left = (os.flags() & std::basic_ostream<charT, traits>::adjustfield) == std::basic_ostream<charT, traits>::left;
|
detail::insert_aligned(os, str);
|
||||||
const std::size_t alignment_size = w - size;
|
os.width(0);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user