mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-12 18:10:27 +01:00
const stuff
This commit is contained in:
parent
beb6f35c63
commit
9243d602fe
@ -76,12 +76,12 @@ public:
|
||||
void setIndentation(std::string indentation);
|
||||
|
||||
/// Do not take ownership of sout, but maintain a reference.
|
||||
StreamWriter* newStreamWriter(std::ostream* sout);
|
||||
StreamWriter* newStreamWriter(std::ostream* sout) const;
|
||||
};
|
||||
};
|
||||
|
||||
/// \brief Write into stringstream, then return string, for convenience.
|
||||
std::string writeString(Value const& root, StreamWriterBuilder const& builder);
|
||||
std::string writeString(Value const& root, StreamWriter::Builder const& builder);
|
||||
|
||||
|
||||
/** \brief Abstract class for writers.
|
||||
|
@ -151,7 +151,6 @@ static int parseAndSaveValueTree(const std::string& input,
|
||||
reader.getFormattedErrorMessages().c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!parseOnly) {
|
||||
FILE* factual = fopen(actual.c_str(), "wt");
|
||||
if (!factual) {
|
||||
@ -182,6 +181,14 @@ static std::string useStyledStreamWriter(
|
||||
writer.write(sout, root);
|
||||
return sout.str();
|
||||
}
|
||||
static std::string useBuiltStyledStreamWriter(
|
||||
Json::Value const& root)
|
||||
{
|
||||
Json::StreamWriterBuilderFactory f;
|
||||
Json::StreamWriter::Builder builder(&f);
|
||||
builder.setCommentStyle(Json::StreamWriter::CommentStyle::All);
|
||||
return writeString(root, builder);
|
||||
}
|
||||
static int rewriteValueTree(
|
||||
const std::string& rewritePath,
|
||||
const Json::Value& root,
|
||||
@ -248,6 +255,8 @@ static int parseCommandLine(
|
||||
opts->write = &useStyledWriter;
|
||||
} else if (writerName == "StyledStreamWriter") {
|
||||
opts->write = &useStyledStreamWriter;
|
||||
} else if (writerName == "BuiltStyledStreamWriter") {
|
||||
opts->write = &useBuiltStyledStreamWriter;
|
||||
} else {
|
||||
printf("Unknown '--json-writer %s'\n", writerName.c_str());
|
||||
return 4;
|
||||
|
@ -772,8 +772,8 @@ void BuiltStyledStreamWriter::writeArrayValue(Value const& value) {
|
||||
if (size == 0)
|
||||
pushValue("[]");
|
||||
else {
|
||||
bool isArrayMultiLine = isMultineArray(value);
|
||||
if (isArrayMultiLine) {
|
||||
bool isMultiLine = (cs_ == CommentStyle::All) || isMultineArray(value);
|
||||
if (isMultiLine) {
|
||||
writeWithIndent("[");
|
||||
indent();
|
||||
bool hasChildValue = !childValues_.empty();
|
||||
@ -969,14 +969,14 @@ void StreamWriter::Builder::setIndentation(std::string v)
|
||||
{
|
||||
own_->setIndentation(v);
|
||||
}
|
||||
StreamWriter* StreamWriter::Builder::newStreamWriter(std::ostream* sout)
|
||||
StreamWriter* StreamWriter::Builder::newStreamWriter(std::ostream* sout) const
|
||||
{
|
||||
return own_->newStreamWriter(sout);
|
||||
}
|
||||
|
||||
/// Do not take ownership of sout, but maintain a reference.
|
||||
StreamWriter* newStreamWriter(std::ostream* sout);
|
||||
std::string writeString(Value const& root, StreamWriterBuilder const& builder) {
|
||||
std::string writeString(Value const& root, StreamWriter::Builder const& builder) {
|
||||
std::ostringstream sout;
|
||||
std::unique_ptr<StreamWriter> const sw(builder.newStreamWriter(&sout));
|
||||
sw->write(root);
|
||||
@ -986,7 +986,7 @@ std::string writeString(Value const& root, StreamWriterBuilder const& builder) {
|
||||
std::ostream& operator<<(std::ostream& sout, Value const& root) {
|
||||
StreamWriterBuilderFactory f;
|
||||
StreamWriter::Builder builder(&f);
|
||||
builder.setCommentStyle(StreamWriter::CommentStyle::Some);
|
||||
builder.setCommentStyle(StreamWriter::CommentStyle::All);
|
||||
std::shared_ptr<StreamWriter> writer(builder.newStreamWriter(&sout));
|
||||
writer->write(root);
|
||||
return sout;
|
||||
|
Loading…
Reference in New Issue
Block a user