mirror of
https://github.com/marzer/tomlplusplus.git
synced 2025-02-22 15:40:00 +00:00
fixed parse failure when parsing an empty file
Blank files are in fact totally valid TOML and should not cause a parse failure (fixes #35).
This commit is contained in:
parent
3792093d09
commit
da024510c5
@ -2557,6 +2557,8 @@ namespace toml::impl
|
||||
{
|
||||
root.source_ = { prev_pos, prev_pos, reader.source_path() };
|
||||
|
||||
if (!reader.peek_eof())
|
||||
{
|
||||
cp = reader.read_next();
|
||||
|
||||
#if !TOML_EXCEPTIONS
|
||||
@ -2569,6 +2571,7 @@ namespace toml::impl
|
||||
|
||||
if (cp)
|
||||
parse_document();
|
||||
}
|
||||
|
||||
update_region_ends(root);
|
||||
}
|
||||
|
@ -46,6 +46,12 @@ namespace toml::impl
|
||||
return position >= source.length();
|
||||
}
|
||||
|
||||
[[nodiscard]] TOML_ALWAYS_INLINE
|
||||
constexpr bool peek_eof() const noexcept
|
||||
{
|
||||
return eof();
|
||||
}
|
||||
|
||||
[[nodiscard]] TOML_ALWAYS_INLINE
|
||||
constexpr bool error() const noexcept
|
||||
{
|
||||
@ -97,6 +103,13 @@ namespace toml::impl
|
||||
return source->eof();
|
||||
}
|
||||
|
||||
[[nodiscard]] TOML_ALWAYS_INLINE
|
||||
bool peek_eof() const
|
||||
{
|
||||
using stream_traits = typename std::remove_pointer_t<decltype(source)>::traits_type;
|
||||
return eof() || source->peek() == stream_traits::eof();
|
||||
}
|
||||
|
||||
[[nodiscard]] TOML_ALWAYS_INLINE
|
||||
bool error() const noexcept
|
||||
{
|
||||
@ -190,6 +203,9 @@ namespace toml::impl
|
||||
[[nodiscard]]
|
||||
virtual const utf8_codepoint* read_next() = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual bool peek_eof() const = 0;
|
||||
|
||||
#if !TOML_EXCEPTIONS
|
||||
|
||||
[[nodiscard]]
|
||||
@ -321,6 +337,12 @@ namespace toml::impl
|
||||
TOML_UNREACHABLE;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool peek_eof() const override
|
||||
{
|
||||
return stream.peek_eof();
|
||||
}
|
||||
|
||||
#if !TOML_EXCEPTIONS
|
||||
|
||||
[[nodiscard]]
|
||||
@ -432,6 +454,12 @@ namespace toml::impl
|
||||
: head;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool peek_eof() const override
|
||||
{
|
||||
return reader.peek_eof();
|
||||
}
|
||||
|
||||
#if !TOML_EXCEPTIONS
|
||||
|
||||
[[nodiscard]]
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#define TOML_LIB_MAJOR 1
|
||||
#define TOML_LIB_MINOR 3
|
||||
#define TOML_LIB_PATCH 0
|
||||
#define TOML_LIB_PATCH 1
|
||||
|
||||
#define TOML_LANG_MAJOR 1
|
||||
#define TOML_LANG_MINOR 0
|
||||
|
@ -1,7 +1,7 @@
|
||||
project(
|
||||
'tomlplusplus',
|
||||
'cpp',
|
||||
version : '1.3.0',
|
||||
version : '1.3.1',
|
||||
license : 'MIT',
|
||||
default_options : [
|
||||
'cpp_std=c++17',
|
||||
|
34
toml.hpp
34
toml.hpp
@ -1,6 +1,6 @@
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// toml++ v1.3.0
|
||||
// toml++ v1.3.1
|
||||
// https://github.com/marzer/tomlplusplus
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
@ -347,7 +347,7 @@
|
||||
#endif
|
||||
#define TOML_LIB_MAJOR 1
|
||||
#define TOML_LIB_MINOR 3
|
||||
#define TOML_LIB_PATCH 0
|
||||
#define TOML_LIB_PATCH 1
|
||||
|
||||
#define TOML_LANG_MAJOR 1
|
||||
#define TOML_LANG_MINOR 0
|
||||
@ -5170,6 +5170,12 @@ namespace toml::impl
|
||||
return position >= source.length();
|
||||
}
|
||||
|
||||
[[nodiscard]] TOML_ALWAYS_INLINE
|
||||
constexpr bool peek_eof() const noexcept
|
||||
{
|
||||
return eof();
|
||||
}
|
||||
|
||||
[[nodiscard]] TOML_ALWAYS_INLINE
|
||||
constexpr bool error() const noexcept
|
||||
{
|
||||
@ -5221,6 +5227,13 @@ namespace toml::impl
|
||||
return source->eof();
|
||||
}
|
||||
|
||||
[[nodiscard]] TOML_ALWAYS_INLINE
|
||||
bool peek_eof() const
|
||||
{
|
||||
using stream_traits = typename std::remove_pointer_t<decltype(source)>::traits_type;
|
||||
return eof() || source->peek() == stream_traits::eof();
|
||||
}
|
||||
|
||||
[[nodiscard]] TOML_ALWAYS_INLINE
|
||||
bool error() const noexcept
|
||||
{
|
||||
@ -5313,6 +5326,8 @@ namespace toml::impl
|
||||
|
||||
[[nodiscard]]
|
||||
virtual const utf8_codepoint* read_next() = 0;
|
||||
[[nodiscard]]
|
||||
virtual bool peek_eof() const = 0;
|
||||
|
||||
#if !TOML_EXCEPTIONS
|
||||
|
||||
@ -5445,6 +5460,12 @@ namespace toml::impl
|
||||
TOML_UNREACHABLE;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool peek_eof() const override
|
||||
{
|
||||
return stream.peek_eof();
|
||||
}
|
||||
|
||||
#if !TOML_EXCEPTIONS
|
||||
|
||||
[[nodiscard]]
|
||||
@ -5556,6 +5577,12 @@ namespace toml::impl
|
||||
: head;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool peek_eof() const override
|
||||
{
|
||||
return reader.peek_eof();
|
||||
}
|
||||
|
||||
#if !TOML_EXCEPTIONS
|
||||
|
||||
[[nodiscard]]
|
||||
@ -9130,6 +9157,8 @@ namespace toml::impl
|
||||
{
|
||||
root.source_ = { prev_pos, prev_pos, reader.source_path() };
|
||||
|
||||
if (!reader.peek_eof())
|
||||
{
|
||||
cp = reader.read_next();
|
||||
|
||||
#if !TOML_EXCEPTIONS
|
||||
@ -9142,6 +9171,7 @@ namespace toml::impl
|
||||
|
||||
if (cp)
|
||||
parse_document();
|
||||
}
|
||||
|
||||
update_region_ends(root);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user