mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 10:28:09 +08:00
fix: line-feed is not required at the EOF
This commit is contained in:
@@ -2209,12 +2209,24 @@ parse(std::istream& is, const std::string& fname = "unknown file")
|
|||||||
std::vector<char> letters(static_cast<std::size_t>(fsize));
|
std::vector<char> letters(static_cast<std::size_t>(fsize));
|
||||||
is.read(letters.data(), fsize);
|
is.read(letters.data(), fsize);
|
||||||
|
|
||||||
|
// remove null character if exists
|
||||||
while(!letters.empty() && letters.back() == '\0')
|
while(!letters.empty() && letters.back() == '\0')
|
||||||
{
|
{
|
||||||
letters.pop_back();
|
letters.pop_back();
|
||||||
}
|
}
|
||||||
assert(letters.empty() || letters.back() != '\0');
|
assert(letters.empty() || letters.back() != '\0');
|
||||||
|
|
||||||
|
// append LF.
|
||||||
|
// Although TOML does not require LF at the EOF, to make parsing logic
|
||||||
|
// simpler, we "normalize" the content by adding LF if it does not exist.
|
||||||
|
// It also checks if the last char is CR, to avoid changing the meaning.
|
||||||
|
// This is not the *best* way to deal with the last character, but is a
|
||||||
|
// simple and quick fix.
|
||||||
|
if(!letters.empty() && letters.back() != '\n' && letters.back() != '\r')
|
||||||
|
{
|
||||||
|
letters.push_back('\n');
|
||||||
|
}
|
||||||
|
|
||||||
detail::location loc(std::move(fname), std::move(letters));
|
detail::location loc(std::move(fname), std::move(letters));
|
||||||
|
|
||||||
// skip BOM if exists.
|
// skip BOM if exists.
|
||||||
|
Reference in New Issue
Block a user