From 9ca019f03e1bb4a507e4bd2d5a7025473df8ccc5 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 27 Jun 2019 22:56:50 -0700 Subject: [PATCH] ircd::m::id::event: Add non-throwing static tests of v3/v4 id from string. --- include/ircd/m/id.h | 4 ++++ ircd/m_id.cc | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/ircd/m/id.h b/include/ircd/m/id.h index 538b2612d..e41d65c13 100644 --- a/include/ircd/m/id.h +++ b/include/ircd/m/id.h @@ -179,6 +179,8 @@ struct ircd::m::id::event struct ircd::m::id::event::v3 :ircd::m::id::event { + static bool is(const string_view &) noexcept; + v3(const mutable_buffer &out, const m::event &); v3(const string_view &id); v3() = default; @@ -188,6 +190,8 @@ struct ircd::m::id::event::v3 struct ircd::m::id::event::v4 :ircd::m::id::event { + static bool is(const string_view &) noexcept; + v4(const mutable_buffer &out, const m::event &); v4(const string_view &id); v4() = default; diff --git a/ircd/m_id.cc b/ircd/m_id.cc index abf79ed98..b6f3c3a7c 100644 --- a/ircd/m_id.cc +++ b/ircd/m_id.cc @@ -732,6 +732,20 @@ ircd::m::id::event::v3::v3(const mutable_buffer &out, { } +bool +ircd::m::id::event::v3::is(const string_view &id) +noexcept +{ + static const parser::rule<> &valid + { + parser.event_id_v3 + }; + + auto *start(std::begin(id)); + auto *const stop(std::end(id)); + return qi::parse(start, stop, valid); +} + // // id::event::v4 // @@ -785,6 +799,20 @@ ircd::m::id::event::v4::v4(const mutable_buffer &out, { } +bool +ircd::m::id::event::v4::is(const string_view &id) +noexcept +{ + static const parser::rule<> &valid + { + parser.event_id_v4 + }; + + auto *start(std::begin(id)); + auto *const stop(std::end(id)); + return qi::parse(start, stop, valid); +} + // // util //