mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Make json output a bit prettier.
This commit is contained in:
parent
60525dbf52
commit
776fec1913
@ -23,6 +23,8 @@
|
||||
|
||||
#include <libdevcore/CommonIO.h>
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
@ -44,7 +46,7 @@ namespace
|
||||
class StreamWriterBuilder: public Json::StreamWriterBuilder
|
||||
{
|
||||
public:
|
||||
explicit StreamWriterBuilder(map<string, string> const& _settings)
|
||||
explicit StreamWriterBuilder(map<string, Json::Value> const& _settings)
|
||||
{
|
||||
for (auto const& iter: _settings)
|
||||
this->settings_[iter.first] = iter.second;
|
||||
@ -89,14 +91,16 @@ bool parse(Json::CharReaderBuilder& _builder, string const& _input, Json::Value&
|
||||
|
||||
string jsonPrettyPrint(Json::Value const& _input)
|
||||
{
|
||||
static map<string, string> settings{{"indentation", " "}};
|
||||
static map<string, Json::Value> settings{{"indentation", " "}, {"enableYAMLCompatibility", true}};
|
||||
static StreamWriterBuilder writerBuilder(settings);
|
||||
return print(_input, writerBuilder);
|
||||
string result = print(_input, writerBuilder);
|
||||
boost::replace_all(result, " \n", "\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
string jsonCompactPrint(Json::Value const& _input)
|
||||
{
|
||||
static map<string, string> settings{{"indentation", ""}};
|
||||
static map<string, Json::Value> settings{{"indentation", ""}};
|
||||
static StreamWriterBuilder writerBuilder(settings);
|
||||
return print(_input, writerBuilder);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user