From 78e8a3668d68b494bf911878fbd996a34ac08e06 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 15 Nov 2017 17:25:15 -0800 Subject: [PATCH] ircd::json: Add missing stringify participant; minor cleanup. --- include/ircd/json/json.h | 1 + include/ircd/json/tuple.h | 44 +++++++++++++++++++-------------------- ircd/json.cc | 14 +++++++++++++ 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/include/ircd/json/json.h b/include/ircd/json/json.h index e1284fe65..b98bfa739 100644 --- a/include/ircd/json/json.h +++ b/include/ircd/json/json.h @@ -70,6 +70,7 @@ namespace ircd::json struct strung; size_t serialized(const string_view &); + string_view stringify(mutable_buffer &, const string_view &); struct string; using members = std::initializer_list; diff --git a/include/ircd/json/tuple.h b/include/ircd/json/tuple.h index 6309d6cde..eaa100570 100644 --- a/include/ircd/json/tuple.h +++ b/include/ircd/json/tuple.h @@ -659,6 +659,28 @@ runtil(tuple &t, false; } +template +constexpr bool +serialized_lex_cast() +{ + using type = typename std::remove_reference::type; + return std::is_arithmetic::value; +} + +template +typename std::enable_if(), size_t>::type +serialized(T&& t) +{ + return lex_cast(t).size(); +} + +template +typename std::enable_if(), bool>::type +defined(T&& t) +{ + return t != typename std::remove_reference::type {0}; +} + template typename std::enable_if @@ -959,28 +981,6 @@ _member_transform(const tuple &tuple, }); } -template -constexpr bool -serialized_lex_cast() -{ - using type = typename std::remove_reference::type; - return std::is_arithmetic::value; -} - -template -typename std::enable_if(), size_t>::type -serialized(T&& t) -{ - return lex_cast(t).size(); -} - -template -typename std::enable_if(), bool>::type -defined(T&& t) -{ - return t != typename std::remove_reference::type {0}; -} - template size_t serialized(const tuple &t) diff --git a/ircd/json.cc b/ircd/json.cc index 7bdba3d28..ec1c99f85 100644 --- a/ircd/json.cc +++ b/ircd/json.cc @@ -1486,6 +1486,20 @@ ircd::json::operator==(const value &a, const value &b) // json.h // +ircd::string_view +ircd::json::stringify(mutable_buffer &buf, + const string_view &v) +{ + if(v.empty() && defined(v)) + { + consume(buf, copy(buf, value::empty_string)); + return value::empty_string; + } + + consume(buf, copy(buf, string_view{v})); + return string_view{v}; +} + size_t ircd::json::serialized(const string_view &s) {