11#ifndef RFL_PARSING_PARSER_STRING_VIEW_HPP_
22#define RFL_PARSING_PARSER_STRING_VIEW_HPP_
33
4+ #include < cstring>
45#include < map>
56#include < string>
67#include < string_view>
@@ -19,12 +20,24 @@ template <class R, class W, class ProcessorsType>
1920struct Parser <R, W, std::string_view, ProcessorsType> {
2021 using InputVarType = typename R::InputVarType;
2122
22- static Result<std::string_view> read (const R&, const InputVarType&) noexcept {
23- static_assert (always_false_v<R>,
24- " Reading into std::string_view is dangerous and "
25- " therefore unsupported. "
26- " Please consider using std::string instead." );
27- return error (" Unsupported." );
23+ static Result<std::string_view> read (const R& _r,
24+ const InputVarType& _var) noexcept {
25+ if constexpr (!ProcessorsType::allow_raw_ptrs_) {
26+ static_assert (always_false_v<R>,
27+ " Reading into std::string_view is dangerous and "
28+ " therefore unsupported. "
29+ " Please consider using std::string instead, or use the "
30+ " rfl::AllowRawPtrs processor." );
31+ return error (" Unsupported." );
32+ } else {
33+ return Parser<R, W, std::string, ProcessorsType>::read (_r, _var)
34+ .transform ([](std::string&& str) {
35+ char * data =
36+ new char [str.size () + 1 ]; // +1 for the null terminator
37+ std::memcpy (data, str.data (), str.size () + 1 );
38+ return std::string_view (data, str.size ());
39+ });
40+ }
2841 }
2942
3043 template <class P >
0 commit comments