From c43a172ded94c6b8bd067a9f60c59d1b772fbf86 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 9 Oct 2021 19:31:41 +0300 Subject: [PATCH] Use `os << ""` for the padding instead of `os << p[0]` --- include/boost/core/string_view.hpp | 33 ++++++++++++------------------ 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/include/boost/core/string_view.hpp b/include/boost/core/string_view.hpp index 4cb120c..2aae97b 100644 --- a/include/boost/core/string_view.hpp +++ b/include/boost/core/string_view.hpp @@ -1153,32 +1153,25 @@ template std::basic_ostream& operator<<( std::basic_ostream& o Ch const* p = str.data(); std::size_t n = str.size(); - if( n == 0 ) + std::size_t m = os.width(); + + if( n >= m ) { + os.write( p, n ); + } + else if( ( os.flags() & std::ios_base::adjustfield ) == std::ios_base::left ) + { + os.write( p, n ); + + os.width( m - n ); os << ""; } else { - std::size_t m = os.width(); + os.width( m - n ); + os << ""; - if( n >= m ) - { - os.write( p, n ); - } - else if( ( os.flags() & std::ios_base::adjustfield ) == std::ios_base::left ) - { - os.write( p, n - 1 ); - - os.width( m - n + 1 ); - os << p[ n-1 ]; - } - else - { - os.width( m - n + 1 ); - os << p[0]; - - os.write( p + 1, n - 1 ); - } + os.write( p, n ); } os.width( 0 );