diff --git a/include/ircd/json/iov.h b/include/ircd/json/iov.h index 7f65d49b2..be5183e6c 100644 --- a/include/ircd/json/iov.h +++ b/include/ircd/json/iov.h @@ -166,7 +166,7 @@ ircd::json::make_iov(iov &ret, size_t i{0}; for(auto&& member : members) if(likely(i < size)) - new (nodes + i++) node(ret, std::move(member)); + new (nodes + i++) node(ret, json::member(member)); return ret; } diff --git a/include/ircd/json/member.h b/include/ircd/json/member.h index fd3834690..69e5a4bae 100644 --- a/include/ircd/json/member.h +++ b/include/ircd/json/member.h @@ -24,16 +24,12 @@ namespace ircd::json /// This is slightly heavier than object::member as that only deals with /// a pair of strings while the value here holds more diverse native state. /// -/// The key value (member.first) should always be a STRING type. We don't use -/// string_view directly in member.first because json::value can take ownership -/// of a string or use a literal depending on the circumstance and it's more -/// consistent this way. -/// struct ircd::json::member :std::pair { - using std::pair::pair; - template member(const K &k, V&& v); + member(const string_view &key, value &&); + template member(const string_view &key, V&&); + template member(const char (&)[N], V&&); explicit member(const string_view &k); explicit member(const object::member &m); member() = default; @@ -60,13 +56,31 @@ namespace ircd::json string_view stringify(mutable_buffer &, const members &); } -template -ircd::json::member::member(const K &k, +inline +ircd::json::member::member(const string_view &key, + value &&v) +:std::pair +{ + { key, json::STRING }, std::move(v) +} +{} + +template +ircd::json::member::member(const char (&key)[N], V&& v) :std::pair { - value { k }, value { std::forward(v) } + { key, json::STRING }, std::forward(v) +} +{} + +template +ircd::json::member::member(const string_view &key, + V&& v) +:std::pair +{ + { key, json::STRING }, std::forward(v) } {} diff --git a/include/ircd/json/value.h b/include/ircd/json/value.h index 8abb13393..368dcd221 100644 --- a/include/ircd/json/value.h +++ b/include/ircd/json/value.h @@ -85,13 +85,15 @@ struct ircd::json::value explicit operator int64_t() const; explicit operator std::string() const; ///< NOTE full stringify() of value + template value(const char (&)[N], const enum type &); value(const string_view &sv, const enum type &); - template value(const char (&)[N]); + value(const char *const &, const enum type &); explicit value(const int64_t &); explicit value(const double &); explicit value(const bool &); - value(const char *const &s); + template value(const char (&)[N]); value(const string_view &sv); + value(const char *const &s); value(const struct member *const &, const size_t &len); value(std::unique_ptr, const size_t &len); // alloc = true value(const struct value *const &, const size_t &len); @@ -143,23 +145,14 @@ ircd::json::value::value(const string_view &sv, {} inline -ircd::json::value::value(const char *const &s) -:string{s} -,len{strlen(s)} -,type{json::type(s, std::nothrow)} -,serial{type == STRING? surrounds(s, '"') : true} -,alloc{false} -,floats{false} +ircd::json::value::value(const char *const &str, + const enum type &type) +:value{string_view{str}, type} {} -template -ircd::json::value::value(const char (&str)[N]) -:string{str} -,len{strnlen(str, N)} -,type{json::type(str, std::nothrow)} -,serial{type == STRING? surrounds(str, '"') : true} -,alloc{false} -,floats{false} +inline +ircd::json::value::value(const char *const &str) +:value{string_view{str}} {} inline @@ -167,6 +160,17 @@ ircd::json::value::value(const string_view &sv) :value{sv, json::type(sv, std::nothrow)} {} +template +ircd::json::value::value(const char (&str)[N]) +:value{string_view{str, strnlen(str, N)}} +{} + +template +ircd::json::value::value(const char (&str)[N], + const enum type &type) +:value{string_view{str, strnlen(str, N)}, type} +{} + inline ircd::json::value::value(const nullptr_t &) :value