mirror of
https://github.com/marzer/tomlplusplus.git
synced 2026-01-19 04:52:09 +00:00
declare toml::get_line(std::string_view, source_index) constexpr (#256)
This commit is contained in:
@@ -237,7 +237,7 @@ TOML_NAMESPACE_START
|
||||
/// \returns The specified line, excluding any possible trailing carriage return or line feed character.
|
||||
/// \remarks Returns an empty string_view when there is no line at the specified line number, in the specified document.
|
||||
TOML_NODISCARD
|
||||
inline std::string_view get_line(std::string_view doc, source_index line_num) noexcept
|
||||
constexpr std::string_view get_line(std::string_view doc, source_index line_num) noexcept
|
||||
{
|
||||
if (line_num == 0)
|
||||
{
|
||||
|
||||
@@ -454,7 +454,11 @@ b = []
|
||||
|
||||
SECTION("tomlplusplus/issues/254") // https://github.com/marzer/tomlplusplus/issues/254
|
||||
{
|
||||
for (const toml::source_index line_num: { 0u, 1u, 2u })
|
||||
// Check constexpr support.
|
||||
static_assert(toml::get_line(""sv, 1) == std::string_view{});
|
||||
static_assert(toml::get_line("alpha = 1\nbeta = 2\n # last line # "sv, 1) == "alpha = 1"sv);
|
||||
|
||||
for (const toml::source_index line_num : { 0u, 1u, 2u })
|
||||
{
|
||||
CHECK(toml::get_line(""sv, line_num) == std::string_view{});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user