From 9c875c71a6db36979d09e64e29a7e6eba50a2445 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 15 Oct 2017 21:21:56 -0700 Subject: [PATCH] ircd::json: Better bool related conversions etc. --- include/ircd/json/value.h | 21 +++++++++++++++++++-- ircd/json.cc | 4 +++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/ircd/json/value.h b/include/ircd/json/value.h index b2fdfce0a..9c2829feb 100644 --- a/include/ircd/json/value.h +++ b/include/ircd/json/value.h @@ -26,9 +26,10 @@ namespace ircd::json { struct value; - using values = std::initializer_list; - + size_t serialized(const bool &); size_t serialized(const value *const &begin, const value *const &end); + + using values = std::initializer_list; size_t serialized(const values &); string_view stringify(mutable_buffer &, const value *const &begin, const value *const &end); @@ -344,3 +345,19 @@ ircd::json::type(const value &a) { return a.type; } + +inline size_t +ircd::json::serialized(const bool &b) +{ + constexpr const size_t t + { + strlen("true") + }; + + constexpr const size_t f + { + strlen("false") + }; + + return b? t : f; +} diff --git a/ircd/json.cc b/ircd/json.cc index 399cb1ca4..d37f86f6f 100644 --- a/ircd/json.cc +++ b/ircd/json.cc @@ -956,7 +956,9 @@ ircd::json::serialized(const value &v) return v.serial? v.len : serialized(v.array, v.array + v.len); case LITERAL: - return v.len; + { + return v.serial? v.len : serialized(bool(v.integer)); + } case NUMBER: {