| 5218 | StreamWriterBuilder::StreamWriterBuilder() { setDefaults(&settings_); } |
| 5219 | StreamWriterBuilder::~StreamWriterBuilder() = default; |
| 5220 | StreamWriter *StreamWriterBuilder::newStreamWriter() const { |
| 5221 | String indentation = settings_["indentation"].asString(); |
| 5222 | String cs_str = settings_["commentStyle"].asString(); |
| 5223 | String pt_str = settings_["precisionType"].asString(); |
| 5224 | bool eyc = settings_["enableYAMLCompatibility"].asBool(); |
| 5225 | bool dnp = settings_["dropNullPlaceholders"].asBool(); |
| 5226 | bool usf = settings_["useSpecialFloats"].asBool(); |
| 5227 | unsigned int pre = settings_["precision"].asUInt(); |
| 5228 | CommentStyle::Enum cs = CommentStyle::All; |
| 5229 | if (cs_str == "All") { |
| 5230 | cs = CommentStyle::All; |
| 5231 | } else if (cs_str == "None") { |
| 5232 | cs = CommentStyle::None; |
| 5233 | } else { |
| 5234 | throwRuntimeError("commentStyle must be 'All' or 'None'"); |
| 5235 | } |
| 5236 | PrecisionType precisionType(significantDigits); |
| 5237 | if (pt_str == "significant") { |
| 5238 | precisionType = PrecisionType::significantDigits; |
| 5239 | } else if (pt_str == "decimal") { |
| 5240 | precisionType = PrecisionType::decimalPlaces; |
| 5241 | } else { |
| 5242 | throwRuntimeError("precisionType must be 'significant' or 'decimal'"); |
| 5243 | } |
| 5244 | String colonSymbol = " : "; |
| 5245 | if (eyc) { |
| 5246 | colonSymbol = ": "; |
| 5247 | } else if (indentation.empty()) { |
| 5248 | colonSymbol = ":"; |
| 5249 | } |
| 5250 | String nullSymbol = "null"; |
| 5251 | if (dnp) { |
| 5252 | nullSymbol.clear(); |
| 5253 | } |
| 5254 | if (pre > 17) |
| 5255 | pre = 17; |
| 5256 | String endingLineFeedSymbol; |
| 5257 | return new BuiltStyledStreamWriter(indentation, cs, colonSymbol, nullSymbol, |
| 5258 | endingLineFeedSymbol, usf, pre, |
| 5259 | precisionType); |
| 5260 | } |
| 5261 | static void getValidWriterKeys(std::set<String> *valid_keys) { |
| 5262 | valid_keys->clear(); |
| 5263 | valid_keys->insert("indentation"); |