0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

ircd::json: Better bool related conversions etc.

This commit is contained in:
Jason Volk 2017-10-15 21:21:56 -07:00
parent 52e2525b30
commit 9c875c71a6
2 changed files with 22 additions and 3 deletions

View file

@ -26,9 +26,10 @@ namespace ircd::json
{
struct value;
using values = std::initializer_list<value>;
size_t serialized(const bool &);
size_t serialized(const value *const &begin, const value *const &end);
using values = std::initializer_list<value>;
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;
}

View file

@ -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:
{