GH #118: JSON::Object::stringify endless loop

This commit is contained in:
aleks-f
2013-03-06 21:21:40 -06:00
parent dc5c8c87da
commit 727e3cd28d
7 changed files with 50 additions and 53 deletions

View File

@@ -123,41 +123,22 @@ bool Array::isObject(unsigned int index) const
void Array::stringify(std::ostream& out, unsigned int indent) const
{
out << "[";
if ( indent > 0 )
out << std::endl;
for(ValueVec::const_iterator it = _values.begin(); it != _values.end();)
if (indent > 0) out << std::endl;
for (ValueVec::const_iterator it = _values.begin(); it != _values.end();)
{
for(int i = 0; i < indent; i++)
{
out << ' ';
}
for(int i = 0; i < indent; i++) out << ' ';
Stringifier::stringify(*it, out, indent);
if ( ++it != _values.end() )
{
out << ",";
if ( indent > 0 )
{
out << std::endl;
}
if ( indent > 0 ) out << std::endl;
}
}
if ( indent > 0 )
{
out << std::endl;
}
if ( indent > 0 )
indent -= 2;
for(int i = 0; i < indent; i++)
{
out << ' ';
}
out << "]";
}

View File

@@ -117,41 +117,23 @@ void Object::getNames(std::vector<std::string>& names) const
void Object::stringify(std::ostream& out, unsigned int indent) const
{
out << '{';
if ( indent > 0 )
{
out << std::endl;
}
for(ValueMap::const_iterator it = _values.begin(); it != _values.end();)
if (indent > 0) out << std::endl;
for (ValueMap::const_iterator it = _values.begin(); it != _values.end();)
{
for(int i = 0; i < indent; i++)
{
out << ' ';
}
for(int i = 0; i < indent; i++) out << ' ';
out << '"' << it->first << '"';
out << (( indent > 0 ) ? " : " : ":");
Stringifier::stringify(it->second, out, indent);
if ( ++it != _values.end() )
{
out << ',';
}
if ( ++it != _values.end() ) out << ',';
if ( indent > 0 )
{
out << std::endl;
}
if ( indent > 0 ) out << std::endl;
}
if ( indent > 0 )
indent -= 2;
for(int i = 0; i < indent; i++)
{
out << ' ';
}
out << '}';
}