Improved support for string_views for TOML and XML (#445)

* Improved support for string_views for TOML and XML

* Upgrade to pugixml 1.15 in order to be able to use string views
This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2025-06-08 21:00:21 +02:00
committed by GitHub
parent c600b9a9d6
commit ec6ab3baf5
5 changed files with 18 additions and 25 deletions
+3 -8
View File
@@ -3,6 +3,7 @@
#include <istream>
#include <string>
#include <string_view>
#include <toml++/toml.hpp>
#include "../Processors.hpp"
@@ -25,18 +26,12 @@ auto read(InputVarType _var) {
return Parser<T, ProcessorsType>::read(r, _var);
}
/// Reads a TOML string.
template <class T, class... Ps>
Result<internal::wrap_in_rfl_array_t<T>> read(const std::string& _toml_str) {
auto table = ::toml::parse(_toml_str);
return read<T, Ps...>(&table);
}
/// Reads a TOML string.
template <class T, class... Ps>
Result<internal::wrap_in_rfl_array_t<T>> read(
const std::string_view _toml_str) {
return read<T, Ps...>(std::string(_toml_str));
auto table = ::toml::parse(_toml_str);
return read<T, Ps...>(&table);
}
/// Parses an object from a stringstream.
+3 -5
View File
@@ -12,8 +12,7 @@
#include "Parser.hpp"
#include "Reader.hpp"
namespace rfl {
namespace xml {
namespace rfl ::xml {
using InputVarType = typename Reader::InputVarType;
@@ -32,7 +31,7 @@ auto read(const InputVarType& _var) {
template <class T, class... Ps>
Result<T> read(const std::string_view _xml_str) {
pugi::xml_document doc;
const auto result = doc.load_string(_xml_str.data());
const auto result = doc.load_buffer(_xml_str.data(), _xml_str.size());
if (!result) {
return error("XML string could not be parsed: " +
std::string(result.description()));
@@ -49,7 +48,6 @@ auto read(std::istream& _stream) {
return read<T, Ps...>(xml_str);
}
} // namespace xml
} // namespace rfl
} // namespace rfl::xml
#endif