Merge pull request #58 from ToruNiina/improve-err-msg-literal

Improve error message from toml literal
This commit is contained in:
Toru Niina
2019-04-22 20:50:11 +09:00
committed by GitHub
2 changed files with 5 additions and 1 deletions

View File

@@ -73,6 +73,9 @@ inline ::toml::value operator""_toml(const char* str, std::size_t len)
if(auto data = ::toml::detail::parse_toml_file(loc)) if(auto data = ::toml::detail::parse_toml_file(loc))
{ {
loc.reset(loc.begin()); // rollback to the top of the literal loc.reset(loc.begin()); // rollback to the top of the literal
// skip needless characters for error message
skip_line::invoke(loc); // skip the first several needless lines
skip_ws::invoke(loc); // skip the first several needless whitespaces
return ::toml::value(std::move(data.unwrap()), return ::toml::value(std::move(data.unwrap()),
::toml::detail::region<std::vector<char>>(std::move(loc))); ::toml::detail::region<std::vector<char>>(std::move(loc)));
} }

View File

@@ -343,7 +343,8 @@ inline std::string format_underline(const std::string& message,
{ {
// invalid // invalid
// ~~~~~~~ // ~~~~~~~
retval << make_string(reg->size(), '~'); const auto underline_len = std::min(reg->size(), reg->line().size());
retval << make_string(underline_len, '~');
} }
retval << ' '; retval << ' ';