mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 10:28:09 +08:00
feat: add key_format
This commit is contained in:
@@ -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;
|
||||||
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
|
// wrapper
|
||||||
|
|
||||||
|
@@ -293,5 +293,41 @@ TOML11_INLINE bool operator!=(const table_format_info& lhs, const table_format_i
|
|||||||
return !(lhs == rhs);
|
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
|
} // namespace toml
|
||||||
#endif // TOML11_FORMAT_IMPL_HPP
|
#endif // TOML11_FORMAT_IMPL_HPP
|
||||||
|
Reference in New Issue
Block a user