feat: detect value type and format as a file

in toml::format
This commit is contained in:
ToruNiina 2019-03-19 21:24:51 +09:00
parent 773c3816be
commit d6714ec450

View File

@ -485,13 +485,15 @@ inline std::string
format(const value& v, std::size_t w = 80,
int fprec = std::numeric_limits<toml::floating>::max_digits10)
{
return visit(serializer(w, fprec, true), v);
// if value is a table, it is considered to be a root object.
// the root object can't be an inline table. so pass false. otherwise, true.
return visit(serializer(w, fprec, !v.is_table()), v);
}
inline std::string
format(const table& t, std::size_t w = 80,
int fprec = std::numeric_limits<toml::floating>::max_digits10)
{
return serializer(w, fprec, true)(t);
return serializer(w, fprec, false)(t);
}
template<typename charT, typename traits>