9#if !TOML_IMPLEMENTATION
10#error This is an implementation-only header.
13#if TOML_ENABLE_FORMATTERS
23 void json_formatter::print(
const toml::table& tbl) {
25 print_unformatted(
"{}"sv);
29 print_unformatted(
'{');
33 for (
auto&& [k, v] : tbl) {
34 if (first) print_unformatted(
',');
39 print_string(k.str(),
false);
41 print_unformatted(
":"sv);
43 print_unformatted(
" : "sv);
45 const auto type = v.type();
48 case node_type::table:
49 print(*
reinterpret_cast<const table*
>(&v));
51 case node_type::array:
52 print(*
reinterpret_cast<const array*
>(&v));
62 print_unformatted(
'}');
66 void json_formatter::print(
const toml::array& arr) {
68 print_unformatted(
"[]"sv);
72 print_unformatted(
'[');
74 for (
size_t i = 0; i < arr.size(); i++) {
75 if (i > 0u) print_unformatted(
',');
80 const auto type = v.type();
83 case node_type::table:
84 print(*
reinterpret_cast<const table*
>(&v));
86 case node_type::array:
87 print(*
reinterpret_cast<const array*
>(&v));
96 print_unformatted(
']');
100 void json_formatter::print() {
101 if (dump_failed_parse_result())
return;
103 switch (
auto source_type = source().type()) {
104 case node_type::table:
105 print(*
reinterpret_cast<const table*
>(&source()));
107 case node_type::array:
108 print(*
reinterpret_cast<const array*
>(&source()));
111 print_value(source(), source_type);
A TOML array.
Definition array.hpp:285
A TOML table.
Definition table.hpp:220
enum TOML_CLOSED_FLAGS_ENUM indent_sub_tables
Apply indentation to tables nested within other tables/arrays.
Definition forward_declarations.hpp:330
enum TOML_CLOSED_FLAGS_ENUM indent_array_elements
Apply indentation to array elements when the array is forced to wrap over multiple lines.
Definition forward_declarations.hpp:333
#define TOML_EXTERNAL_LINKAGE
Definition preprocessor.hpp:1339
#define TOML_NAMESPACE_END
Definition preprocessor.hpp:1320
#define TOML_ASSUME(expr)
Definition preprocessor.hpp:506