Skip to content

Commit 3b9a252

Browse files
Improved support for string_views for TOML and XML
1 parent c600b9a commit 3b9a252

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

include/rfl/toml/read.hpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <istream>
55
#include <string>
6+
#include <string_view>
67
#include <toml++/toml.hpp>
78

89
#include "../Processors.hpp"
@@ -25,18 +26,12 @@ auto read(InputVarType _var) {
2526
return Parser<T, ProcessorsType>::read(r, _var);
2627
}
2728

28-
/// Reads a TOML string.
29-
template <class T, class... Ps>
30-
Result<internal::wrap_in_rfl_array_t<T>> read(const std::string& _toml_str) {
31-
auto table = ::toml::parse(_toml_str);
32-
return read<T, Ps...>(&table);
33-
}
34-
3529
/// Reads a TOML string.
3630
template <class T, class... Ps>
3731
Result<internal::wrap_in_rfl_array_t<T>> read(
3832
const std::string_view _toml_str) {
39-
return read<T, Ps...>(std::string(_toml_str));
33+
auto table = ::toml::parse(_toml_str);
34+
return read<T, Ps...>(&table);
4035
}
4136

4237
/// Parses an object from a stringstream.

include/rfl/xml/read.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
#include "Parser.hpp"
1313
#include "Reader.hpp"
1414

15-
namespace rfl {
16-
namespace xml {
15+
namespace rfl ::xml {
1716

1817
using InputVarType = typename Reader::InputVarType;
1918

@@ -32,7 +31,7 @@ auto read(const InputVarType& _var) {
3231
template <class T, class... Ps>
3332
Result<T> read(const std::string_view _xml_str) {
3433
pugi::xml_document doc;
35-
const auto result = doc.load_string(_xml_str.data());
34+
const auto result = doc.load_buffer(_xml_str.data(), _xml_str.size());
3635
if (!result) {
3736
return error("XML string could not be parsed: " +
3837
std::string(result.description()));
@@ -49,7 +48,6 @@ auto read(std::istream& _stream) {
4948
return read<T, Ps...>(xml_str);
5049
}
5150

52-
} // namespace xml
53-
} // namespace rfl
51+
} // namespace rfl::xml
5452

5553
#endif

0 commit comments

Comments
 (0)