mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-10-14 23:07:55 +02:00
- Made FastWriter output more compact.
- fixed bug in runjsontests.py script.
This commit is contained in:
@@ -115,7 +115,8 @@ rewriteValueTree( const std::string &rewritePath,
|
||||
const Json::Value &root,
|
||||
std::string &rewrite )
|
||||
{
|
||||
// Json::FastWriter writer;
|
||||
//Json::FastWriter writer;
|
||||
//writer.enableYAMLCompatibility();
|
||||
Json::StyledWriter writer;
|
||||
rewrite = writer.write( root );
|
||||
FILE *fout = fopen( rewritePath.c_str(), "wt" );
|
||||
|
@@ -67,10 +67,29 @@ std::string valueToQuotedString( const char *value )
|
||||
return std::string("\"") + value + "\"";
|
||||
}
|
||||
|
||||
// Class Writer
|
||||
// //////////////////////////////////////////////////////////////////
|
||||
Writer::~Writer()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Class FastWriter
|
||||
// //////////////////////////////////////////////////////////////////
|
||||
|
||||
FastWriter::FastWriter()
|
||||
: yamlCompatiblityEnabled_( false )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FastWriter::enableYAMLCompatibility()
|
||||
{
|
||||
yamlCompatiblityEnabled_ = true;
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
FastWriter::write( const Value &root )
|
||||
{
|
||||
@@ -106,33 +125,34 @@ FastWriter::writeValue( const Value &value )
|
||||
break;
|
||||
case arrayValue:
|
||||
{
|
||||
document_ += "[ ";
|
||||
document_ += "[";
|
||||
int size = value.size();
|
||||
for ( int index =0; index < size; ++index )
|
||||
{
|
||||
if ( index > 0 )
|
||||
document_ += ", ";
|
||||
document_ += ",";
|
||||
writeValue( value[index] );
|
||||
}
|
||||
document_ += " ]";
|
||||
document_ += "]";
|
||||
}
|
||||
break;
|
||||
case objectValue:
|
||||
{
|
||||
Value::Members members( value.getMemberNames() );
|
||||
document_ += "{ ";
|
||||
document_ += "{";
|
||||
for ( Value::Members::iterator it = members.begin();
|
||||
it != members.end();
|
||||
++it )
|
||||
{
|
||||
const std::string &name = *it;
|
||||
if ( it != members.begin() )
|
||||
document_ += ", ";
|
||||
document_ += ",";
|
||||
document_ += valueToQuotedString( name.c_str() );
|
||||
document_ += " : ";
|
||||
document_ += yamlCompatiblityEnabled_ ? ": "
|
||||
: ":";
|
||||
writeValue( value[name] );
|
||||
}
|
||||
document_ += " }";
|
||||
document_ += "}";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user