forked from Alepha/Alepha
Use the stacked streambuf to implement wrapping.
This commit is contained in:
13
word_wrap.h
13
word_wrap.h
@ -7,27 +7,30 @@ static_assert( __cplusplus > 2020'00 );
|
||||
#include <string>
|
||||
#include <streambuf>
|
||||
|
||||
#include <Alepha/Utility/StackableStreambuf.h>
|
||||
|
||||
namespace Alepha::inline Cavorite ::detail:: word_wrap
|
||||
{
|
||||
inline namespace exports
|
||||
{
|
||||
std::string wordWrap( const std::string &text, std::size_t width, std::size_t nextLineOffset= 0 );
|
||||
|
||||
struct StartWrap
|
||||
struct StartWrap_params
|
||||
{
|
||||
std::size_t width;
|
||||
std::size_t nextLineOffset;
|
||||
|
||||
explicit StartWrap( const std::size_t width, const std::size_t nextLineOffset= 0 ) : width( width ), nextLineOffset( nextLineOffset ) {}
|
||||
explicit StartWrap_params( const std::size_t width, const std::size_t nextLineOffset= 0 ) : width( width ), nextLineOffset( nextLineOffset ) {}
|
||||
};
|
||||
|
||||
constexpr struct EndWrap_t {} EndWrap;
|
||||
using StartWrap= Utility::PushStack< StartWrap_params >;
|
||||
|
||||
constexpr Utility::PopStack< StartWrap_params > EndWrap;
|
||||
}
|
||||
|
||||
inline namespace impl
|
||||
{
|
||||
std::ostream &operator << ( std::ostream &, StartWrap );
|
||||
std::ostream &operator << ( std::ostream &, EndWrap_t );
|
||||
void build_streambuf( std::ostream &os, StartWrap &&args );
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user