tomlplusplus/include/toml++/toml_json_formatter.hpp
Mark Gillard 53f29d9365 restructuring and minor refactoring
There's no new functionality here. It's purely tooling + CI stuff:
- moved `python` => `tools`
- moved documentation images to subfolder
- moved `vs/tests` to tests/vs projects
- moved `vs` solution etc to root
- added semicolons to macros
- added cpp.hint to help VS intellisense
- migrated documentation generation to external lib
2021-04-18 22:58:41 +03:00

64 lines
1.6 KiB
C++

//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
//# 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;
TOML_NAMESPACE_START
{
template <typename Char>
inline void json_formatter<Char>::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, false);
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<const table*>(&v)); break;
case node_type::array: print(*reinterpret_cast<const array*>(&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_NAMESPACE_END;
TOML_POP_WARNINGS; // TOML_DISABLE_SWITCH_WARNINGS