mirror of
https://github.com/marzer/tomlplusplus.git
synced 2024-10-06 06:49:43 +00:00
fixed missing #include <utility>
also: - added test for `yaml_formatter` - formatter refactoring + cleanup - documentation fixes
This commit is contained in:
parent
7b50df796f
commit
f94de96928
@ -295,7 +295,7 @@
|
||||
TOML is done just by printing it to an ostream. Converting it to JSON and YAML is done in much the same way,
|
||||
but via a toml::json_formatter and toml::yaml_formatter.
|
||||
|
||||
\godbolt{MMNoW4}
|
||||
\godbolt{srdfoWMq6}
|
||||
|
||||
\cpp
|
||||
#include <iostream>
|
||||
@ -327,6 +327,7 @@
|
||||
// serializing as YAML using toml::yaml_formatter:
|
||||
std::cout << "###### YAML ######" << "\n\n";
|
||||
std::cout << toml::yaml_formatter{ tbl } << "\n\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
\ecpp
|
||||
@ -367,7 +368,21 @@
|
||||
|
||||
###### YAML ######
|
||||
|
||||
author:
|
||||
github: 'https://github.com/marzer'
|
||||
name: 'Mark Gillard'
|
||||
twitter: 'https://twitter.com/marzer8789'
|
||||
cpp:
|
||||
- 17
|
||||
- 20
|
||||
- 'and beyond'
|
||||
lib: toml++
|
||||
repo: 'https://github.com/marzer/tomlplusplus/'
|
||||
toml:
|
||||
- '1.0.0'
|
||||
- 'and beyond'
|
||||
\eout
|
||||
|
||||
\see
|
||||
- toml::toml_formatter
|
||||
- toml::json_formatter
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -281,5 +281,51 @@ zero = 0
|
||||
}
|
||||
|
||||
SECTION("yaml_formatter")
|
||||
{}
|
||||
{
|
||||
static constexpr auto expected = R"(*****
|
||||
a:
|
||||
b:
|
||||
c:
|
||||
val: true
|
||||
val: true
|
||||
val: true
|
||||
bools:
|
||||
false: false
|
||||
true: true
|
||||
'dates and times':
|
||||
date-times:
|
||||
local:
|
||||
val: '2021-11-02T20:33:00'
|
||||
offset:
|
||||
val: '2021-11-02T20:33:00Z'
|
||||
dates:
|
||||
val: '2021-11-02'
|
||||
times:
|
||||
val: '20:33:00'
|
||||
floats:
|
||||
neg_inf: -.inf
|
||||
neg_nan: .NAN
|
||||
neg_zero: -0.0
|
||||
one: 1.0
|
||||
pos_inf: .inf
|
||||
pos_nan: .NAN
|
||||
pos_zero: 0.0
|
||||
integers:
|
||||
bin: 10
|
||||
dec: 10
|
||||
hex: 0xA
|
||||
oct: 0o12
|
||||
one: 1
|
||||
zero: 0
|
||||
strings:
|
||||
- ''
|
||||
- string
|
||||
- "string with a single quote in it: '"
|
||||
- 'string with a double quote in it: "'
|
||||
- "string with a tab: \t"
|
||||
- 'a long string to force the array over multiple lines'
|
||||
*****)"sv;
|
||||
|
||||
CHECK_FORMATTER(yaml_formatter, data, expected);
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@
|
||||
<ClInclude Include="include\toml++\impl\array.h" />
|
||||
<ClInclude Include="include\toml++\impl\array.inl" />
|
||||
<ClInclude Include="include\toml++\impl\date_time.h" />
|
||||
<ClInclude Include="include\toml++\impl\std_utility.h" />
|
||||
<ClInclude Include="include\toml++\impl\toml_formatter.h" />
|
||||
<ClInclude Include="include\toml++\impl\toml_formatter.inl" />
|
||||
<ClInclude Include="include\toml++\impl\formatter.h" />
|
||||
|
@ -127,6 +127,9 @@
|
||||
<ClInclude Include="include\toml++\impl\yaml_formatter.h">
|
||||
<Filter>include\impl</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\toml++\impl\std_utility.h">
|
||||
<Filter>include\impl</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="toml++.props" />
|
||||
|
285
toml.hpp
285
toml.hpp
@ -1199,11 +1199,12 @@ TOML_NAMESPACE_START // abi namespace
|
||||
quote_infinities_and_nans = (1ull << 1),
|
||||
allow_literal_strings = (1ull << 2),
|
||||
allow_multi_line_strings = (1ull << 3),
|
||||
allow_binary_integers = (1ull << 4),
|
||||
allow_octal_integers = (1ull << 5),
|
||||
allow_hexadecimal_integers = (1ull << 6),
|
||||
indent_sub_tables = (1ull << 7),
|
||||
indent_array_elements = (1ull << 8),
|
||||
allow_real_tabs_in_strings = (1ull << 4),
|
||||
allow_binary_integers = (1ull << 5),
|
||||
allow_octal_integers = (1ull << 6),
|
||||
allow_hexadecimal_integers = (1ull << 7),
|
||||
indent_sub_tables = (1ull << 8),
|
||||
indent_array_elements = (1ull << 9),
|
||||
indentation = indent_sub_tables | indent_array_elements,
|
||||
};
|
||||
TOML_MAKE_FLAGS(format_flags);
|
||||
@ -2313,6 +2314,9 @@ TOML_POP_WARNINGS;
|
||||
|
||||
//******** impl/node.h ***********************************************************************************************
|
||||
|
||||
TOML_DISABLE_WARNINGS;
|
||||
#include <utility>
|
||||
TOML_ENABLE_WARNINGS;
|
||||
TOML_PUSH_WARNINGS;
|
||||
|
||||
TOML_NAMESPACE_START
|
||||
@ -6035,7 +6039,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
|
||||
@ -6046,8 +6050,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 };
|
||||
@ -6087,7 +6091,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
|
||||
@ -6098,13 +6104,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 };
|
||||
}
|
||||
}
|
||||
@ -6120,7 +6126,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
|
||||
@ -6136,8 +6142,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 };
|
||||
@ -7941,6 +7947,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 //
|
||||
@ -12968,16 +12975,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;
|
||||
@ -12998,7 +13006,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;
|
||||
@ -13010,12 +13019,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
|
||||
{
|
||||
@ -13295,8 +13304,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;
|
||||
}
|
||||
}
|
||||
@ -13304,7 +13313,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
|
||||
@ -13313,7 +13322,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);
|
||||
}
|
||||
}
|
||||
@ -13323,21 +13332,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);
|
||||
@ -13345,11 +13354,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
|
||||
@ -13357,41 +13366,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];
|
||||
@ -13401,19 +13410,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
|
||||
@ -13434,16 +13443,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -13493,20 +13502,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
|
||||
@ -13516,51 +13525,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13583,25 +13592,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);
|
||||
@ -13609,15 +13618,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
|
||||
@ -13625,19 +13634,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();
|
||||
@ -13646,27 +13655,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13699,9 +13708,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();
|
||||
@ -13714,16 +13723,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
|
||||
@ -13731,23 +13740,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);
|
||||
@ -13756,11 +13765,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
|
||||
@ -13768,22 +13777,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);
|
||||
@ -13792,35 +13801,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,27 @@ PUSHD .
|
||||
CD /d "%~dp0\.."
|
||||
|
||||
REM --------------------------------------------------------------------------------------
|
||||
REM Runs clang format on all the non-test C++ files in the project
|
||||
REM Runs clang format on all the C++ files in the project
|
||||
REM --------------------------------------------------------------------------------------
|
||||
|
||||
WHERE /Q clang-format
|
||||
IF %ERRORLEVEL% NEQ 0 (
|
||||
ECHO Could not find clang-format
|
||||
PAUSE
|
||||
POPD
|
||||
ENDLOCAL
|
||||
EXIT /B %ERRORLEVEL%
|
||||
)
|
||||
|
||||
CALL :RunClangFormatOnDirectories ^
|
||||
include\toml++ ^
|
||||
include\toml++\impl ^
|
||||
tests ^
|
||||
examples
|
||||
|
||||
GOTO FINISH
|
||||
POPD
|
||||
@ENDLOCAL
|
||||
EXIT /B 0
|
||||
|
||||
:RunClangFormatOnDirectories
|
||||
(
|
||||
@ -27,8 +38,3 @@ GOTO FINISH
|
||||
)
|
||||
EXIT /B
|
||||
)
|
||||
|
||||
:FINISH
|
||||
POPD
|
||||
@ENDLOCAL
|
||||
EXIT /B 0
|
||||
|
@ -1,4 +1,4 @@
|
||||
misk>=0.5.0
|
||||
poxy>=0.5.1
|
||||
poxy>=0.5.2
|
||||
pyyaml
|
||||
python-dateutil
|
||||
|
Loading…
Reference in New Issue
Block a user