mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:28:12 +08:00
fix: consider closing bracket when collect comments
table = {key = "value"} # comment. a value named "table" ({key = "value"}) has the above comment. but a value named "key" ("value") does not have any comment.
This commit is contained in:
@@ -309,7 +309,6 @@ struct region final : public region_base
|
||||
{
|
||||
iter = std::prev(iter);
|
||||
|
||||
|
||||
// range [line_start, iter) represents the previous line
|
||||
const auto line_start = std::find(
|
||||
rev_iter(iter), rev_iter(this->begin()), '\n').base();
|
||||
@@ -372,10 +371,18 @@ struct region final : public region_base
|
||||
std::find(this->last(), this->line_end(), '#');
|
||||
if(comment_found != this->line_end()) // '#' found
|
||||
{
|
||||
// unwrap the first '#' by std::next.
|
||||
auto str = make_string(std::next(comment_found), this->line_end());
|
||||
if(str.back() == '\r') {str.pop_back();}
|
||||
com.push_back(std::move(str));
|
||||
// table = {key = "value"} # what is this for?
|
||||
// the above comment is not for "value", but {key="value"}.
|
||||
if(comment_found == std::find_if(this->last(), comment_found,
|
||||
[](const char c) noexcept -> bool {
|
||||
return c == '}' || c == ']';
|
||||
}))
|
||||
{
|
||||
// unwrap the first '#' by std::next.
|
||||
auto str = make_string(std::next(comment_found), this->line_end());
|
||||
if(str.back() == '\r') {str.pop_back();}
|
||||
com.push_back(std::move(str));
|
||||
}
|
||||
}
|
||||
}
|
||||
return com;
|
||||
|
Reference in New Issue
Block a user