1
0
forked from Alepha/Alepha

Make the underlying streambuf private in stacks.

This commit is contained in:
2024-04-03 15:01:52 -04:00
parent 8250680e6c
commit d8689b85e8
5 changed files with 55 additions and 24 deletions

View File

@ -64,28 +64,27 @@ namespace Alepha::Hydrogen ::detail:: word_wrap_m
void
WordWrapStreambuf::writeChar( const char ch )
{
std::ostream outWrap{ underlying };
if( ch == '\n' )
{
const auto prev= currentLineLength;
const auto size= currentWord.size();
currentLineLength= applyWordToLine( maximumWidth, nextLineOffset, currentLineLength, std::move( currentWord ), outWrap );
currentLineLength= applyWordToLine( maximumWidth, nextLineOffset, currentLineLength, std::move( currentWord ), out() );
currentWord.clear();
outWrap << '\n';
out() << '\n';
if( currentLineLength == prev + size )
{
std::fill_n( std::ostream_iterator< char >{ outWrap }, nextLineOffset, ' ' );
std::fill_n( std::ostream_iterator< char >{ out() }, nextLineOffset, ' ' );
currentLineLength= nextLineOffset;
}
else currentLineLength= 0;
}
else if( ch == ' ' )
{
currentLineLength= applyWordToLine( maximumWidth, nextLineOffset, currentLineLength, std::move( currentWord ), outWrap );
currentLineLength= applyWordToLine( maximumWidth, nextLineOffset, currentLineLength, std::move( currentWord ), out() );
currentWord.clear();
if( currentLineLength < maximumWidth )
{
outWrap << ' ';
out() << ' ';
++currentLineLength;
}
}
@ -96,8 +95,7 @@ namespace Alepha::Hydrogen ::detail:: word_wrap_m
WordWrapStreambuf::drain()
{
if( currentWord.empty() ) return;
std::ostream outWrap{ underlying };
applyWordToLine( maximumWidth, nextLineOffset, currentLineLength, std::move( currentWord ), outWrap );
applyWordToLine( maximumWidth, nextLineOffset, currentLineLength, std::move( currentWord ), out() );
}
std::string