added toml::format_flags::terse_key_value_pairs

This commit is contained in:
Mark Gillard 2022-11-09 22:33:44 +02:00
parent cc741c9f5f
commit b081c3505d
8 changed files with 54 additions and 13 deletions

View File

@ -29,6 +29,7 @@ template:
- fixed spurious warnings in MSVC 19.34 - fixed spurious warnings in MSVC 19.34
- fixed some `_Float16` detection issues - fixed some `_Float16` detection issues
- fixed `toml::parse_file()` on windows for non-ASCII paths - fixed `toml::parse_file()` on windows for non-ASCII paths
- added `toml::format_flags::terse_key_value_pairs`
<br><br> <br><br>

View File

@ -124,6 +124,12 @@ TOML_IMPL_NAMESPACE_START
return !!(config_.flags & format_flags::allow_unicode_strings); return !!(config_.flags & format_flags::allow_unicode_strings);
} }
TOML_PURE_INLINE_GETTER
bool terse_kvps() const noexcept
{
return !!(config_.flags & format_flags::terse_key_value_pairs);
}
TOML_EXPORTED_MEMBER_FUNCTION TOML_EXPORTED_MEMBER_FUNCTION
void attach(std::ostream& stream) noexcept; void attach(std::ostream& stream) noexcept;

View File

@ -337,6 +337,9 @@ TOML_NAMESPACE_START // abi namespace
/// since floats might have a less precise value upon being written out than they did when being /// since floats might have a less precise value upon being written out than they did when being
/// read in. Use this flag at your own risk. /// read in. Use this flag at your own risk.
relaxed_float_precision = (1ull << 11), relaxed_float_precision = (1ull << 11),
/// \brief Avoids the use of whitespace around key-value pairs.
terse_key_value_pairs = (1ull << 12),
}; };
TOML_MAKE_FLAGS(format_flags); TOML_MAKE_FLAGS(format_flags);

View File

@ -43,7 +43,10 @@ TOML_NAMESPACE_START
print_indent(); print_indent();
print_string(k.str(), false); print_string(k.str(), false);
print_unformatted(" : "sv); if (terse_kvps())
print_unformatted(":"sv);
else
print_unformatted(" : "sv);
const auto type = v.type(); const auto type = v.type();
TOML_ASSUME(type != node_type::none); TOML_ASSUME(type != node_type::none);

View File

@ -152,7 +152,10 @@ TOML_NAMESPACE_START
first = true; first = true;
print(k); print(k);
print_unformatted(" = "sv); if (terse_kvps())
print_unformatted("="sv);
else
print_unformatted(" = "sv);
const auto type = v.type(); const auto type = v.type();
TOML_ASSUME(type != node_type::none); TOML_ASSUME(type != node_type::none);
@ -255,7 +258,10 @@ TOML_NAMESPACE_START
print_newline(); print_newline();
print_indent(); print_indent();
print(k); print(k);
print_unformatted(" = "sv); if (terse_kvps())
print_unformatted("="sv);
else
print_unformatted(" = "sv);
TOML_ASSUME(type != node_type::none); TOML_ASSUME(type != node_type::none);
switch (type) switch (type)
{ {

View File

@ -83,7 +83,10 @@ TOML_NAMESPACE_START
parent_is_array = false; parent_is_array = false;
print_string(k.str(), false, true); print_string(k.str(), false, true);
print_unformatted(": "sv); if (terse_kvps())
print_unformatted(":"sv);
else
print_unformatted(": "sv);
const auto type = v.type(); const auto type = v.type();
TOML_ASSUME(type != node_type::none); TOML_ASSUME(type != node_type::none);

View File

@ -430,16 +430,16 @@ zyx = 42)"sv;
zyx = 42)"sv; zyx = 42)"sv;
static constexpr auto table_quoted_no_close = R"(["where will it end] static constexpr auto table_quoted_no_close = R"(["where will it end]
name = value)"sv; name = value)"sv;
static constexpr auto table_redefine = R"(# Define b as int, and try to use it as a table: error static constexpr auto table_redefine = R"(# Define b as int, and try to use it as a table: error
[a] [a]
b = 1 b = 1
[a.b] [a.b]
c = 2)"sv; c = 2)"sv;
static constexpr auto table_rrbrace = R"([[table] ])"sv; static constexpr auto table_rrbrace = R"([[table] ])"sv;
static constexpr auto table_text_after_table = R"([error] this shouldn't be here)"sv; static constexpr auto table_text_after_table = R"([error] this shouldn't be here)"sv;
static constexpr auto table_whitespace = R"([invalid key])"sv; static constexpr auto table_whitespace = R"([invalid key])"sv;
static constexpr auto table_with_pound = R"([key#group] static constexpr auto table_with_pound = R"([key#group]
answer = 42)"sv; answer = 42)"sv;
} }

View File

@ -1433,6 +1433,7 @@ TOML_NAMESPACE_START // abi namespace
indent_array_elements = (1ull << 10), indent_array_elements = (1ull << 10),
indentation = indent_sub_tables | indent_array_elements, indentation = indent_sub_tables | indent_array_elements,
relaxed_float_precision = (1ull << 11), relaxed_float_precision = (1ull << 11),
terse_key_value_pairs = (1ull << 12),
}; };
TOML_MAKE_FLAGS(format_flags); TOML_MAKE_FLAGS(format_flags);
@ -9343,6 +9344,12 @@ TOML_IMPL_NAMESPACE_START
return !!(config_.flags & format_flags::allow_unicode_strings); return !!(config_.flags & format_flags::allow_unicode_strings);
} }
TOML_PURE_INLINE_GETTER
bool terse_kvps() const noexcept
{
return !!(config_.flags & format_flags::terse_key_value_pairs);
}
TOML_EXPORTED_MEMBER_FUNCTION TOML_EXPORTED_MEMBER_FUNCTION
void attach(std::ostream& stream) noexcept; void attach(std::ostream& stream) noexcept;
@ -16525,7 +16532,10 @@ TOML_NAMESPACE_START
first = true; first = true;
print(k); print(k);
print_unformatted(" = "sv); if (terse_kvps())
print_unformatted("="sv);
else
print_unformatted(" = "sv);
const auto type = v.type(); const auto type = v.type();
TOML_ASSUME(type != node_type::none); TOML_ASSUME(type != node_type::none);
@ -16628,7 +16638,10 @@ TOML_NAMESPACE_START
print_newline(); print_newline();
print_indent(); print_indent();
print(k); print(k);
print_unformatted(" = "sv); if (terse_kvps())
print_unformatted("="sv);
else
print_unformatted(" = "sv);
TOML_ASSUME(type != node_type::none); TOML_ASSUME(type != node_type::none);
switch (type) switch (type)
{ {
@ -16815,7 +16828,10 @@ TOML_NAMESPACE_START
print_indent(); print_indent();
print_string(k.str(), false); print_string(k.str(), false);
print_unformatted(" : "sv); if (terse_kvps())
print_unformatted(":"sv);
else
print_unformatted(" : "sv);
const auto type = v.type(); const auto type = v.type();
TOML_ASSUME(type != node_type::none); TOML_ASSUME(type != node_type::none);
@ -16973,7 +16989,10 @@ TOML_NAMESPACE_START
parent_is_array = false; parent_is_array = false;
print_string(k.str(), false, true); print_string(k.str(), false, true);
print_unformatted(": "sv); if (terse_kvps())
print_unformatted(":"sv);
else
print_unformatted(": "sv);
const auto type = v.type(); const auto type = v.type();
TOML_ASSUME(type != node_type::none); TOML_ASSUME(type != node_type::none);