mirror of
https://github.com/matrix-construct/construct
synced 2024-12-25 23:14:13 +01:00
ircd::rfc3986: Add URI decomposition.
This commit is contained in:
parent
0355391e34
commit
22f3c41603
2 changed files with 50 additions and 0 deletions
|
@ -14,6 +14,7 @@
|
|||
/// Universal Resource Indicator (URI) grammars & tools
|
||||
namespace ircd::rfc3986
|
||||
{
|
||||
struct uri;
|
||||
struct parser;
|
||||
|
||||
IRCD_EXCEPTION(ircd::error, error)
|
||||
|
@ -41,6 +42,19 @@ namespace ircd
|
|||
namespace url = rfc3986;
|
||||
}
|
||||
|
||||
struct ircd::rfc3986::uri
|
||||
{
|
||||
string_view scheme;
|
||||
string_view user;
|
||||
string_view remote;
|
||||
string_view path;
|
||||
string_view query;
|
||||
string_view fragment;
|
||||
|
||||
uri(const string_view &);
|
||||
uri() = default;
|
||||
};
|
||||
|
||||
struct ircd::rfc3986::parser
|
||||
{
|
||||
using it = const char *;
|
||||
|
|
|
@ -426,6 +426,42 @@ ircd::rfc3986::parser::uri_ref
|
|||
,"URI-reference"
|
||||
};
|
||||
|
||||
//
|
||||
// uri decompose
|
||||
//
|
||||
|
||||
BOOST_FUSION_ADAPT_STRUCT
|
||||
(
|
||||
ircd::rfc3986::uri,
|
||||
( decltype(ircd::rfc3986::uri::scheme), scheme )
|
||||
( decltype(ircd::rfc3986::uri::user), user )
|
||||
( decltype(ircd::rfc3986::uri::remote), remote )
|
||||
( decltype(ircd::rfc3986::uri::path), path )
|
||||
( decltype(ircd::rfc3986::uri::query), query )
|
||||
( decltype(ircd::rfc3986::uri::fragment), fragment )
|
||||
)
|
||||
|
||||
ircd::rfc3986::uri::uri(const string_view &input)
|
||||
{
|
||||
static const parser::rule<rfc3986::uri> rule
|
||||
{
|
||||
raw[parser::scheme] >> lit("://")
|
||||
>> -raw[parser::userinfo >> lit('@')]
|
||||
>> raw[parser::remote]
|
||||
>> raw[parser::path_abempty]
|
||||
>> -raw[lit('?') >> parser::query]
|
||||
>> -raw[lit('#') >> parser::fragment]
|
||||
};
|
||||
|
||||
const char *start(begin(input)), *const stop(end(input));
|
||||
qi::parse(start, stop, eps > rule, *this);
|
||||
|
||||
//TODO: XXX Can this go?
|
||||
this->user = rstrip(this->user, '@');
|
||||
this->query = lstrip(this->query, '?');
|
||||
this->fragment = lstrip(this->fragment, '#');
|
||||
}
|
||||
|
||||
//
|
||||
// general interface
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue