Skip to content

Commit

Permalink
Use parsed_path
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Sep 13, 2021
1 parent 3d4fb62 commit fdef641
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 78 deletions.
9 changes: 4 additions & 5 deletions include/boost/url/detail/impl/parse.ipp
Expand Up @@ -134,14 +134,13 @@ apply(
}

void
apply_path(
apply(
parts& p,
string_view path,
std::size_t path_count) noexcept
parsed_path const& t) noexcept
{
p.resize(part::id_path,
path.size());
p.nseg = path_count;
t.path.size());
p.nseg = t.count;
}

void
Expand Down
11 changes: 4 additions & 7 deletions include/boost/url/detail/parse.hpp
Expand Up @@ -11,13 +11,11 @@
#define BOOST_URL_DETAIL_PARSE_HPP

#include <boost/url/detail/parts.hpp>
#include <boost/url/bnf/range.hpp>
#include <boost/url/rfc/authority_bnf.hpp>
#include <boost/url/rfc/fragment_part_bnf.hpp>
#include <boost/url/rfc/host_bnf.hpp>
#include <boost/url/rfc/paths_bnf.hpp>
#include <boost/url/rfc/pct_encoded_bnf.hpp>
#include <boost/url/rfc/detail/query_params_bnf.hpp>

#include <boost/url/rfc/fragment_part_bnf.hpp>
#include <boost/url/rfc/query_part_bnf.hpp>
#include <boost/url/rfc/scheme_part_bnf.hpp>

Expand All @@ -41,10 +39,9 @@ apply(
authority_bnf const& t) noexcept;

void
apply_path(
apply(
parts& p,
string_view path,
std::size_t path_count) noexcept;
parsed_path const& path) noexcept;

void
apply(
Expand Down
20 changes: 8 additions & 12 deletions include/boost/url/impl/path_view.ipp
Expand Up @@ -168,13 +168,12 @@ parse_path_abempty(
error_code& ec) noexcept
{
using bnf::parse_string;
bnf::range<
pct_encoded_str> t;
parsed_path t;
if(! parse_string(s, ec,
path_abempty_bnf{t}))
return {};
return path_view(
t.str(), t.size());
t.path, t.count);
}

path_view
Expand All @@ -194,13 +193,12 @@ parse_path_absolute(
error_code& ec) noexcept
{
using bnf::parse_string;
bnf::range<
pct_encoded_str> t;
parsed_path t;
if(! parse_string(s, ec,
path_absolute_bnf{t}))
return {};
return path_view(
t.str(), t.size());
t.path, t.count);
}

path_view
Expand All @@ -220,13 +218,12 @@ parse_path_noscheme(
error_code& ec) noexcept
{
using bnf::parse_string;
bnf::range<
pct_encoded_str> t;
parsed_path t;
if(! parse_string(s, ec,
path_noscheme_bnf{t}))
return {};
return path_view(
t.str(), t.size());
t.path, t.count);
}

path_view
Expand All @@ -246,13 +243,12 @@ parse_path_rootless(
error_code& ec) noexcept
{
using bnf::parse_string;
bnf::range<
pct_encoded_str> t;
parsed_path t;
if(! parse_string(s, ec,
path_rootless_bnf{t}))
return {};
return path_view(
t.str(), t.size());
t.path, t.count);
}

path_view
Expand Down
9 changes: 3 additions & 6 deletions include/boost/url/impl/url_view.ipp
Expand Up @@ -504,9 +504,7 @@ parse_uri(
t.hier_part.authority);

// path
detail::apply_path(p,
t.hier_part.path,
t.hier_part.path_count);
detail::apply(p, t.hier_part.path);

// query
detail::apply(p, t.query_part);
Expand Down Expand Up @@ -546,9 +544,8 @@ parse_relative_ref(
t.relative_part.authority);

// path
detail::apply_path(p,
t.relative_part.path,
t.relative_part.path_count);
detail::apply(p,
t.relative_part.path);

// query
detail::apply(p, t.query_part);
Expand Down
4 changes: 2 additions & 2 deletions include/boost/url/rfc/hier_part_bnf.hpp
Expand Up @@ -13,6 +13,7 @@
#include <boost/url/detail/config.hpp>
#include <boost/url/error.hpp>
#include <boost/url/rfc/authority_bnf.hpp>
#include <boost/url/rfc/paths_bnf.hpp>

namespace boost {
namespace urls {
Expand All @@ -34,8 +35,7 @@ struct hier_part_bnf
{
bool has_authority = false;
authority_bnf authority;
string_view path;
std::size_t path_count = 0;
parsed_path path;

BOOST_URL_DECL
friend
Expand Down
17 changes: 6 additions & 11 deletions include/boost/url/rfc/impl/hier_part_bnf.ipp
Expand Up @@ -29,20 +29,17 @@ parse(
{
// path-empty
t.path = {};
t.path_count = 0;
t.has_authority = false;
ec = {};
return true;
}
bnf::range<pct_encoded_str> r;
if(it[0] != '/')
{
// path-rootless
if(! parse(it, end, ec,
path_rootless_bnf{r}))
path_rootless_bnf{
t.path}))
return false;
t.path = r.str();
t.path_count = r.size();
t.has_authority = false;
return true;
}
Expand All @@ -51,10 +48,9 @@ parse(
{
// path-absolute
if(! parse(it, end, ec,
path_absolute_bnf{r}))
path_absolute_bnf{
t.path}))
return false;
t.path = r.str();
t.path_count = r.size();
t.has_authority = false;
return true;
}
Expand All @@ -66,10 +62,9 @@ parse(
return false;
// path-abempty
if(! parse(it, end, ec,
path_abempty_bnf{r}))
path_abempty_bnf{
t.path}))
return false;
t.path = r.str();
t.path_count = r.size();
t.has_authority = true;
return true;
}
Expand Down
36 changes: 28 additions & 8 deletions include/boost/url/rfc/impl/paths_bnf.ipp
Expand Up @@ -122,8 +122,13 @@ parse(
error_code& ec,
path_abempty_bnf const& t)
{
return bnf::parse_range(
it, end, ec, t.v, t);
bnf::range<pct_encoded_str> r;
if(! bnf::parse_range(
it, end, ec, r, t))
return false;
t.v.path = r.str();
t.v.count = r.size();
return true;
}

//------------------------------------------------
Expand Down Expand Up @@ -187,8 +192,13 @@ parse(
error_code& ec,
path_absolute_bnf const& t)
{
return bnf::parse_range(
it, end, ec, t.v, t);
bnf::range<pct_encoded_str> r;
if(! bnf::parse_range(
it, end, ec, r, t))
return false;
t.v.path = r.str();
t.v.count = r.size();
return true;
}

//------------------------------------------------
Expand Down Expand Up @@ -235,8 +245,13 @@ parse(
error_code& ec,
path_noscheme_bnf const& t)
{
return bnf::parse_range(
it, end, ec, t.v, t);
bnf::range<pct_encoded_str> r;
if(! bnf::parse_range(
it, end, ec, r, t))
return false;
t.v.path = r.str();
t.v.count = r.size();
return true;
}

//------------------------------------------------
Expand Down Expand Up @@ -279,8 +294,13 @@ parse(
error_code& ec,
path_rootless_bnf const& t)
{
return bnf::parse_range(
it, end, ec, t.v, t);
bnf::range<pct_encoded_str> r;
if(! bnf::parse_range(
it, end, ec, r, t))
return false;
t.v.path = r.str();
t.v.count = r.size();
return true;
}

} // urls
Expand Down
19 changes: 8 additions & 11 deletions include/boost/url/rfc/impl/relative_part_bnf.ipp
Expand Up @@ -30,31 +30,28 @@ parse(
// path-empty
ec = {};
t.path = {};
t.path_count = 0;
t.has_authority = false;
return true;
}
bnf::range<pct_encoded_str> r;
if(it[0] != '/')
{
// path-noscheme
if(! parse(it, end, ec,
path_noscheme_bnf{r}))
path_noscheme_bnf{
t.path}))
return false;
t.path = r.str();
t.path_count = r.size();
t.has_authority = false;
return true;
}
if( end - it == 1 ||
it[1] != '/')
{
// path-absolute
parsed_path t0;
if(! parse(it, end, ec,
path_absolute_bnf{r}))
path_absolute_bnf{
t.path}))
return false;
t.path = r.str();
t.path_count = r.size();
t.has_authority = false;
return true;
}
Expand All @@ -63,11 +60,11 @@ parse(
if(! parse(it, end, ec,
t.authority))
return false;
parsed_path t0;
if(! parse(it, end, ec,
path_abempty_bnf{r}))
path_abempty_bnf{
t.path}))
return false;
t.path = r.str();
t.path_count = r.size();
t.has_authority = true;
return true;
}
Expand Down
29 changes: 20 additions & 9 deletions include/boost/url/rfc/paths_bnf.hpp
Expand Up @@ -12,12 +12,27 @@

#include <boost/url/detail/config.hpp>
#include <boost/url/error.hpp>
#include <boost/url/bnf/range.hpp>
#include <boost/url/pct_encoding_types.hpp>
#include <cstddef>

namespace boost {
namespace urls {

/** Information about a parsed path
*/
struct parsed_path
{
/** The encoded string representing the path
*/
string_view path;

/** The number of segments in the path
*/
std::size_t count = 0;
};

//------------------------------------------------

struct segment_bnf
{
pct_encoded_str& v;
Expand Down Expand Up @@ -69,8 +84,7 @@ struct segment_nz_nc_bnf
// path-abempty = *( "/" segment )
struct path_abempty_bnf
{
bnf::range<
pct_encoded_str>& v;
parsed_path& v;

BOOST_URL_DECL
static
Expand Down Expand Up @@ -105,8 +119,7 @@ struct path_abempty_bnf
// path-absolute = "/" [ segment-nz *( "/" segment ) ]
struct path_absolute_bnf
{
bnf::range<
pct_encoded_str>& v;
parsed_path& v;

BOOST_URL_DECL
static
Expand Down Expand Up @@ -141,8 +154,7 @@ struct path_absolute_bnf
// path-noscheme = segment-nz-nc *( "/" segment )
struct path_noscheme_bnf
{
bnf::range<
pct_encoded_str>& v;
parsed_path& v;

BOOST_URL_DECL
static
Expand Down Expand Up @@ -177,8 +189,7 @@ struct path_noscheme_bnf
// path-rootless = segment-nz *( "/" segment )
struct path_rootless_bnf
{
bnf::range<
pct_encoded_str>& v;
parsed_path& v;

BOOST_URL_DECL
static
Expand Down

0 comments on commit fdef641

Please sign in to comment.