From 82e8c1e68b26a27e58c01d422c9b31b6ea50c828 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 21 Apr 2019 16:31:24 +0900 Subject: [PATCH 1/2] fix: skip first ws/newlines in toml literal when ""_toml literal is used with C++11 raw-string literal, it normally starts with newline like the following. ```cpp const auto v = u8R"( [table] key = "value" )"_toml; ``` With this, the error message shows the first empty line that starts just after `u8R"(` and thus the error message shows nothing. To avoid this, skip the first empty lines and whitespaces in literal. --- toml/literal.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/toml/literal.hpp b/toml/literal.hpp index d7194ed..0e61cc9 100644 --- a/toml/literal.hpp +++ b/toml/literal.hpp @@ -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)) { 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()), ::toml::detail::region>(std::move(loc))); } From 2d9b4992eccedd19cf6d7e4f84338511c3a87e5e Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 21 Apr 2019 16:38:08 +0900 Subject: [PATCH 2/2] fix: restrict length of underline by size of line in some cases, `region` contains several lines and `region::size` returns the whole size that is a sum of lengthes of all the lines. To avoid too long underlines, restrict the length of underline by the length of the line that is shown in the message. --- toml/region.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/toml/region.hpp b/toml/region.hpp index 1720a7f..6ef6f9b 100644 --- a/toml/region.hpp +++ b/toml/region.hpp @@ -343,7 +343,8 @@ inline std::string format_underline(const std::string& message, { // invalid // ~~~~~~~ - retval << make_string(reg->size(), '~'); + const auto underline_len = std::min(reg->size(), reg->line().size()); + retval << make_string(underline_len, '~'); } retval << ' ';