From e400e883c56a960ea69c324fe4c73e8c7845c65c Mon Sep 17 00:00:00 2001 From: Meagan Lang Date: Wed, 28 Aug 2024 01:49:08 -0400 Subject: [PATCH] Handle case of vector of strings from array of strings --- include/rapidjson/document.h | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index a07cb0449..cb9449f1d 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -772,16 +772,30 @@ YGG_GENERIC_HELPER(Ply, Ply) #define YGG_STD_VECTOR_STRING_(T) \ template \ struct TypeHelper > { \ - static bool Is(const ValueType& v) \ - { return v.template IsNDArray(); } \ + static bool Is(const ValueType& v) { \ + if (v.template IsNDArray()) return true; \ + if (!v.IsArray()) return false; \ + for (typename ValueType::ConstValueIterator it = v.Begin(); \ + it != v.End(); it++) { \ + if (!it->template Is()) return false; \ + } \ + return true; \ + } \ static std::vector Get(const ValueType& v) { \ std::vector out; \ - out.resize(static_cast(v.GetNElements())); \ - SizeType prec = v.GetPrecision() / \ - sizeof(typename ValueType::Ch); \ - typename ValueType::Ch* data = v.GetString(); \ - for (size_t i = 0; i < out.size(); i++) { \ - out[i].assign(data + (i * prec), prec); \ + if (v.IsArray()) { \ + for (typename ValueType::ConstValueIterator it = v.Begin(); \ + it != v.End(); it++) { \ + out.push_back(it->template Get()); \ + } \ + } else { \ + out.resize(static_cast(v.GetNElements())); \ + SizeType prec = v.GetPrecision() / \ + sizeof(typename ValueType::Ch); \ + const typename ValueType::Ch* data = v.GetString(); \ + for (size_t i = 0; i < out.size(); i++) { \ + out[i].assign(data + (i * prec), prec); \ + } \ } \ return out; \ } \