mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-06 18:56:19 +08:00
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:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user