mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-05-19 19:56:53 +02:00
enableYAMLCompatibility and dropNullPlaceholders for StreamWriterBuilder
This commit is contained in:
parent
07f0e9308d
commit
5a744708fc
@ -90,8 +90,15 @@ public:
|
||||
// without a major version bump.
|
||||
/** Configuration of this builder.
|
||||
Available settings (case-sensitive):
|
||||
- "commentStyle": "None", "Some", or "All"
|
||||
- "commentStyle": "None" or "All"
|
||||
- "indentation": "<anything>"
|
||||
- "enableYAMLCompatibility": False or True
|
||||
- slightly change the whitespace around colons
|
||||
- "dropNullPlaceholders": False or True
|
||||
- Drop the "null" string from the writer's output for nullValues.
|
||||
Strictly speaking, this is not valid JSON. But when the output is being
|
||||
fed to a browser's Javascript, it makes for smaller output and the
|
||||
browser can handle the output just fine.
|
||||
|
||||
You can examine 'settings_` yourself
|
||||
to see the defaults. You can also write and read them just like any
|
||||
|
@ -973,6 +973,8 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const
|
||||
|
||||
std::string indentation = settings_["indentation"].asString();
|
||||
std::string cs_str = settings_["commentStyle"].asString();
|
||||
bool eyc = settings_["enableYAMLCompatibility"].asBool();
|
||||
bool dnp = settings_["dropNullPlaceholders"].asBool();
|
||||
CommentStyle::Enum cs = CommentStyle::All;
|
||||
if (cs_str == "All") {
|
||||
cs = CommentStyle::All;
|
||||
@ -982,10 +984,15 @@ StreamWriter* StreamWriterBuilder::newStreamWriter() const
|
||||
return NULL;
|
||||
}
|
||||
std::string colonSymbol = " : ";
|
||||
if (indentation.empty()) {
|
||||
if (eyc) {
|
||||
colonSymbol = ": ";
|
||||
} else if (indentation.empty()) {
|
||||
colonSymbol = ":";
|
||||
}
|
||||
std::string nullSymbol = "null";
|
||||
if (dnp) {
|
||||
nullSymbol = "";
|
||||
}
|
||||
std::string endingLineFeedSymbol = "";
|
||||
return new BuiltStyledStreamWriter(
|
||||
indentation, cs,
|
||||
@ -996,6 +1003,8 @@ static void getValidWriterKeys(std::set<std::string>* valid_keys)
|
||||
valid_keys->clear();
|
||||
valid_keys->insert("indentation");
|
||||
valid_keys->insert("commentStyle");
|
||||
valid_keys->insert("enableYAMLCompatibility");
|
||||
valid_keys->insert("dropNullPlaceholders");
|
||||
}
|
||||
bool StreamWriterBuilder::validate(Json::Value* invalid) const
|
||||
{
|
||||
@ -1021,6 +1030,8 @@ void StreamWriterBuilder::setDefaults(Json::Value* settings)
|
||||
//! [StreamWriterBuilderDefaults]
|
||||
(*settings)["commentStyle"] = "All";
|
||||
(*settings)["indentation"] = "\t";
|
||||
(*settings)["enableYAMLCompatibility"] = false;
|
||||
(*settings)["dropNullPlaceholders"] = false;
|
||||
//! [StreamWriterBuilderDefaults]
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user