mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-19 03:18:09 +08:00
feat: format any number of values into an err msg
```cpp toml::format_error("[error] message", v1, "v1", v2, "v2", ...); ```
This commit is contained in:
@@ -794,24 +794,38 @@ inline bool operator>=(const toml::value& lhs, const toml::value& rhs)
|
|||||||
return !(lhs < rhs);
|
return !(lhs < rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string format_error(const std::string& err_msg,
|
namespace detail
|
||||||
const toml::value& v, const std::string& comment,
|
|
||||||
std::vector<std::string> hints = {})
|
|
||||||
{
|
{
|
||||||
return detail::format_underline(err_msg, {
|
inline std::string format_error_impl(const std::string& err_msg,
|
||||||
{std::addressof(detail::get_region(v)), comment}
|
std::vector<std::pair<region_base const*, std::string>> val,
|
||||||
}, std::move(hints));
|
std::vector<std::string> hints)
|
||||||
|
{
|
||||||
|
return format_underline(err_msg, std::move(val), std::move(hints));
|
||||||
|
}
|
||||||
|
inline std::string format_error_impl(const std::string& err_msg,
|
||||||
|
std::vector<std::pair<region_base const*, std::string>> val)
|
||||||
|
{
|
||||||
|
return format_underline(err_msg, std::move(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string format_error(const std::string& err_msg,
|
template<typename ... Ts>
|
||||||
const toml::value& v1, const std::string& comment1,
|
std::string format_error_impl(const std::string& err_msg,
|
||||||
const toml::value& v2, const std::string& comment2,
|
std::vector<std::pair<region_base const*, std::string>> val,
|
||||||
std::vector<std::string> hints = {})
|
const toml::value& v, const std::string& comment,
|
||||||
|
Ts&& ... args)
|
||||||
{
|
{
|
||||||
return detail::format_underline(err_msg, {
|
val.push_back(std::make_pair(std::addressof(get_region(v)), comment));
|
||||||
{std::addressof(detail::get_region(v1)), comment1},
|
return format_error_impl(err_msg, std::move(val), std::forward<Ts>(args)...);
|
||||||
{std::addressof(detail::get_region(v2)), comment2}
|
}
|
||||||
}, std::move(hints));
|
} // detail
|
||||||
|
|
||||||
|
template<typename ... Ts>
|
||||||
|
std::string format_error(const std::string& err_msg, Ts&& ... args)
|
||||||
|
{
|
||||||
|
std::vector<std::pair<detail::region_base const*, std::string>> val;
|
||||||
|
val.reserve(sizeof...(args) / 2);
|
||||||
|
return detail::format_error_impl(err_msg, std::move(val),
|
||||||
|
std::forward<Ts>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Visitor>
|
template<typename Visitor>
|
||||||
|
Reference in New Issue
Block a user