Make indentation work in toString

This commit is contained in:
fbraem 2013-02-17 18:41:36 +01:00
parent b19401af37
commit 13380b5eb9
3 changed files with 46 additions and 12 deletions

View File

@ -72,7 +72,7 @@ struct ElementTraits<Array::Ptr>
static std::string toString(const Array::Ptr& value, int indent = 0)
{
//TODO:
return value.isNull() ? "null" : value->toString();
return value.isNull() ? "null" : value->toString(indent);
}
};

View File

@ -64,28 +64,32 @@ std::string Array::toString(int indent) const
{
if ( it != _elements.begin() )
{
if ( indent > 0 )
{
for(int i = 0; i < indent; ++i)
{
oss << ' ';
}
}
oss << ",";
if ( indent > 0 )
{
oss << std::endl;
}
}
for(int i = 0; i < indent; ++i)
{
oss << ' ';
}
oss << (*it)->toString();
}
oss << "]";
if ( indent > 0 )
if ( indent > 0 )
{
oss << std::endl;
indent -= 2;
for(int i = 0; i < indent; ++i)
{
oss << ' ';
}
}
oss << "]";
return oss.str();
}

View File

@ -155,10 +155,40 @@ std::string Document::toString(int indent) const
{
if ( it != _elements.begin() )
{
oss << ", ";
oss << ",";
if ( indent > 0 )
{
oss << std::endl;
}
}
if ( indent > 0 )
{
for(int i = 0; i < indent; ++i)
{
oss << ' ';
}
}
oss << '"' << (*it)->name() << '"' << " : ";
if ( indent > 0 )
{
oss << (*it)->toString(indent + 2);
}
else
{
oss << (*it)->toString();
}
oss << '"' << (*it)->name() << '"' << " : " << (*it)->toString();
}
if ( indent > 0 )
{
oss << std::endl;
indent -= 2;
for(int i = 0; i < indent; ++i)
{
oss << ' ';
}
}
oss << "}" << std::endl;
return oss.str();
}