From 3789268ac38810c0614ddef5fdc0ce0a177972a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=2E=20Patrick=20Urbanke=20=28=E5=8A=89=E8=87=AA=E6=88=90?= =?UTF-8?q?=29?= Date: Mon, 9 Jun 2025 21:45:09 +0200 Subject: [PATCH] Added support for exception-free TOML; resolves #436 (#447) --- include/rfl/toml/read.hpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/include/rfl/toml/read.hpp b/include/rfl/toml/read.hpp index b9a26cb3..ae7c2168 100644 --- a/include/rfl/toml/read.hpp +++ b/include/rfl/toml/read.hpp @@ -29,9 +29,21 @@ auto read(InputVarType _var) { /// Reads a TOML string. template Result> read( - const std::string_view _toml_str) { - auto table = ::toml::parse(_toml_str); - return read(&table); + const std::string_view _toml_str) noexcept { +#if TOML_EXCEPTIONS + try { + auto table = ::toml::parse(_toml_str); + return read(&table); + } catch (const std::exception& e) { + return error(e.what()); + } +#else + auto result = ::toml::parse(_toml_str); + if (!result) { + return error(std::string(result.error().description())); + } + return read(&result.table()); +#endif } /// Parses an object from a stringstream.