Make StructureData objects dump themselves with correct indentation.

llvm-svn: 238279
This commit is contained in:
Greg Clayton
2015-05-27 03:23:26 +00:00
parent b1ca494b6e
commit 66b8294cae

View File

@@ -356,20 +356,28 @@ StructuredData::Object::DumpToStdout() const
{
StreamString stream;
Dump(stream);
printf("%s", stream.GetString().c_str());
printf("%s\n", stream.GetString().c_str());
}
void
StructuredData::Array::Dump(Stream &s) const
{
s << "[";
const size_t arrsize = m_items.size();
for (size_t i = 0; i < arrsize; ++i)
bool first = true;
s << "[\n";
s.IndentMore();
for (const auto &item_sp : m_items)
{
m_items[i]->Dump(s);
if (i + 1 < arrsize)
s << ",";
if (first)
first = false;
else
s << ",\n";
s.Indent();
item_sp->Dump(s);
}
s.IndentLess();
s.EOL();
s.Indent();
s << "]";
}
@@ -414,21 +422,22 @@ StructuredData::String::Dump (Stream &s) const
void
StructuredData::Dictionary::Dump (Stream &s) const
{
bool have_printed_one_elem = false;
s << "{";
for (collection::const_iterator iter = m_dict.begin(); iter != m_dict.end(); ++iter)
bool first = true;
s << "{\n";
s.IndentMore();
for (const auto &pair : m_dict)
{
if (have_printed_one_elem == false)
{
have_printed_one_elem = true;
}
if (first)
first = false;
else
{
s << ",";
}
s << "\"" << iter->first.AsCString() << "\":";
iter->second->Dump(s);
s << ",\n";
s.Indent();
s << "\"" << pair.first.AsCString() << "\" : ";
pair.second->Dump(s);
}
s.IndentLess();
s.EOL();
s.Indent();
s << "}";
}