2
0
mirror of https://github.com/boostorg/url.git synced 2026-02-14 01:02:17 +00:00

Add set_path_absolute

This commit is contained in:
Vinnie Falco
2021-10-15 09:07:35 -07:00
parent f9adf6db31
commit dabdc5ff33
5 changed files with 140 additions and 2 deletions

View File

@@ -1139,6 +1139,14 @@ edit_segments(
detail::any_path_iter&& it1,
int abs_hint)
{
if(abs_hint == -1)
{
if(get(id_path).starts_with('/'))
abs_hint = 1;
else
abs_hint = 0;
}
// measure
error_code ec;
std::size_t n = 0;
@@ -1254,6 +1262,46 @@ edit_segments(
//------------------------------------------------
bool
url::
set_path_absolute(bool absolute)
{
if(len(id_path) == 0)
{
if(! absolute)
return true;
auto dest = resize_impl(
id_path, 1);
*dest = '/';
// VFALCO Update table
return true;
}
if(s_[offset(id_path)] == '/')
{
if(absolute)
return true;
if( has_authority() &&
len(id_path) > 1)
return false;
auto n = len(id_port);
split(id_port, n + 1);
resize_impl(id_port, n);
// VFALCO Update table
return true;
}
if(! absolute)
return true;
auto n = len(id_port);
auto dest = resize_impl(
id_port, n + 1) + n;
split(id_port, n);
*dest = '/';
// VFALCO Update table
return true;
}
url&
url::
set_encoded_path(

View File

@@ -75,7 +75,7 @@ split(
std::size_t n) noexcept
{
BOOST_ASSERT(id < id_end - 1);
BOOST_ASSERT(n <= len(id));
//BOOST_ASSERT(n <= len(id));
offset_[id + 1] = offset(id) + n;
}

View File

@@ -898,6 +898,17 @@ private:
int abs_hint = -1);
public:
/** Set whether the path is absolute.
This modifies the path as needed to
make it absolute or relative.
@return true on success.
*/
BOOST_URL_DECL
bool
set_path_absolute(bool absolute);
/** Set the path.
This function validates the given percent-encoded