Extracted class IndentedPrintDecorator from PrettyPrintDecorator

This commit is contained in:
Benoit Blanchon
2014-08-26 09:28:41 +02:00
parent d877d77b63
commit 6539c6982c
12 changed files with 128 additions and 31 deletions

View File

@ -0,0 +1,40 @@
#include "IndentedPrintDecorator.h"
void IndentedPrintDecorator::indent()
{
currentTabCount++;
}
void IndentedPrintDecorator::unindent()
{
currentTabCount--;
}
size_t IndentedPrintDecorator::write(uint8_t c)
{
size_t n = 0;
if (isNewLine)
n += writeCurrentTabs();
n += sink.write(c);
isNewLine = c == '\n';
return n;
}
size_t IndentedPrintDecorator::writeCurrentTabs()
{
return writeTabs(currentTabCount);
}
size_t IndentedPrintDecorator::writeTabs(int count)
{
size_t n = 0;
for (int i = 0; i<count; i++)
n += sink.write(' ');
return n;
}