mirror of
https://github.com/marzer/tomlplusplus.git
synced 2026-01-31 21:02:08 +00:00
fixed missing #include <utility>
also: - added test for `yaml_formatter` - formatter refactoring + cleanup - documentation fixes
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "value.h"
|
||||
#include "std_utility.h"
|
||||
#include "std_vector.h"
|
||||
#include "std_initializer_list.h"
|
||||
#include "make_node.h"
|
||||
|
||||
@@ -101,16 +101,17 @@ TOML_IMPL_NAMESPACE_START
|
||||
TOML_EXTERNAL_LINKAGE
|
||||
void formatter::print_string(std::string_view str, bool allow_multi_line, bool allow_bare)
|
||||
{
|
||||
auto literals = literal_strings_allowed();
|
||||
auto literal = literal_strings_allowed();
|
||||
if (str.empty())
|
||||
{
|
||||
print_to_stream(*stream_, literals ? "''"sv : "\"\""sv);
|
||||
print_to_stream(*stream_, literal ? "''"sv : "\"\""sv);
|
||||
naked_newline_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
auto multi_line = allow_multi_line && !!(config_.flags & format_flags::allow_multi_line_strings);
|
||||
if (multi_line || literals || allow_bare)
|
||||
bool multi_line = allow_multi_line && !!(config_.flags & format_flags::allow_multi_line_strings);
|
||||
const bool treat_raw_tab_as_control_char = !(config_.flags & format_flags::allow_real_tabs_in_strings);
|
||||
if (multi_line || literal || treat_raw_tab_as_control_char || allow_bare)
|
||||
{
|
||||
utf8_decoder decoder;
|
||||
bool has_line_breaks = false;
|
||||
@@ -131,7 +132,8 @@ TOML_IMPL_NAMESPACE_START
|
||||
{
|
||||
if (is_line_break(decoder.codepoint))
|
||||
has_line_breaks = true;
|
||||
else if (is_nontab_control_character(decoder.codepoint))
|
||||
else if (is_nontab_control_character(decoder.codepoint)
|
||||
|| (treat_raw_tab_as_control_char && decoder.codepoint == U'\t'))
|
||||
has_control_chars = true;
|
||||
else if (decoder.codepoint == U'\'')
|
||||
has_single_quotes = true;
|
||||
@@ -143,12 +145,12 @@ TOML_IMPL_NAMESPACE_START
|
||||
break;
|
||||
}
|
||||
multi_line = multi_line && has_line_breaks;
|
||||
literals = literals && !has_control_chars && !(!multi_line && has_single_quotes);
|
||||
literal = literal && !has_control_chars && !(!multi_line && has_single_quotes);
|
||||
}
|
||||
|
||||
if (allow_bare)
|
||||
print_to_stream(*stream_, str);
|
||||
else if (literals)
|
||||
else if (literal)
|
||||
print_to_stream_bookended(*stream_, str, multi_line ? "'''"sv : "'"sv);
|
||||
else
|
||||
{
|
||||
|
||||
@@ -292,7 +292,7 @@ TOML_NAMESPACE_START // abi namespace
|
||||
/// \brief Format flags for modifying how TOML data is printed to streams.
|
||||
///
|
||||
/// \note Formatters may disregard/override any of these flags according to the requirements of their
|
||||
/// output target (e.g. #toml::json_formatter JSON always apply quotes to dates and times).
|
||||
/// output target (e.g. #toml::json_formatter will always apply quotes to dates and times).
|
||||
enum class format_flags : uint64_t
|
||||
{
|
||||
/// \brief None.
|
||||
@@ -310,20 +310,23 @@ TOML_NAMESPACE_START // abi namespace
|
||||
/// \brief Strings containing newlines will be emitted as triple-quoted 'multi-line' strings where possible.
|
||||
allow_multi_line_strings = (1ull << 3),
|
||||
|
||||
/// \brief Allow real tab characters in string literals (as opposed to the escaped form `\t`).
|
||||
allow_real_tabs_in_strings = (1ull << 4),
|
||||
|
||||
/// \brief Allow integers with #value_flags::format_as_binary to be emitted as binary.
|
||||
allow_binary_integers = (1ull << 4),
|
||||
allow_binary_integers = (1ull << 5),
|
||||
|
||||
/// \brief Allow integers with #value_flags::format_as_octal to be emitted as octal.
|
||||
allow_octal_integers = (1ull << 5),
|
||||
allow_octal_integers = (1ull << 6),
|
||||
|
||||
/// \brief Allow integers with #value_flags::format_as_hexadecimal to be emitted as hexadecimal.
|
||||
allow_hexadecimal_integers = (1ull << 6),
|
||||
allow_hexadecimal_integers = (1ull << 7),
|
||||
|
||||
/// \brief Apply indentation to tables nested within other tables/arrays.
|
||||
indent_sub_tables = (1ull << 7),
|
||||
indent_sub_tables = (1ull << 8),
|
||||
|
||||
/// \brief Apply indentation to array elements when the array is forced to wrap over multiple lines.
|
||||
indent_array_elements = (1ull << 8),
|
||||
indent_array_elements = (1ull << 9),
|
||||
|
||||
/// \brief Combination mask of all indentation-enabling flags.
|
||||
indentation = indent_sub_tables | indent_array_elements,
|
||||
|
||||
@@ -25,25 +25,25 @@ TOML_NAMESPACE_START
|
||||
{
|
||||
if (tbl.empty())
|
||||
{
|
||||
base::print_unformatted("{}"sv);
|
||||
print_unformatted("{}"sv);
|
||||
return;
|
||||
}
|
||||
|
||||
base::print_unformatted('{');
|
||||
print_unformatted('{');
|
||||
|
||||
if (base::indent_sub_tables())
|
||||
base::increase_indent();
|
||||
if (indent_sub_tables())
|
||||
increase_indent();
|
||||
bool first = false;
|
||||
for (auto&& [k, v] : tbl)
|
||||
{
|
||||
if (first)
|
||||
base::print_unformatted(',');
|
||||
print_unformatted(',');
|
||||
first = true;
|
||||
base::print_newline(true);
|
||||
base::print_indent();
|
||||
print_newline(true);
|
||||
print_indent();
|
||||
|
||||
base::print_string(k, false);
|
||||
base::print_unformatted(" : "sv);
|
||||
print_string(k, false);
|
||||
print_unformatted(" : "sv);
|
||||
|
||||
const auto type = v.type();
|
||||
TOML_ASSUME(type != node_type::none);
|
||||
@@ -51,15 +51,15 @@ TOML_NAMESPACE_START
|
||||
{
|
||||
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);
|
||||
default: print_value(v, type);
|
||||
}
|
||||
}
|
||||
if (base::indent_sub_tables())
|
||||
base::decrease_indent();
|
||||
base::print_newline(true);
|
||||
base::print_indent();
|
||||
if (indent_sub_tables())
|
||||
decrease_indent();
|
||||
print_newline(true);
|
||||
print_indent();
|
||||
|
||||
base::print_unformatted('}');
|
||||
print_unformatted('}');
|
||||
}
|
||||
|
||||
TOML_EXTERNAL_LINKAGE
|
||||
@@ -67,19 +67,19 @@ TOML_NAMESPACE_START
|
||||
{
|
||||
if (arr.empty())
|
||||
{
|
||||
base::print_unformatted("[]"sv);
|
||||
print_unformatted("[]"sv);
|
||||
return;
|
||||
}
|
||||
|
||||
base::print_unformatted('[');
|
||||
if (base::indent_array_elements())
|
||||
base::increase_indent();
|
||||
print_unformatted('[');
|
||||
if (indent_array_elements())
|
||||
increase_indent();
|
||||
for (size_t i = 0; i < arr.size(); i++)
|
||||
{
|
||||
if (i > 0u)
|
||||
base::print_unformatted(',');
|
||||
base::print_newline(true);
|
||||
base::print_indent();
|
||||
print_unformatted(',');
|
||||
print_newline(true);
|
||||
print_indent();
|
||||
|
||||
auto& v = arr[i];
|
||||
const auto type = v.type();
|
||||
@@ -88,27 +88,27 @@ TOML_NAMESPACE_START
|
||||
{
|
||||
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);
|
||||
default: print_value(v, type);
|
||||
}
|
||||
}
|
||||
if (base::indent_array_elements())
|
||||
base::decrease_indent();
|
||||
base::print_newline(true);
|
||||
base::print_indent();
|
||||
base::print_unformatted(']');
|
||||
if (indent_array_elements())
|
||||
decrease_indent();
|
||||
print_newline(true);
|
||||
print_indent();
|
||||
print_unformatted(']');
|
||||
}
|
||||
|
||||
TOML_EXTERNAL_LINKAGE
|
||||
void json_formatter::print()
|
||||
{
|
||||
if (base::dump_failed_parse_result())
|
||||
if (dump_failed_parse_result())
|
||||
return;
|
||||
|
||||
switch (auto source_type = base::source().type())
|
||||
switch (auto source_type = source().type())
|
||||
{
|
||||
case node_type::table: print(*reinterpret_cast<const table*>(&base::source())); break;
|
||||
case node_type::array: print(*reinterpret_cast<const array*>(&base::source())); break;
|
||||
default: base::print_value(base::source(), source_type);
|
||||
case node_type::table: print(*reinterpret_cast<const table*>(&source())); break;
|
||||
case node_type::array: print(*reinterpret_cast<const array*>(&source())); break;
|
||||
default: print_value(source(), source_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "forward_declarations.h"
|
||||
#include "std_utility.h"
|
||||
#include "source_region.h"
|
||||
#include "header_start.h"
|
||||
|
||||
|
||||
10
include/toml++/impl/std_utility.h
Normal file
10
include/toml++/impl/std_utility.h
Normal file
@@ -0,0 +1,10 @@
|
||||
//# 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 "preprocessor.h"
|
||||
TOML_DISABLE_WARNINGS;
|
||||
#include <utility>
|
||||
TOML_ENABLE_WARNINGS;
|
||||
@@ -878,7 +878,7 @@ TOML_NAMESPACE_START
|
||||
if constexpr (impl::is_wide_string<KeyType>)
|
||||
{
|
||||
#if TOML_ENABLE_WINDOWS_COMPAT
|
||||
return insert(impl::narrow(std::forward<KeyType>(key)), std::forward<ValueType>(val), flags);
|
||||
return insert(impl::narrow(static_cast<KeyType&&>(key)), static_cast<ValueType&&>(val), flags);
|
||||
#else
|
||||
static_assert(impl::dependent_false<KeyType>, "Evaluated unreachable branch!");
|
||||
#endif
|
||||
@@ -889,8 +889,8 @@ TOML_NAMESPACE_START
|
||||
if (ipos == map_.end() || ipos->first != key)
|
||||
{
|
||||
ipos = map_.emplace_hint(ipos,
|
||||
std::forward<KeyType>(key),
|
||||
impl::make_node(std::forward<ValueType>(val), flags));
|
||||
static_cast<KeyType&&>(key),
|
||||
impl::make_node(static_cast<ValueType&&>(val), flags));
|
||||
return { iterator{ ipos }, true };
|
||||
}
|
||||
return { iterator{ ipos }, false };
|
||||
@@ -1023,7 +1023,9 @@ TOML_NAMESPACE_START
|
||||
if constexpr (impl::is_wide_string<KeyType>)
|
||||
{
|
||||
#if TOML_ENABLE_WINDOWS_COMPAT
|
||||
return insert_or_assign(impl::narrow(std::forward<KeyType>(key)), std::forward<ValueType>(val), flags);
|
||||
return insert_or_assign(impl::narrow(static_cast<KeyType&&>(key)),
|
||||
static_cast<ValueType&&>(val),
|
||||
flags);
|
||||
#else
|
||||
static_assert(impl::dependent_false<KeyType>, "Evaluated unreachable branch!");
|
||||
#endif
|
||||
@@ -1034,13 +1036,13 @@ TOML_NAMESPACE_START
|
||||
if (ipos == map_.end() || ipos->first != key)
|
||||
{
|
||||
ipos = map_.emplace_hint(ipos,
|
||||
std::forward<KeyType>(key),
|
||||
impl::make_node(std::forward<ValueType>(val), flags));
|
||||
static_cast<KeyType&&>(key),
|
||||
impl::make_node(static_cast<ValueType&&>(val), flags));
|
||||
return { iterator{ ipos }, true };
|
||||
}
|
||||
else
|
||||
{
|
||||
(*ipos).second.reset(impl::make_node(std::forward<ValueType>(val), flags));
|
||||
(*ipos).second.reset(impl::make_node(static_cast<ValueType&&>(val), flags));
|
||||
return { iterator{ ipos }, false };
|
||||
}
|
||||
}
|
||||
@@ -1094,7 +1096,7 @@ TOML_NAMESPACE_START
|
||||
if constexpr (impl::is_wide_string<KeyType>)
|
||||
{
|
||||
#if TOML_ENABLE_WINDOWS_COMPAT
|
||||
return emplace<ValueType>(impl::narrow(std::forward<KeyType>(key)), std::forward<ValueArgs>(args)...);
|
||||
return emplace<ValueType>(impl::narrow(static_cast<KeyType&&>(key)), static_cast<ValueArgs&&>(args)...);
|
||||
#else
|
||||
static_assert(impl::dependent_false<KeyType>, "Evaluated unreachable branch!");
|
||||
#endif
|
||||
@@ -1110,8 +1112,8 @@ TOML_NAMESPACE_START
|
||||
if (ipos == map_.end() || ipos->first != key)
|
||||
{
|
||||
ipos = map_.emplace_hint(ipos,
|
||||
std::forward<KeyType>(key),
|
||||
new impl::wrap_node<type>{ std::forward<ValueArgs>(args)... });
|
||||
static_cast<KeyType&&>(key),
|
||||
new impl::wrap_node<type>{ static_cast<ValueArgs&&>(args)... });
|
||||
return { iterator{ ipos }, true };
|
||||
}
|
||||
return { iterator{ ipos }, false };
|
||||
|
||||
@@ -86,6 +86,7 @@ TOML_NAMESPACE_START
|
||||
static constexpr format_flags default_flags = constants.mandatory_flags //
|
||||
| format_flags::allow_literal_strings //
|
||||
| format_flags::allow_multi_line_strings //
|
||||
| format_flags::allow_real_tabs_in_strings //
|
||||
| format_flags::allow_binary_integers //
|
||||
| format_flags::allow_octal_integers //
|
||||
| format_flags::allow_hexadecimal_integers //
|
||||
|
||||
@@ -121,8 +121,8 @@ TOML_NAMESPACE_START
|
||||
{
|
||||
if (pending_table_separator_)
|
||||
{
|
||||
base::print_newline(true);
|
||||
base::print_newline(true);
|
||||
print_newline(true);
|
||||
print_newline(true);
|
||||
pending_table_separator_ = false;
|
||||
}
|
||||
}
|
||||
@@ -130,7 +130,7 @@ TOML_NAMESPACE_START
|
||||
TOML_EXTERNAL_LINKAGE
|
||||
void toml_formatter::print_key_segment(std::string_view str)
|
||||
{
|
||||
base::print_string(str, false, true);
|
||||
print_string(str, false, true);
|
||||
}
|
||||
|
||||
TOML_EXTERNAL_LINKAGE
|
||||
@@ -139,7 +139,7 @@ TOML_NAMESPACE_START
|
||||
for (const auto& segment : key_path_)
|
||||
{
|
||||
if (std::addressof(segment) > key_path_.data())
|
||||
base::print_unformatted('.');
|
||||
print_unformatted('.');
|
||||
print_key_segment(segment);
|
||||
}
|
||||
}
|
||||
@@ -149,21 +149,21 @@ TOML_NAMESPACE_START
|
||||
{
|
||||
if (tbl.empty())
|
||||
{
|
||||
base::print_unformatted("{}"sv);
|
||||
print_unformatted("{}"sv);
|
||||
return;
|
||||
}
|
||||
|
||||
base::print_unformatted("{ "sv);
|
||||
print_unformatted("{ "sv);
|
||||
|
||||
bool first = false;
|
||||
for (auto&& [k, v] : tbl)
|
||||
{
|
||||
if (first)
|
||||
base::print_unformatted(", "sv);
|
||||
print_unformatted(", "sv);
|
||||
first = true;
|
||||
|
||||
print_key_segment(k);
|
||||
base::print_unformatted(" = "sv);
|
||||
print_unformatted(" = "sv);
|
||||
|
||||
const auto type = v.type();
|
||||
TOML_ASSUME(type != node_type::none);
|
||||
@@ -171,11 +171,11 @@ TOML_NAMESPACE_START
|
||||
{
|
||||
case node_type::table: print_inline(*reinterpret_cast<const table*>(&v)); break;
|
||||
case node_type::array: print(*reinterpret_cast<const array*>(&v)); break;
|
||||
default: base::print_value(v, type);
|
||||
default: print_value(v, type);
|
||||
}
|
||||
}
|
||||
|
||||
base::print_unformatted(" }"sv);
|
||||
print_unformatted(" }"sv);
|
||||
}
|
||||
|
||||
TOML_EXTERNAL_LINKAGE
|
||||
@@ -183,41 +183,41 @@ TOML_NAMESPACE_START
|
||||
{
|
||||
if (arr.empty())
|
||||
{
|
||||
base::print_unformatted("[]"sv);
|
||||
print_unformatted("[]"sv);
|
||||
return;
|
||||
}
|
||||
|
||||
const auto original_indent = base::indent();
|
||||
const auto original_indent = indent();
|
||||
const auto multiline = TOML_ANON_NAMESPACE::toml_formatter_forces_multiline(
|
||||
arr,
|
||||
120u,
|
||||
base::indent_columns() * static_cast<size_t>(original_indent < 0 ? 0 : original_indent));
|
||||
indent_columns() * static_cast<size_t>(original_indent < 0 ? 0 : original_indent));
|
||||
|
||||
base::print_unformatted("["sv);
|
||||
print_unformatted("["sv);
|
||||
|
||||
if (multiline)
|
||||
{
|
||||
if (original_indent < 0)
|
||||
base::indent(0);
|
||||
if (base::indent_array_elements())
|
||||
base::increase_indent();
|
||||
indent(0);
|
||||
if (indent_array_elements())
|
||||
increase_indent();
|
||||
}
|
||||
else
|
||||
base::print_unformatted(' ');
|
||||
print_unformatted(' ');
|
||||
|
||||
for (size_t i = 0; i < arr.size(); i++)
|
||||
{
|
||||
if (i > 0u)
|
||||
{
|
||||
base::print_unformatted(',');
|
||||
print_unformatted(',');
|
||||
if (!multiline)
|
||||
base::print_unformatted(' ');
|
||||
print_unformatted(' ');
|
||||
}
|
||||
|
||||
if (multiline)
|
||||
{
|
||||
base::print_newline(true);
|
||||
base::print_indent();
|
||||
print_newline(true);
|
||||
print_indent();
|
||||
}
|
||||
|
||||
auto& v = arr[i];
|
||||
@@ -227,19 +227,19 @@ TOML_NAMESPACE_START
|
||||
{
|
||||
case node_type::table: print_inline(*reinterpret_cast<const table*>(&v)); break;
|
||||
case node_type::array: print(*reinterpret_cast<const array*>(&v)); break;
|
||||
default: base::print_value(v, type);
|
||||
default: print_value(v, type);
|
||||
}
|
||||
}
|
||||
if (multiline)
|
||||
{
|
||||
base::indent(original_indent);
|
||||
base::print_newline(true);
|
||||
base::print_indent();
|
||||
indent(original_indent);
|
||||
print_newline(true);
|
||||
print_indent();
|
||||
}
|
||||
else
|
||||
base::print_unformatted(' ');
|
||||
print_unformatted(' ');
|
||||
|
||||
base::print_unformatted("]"sv);
|
||||
print_unformatted("]"sv);
|
||||
}
|
||||
|
||||
TOML_EXTERNAL_LINKAGE
|
||||
@@ -260,16 +260,16 @@ TOML_NAMESPACE_START
|
||||
continue;
|
||||
|
||||
pending_table_separator_ = true;
|
||||
base::print_newline();
|
||||
base::print_indent();
|
||||
print_newline();
|
||||
print_indent();
|
||||
print_key_segment(k);
|
||||
base::print_unformatted(" = "sv);
|
||||
print_unformatted(" = "sv);
|
||||
TOML_ASSUME(type != node_type::none);
|
||||
switch (type)
|
||||
{
|
||||
case node_type::table: print_inline(*reinterpret_cast<const table*>(&v)); break;
|
||||
case node_type::array: print(*reinterpret_cast<const array*>(&v)); break;
|
||||
default: base::print_value(v, type);
|
||||
default: print_value(v, type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,20 +319,20 @@ TOML_NAMESPACE_START
|
||||
if (!skip_self)
|
||||
{
|
||||
print_pending_table_separator();
|
||||
if (base::indent_sub_tables())
|
||||
base::increase_indent();
|
||||
base::print_indent();
|
||||
base::print_unformatted("["sv);
|
||||
if (indent_sub_tables())
|
||||
increase_indent();
|
||||
print_indent();
|
||||
print_unformatted("["sv);
|
||||
print_key_path();
|
||||
base::print_unformatted("]"sv);
|
||||
print_unformatted("]"sv);
|
||||
pending_table_separator_ = true;
|
||||
}
|
||||
|
||||
print(child_tbl);
|
||||
|
||||
key_path_.pop_back();
|
||||
if (!skip_self && base::indent_sub_tables())
|
||||
base::decrease_indent();
|
||||
if (!skip_self && indent_sub_tables())
|
||||
decrease_indent();
|
||||
}
|
||||
|
||||
// table arrays
|
||||
@@ -342,51 +342,51 @@ TOML_NAMESPACE_START
|
||||
continue;
|
||||
auto& arr = *reinterpret_cast<const array*>(&v);
|
||||
|
||||
if (base::indent_sub_tables())
|
||||
base::increase_indent();
|
||||
if (indent_sub_tables())
|
||||
increase_indent();
|
||||
key_path_.push_back(std::string_view{ k });
|
||||
|
||||
for (size_t i = 0; i < arr.size(); i++)
|
||||
{
|
||||
print_pending_table_separator();
|
||||
base::print_indent();
|
||||
base::print_unformatted("[["sv);
|
||||
print_indent();
|
||||
print_unformatted("[["sv);
|
||||
print_key_path();
|
||||
base::print_unformatted("]]"sv);
|
||||
print_unformatted("]]"sv);
|
||||
pending_table_separator_ = true;
|
||||
print(*reinterpret_cast<const table*>(&arr[i]));
|
||||
}
|
||||
|
||||
key_path_.pop_back();
|
||||
if (base::indent_sub_tables())
|
||||
base::decrease_indent();
|
||||
if (indent_sub_tables())
|
||||
decrease_indent();
|
||||
}
|
||||
}
|
||||
|
||||
TOML_EXTERNAL_LINKAGE
|
||||
void toml_formatter::print()
|
||||
{
|
||||
if (base::dump_failed_parse_result())
|
||||
if (dump_failed_parse_result())
|
||||
return;
|
||||
|
||||
switch (auto source_type = base::source().type())
|
||||
switch (auto source_type = source().type())
|
||||
{
|
||||
case node_type::table:
|
||||
{
|
||||
auto& tbl = *reinterpret_cast<const table*>(&base::source());
|
||||
auto& tbl = *reinterpret_cast<const table*>(&source());
|
||||
if (tbl.is_inline())
|
||||
print_inline(tbl);
|
||||
else
|
||||
{
|
||||
base::decrease_indent(); // so root kvps and tables have the same indent
|
||||
decrease_indent(); // so root kvps and tables have the same indent
|
||||
print(tbl);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case node_type::array: print(*reinterpret_cast<const array*>(&base::source())); break;
|
||||
case node_type::array: print(*reinterpret_cast<const array*>(&source())); break;
|
||||
|
||||
default: base::print_value(base::source(), source_type);
|
||||
default: print_value(source(), source_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,9 +35,9 @@ TOML_NAMESPACE_START
|
||||
|
||||
if (contains_newline)
|
||||
{
|
||||
base::print_unformatted("|-"sv);
|
||||
print_unformatted("|-"sv);
|
||||
|
||||
base::increase_indent();
|
||||
increase_indent();
|
||||
|
||||
auto line_end = str->c_str() - 1u;
|
||||
const auto end = str->c_str() + str->length();
|
||||
@@ -50,16 +50,16 @@ TOML_NAMESPACE_START
|
||||
|
||||
if TOML_LIKELY(line_start != line_end || line_end != end)
|
||||
{
|
||||
base::print_newline();
|
||||
base::print_indent();
|
||||
base::print_unformatted(std::string_view{ line_start, static_cast<size_t>(line_end - line_start) });
|
||||
print_newline();
|
||||
print_indent();
|
||||
print_unformatted(std::string_view{ line_start, static_cast<size_t>(line_end - line_start) });
|
||||
}
|
||||
}
|
||||
|
||||
base::decrease_indent();
|
||||
decrease_indent();
|
||||
}
|
||||
else
|
||||
base::print_string(*str, false, true);
|
||||
print_string(*str, false, true);
|
||||
}
|
||||
|
||||
TOML_EXTERNAL_LINKAGE
|
||||
@@ -67,23 +67,23 @@ TOML_NAMESPACE_START
|
||||
{
|
||||
if (tbl.empty())
|
||||
{
|
||||
base::print_unformatted("{}"sv);
|
||||
print_unformatted("{}"sv);
|
||||
return;
|
||||
}
|
||||
|
||||
base::increase_indent();
|
||||
increase_indent();
|
||||
|
||||
for (auto&& [k, v] : tbl)
|
||||
{
|
||||
if (!parent_is_array)
|
||||
{
|
||||
base::print_newline();
|
||||
base::print_indent();
|
||||
print_newline();
|
||||
print_indent();
|
||||
}
|
||||
parent_is_array = false;
|
||||
|
||||
base::print_string(k, false, true);
|
||||
base::print_unformatted(": "sv);
|
||||
print_string(k, false, true);
|
||||
print_unformatted(": "sv);
|
||||
|
||||
const auto type = v.type();
|
||||
TOML_ASSUME(type != node_type::none);
|
||||
@@ -92,11 +92,11 @@ TOML_NAMESPACE_START
|
||||
case node_type::table: print(*reinterpret_cast<const table*>(&v)); break;
|
||||
case node_type::array: print(*reinterpret_cast<const array*>(&v)); break;
|
||||
case node_type::string: print_yaml_string(*reinterpret_cast<const value<std::string>*>(&v)); break;
|
||||
default: base::print_value(v, type);
|
||||
default: print_value(v, type);
|
||||
}
|
||||
}
|
||||
|
||||
base::decrease_indent();
|
||||
decrease_indent();
|
||||
}
|
||||
|
||||
TOML_EXTERNAL_LINKAGE
|
||||
@@ -104,22 +104,22 @@ TOML_NAMESPACE_START
|
||||
{
|
||||
if (arr.empty())
|
||||
{
|
||||
base::print_unformatted("[]"sv);
|
||||
print_unformatted("[]"sv);
|
||||
return;
|
||||
}
|
||||
|
||||
base::increase_indent();
|
||||
increase_indent();
|
||||
|
||||
for (auto&& v : arr)
|
||||
{
|
||||
if (!parent_is_array)
|
||||
{
|
||||
base::print_newline();
|
||||
base::print_indent();
|
||||
print_newline();
|
||||
print_indent();
|
||||
}
|
||||
parent_is_array = false;
|
||||
|
||||
base::print_unformatted("- "sv);
|
||||
print_unformatted("- "sv);
|
||||
|
||||
const auto type = v.type();
|
||||
TOML_ASSUME(type != node_type::none);
|
||||
@@ -128,35 +128,31 @@ TOML_NAMESPACE_START
|
||||
case node_type::table: print(*reinterpret_cast<const table*>(&v), true); break;
|
||||
case node_type::array: print(*reinterpret_cast<const array*>(&v), true); break;
|
||||
case node_type::string: print_yaml_string(*reinterpret_cast<const value<std::string>*>(&v)); break;
|
||||
default: base::print_value(v, type);
|
||||
default: print_value(v, type);
|
||||
}
|
||||
|
||||
base::print_newline();
|
||||
}
|
||||
|
||||
base::decrease_indent();
|
||||
decrease_indent();
|
||||
}
|
||||
|
||||
TOML_EXTERNAL_LINKAGE
|
||||
void yaml_formatter::print()
|
||||
{
|
||||
if (base::dump_failed_parse_result())
|
||||
if (dump_failed_parse_result())
|
||||
return;
|
||||
|
||||
switch (auto source_type = base::source().type())
|
||||
switch (auto source_type = source().type())
|
||||
{
|
||||
case node_type::table:
|
||||
base::decrease_indent(); // so root kvps and tables have the same indent
|
||||
print(*reinterpret_cast<const table*>(&base::source()));
|
||||
decrease_indent(); // so root kvps and tables have the same indent
|
||||
print(*reinterpret_cast<const table*>(&source()));
|
||||
break;
|
||||
|
||||
case node_type::array: print(*reinterpret_cast<const array*>(&base::source())); break;
|
||||
case node_type::array: print(*reinterpret_cast<const array*>(&source())); break;
|
||||
|
||||
case node_type::string:
|
||||
print_yaml_string(*reinterpret_cast<const value<std::string>*>(&base::source()));
|
||||
break;
|
||||
case node_type::string: print_yaml_string(*reinterpret_cast<const value<std::string>*>(&source())); break;
|
||||
|
||||
default: base::print_value(base::source(), source_type);
|
||||
default: print_value(source(), source_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user