Add sv_stream_insert_test

This commit is contained in:
Peter Dimov
2021-10-09 17:36:06 +03:00
parent e9ffc4336c
commit c8b860704e
3 changed files with 144 additions and 1 deletions

View File

@@ -928,7 +928,38 @@ public:
template<class Ch> std::basic_ostream<Ch>& operator<<( std::basic_ostream<Ch>& os, basic_string_view<Ch> str )
{
os.write( str.data(), str.size() );
Ch const* p = str.data();
std::size_t n = str.size();
if( n == 0 )
{
os << "";
}
else
{
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 - 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.width( 0 );
return os;
}