2018-02-04 03:22:01 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2016-08-27 10:59:01 +02:00
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
namespace ircd::lex
|
|
|
|
{
|
|
|
|
struct to_float_policy;
|
|
|
|
struct to_double_policy;
|
|
|
|
struct to_long_double_policy;
|
|
|
|
|
|
|
|
struct from_float_policy;
|
|
|
|
struct from_double_policy;
|
|
|
|
struct from_long_double_policy;
|
|
|
|
|
|
|
|
template<class T,
|
|
|
|
class... A>
|
2022-05-19 23:03:20 +02:00
|
|
|
using rule_to = spirit::qi::rule<const char *, T, A...>;
|
2021-03-01 23:42:54 +01:00
|
|
|
|
|
|
|
template<class T,
|
|
|
|
class... A>
|
2022-05-19 23:03:20 +02:00
|
|
|
using rule_from = spirit::karma::rule<char *, T, A...>;
|
2021-03-01 23:42:54 +01:00
|
|
|
|
|
|
|
template<class T,
|
|
|
|
class rule,
|
|
|
|
class exception>
|
|
|
|
[[noreturn]]
|
|
|
|
static void throw_error(const rule &, const exception &e);
|
|
|
|
|
|
|
|
template<class T,
|
|
|
|
const rule_to<T> &r>
|
|
|
|
static bool test(const string_view &) noexcept;
|
|
|
|
|
|
|
|
template<class T,
|
|
|
|
const rule_to<T> &r>
|
|
|
|
static T cast(const string_view &);
|
|
|
|
|
|
|
|
template<class T,
|
|
|
|
const rule_from<T()> &r>
|
|
|
|
static string_view cast(const mutable_buffer &, T);
|
2022-05-19 23:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma GCC visibility push(internal)
|
|
|
|
namespace ircd::lex
|
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
extern const rule_from<bool()> from_bool;
|
|
|
|
extern const rule_from<int8_t()> from_int8_t;
|
|
|
|
extern const rule_from<uint8_t()> from_uint8_t;
|
|
|
|
extern const rule_from<short()> from_short;
|
|
|
|
extern const rule_from<ushort()> from_ushort;
|
|
|
|
extern const rule_from<int()> from_int;
|
|
|
|
extern const rule_from<uint()> from_uint;
|
|
|
|
extern const rule_from<long()> from_long;
|
|
|
|
extern const rule_from<ulong()> from_ulong;
|
|
|
|
extern const rule_from<float()> from_float;
|
|
|
|
extern const rule_from<double()> from_double;
|
|
|
|
extern const rule_from<long double()> from_long_double;
|
2022-05-19 23:03:20 +02:00
|
|
|
|
|
|
|
extern const rule_to<bool> to_bool, is_bool;
|
|
|
|
extern const rule_to<int8_t> to_int8_t, is_int8_t;
|
|
|
|
extern const rule_to<uint8_t> to_uint8_t, is_uint8_t;
|
|
|
|
extern const rule_to<short> to_short, is_short;
|
|
|
|
extern const rule_to<ushort> to_ushort, is_ushort;
|
|
|
|
extern const rule_to<int> to_int, is_int;
|
|
|
|
extern const rule_to<uint> to_uint, is_uint;
|
|
|
|
extern const rule_to<long> to_long, is_long;
|
|
|
|
extern const rule_to<ulong> to_ulong, is_ulong;
|
|
|
|
extern const rule_to<float> to_float, is_float;
|
|
|
|
extern const rule_to<double> to_double, is_double;
|
|
|
|
extern const rule_to<long double> to_long_double, is_long_double;
|
|
|
|
}
|
|
|
|
#pragma GCC visibility pop
|
2021-03-01 23:42:54 +01:00
|
|
|
|
|
|
|
static_assert
|
|
|
|
(
|
|
|
|
ircd::LEX_CAST_BUFS == 256 && sizeof(ircd::lex_cast_buf_head) == 1,
|
|
|
|
"ircd::lex_cast ring buffer integer may not modulate as intended"
|
|
|
|
);
|
|
|
|
|
|
|
|
/// Indicates the next buffer to be used in the ring. See below.
|
|
|
|
thread_local
|
|
|
|
decltype(ircd::lex_cast_buf_head)
|
|
|
|
ircd::lex_cast_buf_head
|
|
|
|
alignas(16);
|
|
|
|
|
|
|
|
/// This is a static "ring buffer" to simplify a majority of lex_cast uses.
|
|
|
|
/// The returned string_view of data from this buffer is only valid for
|
|
|
|
/// several more calls to lex_cast before it is overwritten.
|
|
|
|
thread_local
|
|
|
|
decltype(ircd::lex_cast_buf)
|
|
|
|
ircd::lex_cast_buf
|
|
|
|
alignas(64);
|
|
|
|
|
|
|
|
template<class T,
|
|
|
|
const ircd::lex::rule_from<T()> &rule>
|
|
|
|
[[gnu::always_inline]]
|
|
|
|
inline ircd::string_view
|
|
|
|
ircd::lex::cast(const mutable_buffer &out,
|
|
|
|
T in)
|
|
|
|
try
|
2019-03-01 20:47:13 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
constexpr bool truncation
|
|
|
|
{
|
|
|
|
false
|
|
|
|
};
|
2019-03-01 20:47:13 +01:00
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
mutable_buffer buf
|
|
|
|
{
|
|
|
|
out
|
|
|
|
};
|
2017-09-23 00:50:28 +02:00
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
const bool pass
|
|
|
|
{
|
|
|
|
ircd::generate<truncation>
|
|
|
|
(
|
|
|
|
buf, rule | spirit::eps, in
|
|
|
|
)
|
|
|
|
};
|
2017-09-23 00:50:28 +02:00
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
assert(pass);
|
|
|
|
return string_view
|
|
|
|
{
|
|
|
|
data(out), data(buf)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
|
|
|
throw_error<T>(rule, e);
|
|
|
|
__builtin_unreachable();
|
2017-09-23 00:50:28 +02:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<class T,
|
|
|
|
const ircd::lex::rule_to<T> &rule>
|
|
|
|
[[gnu::always_inline]]
|
|
|
|
inline T
|
|
|
|
ircd::lex::cast(const string_view &s)
|
2017-03-16 21:31:17 +01:00
|
|
|
try
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2022-07-04 23:16:18 +02:00
|
|
|
T ret {};
|
2022-05-19 23:03:20 +02:00
|
|
|
const char *start(begin(s)), *const stop(end(s));
|
2021-03-01 23:42:54 +01:00
|
|
|
const bool pass
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
ircd::parse(start, stop, rule, ret)
|
2021-03-01 23:42:54 +01:00
|
|
|
};
|
2017-03-14 19:39:26 +01:00
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
assert(pass);
|
|
|
|
return ret;
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
2021-03-01 23:42:54 +01:00
|
|
|
catch(const std::exception &e)
|
2017-03-16 21:31:17 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
throw_error<T>(rule, e);
|
|
|
|
__builtin_unreachable();
|
2017-03-16 21:31:17 +01:00
|
|
|
}
|
2017-03-14 19:39:26 +01:00
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<class T,
|
|
|
|
const ircd::lex::rule_to<T> &rule>
|
|
|
|
[[gnu::always_inline]]
|
|
|
|
inline bool
|
|
|
|
ircd::lex::test(const string_view &s)
|
|
|
|
noexcept
|
2017-03-16 21:31:17 +01:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
const char *start(begin(s)), *const stop(end(s));
|
|
|
|
return ircd::parse(std::nothrow, start, stop, rule);
|
2018-03-16 20:42:49 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<class T,
|
|
|
|
class rule,
|
|
|
|
class exception>
|
|
|
|
[[noreturn, gnu::noinline, gnu::cold]]
|
2018-03-16 20:42:49 +01:00
|
|
|
void
|
2021-03-01 23:42:54 +01:00
|
|
|
ircd::lex::throw_error(const rule &r,
|
|
|
|
const exception &e)
|
2018-03-16 20:42:49 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
throw bad_lex_cast
|
2018-03-16 20:42:49 +01:00
|
|
|
{
|
2021-04-10 19:48:11 +02:00
|
|
|
"Invalid lexical conversion of %s (%s).",
|
|
|
|
r.name(),
|
|
|
|
demangle(typeid(T).name()),
|
2018-03-16 20:42:49 +01:00
|
|
|
};
|
2017-03-16 21:31:17 +01:00
|
|
|
}
|
2017-03-14 19:39:26 +01:00
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
//
|
|
|
|
// bool
|
|
|
|
//
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::from_bool)
|
|
|
|
ircd::lex::from_bool
|
|
|
|
{
|
|
|
|
spirit::karma::bool_
|
|
|
|
,"boolean"
|
|
|
|
};
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
decltype(ircd::lex::to_bool)
|
|
|
|
ircd::lex::to_bool
|
|
|
|
{
|
2022-07-04 23:12:55 +02:00
|
|
|
spirit::expect[spirit::qi::bool_ >> spirit::eoi]
|
2021-03-01 23:42:54 +01:00
|
|
|
,"boolean"
|
|
|
|
};
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::is_bool)
|
|
|
|
ircd::lex::is_bool
|
2021-03-01 23:42:54 +01:00
|
|
|
{
|
2022-07-10 02:19:40 +02:00
|
|
|
spirit::qi::bool_ >> spirit::eoi
|
2021-03-01 23:42:54 +01:00
|
|
|
,"boolean"
|
|
|
|
};
|
|
|
|
|
2017-03-14 19:39:26 +01:00
|
|
|
template<> ircd::string_view
|
|
|
|
ircd::lex_cast(bool i,
|
2017-10-17 09:41:51 +02:00
|
|
|
const mutable_buffer &buf)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<bool, lex::from_bool>(buf, i);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> bool
|
|
|
|
ircd::lex_cast(const string_view &s)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2022-10-08 19:49:41 +02:00
|
|
|
const bool literal[]
|
2022-05-19 23:03:20 +02:00
|
|
|
{
|
|
|
|
s == "true",
|
|
|
|
s == "false",
|
2022-10-08 19:49:41 +02:00
|
|
|
s == "null",
|
2022-05-19 23:03:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Handle the common cases early in this frame before call.
|
2022-10-08 19:49:41 +02:00
|
|
|
if(likely(literal[0] | literal[1] | literal[2]))
|
2022-05-19 23:03:20 +02:00
|
|
|
return literal[0];
|
|
|
|
|
|
|
|
return lex::cast<bool, lex::to_bool>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> bool
|
|
|
|
ircd::lex_castable<bool>(const string_view &s)
|
|
|
|
noexcept
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2022-10-08 19:49:41 +02:00
|
|
|
const bool literal[]
|
2022-05-19 23:03:20 +02:00
|
|
|
{
|
|
|
|
s == "true",
|
|
|
|
s == "false",
|
2022-10-08 19:49:41 +02:00
|
|
|
s == "null",
|
2022-05-19 23:03:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Handle the common cases early in this frame before call.
|
2022-10-08 19:49:41 +02:00
|
|
|
if(likely(literal[0] | literal[1] | literal[2]))
|
2022-05-19 23:03:20 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return lex::test<bool, lex::is_bool>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
//
|
|
|
|
// int8_t
|
|
|
|
//
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::from_int8_t)
|
|
|
|
ircd::lex::from_int8_t
|
|
|
|
{
|
2022-07-04 23:12:55 +02:00
|
|
|
spirit::karma::ushort_
|
2022-05-19 23:03:20 +02:00
|
|
|
,"signed byte"
|
|
|
|
};
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
decltype(ircd::lex::to_int8_t)
|
|
|
|
ircd::lex::to_int8_t
|
|
|
|
{
|
2022-07-04 23:12:55 +02:00
|
|
|
spirit::expect[spirit::qi::ushort_ >> spirit::eoi]
|
2021-03-01 23:42:54 +01:00
|
|
|
,"signed byte"
|
|
|
|
};
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::is_int8_t)
|
|
|
|
ircd::lex::is_int8_t
|
2021-03-01 23:42:54 +01:00
|
|
|
{
|
2022-07-10 02:19:40 +02:00
|
|
|
spirit::qi::ushort_ >> spirit::eoi
|
2021-03-01 23:42:54 +01:00
|
|
|
,"signed byte"
|
|
|
|
};
|
|
|
|
|
2017-03-14 19:39:26 +01:00
|
|
|
template<> ircd::string_view
|
2021-03-01 23:42:54 +01:00
|
|
|
ircd::lex_cast(int8_t i,
|
2017-10-17 09:41:51 +02:00
|
|
|
const mutable_buffer &buf)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<int8_t, lex::from_int8_t>(buf, i);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> int8_t
|
|
|
|
ircd::lex_cast(const string_view &s)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<int8_t, lex::to_int8_t>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> bool
|
|
|
|
ircd::lex_castable<int8_t>(const string_view &s)
|
|
|
|
noexcept
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
return lex::test<int8_t, lex::is_int8_t>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
//
|
|
|
|
// uint8_t
|
|
|
|
//
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::from_uint8_t)
|
|
|
|
ircd::lex::from_uint8_t
|
|
|
|
{
|
|
|
|
spirit::karma::ushort_
|
|
|
|
,"unsigned byte"
|
|
|
|
};
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
decltype(ircd::lex::to_uint8_t)
|
|
|
|
ircd::lex::to_uint8_t
|
|
|
|
{
|
2022-07-04 23:12:55 +02:00
|
|
|
spirit::expect[spirit::qi::ushort_ >> spirit::eoi]
|
2021-03-01 23:42:54 +01:00
|
|
|
,"unsigned byte"
|
|
|
|
};
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::is_uint8_t)
|
|
|
|
ircd::lex::is_uint8_t
|
2021-03-01 23:42:54 +01:00
|
|
|
{
|
2022-07-10 02:19:40 +02:00
|
|
|
spirit::qi::ushort_ >> spirit::eoi
|
2021-03-01 23:42:54 +01:00
|
|
|
,"unsigned byte"
|
|
|
|
};
|
|
|
|
|
2017-03-14 19:39:26 +01:00
|
|
|
template<> ircd::string_view
|
2021-03-01 23:42:54 +01:00
|
|
|
ircd::lex_cast(uint8_t i,
|
2017-10-17 09:41:51 +02:00
|
|
|
const mutable_buffer &buf)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<uint8_t, lex::from_uint8_t>(buf, i);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> uint8_t
|
|
|
|
ircd::lex_cast(const string_view &s)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<uint8_t, lex::to_uint8_t>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> bool
|
|
|
|
ircd::lex_castable<uint8_t>(const string_view &s)
|
|
|
|
noexcept
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
return lex::test<uint8_t, lex::is_uint8_t>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
//
|
|
|
|
// short
|
|
|
|
//
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::from_short)
|
|
|
|
ircd::lex::from_short
|
|
|
|
{
|
|
|
|
spirit::karma::short_
|
|
|
|
,"signed short integer"
|
|
|
|
};
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
decltype(ircd::lex::to_short)
|
|
|
|
ircd::lex::to_short
|
|
|
|
{
|
2022-07-04 23:12:55 +02:00
|
|
|
spirit::expect[spirit::qi::short_ >> spirit::eoi]
|
2021-03-01 23:42:54 +01:00
|
|
|
,"signed short integer"
|
|
|
|
};
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::is_short)
|
|
|
|
ircd::lex::is_short
|
2021-03-01 23:42:54 +01:00
|
|
|
{
|
2022-07-10 02:19:40 +02:00
|
|
|
spirit::qi::short_ >> spirit::eoi
|
2021-03-01 23:42:54 +01:00
|
|
|
,"signed short integer"
|
|
|
|
};
|
|
|
|
|
2019-10-09 01:59:31 +02:00
|
|
|
template<> ircd::string_view
|
2021-03-01 23:42:54 +01:00
|
|
|
ircd::lex_cast(short i,
|
2019-10-09 01:59:31 +02:00
|
|
|
const mutable_buffer &buf)
|
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<short, lex::from_short>(buf, i);
|
2019-10-09 01:59:31 +02:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> short
|
|
|
|
ircd::lex_cast(const string_view &s)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<short, lex::to_short>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> bool
|
|
|
|
ircd::lex_castable<short>(const string_view &s)
|
|
|
|
noexcept
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
return lex::test<short, lex::is_short>(s);
|
2017-10-17 09:41:51 +02:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
//
|
|
|
|
// ushort
|
|
|
|
//
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::from_ushort)
|
|
|
|
ircd::lex::from_ushort
|
|
|
|
{
|
|
|
|
spirit::karma::ushort_
|
|
|
|
,"unsigned short integer"
|
|
|
|
};
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
decltype(ircd::lex::to_ushort)
|
|
|
|
ircd::lex::to_ushort
|
|
|
|
{
|
2022-07-04 23:12:55 +02:00
|
|
|
spirit::expect[spirit::qi::ushort_ >> spirit::eoi]
|
2021-03-01 23:42:54 +01:00
|
|
|
,"unsigned short integer"
|
|
|
|
};
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::is_ushort)
|
|
|
|
ircd::lex::is_ushort
|
2021-03-01 23:42:54 +01:00
|
|
|
{
|
2022-07-10 02:19:40 +02:00
|
|
|
spirit::qi::ushort_ >> spirit::eoi
|
2021-03-01 23:42:54 +01:00
|
|
|
,"unsigned short integer"
|
|
|
|
};
|
|
|
|
|
2017-10-17 09:41:51 +02:00
|
|
|
template<> ircd::string_view
|
2021-03-01 23:42:54 +01:00
|
|
|
ircd::lex_cast(ushort i,
|
2017-10-17 09:41:51 +02:00
|
|
|
const mutable_buffer &buf)
|
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<ushort, lex::from_ushort>(buf, i);
|
2017-10-17 09:41:51 +02:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> ushort
|
|
|
|
ircd::lex_cast(const string_view &s)
|
2017-10-17 09:41:51 +02:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<ushort, lex::to_ushort>(s);
|
2017-10-17 09:41:51 +02:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> bool
|
|
|
|
ircd::lex_castable<ushort>(const string_view &s)
|
|
|
|
noexcept
|
2017-10-17 09:41:51 +02:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
return lex::test<ushort, lex::is_ushort>(s);
|
2017-10-17 09:41:51 +02:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
//
|
|
|
|
// signed
|
|
|
|
//
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::from_int)
|
|
|
|
ircd::lex::from_int
|
|
|
|
{
|
|
|
|
spirit::karma::int_
|
|
|
|
,"signed integer"
|
|
|
|
};
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
decltype(ircd::lex::to_int)
|
|
|
|
ircd::lex::to_int
|
|
|
|
{
|
2022-07-04 23:12:55 +02:00
|
|
|
spirit::expect[spirit::qi::int_ >> spirit::eoi]
|
2021-03-01 23:42:54 +01:00
|
|
|
,"signed integer"
|
|
|
|
};
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::is_int)
|
|
|
|
ircd::lex::is_int
|
2021-03-01 23:42:54 +01:00
|
|
|
{
|
2022-07-10 02:19:40 +02:00
|
|
|
spirit::qi::int_ >> spirit::eoi
|
2021-03-01 23:42:54 +01:00
|
|
|
,"signed integer"
|
|
|
|
};
|
|
|
|
|
2017-10-17 09:41:51 +02:00
|
|
|
template<> ircd::string_view
|
2021-03-01 23:42:54 +01:00
|
|
|
ircd::lex_cast(int i,
|
2017-10-17 09:41:51 +02:00
|
|
|
const mutable_buffer &buf)
|
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<int, lex::from_int>(buf, i);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> int
|
2017-03-14 19:39:26 +01:00
|
|
|
ircd::lex_cast(const string_view &s)
|
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<int, lex::to_int>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> bool
|
|
|
|
ircd::lex_castable<int>(const string_view &s)
|
|
|
|
noexcept
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
return lex::test<int, lex::is_int>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
//
|
|
|
|
// unsigned
|
|
|
|
//
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::from_uint)
|
|
|
|
ircd::lex::from_uint
|
|
|
|
{
|
|
|
|
spirit::karma::uint_
|
|
|
|
,"unsigned integer"
|
|
|
|
};
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
decltype(ircd::lex::to_uint)
|
|
|
|
ircd::lex::to_uint
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2022-07-04 23:12:55 +02:00
|
|
|
spirit::expect[spirit::qi::uint_ >> spirit::eoi]
|
2021-03-01 23:42:54 +01:00
|
|
|
,"unsigned integer"
|
|
|
|
};
|
2017-03-14 19:39:26 +01:00
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::is_uint)
|
|
|
|
ircd::lex::is_uint
|
2021-03-01 23:42:54 +01:00
|
|
|
{
|
2022-07-10 02:19:40 +02:00
|
|
|
spirit::qi::uint_ >> spirit::eoi
|
2021-03-01 23:42:54 +01:00
|
|
|
,"unsigned integer"
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> ircd::string_view
|
|
|
|
ircd::lex_cast(uint i,
|
|
|
|
const mutable_buffer &buf)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<uint, lex::from_uint>(buf, i);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> unsigned int
|
2017-03-14 19:39:26 +01:00
|
|
|
ircd::lex_cast(const string_view &s)
|
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<uint, lex::to_uint>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> bool
|
|
|
|
ircd::lex_castable<uint>(const string_view &s)
|
|
|
|
noexcept
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
return lex::test<uint, lex::is_uint>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
//
|
|
|
|
// long
|
|
|
|
//
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::from_long)
|
|
|
|
ircd::lex::from_long
|
|
|
|
{
|
|
|
|
spirit::karma::long_
|
|
|
|
,"long integer"
|
|
|
|
};
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
decltype(ircd::lex::to_long)
|
|
|
|
ircd::lex::to_long
|
|
|
|
{
|
2022-07-04 23:12:55 +02:00
|
|
|
spirit::expect[spirit::qi::long_ >> spirit::eoi]
|
2021-03-01 23:42:54 +01:00
|
|
|
,"long integer"
|
|
|
|
};
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::is_long)
|
|
|
|
ircd::lex::is_long
|
2021-03-01 23:42:54 +01:00
|
|
|
{
|
2022-07-10 02:19:40 +02:00
|
|
|
spirit::qi::long_ >> spirit::eoi
|
2021-03-01 23:42:54 +01:00
|
|
|
,"long integer"
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> ircd::string_view
|
|
|
|
ircd::lex_cast(long i,
|
|
|
|
const mutable_buffer &buf)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<long, lex::from_long>(buf, i);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<> long
|
|
|
|
ircd::lex_cast(const string_view &s)
|
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<long, lex::to_long>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> bool
|
|
|
|
ircd::lex_castable<long>(const string_view &s)
|
|
|
|
noexcept
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
return lex::test<long, lex::is_long>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
//
|
|
|
|
// ulong
|
|
|
|
//
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::from_ulong)
|
|
|
|
ircd::lex::from_ulong
|
|
|
|
{
|
|
|
|
spirit::karma::ulong_
|
|
|
|
,"long unsigned integer"
|
|
|
|
};
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
decltype(ircd::lex::to_ulong)
|
|
|
|
ircd::lex::to_ulong
|
2019-10-09 01:59:31 +02:00
|
|
|
{
|
2022-07-04 23:12:55 +02:00
|
|
|
spirit::expect[spirit::qi::ulong_ >> spirit::eoi]
|
2021-03-01 23:42:54 +01:00
|
|
|
,"long unsigned integer"
|
|
|
|
};
|
2019-10-09 01:59:31 +02:00
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::is_ulong)
|
|
|
|
ircd::lex::is_ulong
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2022-07-10 02:19:40 +02:00
|
|
|
spirit::qi::ulong_ >> spirit::eoi
|
2021-03-01 23:42:54 +01:00
|
|
|
,"long unsigned integer"
|
|
|
|
};
|
2017-03-14 19:39:26 +01:00
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> ircd::string_view
|
|
|
|
ircd::lex_cast(ulong i,
|
|
|
|
const mutable_buffer &buf)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<ulong, lex::from_ulong>(buf, i);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> unsigned long
|
2017-10-17 09:41:51 +02:00
|
|
|
ircd::lex_cast(const string_view &s)
|
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<ulong, lex::to_ulong>(s);
|
2017-10-17 09:41:51 +02:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> bool
|
|
|
|
ircd::lex_castable<ulong>(const string_view &s)
|
|
|
|
noexcept
|
2017-10-17 09:41:51 +02:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
return lex::test<ulong, lex::is_ulong>(s);
|
2017-10-17 09:41:51 +02:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
//
|
|
|
|
// float
|
|
|
|
//
|
|
|
|
|
|
|
|
struct [[gnu::visibility("internal")]]
|
|
|
|
ircd::lex::to_float_policy
|
|
|
|
:spirit::qi::real_policies<float>
|
2017-10-17 09:41:51 +02:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
static const bool
|
|
|
|
allow_leading_dot { false },
|
|
|
|
allow_trailing_dot { false },
|
|
|
|
expect_dot { false };
|
|
|
|
};
|
|
|
|
|
|
|
|
struct [[gnu::visibility("internal")]]
|
|
|
|
ircd::lex::from_float_policy
|
|
|
|
:spirit::karma::real_policies<float>
|
|
|
|
{
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::from_float)
|
|
|
|
ircd::lex::from_float
|
|
|
|
{
|
|
|
|
spirit::karma::real_generator<float, from_float_policy>{}
|
|
|
|
,"single floating point precision"
|
|
|
|
};
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
decltype(ircd::lex::to_float)
|
|
|
|
ircd::lex::to_float
|
|
|
|
{
|
2022-07-04 23:12:55 +02:00
|
|
|
spirit::expect[spirit::qi::real_parser<float, to_float_policy>{} >> spirit::eoi]
|
2021-03-01 23:42:54 +01:00
|
|
|
,"single floating point precision"
|
|
|
|
};
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::is_float)
|
|
|
|
ircd::lex::is_float
|
2021-03-01 23:42:54 +01:00
|
|
|
{
|
2022-07-10 02:19:40 +02:00
|
|
|
spirit::qi::real_parser<float, to_float_policy>{} >> spirit::eoi
|
2021-03-01 23:42:54 +01:00
|
|
|
,"single floating point precision"
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> ircd::string_view
|
|
|
|
ircd::lex_cast(float i,
|
|
|
|
const mutable_buffer &buf)
|
|
|
|
{
|
|
|
|
return lex::cast<float, lex::from_float>(buf, i);
|
2017-10-17 09:41:51 +02:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> float
|
2017-10-17 09:41:51 +02:00
|
|
|
ircd::lex_cast(const string_view &s)
|
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<float, lex::to_float>(s);
|
2017-10-17 09:41:51 +02:00
|
|
|
}
|
|
|
|
|
2017-03-14 19:39:26 +01:00
|
|
|
template<> bool
|
2021-03-01 23:42:54 +01:00
|
|
|
ircd::lex_castable<float>(const string_view &s)
|
2020-08-06 04:12:22 +02:00
|
|
|
noexcept
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
return lex::test<float, lex::is_float>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
//
|
|
|
|
// double
|
|
|
|
//
|
|
|
|
|
|
|
|
struct [[gnu::visibility("internal")]]
|
|
|
|
ircd::lex::to_double_policy
|
|
|
|
:spirit::qi::real_policies<double>
|
|
|
|
{
|
|
|
|
static const bool
|
|
|
|
allow_leading_dot { false },
|
|
|
|
allow_trailing_dot { false },
|
|
|
|
expect_dot { false };
|
|
|
|
};
|
|
|
|
|
|
|
|
struct [[gnu::visibility("internal")]]
|
|
|
|
ircd::lex::from_double_policy
|
|
|
|
:spirit::karma::real_policies<double>
|
|
|
|
{
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::from_double)
|
|
|
|
ircd::lex::from_double
|
|
|
|
{
|
|
|
|
spirit::karma::real_generator<double, from_double_policy>{}
|
|
|
|
,"double floating point precision"
|
|
|
|
};
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
decltype(ircd::lex::to_double)
|
|
|
|
ircd::lex::to_double
|
|
|
|
{
|
2022-07-04 23:12:55 +02:00
|
|
|
spirit::expect[spirit::qi::real_parser<double, to_double_policy>{} >> spirit::eoi]
|
2021-03-01 23:42:54 +01:00
|
|
|
,"double floating point precision"
|
|
|
|
};
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::is_double)
|
|
|
|
ircd::lex::is_double
|
2021-03-01 23:42:54 +01:00
|
|
|
{
|
2022-07-10 02:19:40 +02:00
|
|
|
spirit::qi::real_parser<double, to_double_policy>{} >> spirit::eoi
|
2021-03-01 23:42:54 +01:00
|
|
|
,"double floating point precision"
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> ircd::string_view
|
|
|
|
ircd::lex_cast(double i,
|
|
|
|
const mutable_buffer &buf)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<double, lex::from_double>(buf, i);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> double
|
|
|
|
ircd::lex_cast(const string_view &s)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<double, lex::to_double>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<> bool
|
2021-03-01 23:42:54 +01:00
|
|
|
ircd::lex_castable<double>(const string_view &s)
|
2020-08-06 04:12:22 +02:00
|
|
|
noexcept
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
return lex::test<double, lex::is_double>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
//
|
|
|
|
// long double
|
|
|
|
//
|
|
|
|
|
|
|
|
struct [[gnu::visibility("internal")]]
|
|
|
|
ircd::lex::to_long_double_policy
|
|
|
|
:spirit::qi::real_policies<long double>
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
static const bool
|
|
|
|
allow_leading_dot { false },
|
|
|
|
allow_trailing_dot { false },
|
|
|
|
expect_dot { false };
|
|
|
|
};
|
|
|
|
|
|
|
|
struct [[gnu::visibility("internal")]]
|
|
|
|
ircd::lex::from_long_double_policy
|
|
|
|
:spirit::karma::real_policies<long double>
|
|
|
|
{
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::from_long_double)
|
|
|
|
ircd::lex::from_long_double
|
|
|
|
{
|
|
|
|
spirit::karma::real_generator<long double, from_long_double_policy>{}
|
|
|
|
,"long double floating point precision"
|
|
|
|
};
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
decltype(ircd::lex::to_long_double)
|
|
|
|
ircd::lex::to_long_double
|
|
|
|
{
|
2022-07-04 23:12:55 +02:00
|
|
|
spirit::expect[spirit::qi::real_parser<long double, to_long_double_policy>{} >> spirit::eoi]
|
2021-03-01 23:42:54 +01:00
|
|
|
,"long double floating point precision"
|
|
|
|
};
|
|
|
|
|
2022-05-19 23:03:20 +02:00
|
|
|
decltype(ircd::lex::is_long_double)
|
|
|
|
ircd::lex::is_long_double
|
2021-03-01 23:42:54 +01:00
|
|
|
{
|
2022-07-10 02:19:40 +02:00
|
|
|
spirit::qi::real_parser<long double, to_long_double_policy>{} >> spirit::eoi
|
2021-03-01 23:42:54 +01:00
|
|
|
,"long double floating point precision"
|
|
|
|
};
|
|
|
|
|
|
|
|
template<> ircd::string_view
|
|
|
|
ircd::lex_cast(long double i,
|
|
|
|
const mutable_buffer &buf)
|
|
|
|
{
|
|
|
|
return lex::cast<long double, lex::from_long_double>(buf, i);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> long double
|
|
|
|
ircd::lex_cast(const string_view &s)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<long double, lex::to_long_double>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template<> bool
|
2021-03-01 23:42:54 +01:00
|
|
|
ircd::lex_castable<long double>(const string_view &s)
|
2020-08-06 04:12:22 +02:00
|
|
|
noexcept
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
return lex::test<long double, lex::is_long_double>(s);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2022-05-23 05:30:51 +02:00
|
|
|
//
|
|
|
|
// hours
|
|
|
|
//
|
|
|
|
|
|
|
|
template<> ircd::string_view
|
|
|
|
ircd::lex_cast(hours i,
|
|
|
|
const mutable_buffer &buf)
|
|
|
|
{
|
|
|
|
return lex::cast<time_t, lex::from_long>(buf, i.count());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> ircd::hours
|
|
|
|
ircd::lex_cast(const string_view &s)
|
|
|
|
{
|
|
|
|
return std::chrono::duration<time_t, std::ratio<3600L, 1L>>
|
|
|
|
(
|
|
|
|
lex::cast<time_t, lex::to_long>(s)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> bool
|
|
|
|
ircd::lex_castable<ircd::hours>(const string_view &s)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return lex::test<time_t, lex::is_long>(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// minutes
|
|
|
|
//
|
|
|
|
|
|
|
|
template<> ircd::string_view
|
|
|
|
ircd::lex_cast(minutes i,
|
|
|
|
const mutable_buffer &buf)
|
|
|
|
{
|
|
|
|
return lex::cast<time_t, lex::from_long>(buf, i.count());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> ircd::minutes
|
|
|
|
ircd::lex_cast(const string_view &s)
|
|
|
|
{
|
|
|
|
return std::chrono::duration<time_t, std::ratio<60L, 1L>>
|
|
|
|
(
|
|
|
|
lex::cast<time_t, lex::to_long>(s)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> bool
|
|
|
|
ircd::lex_castable<ircd::minutes>(const string_view &s)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
return lex::test<time_t, lex::is_long>(s);
|
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
//
|
|
|
|
// seconds
|
|
|
|
//
|
|
|
|
|
|
|
|
template<> ircd::string_view
|
|
|
|
ircd::lex_cast(seconds i,
|
|
|
|
const mutable_buffer &buf)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<time_t, lex::from_long>(buf, i.count());
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> ircd::seconds
|
|
|
|
ircd::lex_cast(const string_view &s)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return std::chrono::duration<time_t, std::ratio<1L, 1L>>
|
|
|
|
(
|
|
|
|
lex::cast<time_t, lex::to_long>(s)
|
|
|
|
);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2019-10-09 01:59:31 +02:00
|
|
|
template<> bool
|
2021-03-01 23:42:54 +01:00
|
|
|
ircd::lex_castable<ircd::seconds>(const string_view &s)
|
2020-08-06 04:12:22 +02:00
|
|
|
noexcept
|
2019-10-09 01:59:31 +02:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
return lex::test<time_t, lex::is_long>(s);
|
2019-10-09 01:59:31 +02:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
//
|
|
|
|
// milliseconds
|
|
|
|
//
|
|
|
|
|
|
|
|
template<> ircd::string_view
|
|
|
|
ircd::lex_cast(milliseconds i,
|
|
|
|
const mutable_buffer &buf)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<time_t, lex::from_long>(buf, i.count());
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
template<> ircd::milliseconds
|
|
|
|
ircd::lex_cast(const string_view &s)
|
2017-03-14 19:39:26 +01:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return std::chrono::duration<time_t, std::ratio<1L, 1000L>>
|
|
|
|
(
|
|
|
|
lex::cast<time_t, lex::to_long>(s)
|
|
|
|
);
|
2017-03-14 19:39:26 +01:00
|
|
|
}
|
|
|
|
|
2017-10-17 09:41:51 +02:00
|
|
|
template<> bool
|
2021-03-01 23:42:54 +01:00
|
|
|
ircd::lex_castable<ircd::milliseconds>(const string_view &s)
|
2020-08-06 04:12:22 +02:00
|
|
|
noexcept
|
2017-10-17 09:41:51 +02:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
return lex::test<time_t, lex::is_long>(s);
|
2021-03-01 23:42:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// microseconds
|
|
|
|
//
|
|
|
|
|
|
|
|
template<> ircd::string_view
|
|
|
|
ircd::lex_cast(microseconds i,
|
|
|
|
const mutable_buffer &buf)
|
|
|
|
{
|
|
|
|
return lex::cast<time_t, lex::from_long>(buf, i.count());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> ircd::microseconds
|
|
|
|
ircd::lex_cast(const string_view &s)
|
|
|
|
{
|
|
|
|
return std::chrono::duration<time_t, std::ratio<1L, 1000000L>>
|
|
|
|
(
|
|
|
|
lex::cast<time_t, lex::to_long>(s)
|
|
|
|
);
|
2017-10-17 09:41:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<> bool
|
2020-03-12 17:34:06 +01:00
|
|
|
ircd::lex_castable<ircd::microseconds>(const string_view &s)
|
2020-08-06 04:12:22 +02:00
|
|
|
noexcept
|
2017-10-17 09:41:51 +02:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
return lex::test<time_t, lex::is_long>(s);
|
2017-10-17 09:41:51 +02:00
|
|
|
}
|
|
|
|
|
2021-03-01 23:42:54 +01:00
|
|
|
//
|
|
|
|
// nanoseconds
|
|
|
|
//
|
|
|
|
|
|
|
|
template<> ircd::string_view
|
|
|
|
ircd::lex_cast(nanoseconds i,
|
|
|
|
const mutable_buffer &buf)
|
2017-10-17 09:41:51 +02:00
|
|
|
{
|
2021-03-01 23:42:54 +01:00
|
|
|
return lex::cast<time_t, lex::from_long>(buf, i.count());
|
|
|
|
}
|
|
|
|
|
|
|
|
template<> ircd::nanoseconds
|
|
|
|
ircd::lex_cast(const string_view &s)
|
|
|
|
{
|
|
|
|
return std::chrono::duration<time_t, std::ratio<1L, 1000000000L>>
|
|
|
|
(
|
|
|
|
lex::cast<time_t, lex::to_long>(s)
|
|
|
|
);
|
2017-10-17 09:41:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<> bool
|
2021-03-01 23:42:54 +01:00
|
|
|
ircd::lex_castable<ircd::nanoseconds>(const string_view &s)
|
2020-08-06 04:12:22 +02:00
|
|
|
noexcept
|
2017-10-17 09:41:51 +02:00
|
|
|
{
|
2022-05-19 23:03:20 +02:00
|
|
|
return lex::test<time_t, lex::is_long>(s);
|
2017-10-17 09:41:51 +02:00
|
|
|
}
|