forked from Alepha/Alepha
Make it possible to use arbitrary code in making delimited lists.
This commit is contained in:
@ -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 &¶ms )
|
||||
{
|
||||
new impl_cc::DelimitedListStreambuf( os, params.delimiter );
|
||||
new impl_cc::DelimitedListStreambuf( os, params.writer );
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user