mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 16:56:17 +08:00
Avoid assuming that "std::string_view" is nullterminated. Generally it is really not. (#538)
Co-authored-by: ActuallyaDeviloper <ActuallyaDeviloper@users.noreply.github.com> Co-authored-by: Dr. Patrick Urbanke <patrick@getml.com>
This commit is contained in:
co-authored by
ActuallyaDeviloper
Dr. Patrick Urbanke
parent
36bc907d78
commit
8b2833b136
@@ -147,7 +147,8 @@ class RFL_API Writer {
|
|||||||
OutputVarType add_value_to_map(const std::string_view& _name, const T& _var,
|
OutputVarType add_value_to_map(const std::string_view& _name, const T& _var,
|
||||||
OutputMapType* _parent) const {
|
OutputMapType* _parent) const {
|
||||||
avro_value_t new_value;
|
avro_value_t new_value;
|
||||||
int result = avro_value_add(&_parent->val_, _name.data(), &new_value,
|
// Copy name to nullterminate.
|
||||||
|
int result = avro_value_add(&_parent->val_, std::string(_name).c_str(), &new_value,
|
||||||
nullptr, nullptr);
|
nullptr, nullptr);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
throw std::runtime_error("Error adding value to map: error(" +
|
throw std::runtime_error("Error adding value to map: error(" +
|
||||||
@@ -163,7 +164,8 @@ class RFL_API Writer {
|
|||||||
const T& _var,
|
const T& _var,
|
||||||
OutputObjectType* _parent) const {
|
OutputObjectType* _parent) const {
|
||||||
avro_value_t new_value;
|
avro_value_t new_value;
|
||||||
int result = avro_value_get_by_name(&_parent->val_, _name.data(),
|
// Copy name to nullterminate.
|
||||||
|
int result = avro_value_get_by_name(&_parent->val_, std::string(_name).c_str(),
|
||||||
&new_value, nullptr);
|
&new_value, nullptr);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
throw std::runtime_error("Error adding value to object: error(" +
|
throw std::runtime_error("Error adding value to object: error(" +
|
||||||
|
|||||||
@@ -165,8 +165,9 @@ class RFL_API Reader {
|
|||||||
const auto entries = _map.val_.get("entries").as<capnp::DynamicList>();
|
const auto entries = _map.val_.get("entries").as<capnp::DynamicList>();
|
||||||
for (auto entry : entries) {
|
for (auto entry : entries) {
|
||||||
auto s = entry.template as<capnp::DynamicStruct>();
|
auto s = entry.template as<capnp::DynamicStruct>();
|
||||||
const char* key = s.get("key").as<capnp::Text>().cStr();
|
const auto key = s.get("key").as<capnp::Text>();
|
||||||
_map_reader.read(std::string_view(key), InputVarType{s.get("value")});
|
_map_reader.read(std::string_view(key.cStr(), key.size()),
|
||||||
|
InputVarType{s.get("value")});
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
|
|||||||
@@ -10,15 +10,11 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
// #include "../Box.hpp"
|
|
||||||
#include "../Bytestring.hpp"
|
#include "../Bytestring.hpp"
|
||||||
// #include "../Ref.hpp"
|
|
||||||
// #include "../Result.hpp"
|
|
||||||
#include "../Vectorstring.hpp"
|
#include "../Vectorstring.hpp"
|
||||||
#include "../always_false.hpp"
|
#include "../always_false.hpp"
|
||||||
#include "../internal/is_literal.hpp"
|
|
||||||
// #include "../internal/ptr_cast.hpp"
|
|
||||||
#include "../common.hpp"
|
#include "../common.hpp"
|
||||||
|
#include "../internal/is_literal.hpp"
|
||||||
|
|
||||||
namespace rfl::capnproto {
|
namespace rfl::capnproto {
|
||||||
|
|
||||||
@@ -193,7 +189,7 @@ class RFL_API Writer {
|
|||||||
auto entries =
|
auto entries =
|
||||||
OutputArrayType{_parent->val_.get("entries").as<capnp::DynamicList>()};
|
OutputArrayType{_parent->val_.get("entries").as<capnp::DynamicList>()};
|
||||||
auto new_entry = add_object_to_array(2, &entries);
|
auto new_entry = add_object_to_array(2, &entries);
|
||||||
add_value_to_object("key", std::string(_name), &new_entry);
|
add_value_to_object("key", _name, &new_entry);
|
||||||
return add_value_to_object("value", _var, &new_entry);
|
return add_value_to_object("value", _var, &new_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,20 +198,22 @@ class RFL_API Writer {
|
|||||||
const T& _var,
|
const T& _var,
|
||||||
OutputObjectType* _parent) const {
|
OutputObjectType* _parent) const {
|
||||||
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
|
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
|
||||||
_parent->val_.set(_name.data(), _var.c_str());
|
_parent->val_.set(to_kj_string_ptr(_name), _var.c_str());
|
||||||
|
|
||||||
} else if constexpr (std::is_same<std::remove_cvref_t<T>,
|
} else if constexpr (std::is_same<std::remove_cvref_t<T>,
|
||||||
rfl::Bytestring>()) {
|
rfl::Bytestring>()) {
|
||||||
const auto array_ptr = kj::ArrayPtr<const kj::byte>(
|
const auto array_ptr = kj::ArrayPtr<const kj::byte>(
|
||||||
internal::ptr_cast<const unsigned char*>(_var.data()), _var.size());
|
internal::ptr_cast<const unsigned char*>(_var.data()), _var.size());
|
||||||
_parent->val_.set(_name.data(), capnp::Data::Reader(array_ptr));
|
_parent->val_.set(to_kj_string_ptr(_name),
|
||||||
|
capnp::Data::Reader(array_ptr));
|
||||||
|
|
||||||
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>() ||
|
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>() ||
|
||||||
std::is_same<std::remove_cvref_t<T>, bool>()) {
|
std::is_same<std::remove_cvref_t<T>, bool>()) {
|
||||||
_parent->val_.set(_name.data(), _var);
|
_parent->val_.set(to_kj_string_ptr(_name), _var);
|
||||||
|
|
||||||
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
|
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
|
||||||
_parent->val_.set(_name.data(), static_cast<std::int64_t>(_var));
|
_parent->val_.set(to_kj_string_ptr(_name),
|
||||||
|
static_cast<std::int64_t>(_var));
|
||||||
|
|
||||||
} else if constexpr (internal::is_literal_v<T>) {
|
} else if constexpr (internal::is_literal_v<T>) {
|
||||||
return add_value_to_object(_name, _var.value(), _parent);
|
return add_value_to_object(_name, _var.value(), _parent);
|
||||||
@@ -262,6 +260,11 @@ class RFL_API Writer {
|
|||||||
|
|
||||||
void end_object(OutputObjectType* /*_obj*/) const {}
|
void end_object(OutputObjectType* /*_obj*/) const {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
kj::StringPtr to_kj_string_ptr(const std::string_view& _str) const {
|
||||||
|
return kj::StringPtr(_str.data(), _str.size());
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
capnp::DynamicStruct::Builder* root_;
|
capnp::DynamicStruct::Builder* root_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ struct Reader {
|
|||||||
yyjson_obj_iter_init(_obj.val_, &iter);
|
yyjson_obj_iter_init(_obj.val_, &iter);
|
||||||
yyjson_val* key;
|
yyjson_val* key;
|
||||||
while ((key = yyjson_obj_iter_next(&iter))) {
|
while ((key = yyjson_obj_iter_next(&iter))) {
|
||||||
const auto name = std::string_view(yyjson_get_str(key));
|
const auto name = std::string_view(yyjson_get_str(key), yyjson_get_len(key));
|
||||||
_object_reader.read(name, InputVarType(yyjson_obj_iter_get_val(key)));
|
_object_reader.read(name, InputVarType(yyjson_obj_iter_get_val(key)));
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
@@ -101,7 +101,7 @@ struct Reader {
|
|||||||
if (r == NULL) {
|
if (r == NULL) {
|
||||||
return error("Could not cast to string.");
|
return error("Could not cast to string.");
|
||||||
}
|
}
|
||||||
return std::string(r);
|
return std::string(r, yyjson_get_len(_var.val_));
|
||||||
|
|
||||||
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
|
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
|
||||||
if (!yyjson_is_bool(_var.val_)) {
|
if (!yyjson_is_bool(_var.val_)) {
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class RFL_API Writer {
|
|||||||
OutputObjectType* _parent) const {
|
OutputObjectType* _parent) const {
|
||||||
const auto val = from_basic_type(_var);
|
const auto val = from_basic_type(_var);
|
||||||
const bool ok = yyjson_mut_obj_add(
|
const bool ok = yyjson_mut_obj_add(
|
||||||
_parent->val_, yyjson_mut_strcpy(doc(), _name.data()), val.val_);
|
_parent->val_, yyjson_mut_strncpy(doc(), _name.data(), _name.size()), val.val_);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
throw std::runtime_error("Could not add field '" + std::string(_name) +
|
throw std::runtime_error("Could not add field '" + std::string(_name) +
|
||||||
"' to object.");
|
"' to object.");
|
||||||
@@ -117,7 +117,7 @@ class RFL_API Writer {
|
|||||||
template <class T>
|
template <class T>
|
||||||
OutputVarType from_basic_type(const T& _var) const noexcept {
|
OutputVarType from_basic_type(const T& _var) const noexcept {
|
||||||
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
|
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
|
||||||
return OutputVarType(yyjson_mut_strcpy(doc(), _var.c_str()));
|
return OutputVarType(yyjson_mut_strncpy(doc(), _var.c_str(), _var.size()));
|
||||||
|
|
||||||
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
|
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
|
||||||
return OutputVarType(yyjson_mut_bool(doc(), _var));
|
return OutputVarType(yyjson_mut_bool(doc(), _var));
|
||||||
|
|||||||
@@ -93,9 +93,9 @@ struct RFL_API Writer {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
template <class T>
|
template <class T>
|
||||||
std::string to_string(const T& _val) const {
|
decltype(auto) to_string(const T& _val) const {
|
||||||
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
|
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
|
||||||
return _val;
|
return _val; // Return reference to avoid expensive string copy.
|
||||||
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
|
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
|
||||||
return _val ? "true" : "false";
|
return _val ? "true" : "false";
|
||||||
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>() ||
|
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>() ||
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ class RFL_API Writer {
|
|||||||
|
|
||||||
void end_object(OutputObjectType* _obj) const;
|
void end_object(OutputObjectType* _obj) const;
|
||||||
|
|
||||||
private:
|
|
||||||
template <class T>
|
template <class T>
|
||||||
OutputVarType insert_value(const std::string_view& _name,
|
OutputVarType insert_value(const std::string_view& _name,
|
||||||
const T& _var) const {
|
const T& _var) const {
|
||||||
@@ -85,14 +84,14 @@ class RFL_API Writer {
|
|||||||
std::is_same<std::remove_cvref_t<T>, bool>() ||
|
std::is_same<std::remove_cvref_t<T>, bool>() ||
|
||||||
std::is_same<std::remove_cvref_t<T>,
|
std::is_same<std::remove_cvref_t<T>,
|
||||||
std::remove_cvref_t<decltype(YAML::Null)>>()) {
|
std::remove_cvref_t<decltype(YAML::Null)>>()) {
|
||||||
(*out_) << YAML::Key << _name.data() << YAML::Value << _var;
|
(*out_) << YAML::Key << std::string(_name) << YAML::Value << _var;
|
||||||
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>()) {
|
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>()) {
|
||||||
// std::to_string is necessary to ensure that floating point values are
|
// std::to_string is necessary to ensure that floating point values are
|
||||||
// always written as floats.
|
// always written as floats.
|
||||||
(*out_) << YAML::Key << _name.data() << YAML::Value
|
(*out_) << YAML::Key << std::string(_name) << YAML::Value
|
||||||
<< std::to_string(_var);
|
<< std::to_string(_var);
|
||||||
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
|
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
|
||||||
(*out_) << YAML::Key << _name.data() << YAML::Value
|
(*out_) << YAML::Key << std::string(_name) << YAML::Value
|
||||||
<< static_cast<int64_t>(_var);
|
<< static_cast<int64_t>(_var);
|
||||||
} else {
|
} else {
|
||||||
static_assert(rfl::always_false_v<T>, "Unsupported type.");
|
static_assert(rfl::always_false_v<T>, "Unsupported type.");
|
||||||
|
|||||||
@@ -47,8 +47,9 @@ Writer::OutputArrayType Writer::add_array_to_map(const std::string_view& _name,
|
|||||||
Writer::OutputArrayType Writer::add_array_to_object(
|
Writer::OutputArrayType Writer::add_array_to_object(
|
||||||
const std::string_view& _name, const size_t _size,
|
const std::string_view& _name, const size_t _size,
|
||||||
OutputObjectType* _parent) const {
|
OutputObjectType* _parent) const {
|
||||||
return OutputArrayType{_parent->val_.init(_name.data(), SafeSizeToUInt(_size))
|
return OutputArrayType{
|
||||||
.as<capnp::DynamicList>()};
|
_parent->val_.init(to_kj_string_ptr(_name), SafeSizeToUInt(_size))
|
||||||
|
.as<capnp::DynamicList>()};
|
||||||
}
|
}
|
||||||
|
|
||||||
Writer::OutputArrayType Writer::add_array_to_union(
|
Writer::OutputArrayType Writer::add_array_to_union(
|
||||||
@@ -111,7 +112,7 @@ Writer::OutputObjectType Writer::add_object_to_object(
|
|||||||
const std::string_view& _name, const size_t /*_size*/,
|
const std::string_view& _name, const size_t /*_size*/,
|
||||||
OutputObjectType* _parent) const {
|
OutputObjectType* _parent) const {
|
||||||
return OutputObjectType{
|
return OutputObjectType{
|
||||||
_parent->val_.get(_name.data()).as<capnp::DynamicStruct>()};
|
_parent->val_.get(to_kj_string_ptr(_name)).as<capnp::DynamicStruct>()};
|
||||||
}
|
}
|
||||||
|
|
||||||
Writer::OutputObjectType Writer::add_object_to_union(
|
Writer::OutputObjectType Writer::add_object_to_union(
|
||||||
@@ -142,7 +143,7 @@ Writer::OutputUnionType Writer::add_union_to_map(const std::string_view& _name,
|
|||||||
Writer::OutputUnionType Writer::add_union_to_object(
|
Writer::OutputUnionType Writer::add_union_to_object(
|
||||||
const std::string_view& _name, OutputObjectType* _parent) const {
|
const std::string_view& _name, OutputObjectType* _parent) const {
|
||||||
return OutputUnionType{
|
return OutputUnionType{
|
||||||
_parent->val_.get(_name.data()).as<capnp::DynamicStruct>()};
|
_parent->val_.get(to_kj_string_ptr(_name)).as<capnp::DynamicStruct>()};
|
||||||
}
|
}
|
||||||
|
|
||||||
Writer::OutputUnionType Writer::add_union_to_union(
|
Writer::OutputUnionType Writer::add_union_to_union(
|
||||||
@@ -171,7 +172,7 @@ Writer::OutputVarType Writer::add_null_to_map(const std::string_view& _name,
|
|||||||
|
|
||||||
Writer::OutputVarType Writer::add_null_to_object(
|
Writer::OutputVarType Writer::add_null_to_object(
|
||||||
const std::string_view& _name, OutputObjectType* _parent) const {
|
const std::string_view& _name, OutputObjectType* _parent) const {
|
||||||
_parent->val_.set(_name.data(), capnp::VOID);
|
_parent->val_.set(to_kj_string_ptr(_name), capnp::VOID);
|
||||||
return OutputVarType{};
|
return OutputVarType{};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ Writer::OutputVarType Writer::add_null_to_array(
|
|||||||
|
|
||||||
Writer::OutputVarType Writer::add_null_to_object(
|
Writer::OutputVarType Writer::add_null_to_object(
|
||||||
const std::string_view& _name, OutputObjectType* /*_parent*/) const {
|
const std::string_view& _name, OutputObjectType* /*_parent*/) const {
|
||||||
fbb_->Null(_name.data());
|
// Copy the string, because "std::string_view" might not be nullterminated.
|
||||||
|
fbb_->Null(std::string(_name).c_str());
|
||||||
return OutputVarType{};
|
return OutputVarType{};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +65,8 @@ void Writer::end_object(OutputObjectType* _obj) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Writer::OutputArrayType Writer::new_array(const std::string_view& _name) const {
|
Writer::OutputArrayType Writer::new_array(const std::string_view& _name) const {
|
||||||
const auto start = fbb_->StartVector(_name.data());
|
// Copy the string, because "std::string_view" might not be nullterminated.
|
||||||
|
const auto start = fbb_->StartVector(std::string(_name).c_str());
|
||||||
return OutputArrayType{start};
|
return OutputArrayType{start};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +77,8 @@ Writer::OutputArrayType Writer::new_array() const {
|
|||||||
|
|
||||||
Writer::OutputObjectType Writer::new_object(
|
Writer::OutputObjectType Writer::new_object(
|
||||||
const std::string_view& _name) const {
|
const std::string_view& _name) const {
|
||||||
const auto start = fbb_->StartMap(_name.data());
|
// Copy the string, because "std::string_view" might not be nullterminated.
|
||||||
|
const auto start = fbb_->StartMap(std::string(_name).c_str());
|
||||||
return OutputObjectType{start};
|
return OutputObjectType{start};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,27 +39,27 @@ Writer::~Writer() = default;
|
|||||||
|
|
||||||
Writer::OutputArrayType Writer::array_as_root(const size_t /*_size*/) const {
|
Writer::OutputArrayType Writer::array_as_root(const size_t /*_size*/) const {
|
||||||
auto node_child =
|
auto node_child =
|
||||||
Ref<pugi::xml_node>::make(root_->append_child(root_name_.c_str()));
|
Ref<pugi::xml_node>::make(root_->append_child(root_name_));
|
||||||
return OutputArrayType(root_name_, node_child);
|
return OutputArrayType(root_name_, node_child);
|
||||||
}
|
}
|
||||||
|
|
||||||
Writer::OutputObjectType Writer::object_as_root(const size_t /*_size*/) const {
|
Writer::OutputObjectType Writer::object_as_root(const size_t /*_size*/) const {
|
||||||
auto node_child =
|
auto node_child =
|
||||||
Ref<pugi::xml_node>::make(root_->append_child(root_name_.c_str()));
|
Ref<pugi::xml_node>::make(root_->append_child(root_name_));
|
||||||
return OutputObjectType(node_child);
|
return OutputObjectType(node_child);
|
||||||
}
|
}
|
||||||
|
|
||||||
Writer::OutputVarType Writer::null_as_root() const {
|
Writer::OutputVarType Writer::null_as_root() const {
|
||||||
auto node_child =
|
auto node_child =
|
||||||
Ref<pugi::xml_node>::make(root_->append_child(root_name_.c_str()));
|
Ref<pugi::xml_node>::make(root_->append_child(root_name_));
|
||||||
return OutputVarType(node_child);
|
return OutputVarType(node_child);
|
||||||
}
|
}
|
||||||
|
|
||||||
Writer::OutputVarType Writer::value_as_root_impl(
|
Writer::OutputVarType Writer::value_as_root_impl(
|
||||||
const std::string& _str) const {
|
const std::string& _str) const {
|
||||||
auto node_child =
|
auto node_child =
|
||||||
Ref<pugi::xml_node>::make(root_->append_child(root_name_.c_str()));
|
Ref<pugi::xml_node>::make(root_->append_child(root_name_));
|
||||||
node_child->append_child(pugi::node_pcdata).set_value(_str.c_str());
|
node_child->append_child(pugi::node_pcdata).set_value(_str);
|
||||||
return OutputVarType(node_child);
|
return OutputVarType(node_child);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ Writer::OutputVarType Writer::add_value_to_array_impl(
|
|||||||
const std::string& _str, OutputArrayType* _parent) const {
|
const std::string& _str, OutputArrayType* _parent) const {
|
||||||
auto node_child =
|
auto node_child =
|
||||||
Ref<pugi::xml_node>::make(_parent->node_->append_child(_parent->name_));
|
Ref<pugi::xml_node>::make(_parent->node_->append_child(_parent->name_));
|
||||||
node_child->append_child(pugi::node_pcdata).set_value(_str.c_str());
|
node_child->append_child(pugi::node_pcdata).set_value(_str);
|
||||||
return OutputVarType(node_child);
|
return OutputVarType(node_child);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,15 +86,15 @@ Writer::OutputVarType Writer::add_value_to_object_impl(
|
|||||||
const std::string_view& _name, const std::string& _str,
|
const std::string_view& _name, const std::string& _str,
|
||||||
OutputObjectType* _parent, const bool _is_attribute) const {
|
OutputObjectType* _parent, const bool _is_attribute) const {
|
||||||
if (_is_attribute) {
|
if (_is_attribute) {
|
||||||
_parent->node_->append_attribute(_name) = _str.c_str();
|
_parent->node_->append_attribute(_name) = _str;
|
||||||
return OutputVarType(_parent->node_);
|
return OutputVarType(_parent->node_);
|
||||||
} else if (_name == XML_CONTENT) {
|
} else if (_name == XML_CONTENT) {
|
||||||
_parent->node_->append_child(pugi::node_pcdata).set_value(_str.c_str());
|
_parent->node_->append_child(pugi::node_pcdata).set_value(_str);
|
||||||
return OutputVarType(_parent->node_);
|
return OutputVarType(_parent->node_);
|
||||||
} else {
|
} else {
|
||||||
auto node_child =
|
auto node_child =
|
||||||
Ref<pugi::xml_node>::make(_parent->node_->append_child(_name));
|
Ref<pugi::xml_node>::make(_parent->node_->append_child(_name));
|
||||||
node_child->append_child(pugi::node_pcdata).set_value(_str.c_str());
|
node_child->append_child(pugi::node_pcdata).set_value(_str);
|
||||||
return OutputVarType(node_child);
|
return OutputVarType(node_child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ void Writer::end_object(OutputObjectType* /*_obj*/) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Writer::OutputArrayType Writer::new_array(const std::string_view& _name) const {
|
Writer::OutputArrayType Writer::new_array(const std::string_view& _name) const {
|
||||||
(*out_) << YAML::Key << _name.data() << YAML::Value << YAML::BeginSeq;
|
(*out_) << YAML::Key << std::string(_name) << YAML::Value << YAML::BeginSeq;
|
||||||
return OutputArrayType{};
|
return OutputArrayType{};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ Writer::OutputArrayType Writer::new_array() const {
|
|||||||
|
|
||||||
Writer::OutputObjectType Writer::new_object(
|
Writer::OutputObjectType Writer::new_object(
|
||||||
const std::string_view& _name) const {
|
const std::string_view& _name) const {
|
||||||
(*out_) << YAML::Key << _name.data() << YAML::Value << YAML::BeginMap;
|
(*out_) << YAML::Key << std::string(_name) << YAML::Value << YAML::BeginMap;
|
||||||
return OutputObjectType{};
|
return OutputObjectType{};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user