diff --git a/tooling/pipeline/includes/json_handling/pretty_print.h b/tooling/pipeline/includes/json_handling/pretty_print.h index 3d148c31..c3a4368f 100644 --- a/tooling/pipeline/includes/json_handling/pretty_print.h +++ b/tooling/pipeline/includes/json_handling/pretty_print.h @@ -27,83 +27,84 @@ inline void PrettyPrint(std::ostream& outstream, boost::json::value const& json_val, std::string* indent = nullptr) { - std::string str; - if (indent == nullptr) { - indent = &str; - } - switch (json_val.kind()) { - case boost::json::kind::object: { - outstream << "{\n"; - indent->append(4, ' '); - auto const& obj = json_val.get_object(); - if (!obj.empty()) { - const auto* iter = obj.begin(); - for (;;) { - outstream << *indent << boost::json::serialize(iter->key()) << " : "; - PrettyPrint(outstream, iter->value(), indent); - iter = std::next(iter); - if (iter == obj.end()) { - break; - } + std::string str; + if (indent == nullptr) { + indent = &str; + } + switch (json_val.kind()) { + case boost::json::kind::object: { + outstream << "{\n"; + indent->append(4, ' '); + auto const& obj = json_val.get_object(); + if (!obj.empty()) { + const auto* iter = obj.begin(); + for (;;) { + outstream << *indent << boost::json::serialize(iter->key()) + << " : "; + PrettyPrint(outstream, iter->value(), indent); + iter = std::next(iter); + if (iter == obj.end()) { + break; + } - outstream << ",\n"; - } + outstream << ",\n"; + } + } + outstream << "\n"; + indent->resize(indent->size() - 4); + outstream << *indent << "}"; + break; } + + case boost::json::kind::array: { + outstream << "[\n"; + indent->append(4, ' '); + auto const& arr = json_val.get_array(); + if (!arr.empty()) { + const auto* iter = arr.begin(); + for (;;) { + outstream << *indent; + PrettyPrint(outstream, *iter, indent); + iter = std::next(iter); + if (iter == arr.end()) { + break; + } + outstream << ",\n"; + } + } + outstream << "\n"; + indent->resize(indent->size() - 4); + outstream << *indent << "]"; + break; + } + + case boost::json::kind::string: { + outstream << serialize(json_val.get_string()); + break; + } + + case boost::json::kind::uint64: + case boost::json::kind::int64: + case boost::json::kind::double_: + outstream << json_val; + break; + + case boost::json::kind::bool_: + if (json_val.get_bool()) { + outstream << "true"; + } else { + outstream << "false"; + } + break; + + case boost::json::kind::null: + outstream << "null"; + break; + } + + if (indent->empty()) { outstream << "\n"; - indent->resize(indent->size() - 4); - outstream << *indent << "}"; - break; - } - - case boost::json::kind::array: { - outstream << "[\n"; - indent->append(4, ' '); - auto const& arr = json_val.get_array(); - if (!arr.empty()) { - const auto* iter = arr.begin(); - for (;;) { - outstream << *indent; - PrettyPrint(outstream, *iter, indent); - iter = std::next(iter); - if (iter == arr.end()) { - break; - } - outstream << ",\n"; - } - } - outstream << "\n"; - indent->resize(indent->size() - 4); - outstream << *indent << "]"; - break; - } - - case boost::json::kind::string: { - outstream << serialize(json_val.get_string()); - break; - } - - case boost::json::kind::uint64: - case boost::json::kind::int64: - case boost::json::kind::double_: - outstream << json_val; - break; - - case boost::json::kind::bool_: - if (json_val.get_bool()) { - outstream << "true"; - } else { - outstream << "false"; - } - break; - - case boost::json::kind::null: - outstream << "null"; - break; - } - - if (indent->empty()) { - outstream << "\n"; - } + } } #endif // BIERGARTEN_PIPELINE_INCLUDES_JSON_HANDLING_PRETTY_PRINT_H_