1
0
forked from Alepha/Alepha

Make it possible to use arbitrary code in making delimited lists.

This commit is contained in:
2024-04-04 15:41:27 -04:00
parent 58327d5afd
commit a6467772f4
3 changed files with 48 additions and 9 deletions

View File

@ -28,23 +28,23 @@ namespace Alepha::Hydrogen ::detail:: delimited_list_m
: virtual public IOStreams::StackableStreambuf, virtual public std::streambuf
{
private:
std::string delim;
DelimiterWriter writer;
bool first= true;
public:
explicit
DelimitedListStreambuf( std::ios &is, const std::string delim )
: StackableStreambuf( is ), delim( delim )
DelimitedListStreambuf( std::ios &is, const DelimiterWriter writer )
: StackableStreambuf( is ), writer( writer )
{
tracker.get( is )= this;
if( C::debug ) error() << "Streambuf adapted." << std::endl;
}
void
doNext()
doNext( std::ostream &out )
{
if( C::debug ) error() << "Do Next called" << std::endl;
if( not first ) out() << delim;
if( not first ) writer( out );
first= false;
}
@ -66,7 +66,7 @@ namespace Alepha::Hydrogen ::detail:: delimited_list_m
{
if( C::debug ) error() << "Marker called" << std::endl;
auto thisTracker= tracker.get( os );
if( thisTracker != nullptr ) thisTracker->doNext();
if( thisTracker != nullptr ) thisTracker->doNext( os );
return os;
}
@ -74,6 +74,6 @@ namespace Alepha::Hydrogen ::detail:: delimited_list_m
void
impl::build_streambuf( std::ostream &os, StartDelimitedList &&params )
{
new impl_cc::DelimitedListStreambuf( os, params.delimiter );
new impl_cc::DelimitedListStreambuf( os, params.writer );
}
}