Fixed empty object output

This commit is contained in:
Benoit Blanchon
2014-08-25 09:56:51 +02:00
parent 75c89e7b35
commit eb1a774778
2 changed files with 24 additions and 5 deletions

View File

@ -11,16 +11,34 @@ size_t IndentedPrintDecorator::write(uint8_t c)
{
case '{':
indent++;
return sink.write(c) + writeln();
emptyBlock = true;
return sink.write(c);
case '}':
indent--;
if (emptyBlock)
{
return sink.write(c);
}
else
{
return writeln() + sink.write(c);
}
default:
if (emptyBlock)
{
emptyBlock = false;
return writeln() + sink.write(c);
}
else
{
return sink.write(c);
}
}
}
size_t IndentedPrintDecorator::writeln()
{

View File

@ -13,7 +13,7 @@ class IndentedPrintDecorator : public Print
public:
IndentedPrintDecorator(Print& p)
: indent(0), sink(p)
: indent(0), sink(p), emptyBlock(false)
{
}
@ -21,6 +21,7 @@ public:
private:
int indent;
bool emptyBlock;
Print& sink;
size_t writeln();