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,9 +46,9 @@ 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)
|
||||
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);
|
||||
}
|
||||
|
@ -45,12 +45,12 @@ BOOST_AUTO_TEST_CASE(json_pretty_print)
|
||||
|
||||
BOOST_CHECK(
|
||||
"{\n"
|
||||
" \"1\" : 1,\n"
|
||||
" \"2\" : \"2\",\n"
|
||||
" \"3\" : \n"
|
||||
" \"1\": 1,\n"
|
||||
" \"2\": \"2\",\n"
|
||||
" \"3\":\n"
|
||||
" {\n"
|
||||
" \"3.1\" : \"3.1\",\n"
|
||||
" \"3.2\" : 2\n"
|
||||
" \"3.1\": \"3.1\",\n"
|
||||
" \"3.2\": 2\n"
|
||||
" }\n"
|
||||
"}" == jsonPrettyPrint(json));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user