mirror of
https://github.com/boostorg/url.git
synced 2026-02-21 15:32:13 +00:00
tidy up hier-part rule
This commit is contained in:
@@ -37,10 +37,12 @@ struct hier_part_rule_t
|
||||
{
|
||||
struct value_type
|
||||
{
|
||||
bool has_authority = false;
|
||||
authority_view authority;
|
||||
grammar::range<
|
||||
pct_string_view> path;
|
||||
pct_string_view path;
|
||||
std::size_t segment_count = 0;
|
||||
bool has_authority = false;
|
||||
|
||||
//grammar::range<pct_string_view> path;
|
||||
};
|
||||
|
||||
BOOST_URL_DECL
|
||||
|
||||
@@ -28,65 +28,74 @@ parse(
|
||||
result<value_type>
|
||||
{
|
||||
value_type t;
|
||||
|
||||
if(it == end)
|
||||
{
|
||||
// path-empty
|
||||
BOOST_URL_RETURN(t);
|
||||
return {};
|
||||
}
|
||||
if(it[0] != '/')
|
||||
if(end - it == 1)
|
||||
{
|
||||
// path-rootless
|
||||
auto const it0 = it;
|
||||
auto rv = grammar::parse(
|
||||
it, end,
|
||||
path_rootless_rule);
|
||||
if( rv )
|
||||
if(*it == '/')
|
||||
{
|
||||
t.path = std::move(*rv);
|
||||
BOOST_URL_RETURN(t);
|
||||
t.path = detail::make_pct_string_view(
|
||||
it, 1, 1);
|
||||
t.segment_count = 1;
|
||||
++it;
|
||||
return t;
|
||||
}
|
||||
it = it0;
|
||||
|
||||
// path-empty
|
||||
BOOST_URL_RETURN(t);
|
||||
}
|
||||
if( end - it == 1 ||
|
||||
it[1] != '/')
|
||||
{
|
||||
// path-absolute
|
||||
auto rv = grammar::parse(
|
||||
it, end,
|
||||
path_absolute_rule);
|
||||
it, end, segment_rule);
|
||||
if(! rv)
|
||||
return rv.error();
|
||||
t.path = std::move(*rv);
|
||||
t.has_authority = false;
|
||||
BOOST_URL_RETURN(t);
|
||||
t.path = *rv;
|
||||
t.segment_count = 1;
|
||||
return t;
|
||||
}
|
||||
|
||||
// "//" authority path-abempty
|
||||
it += 2;
|
||||
// authority
|
||||
if( it[0] == '/' &&
|
||||
it[1] == '/')
|
||||
{
|
||||
it += 2;
|
||||
auto rv = grammar::parse(
|
||||
it, end, authority_rule);
|
||||
if(! rv)
|
||||
return rv.error();
|
||||
t.authority = *rv;
|
||||
}
|
||||
|
||||
// path-abempty
|
||||
{
|
||||
auto rv = grammar::parse(
|
||||
it, end, path_abempty_rule);
|
||||
if(! rv)
|
||||
return rv.error();
|
||||
t.path = std::move(*rv);
|
||||
t.has_authority = true;
|
||||
}
|
||||
|
||||
BOOST_URL_RETURN(t);
|
||||
auto const it0 = it;
|
||||
std::size_t dn = 0;
|
||||
if( it != end &&
|
||||
*it != '/')
|
||||
{
|
||||
auto rv = grammar::parse(
|
||||
it, end, segment_rule);
|
||||
if(! rv)
|
||||
return rv.error();
|
||||
if(rv->empty())
|
||||
return t;
|
||||
dn += rv->decoded_size();
|
||||
++t.segment_count;
|
||||
}
|
||||
while(it != end)
|
||||
{
|
||||
if(*it == '/')
|
||||
{
|
||||
++dn;
|
||||
++it;
|
||||
++t.segment_count;
|
||||
continue;
|
||||
}
|
||||
auto rv = grammar::parse(
|
||||
it, end, segment_rule);
|
||||
if(! rv)
|
||||
return rv.error();
|
||||
if(rv->empty())
|
||||
break;
|
||||
dn += rv->decoded_size();
|
||||
}
|
||||
t.path = detail::make_pct_string_view(
|
||||
it0, it - it0, dn);
|
||||
return t;
|
||||
}
|
||||
|
||||
} // detail
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace detail {
|
||||
@ref grammar::parse.
|
||||
*/
|
||||
constexpr auto segment_rule =
|
||||
pct_encoded_rule(grammar::ref(pchars));
|
||||
pct_encoded_rule(pchars);
|
||||
|
||||
//------------------------------------------------
|
||||
|
||||
|
||||
@@ -56,8 +56,8 @@ parse(
|
||||
if(rv->has_authority)
|
||||
u.apply_authority(rv->authority);
|
||||
u.apply_path(
|
||||
rv->path.string(),
|
||||
rv->path.size());
|
||||
rv->path,
|
||||
rv->segment_count);
|
||||
}
|
||||
|
||||
// [ "?" query ]
|
||||
|
||||
@@ -57,8 +57,8 @@ parse(
|
||||
if(rv->has_authority)
|
||||
u.apply_authority(rv->authority);
|
||||
u.apply_path(
|
||||
rv->path.string(),
|
||||
rv->path.size());
|
||||
rv->path,
|
||||
rv->segment_count);
|
||||
}
|
||||
|
||||
// [ "?" query ]
|
||||
|
||||
Reference in New Issue
Block a user