mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +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);
|
iter = std::prev(iter);
|
||||||
|
|
||||||
|
|
||||||
// range [line_start, iter) represents the previous line
|
// range [line_start, iter) represents the previous line
|
||||||
const auto line_start = std::find(
|
const auto line_start = std::find(
|
||||||
rev_iter(iter), rev_iter(this->begin()), '\n').base();
|
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(), '#');
|
std::find(this->last(), this->line_end(), '#');
|
||||||
if(comment_found != this->line_end()) // '#' found
|
if(comment_found != this->line_end()) // '#' found
|
||||||
{
|
{
|
||||||
// unwrap the first '#' by std::next.
|
// table = {key = "value"} # what is this for?
|
||||||
auto str = make_string(std::next(comment_found), this->line_end());
|
// the above comment is not for "value", but {key="value"}.
|
||||||
if(str.back() == '\r') {str.pop_back();}
|
if(comment_found == std::find_if(this->last(), comment_found,
|
||||||
com.push_back(std::move(str));
|
[](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;
|
return com;
|
||||||
|
|||||||
Reference in New Issue
Block a user