//# This file is a part of toml++ and is subject to the the terms of the MIT license. //# Copyright (c) 2019-2020 Mark Gillard //# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text. // SPDX-License-Identifier: MIT #pragma once //# {{ #include "toml_preprocessor.h" #if !TOML_IMPLEMENTATION #error This is an implementation-only header. #endif //# }} #include "toml_json_formatter.h" TOML_PUSH_WARNINGS TOML_DISABLE_SWITCH_WARNINGS namespace toml { template TOML_EXTERNAL_LINKAGE void json_formatter::print(const toml::table& tbl) { if (tbl.empty()) impl::print_to_stream("{}"sv, base::stream()); else { impl::print_to_stream('{', base::stream()); base::increase_indent(); bool first = false; for (auto&& [k, v] : tbl) { if (first) impl::print_to_stream(", "sv, base::stream()); first = true; base::print_newline(true); base::print_indent(); base::print_quoted_string(k); impl::print_to_stream(" : "sv, base::stream()); const auto type = v.type(); TOML_ASSUME(type != node_type::none); switch (type) { case node_type::table: print(*reinterpret_cast(&v)); break; case node_type::array: print(*reinterpret_cast(&v)); break; default: base::print_value(v, type); } } base::decrease_indent(); base::print_newline(true); base::print_indent(); impl::print_to_stream('}', base::stream()); } base::clear_naked_newline(); } } TOML_POP_WARNINGS // TOML_DISABLE_SWITCH_WARNINGS