Skip to content

Commit

Permalink
setting path bypasses edit_segments
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Mar 10, 2023
1 parent e549f40 commit a057fab
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 283 deletions.
41 changes: 0 additions & 41 deletions include/boost/url/detail/any_segments_iter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,47 +71,6 @@ struct BOOST_SYMBOL_VISIBLE
char const* end) noexcept = 0;
};

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

// iterates segments in a string
struct BOOST_SYMBOL_VISIBLE
path_iter
: any_segments_iter
{
virtual ~path_iter() = default;

explicit
path_iter(
string_view s) noexcept;

protected:
std::size_t pos_;
std::size_t next_;

void increment() noexcept;
void rewind() noexcept override;
bool measure(std::size_t&) noexcept override;
void copy(char*&, char const*) noexcept override;
};

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

// iterates segments in an encoded string
struct BOOST_SYMBOL_VISIBLE
path_encoded_iter
: public path_iter
{
virtual ~path_encoded_iter() = default;

explicit
path_encoded_iter(
pct_string_view s) noexcept;

private:
bool measure(std::size_t&) noexcept override;
void copy(char*&, char const*) noexcept override;
};

//------------------------------------------------
//
// segment_iter
Expand Down
188 changes: 0 additions & 188 deletions include/boost/url/detail/impl/any_segments_iter.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -19,194 +19,6 @@ namespace boost {
namespace urls {
namespace detail {

//------------------------------------------------
//
// path_iter
//
//------------------------------------------------

path_iter::
path_iter(
string_view s_) noexcept
: any_segments_iter(s_)
{
rewind();
}

void
path_iter::
increment() noexcept
{
pos_ = next_;
if(pos_ == s.size())
{
pos_ = string_view::npos;
return;
}
// skip '/'
++pos_;
auto const end =
s.data() + s.size();
auto const p0 =
s.data() + pos_;
auto p = p0;
while(p != end)
{
if(*p == '/')
{
next_ = p - s.data();
return;
}
++p;
}
next_ = s.size();
}

void
path_iter::
rewind() noexcept
{
pos_ = 0;
auto p0 = s.data();
auto const end = p0 + s.size();
if(p0 != end)
{
fast_nseg = 1;
// skip leading '/'
// of absolute-path
if(*p0 == '/')
{
++p0;
++pos_;
if (p0 == end)
{
fast_nseg = 0;
pos_ = string_view::npos;
}
}
auto p = p0;
while(p != end)
{
if(*p == '/')
{
++fast_nseg;
break;
}
++p;
}
front = string_view(
p0, p - p0);
next_ = p - s.data();
}
else
{
pos_ = string_view::npos;
front = { p0, 0 };
fast_nseg = 0;
}
}

bool
path_iter::
measure(
std::size_t& n) noexcept
{
if(pos_ == string_view::npos)
return false;
encoding_opts opt;
opt.space_as_plus = false;
n += encoded_size(
s.substr(
pos_,
next_ - pos_),
encode_colons ?
nocolon_pchars :
pchars,
opt);
increment();
return true;
}

void
path_iter::
copy(
char*& dest,
char const* end) noexcept
{
BOOST_ASSERT(pos_ !=
string_view::npos);
encoding_opts opt;
opt.space_as_plus = false;
dest += encode(
dest,
end - dest,
s.substr(
pos_,
next_ - pos_),
encode_colons ?
nocolon_pchars :
pchars,
opt);
increment();
}

//------------------------------------------------
//
// path_encoded_iter
//
//------------------------------------------------

path_encoded_iter::
path_encoded_iter(
pct_string_view s) noexcept
: path_iter(s)
{
}

bool
path_encoded_iter::
measure(
std::size_t& n) noexcept
{
if(pos_ == string_view::npos)
return false;
encoding_opts opt;
opt.space_as_plus = false;
n += detail::re_encoded_size_unsafe(
s.substr(
pos_,
next_ - pos_),
encode_colons ?
nocolon_pchars :
pchars,
opt);
increment();
return true;
}

void
path_encoded_iter::
copy(
char*& dest,
char const* end) noexcept
{
BOOST_ASSERT(pos_ !=
string_view::npos);
encoding_opts opt;
opt.space_as_plus = false;
detail::re_encode_unsafe(
dest,
end,
s.substr(
pos_,
next_ - pos_),
encode_colons ?
nocolon_pchars :
pchars,
opt);
increment();
}

//------------------------------------------------
//
// segment_iter
Expand Down
Loading

0 comments on commit a057fab

Please sign in to comment.