mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 18:56:23 +08:00
Preserve empty location for empty files
Without a region, error messages in exceptions are unable to print a filename. By retaining the location in a zero-length region and detecting this when formatting the exception text it is possible to print the filename and explicitly state that the file is completely empty. Fixes #160
This commit is contained in:
@@ -1977,7 +1977,9 @@ result<Value, std::string> parse_toml_file(location& loc)
|
||||
const auto first = loc.iter();
|
||||
if(first == loc.end())
|
||||
{
|
||||
return ok(value_type(table_type{} /*, empty file has no region ...*/));
|
||||
// For empty files, return an empty table with an empty region (zero-length).
|
||||
// Without the region, error messages would miss the filename.
|
||||
return ok(value_type(table_type{}, region(loc, first, first), {}));
|
||||
}
|
||||
|
||||
// put the first line as a region of a file
|
||||
|
Reference in New Issue
Block a user