diff --git a/include/rfl/internal/StringLiteral.hpp b/include/rfl/internal/StringLiteral.hpp index daa7a046..c5cfc7b2 100644 --- a/include/rfl/internal/StringLiteral.hpp +++ b/include/rfl/internal/StringLiteral.hpp @@ -21,6 +21,11 @@ struct StringLiteral { /// Returns the value as a string. std::string str() const { return std::string(value_); } + + /// Returns the value as a string. + std::string_view string_view() const { + return std::string_view(value_, N - 1); + } }; template diff --git a/include/rfl/json/Reader.hpp b/include/rfl/json/Reader.hpp index fcbc6a8f..cb9b0484 100644 --- a/include/rfl/json/Reader.hpp +++ b/include/rfl/json/Reader.hpp @@ -103,14 +103,15 @@ struct Reader { } std::vector> to_fields_vec( - const std::unordered_map& _field_indices, + const std::unordered_map& _field_indices, InputObjectType* _obj) const noexcept { std::vector> f_vec(_field_indices.size()); yyjson_obj_iter iter; yyjson_obj_iter_init(_obj->val_, &iter); yyjson_val* key; while ((key = yyjson_obj_iter_next(&iter))) { - const auto it = _field_indices.find(yyjson_get_str(key)); + const char* k = yyjson_get_str(key); + const auto it = _field_indices.find(std::string_view(k, strlen(k))); if (it != _field_indices.end()) { f_vec[it->second] = InputVarType(yyjson_obj_iter_get_val(key)); } diff --git a/include/rfl/parsing/Parser.hpp b/include/rfl/parsing/Parser.hpp index 75ec9afa..fd07516d 100644 --- a/include/rfl/parsing/Parser.hpp +++ b/include/rfl/parsing/Parser.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -466,7 +467,7 @@ struct Parser> { using FieldType = typename std::tuple_element<_i, std::tuple>::type; - const auto name = FieldType::name_.str(); + const auto name = FieldType::name_.string_view(); Parser>::field_indices_[name] = _i; set_field_indices<_i + 1>(); @@ -475,7 +476,7 @@ struct Parser> { private: /// Maps each of the field names to an index signifying their order. - static inline std::unordered_map field_indices_; + static inline std::unordered_map field_indices_; }; // ----------------------------------------------------------------------------