| 5334 | StreamWriterBuilder::StreamWriterBuilder() { setDefaults(&settings_); } |
| 5335 | StreamWriterBuilder::~StreamWriterBuilder() {} |
| 5336 | StreamWriter* StreamWriterBuilder::newStreamWriter() const { |
| 5337 | JSONCPP_STRING indentation = settings_["indentation"].asString(); |
| 5338 | JSONCPP_STRING cs_str = settings_["commentStyle"].asString(); |
| 5339 | JSONCPP_STRING pt_str = settings_["precisionType"].asString(); |
| 5340 | bool eyc = settings_["enableYAMLCompatibility"].asBool(); |
| 5341 | bool dnp = settings_["dropNullPlaceholders"].asBool(); |
| 5342 | bool usf = settings_["useSpecialFloats"].asBool(); |
| 5343 | unsigned int pre = settings_["precision"].asUInt(); |
| 5344 | CommentStyle::Enum cs = CommentStyle::All; |
| 5345 | if (cs_str == "All") { |
| 5346 | cs = CommentStyle::All; |
| 5347 | } else if (cs_str == "None") { |
| 5348 | cs = CommentStyle::None; |
| 5349 | } else { |
| 5350 | throwRuntimeError("commentStyle must be 'All' or 'None'"); |
| 5351 | } |
| 5352 | PrecisionType precisionType(significantDigits); |
| 5353 | if (pt_str == "significant") { |
| 5354 | precisionType = PrecisionType::significantDigits; |
| 5355 | } else if (pt_str == "decimal") { |
| 5356 | precisionType = PrecisionType::decimalPlaces; |
| 5357 | } else { |
| 5358 | throwRuntimeError("precisionType must be 'significant' or 'decimal'"); |
| 5359 | } |
| 5360 | JSONCPP_STRING colonSymbol = " : "; |
| 5361 | if (eyc) { |
| 5362 | colonSymbol = ": "; |
| 5363 | } else if (indentation.empty()) { |
| 5364 | colonSymbol = ":"; |
| 5365 | } |
| 5366 | JSONCPP_STRING nullSymbol = "null"; |
| 5367 | if (dnp) { |
| 5368 | nullSymbol.clear(); |
| 5369 | } |
| 5370 | if (pre > 17) |
| 5371 | pre = 17; |
| 5372 | JSONCPP_STRING endingLineFeedSymbol; |
| 5373 | return new BuiltStyledStreamWriter(indentation, cs, colonSymbol, nullSymbol, |
| 5374 | endingLineFeedSymbol, usf, pre, |
| 5375 | precisionType); |
| 5376 | } |
| 5377 | static void getValidWriterKeys(std::set<JSONCPP_STRING>* valid_keys) { |
| 5378 | valid_keys->clear(); |
| 5379 | valid_keys->insert("indentation"); |