| 1165 | StreamWriterBuilder::StreamWriterBuilder() { setDefaults(&settings_); } |
| 1166 | StreamWriterBuilder::~StreamWriterBuilder() = default; |
| 1167 | StreamWriter* StreamWriterBuilder::newStreamWriter() const { |
| 1168 | const String indentation = settings_["indentation"].asString(); |
| 1169 | const String cs_str = settings_["commentStyle"].asString(); |
| 1170 | const String pt_str = settings_["precisionType"].asString(); |
| 1171 | const bool eyc = settings_["enableYAMLCompatibility"].asBool(); |
| 1172 | const bool dnp = settings_["dropNullPlaceholders"].asBool(); |
| 1173 | const bool usf = settings_["useSpecialFloats"].asBool(); |
| 1174 | const bool emitUTF8 = settings_["emitUTF8"].asBool(); |
| 1175 | unsigned int pre = settings_["precision"].asUInt(); |
| 1176 | CommentStyle::Enum cs = CommentStyle::All; |
| 1177 | if (cs_str == "All") { |
| 1178 | cs = CommentStyle::All; |
| 1179 | } else if (cs_str == "None") { |
| 1180 | cs = CommentStyle::None; |
| 1181 | } else { |
| 1182 | throwRuntimeError("commentStyle must be 'All' or 'None'"); |
| 1183 | } |
| 1184 | PrecisionType precisionType(significantDigits); |
| 1185 | if (pt_str == "significant") { |
| 1186 | precisionType = PrecisionType::significantDigits; |
| 1187 | } else if (pt_str == "decimal") { |
| 1188 | precisionType = PrecisionType::decimalPlaces; |
| 1189 | } else { |
| 1190 | throwRuntimeError("precisionType must be 'significant' or 'decimal'"); |
| 1191 | } |
| 1192 | String colonSymbol = " : "; |
| 1193 | if (eyc) { |
| 1194 | colonSymbol = ": "; |
| 1195 | } else if (indentation.empty()) { |
| 1196 | colonSymbol = ":"; |
| 1197 | } |
| 1198 | String nullSymbol = "null"; |
| 1199 | if (dnp) { |
| 1200 | nullSymbol.clear(); |
| 1201 | } |
| 1202 | if (pre > 17) |
| 1203 | pre = 17; |
| 1204 | String endingLineFeedSymbol; |
| 1205 | return new BuiltStyledStreamWriter(indentation, cs, colonSymbol, nullSymbol, |
| 1206 | endingLineFeedSymbol, usf, emitUTF8, pre, |
| 1207 | precisionType); |
| 1208 | } |
| 1209 | |
| 1210 | bool StreamWriterBuilder::validate(Json::Value* invalid) const { |
| 1211 | static const auto& valid_keys = *new std::set<String>{ |