0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 07:20:55 +01:00

ircd::json: Add missing stringify participant; minor cleanup.

This commit is contained in:
Jason Volk 2017-11-15 17:25:15 -08:00
parent 9b5834afd4
commit 78e8a3668d
3 changed files with 37 additions and 22 deletions

View file

@ -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<member>;

View file

@ -659,6 +659,28 @@ runtil(tuple &t,
false;
}
template<class T>
constexpr bool
serialized_lex_cast()
{
using type = typename std::remove_reference<T>::type;
return std::is_arithmetic<type>::value;
}
template<class T>
typename std::enable_if<serialized_lex_cast<T>(), size_t>::type
serialized(T&& t)
{
return lex_cast(t).size();
}
template<class T>
typename std::enable_if<serialized_lex_cast<T>(), bool>::type
defined(T&& t)
{
return t != typename std::remove_reference<T>::type {0};
}
template<class dst,
class src>
typename std::enable_if
@ -959,28 +981,6 @@ _member_transform(const tuple<T...> &tuple,
});
}
template<class T>
constexpr bool
serialized_lex_cast()
{
using type = typename std::remove_reference<T>::type;
return std::is_arithmetic<type>::value;
}
template<class T>
typename std::enable_if<serialized_lex_cast<T>(), size_t>::type
serialized(T&& t)
{
return lex_cast(t).size();
}
template<class T>
typename std::enable_if<serialized_lex_cast<T>(), bool>::type
defined(T&& t)
{
return t != typename std::remove_reference<T>::type {0};
}
template<class... T>
size_t
serialized(const tuple<T...> &t)

View file

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