feat: add key_format

This commit is contained in:
ToruNiina
2024-07-25 01:24:55 +09:00
parent 572781971f
commit 19199ac82c
2 changed files with 59 additions and 0 deletions

View File

@@ -214,6 +214,29 @@ struct table_format_info
bool operator==(const table_format_info&, const table_format_info&) noexcept;
bool operator!=(const table_format_info&, const table_format_info&) noexcept;
// ----------------------------------------------------------------------------
// key
enum class key_format : std::uint8_t
{
bare = 0,
quoted = 1, // ""
quoted_literal = 2 // ''
};
std::ostream& operator<<(std::ostream& os, const key_format f);
std::string to_string(const key_format);
struct key_format_info
{
key_format fmt = key_format::bare;
std::int32_t spaces_before_equal = 1;
std::int32_t spaces_after_equal = 1;
};
bool operator==(const key_format_info&, const key_format_info&) noexcept;
bool operator!=(const key_format_info&, const key_format_info&) noexcept;
// ----------------------------------------------------------------------------
// wrapper

View File

@@ -293,5 +293,41 @@ TOML11_INLINE bool operator!=(const table_format_info& lhs, const table_format_i
return !(lhs == rhs);
}
// ----------------------------------------------------------------------------
// key
TOML11_INLINE std::ostream& operator<<(std::ostream& os, const key_format f)
{
switch(f)
{
case key_format::bare : {os << "bare" ; break;}
case key_format::quoted : {os << "quoted" ; break;}
case key_format::quoted_literal : {os << "quoted_literal"; break;}
default:
{
os << "unknown key_format: " << static_cast<std::uint8_t>(f);
break;
}
}
return os;
}
TOML11_INLINE std::string to_string(const key_format c)
{
std::ostringstream oss;
oss << c;
return oss.str();
}
TOML11_INLINE bool operator==(const key_format_info& lhs, const key_format_info& rhs) noexcept
{
return lhs.fmt == rhs.fmt &&
lhs.spaces_before_equal == rhs.spaces_before_equal &&
lhs.spaces_after_equal == rhs.spaces_after_equal ;
}
TOML11_INLINE bool operator!=(const key_format_info& lhs, const key_format_info& rhs) noexcept
{
return !(lhs == rhs);
}
} // namespace toml
#endif // TOML11_FORMAT_IMPL_HPP