fix: fix #141; Merge branch 'issue-141'

This commit is contained in:
ToruNiina 2020-11-05 00:01:41 +09:00
commit be0d4bd0a9
2 changed files with 9 additions and 6 deletions

View File

@ -344,7 +344,7 @@ struct region final : public region_base
{
// unwrap the first '#' by std::next.
auto str = make_string(std::next(comment_found), iter);
if(str.back() == '\r') {str.pop_back();}
if(!str.empty() && str.back() == '\r') {str.pop_back();}
com.push_back(std::move(str));
}
else
@ -397,7 +397,7 @@ struct region final : public region_base
{
// unwrap the first '#' by std::next.
auto str = make_string(std::next(comment_found), this->line_end());
if(str.back() == '\r') {str.pop_back();}
if(!str.empty() && str.back() == '\r') {str.pop_back();}
com.push_back(std::move(str));
}
}

View File

@ -122,7 +122,7 @@ struct serializer
std::snprintf(buf.data(), buf.size(), fmt, this->float_prec_, f);
std::string token(buf.begin(), std::prev(buf.end()));
if(token.back() == '.') // 1. => 1.0
if(!token.empty() && token.back() == '.') // 1. => 1.0
{
token += '0';
}
@ -304,7 +304,7 @@ struct serializer
token += '\n';
}
token += toml::visit(*this, item);
if(token.back() == '\n') {token.pop_back();}
if(!token.empty() && token.back() == '\n') {token.pop_back();}
token += ",\n";
continue;
}
@ -312,7 +312,7 @@ struct serializer
next_elem += toml::visit(*this, item);
// comma before newline.
if(next_elem.back() == '\n') {next_elem.pop_back();}
if(!next_elem.empty() && next_elem.back() == '\n') {next_elem.pop_back();}
// if current line does not exceeds the width limit, continue.
if(current_line.size() + next_elem.size() + 1 < this->width_)
@ -339,7 +339,10 @@ struct serializer
}
if(!current_line.empty())
{
if(current_line.back() != '\n') {current_line += '\n';}
if(!current_line.empty() && current_line.back() != '\n')
{
current_line += '\n';
}
token += current_line;
}
token += "]\n";