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 some `_Float16` detection issues
- fixed `toml::parse_file()` on windows for non-ASCII paths
- added `toml::format_flags::terse_key_value_pairs`
<br><br>

View File

@ -124,6 +124,12 @@ TOML_IMPL_NAMESPACE_START
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
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
/// read in. Use this flag at your own risk.
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);

View File

@ -43,6 +43,9 @@ TOML_NAMESPACE_START
print_indent();
print_string(k.str(), false);
if (terse_kvps())
print_unformatted(":"sv);
else
print_unformatted(" : "sv);
const auto type = v.type();

View File

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

View File

@ -83,6 +83,9 @@ TOML_NAMESPACE_START
parent_is_array = false;
print_string(k.str(), false, true);
if (terse_kvps())
print_unformatted(":"sv);
else
print_unformatted(": "sv);
const auto type = v.type();

View File

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