mirror of
https://github.com/marzer/tomlplusplus.git
synced 2024-11-05 02:28:54 +00:00
64 lines
1.6 KiB
C++
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) 2019-2020 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
|
|
|
|
namespace toml
|
|
{
|
|
template <typename Char>
|
|
TOML_EXTERNAL_LINKAGE
|
|
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);
|
|
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_POP_WARNINGS // TOML_DISABLE_SWITCH_WARNINGS
|