Skip to content

Commit

Permalink
relative
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Sep 7, 2022
1 parent 8ea85d2 commit 9c40e38
Show file tree
Hide file tree
Showing 7 changed files with 788 additions and 30 deletions.
1 change: 1 addition & 0 deletions doc/qbk/quickref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<member><link linkend="url.ref.boost__urls__parse_relative_ref">parse_relative_ref</link></member>
<member><link linkend="url.ref.boost__urls__parse_uri">parse_uri</link></member>
<member><link linkend="url.ref.boost__urls__parse_uri_reference">parse_uri_reference</link></member>
<member><link linkend="url.ref.boost__urls__relative">relative</link></member>
<member><link linkend="url.ref.boost__urls__resolve">resolve</link></member>
</simplelist>

Expand Down
175 changes: 175 additions & 0 deletions include/boost/url/authority_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,181 @@ class BOOST_SYMBOL_VISIBLE
encoded_host_and_port() const noexcept;

//--------------------------------------------
//
// Comparison
//
//--------------------------------------------

/** Return the result of comparing this with another authority
This function compares two authorities
according to Syntax-Based comparison
algorithm.
@par Exception Safety
Throws nothing.
@return -1 if `*this < other`, 0 if
`this == other`, and 1 if `this > other`.
@par Specification
@li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2"
>6.2.2 Syntax-Based Normalization (rfc3986)</a>
*/
BOOST_URL_DECL
int
compare(authority_view const& other) const noexcept;

/** Return the result of comparing two authorities
The authorities are compared component
by component as if they were first
normalized.
@par Complexity
Linear in `min( a0.size(), a1.size() )`
@par Exception Safety
Throws nothing
*/
friend
bool
operator==(
authority_view const& a0,
authority_view const& a1) noexcept
{
return a0.compare(a1) == 0;
}

/** Return the result of comparing two authorities
The authorities are compared component
by component as if they were first
normalized.
@par Effects
@code
return url( a0 ).normalize() != url( a1 ).normalize();
@endcode
@par Complexity
Linear in `min( a0.size(), a1.size() )`
@par Exception Safety
Throws nothing
*/
friend
bool
operator!=(
authority_view const& a0,
authority_view const& a1) noexcept
{
return ! (a0 == a1);
}

/** Return the result of comparing two authorities
The authorities are compared component
by component as if they were first
normalized.
@par Effects
@code
return url( a0 ).normalize() < url( a1 ).normalize();
@endcode
@par Complexity
Linear in `min( a0.size(), a1.size() )`
@par Exception Safety
Throws nothing
*/
friend
bool
operator<(
authority_view const& a0,
authority_view const& a1) noexcept
{
return a0.compare(a1) < 0;
}

/** Return the result of comparing two authorities
The authorities are compared component
by component as if they were first
normalized.
@par Effects
@code
return url( a0 ).normalize() <= url( a1 ).normalize();
@endcode
@par Complexity
Linear in `min( a0.size(), a1.size() )`
@par Exception Safety
Throws nothing
*/
friend
bool
operator<=(
authority_view const& a0,
authority_view const& a1) noexcept
{
return a0.compare(a1) <= 0;
}

/** Return the result of comparing two authorities
The authorities are compared component
by component as if they were first
normalized.
@par Effects
@code
return url( a0 ).normalize() > url( a1 ).normalize();
@endcode
@par Complexity
Linear in `min( a0.size(), a1.size() )`
@par Exception Safety
Throws nothing
*/
friend
bool
operator>(
authority_view const& a0,
authority_view const& a1) noexcept
{
return a0.compare(a1) > 0;
}

/** Return the result of comparing two authorities
The authorities are compared component
by component as if they were first
normalized.
@par Effects
@code
return url( a0 ).normalize() >= url( a1 ).normalize();
@endcode
@par Complexity
Linear in `min( a0.size(), a1.size() )`
@par Exception Safety
Throws nothing
*/
friend
bool
operator>=(
authority_view const& a0,
authority_view const& a1) noexcept
{
return a0.compare(a1) >= 0;
}

// hidden friend
friend
Expand Down
59 changes: 59 additions & 0 deletions include/boost/url/impl/authority_view.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,65 @@ parse_authority(
return grammar::parse(s, authority_rule);
}

//------------------------------------------------
//
// Comparisons
//
//------------------------------------------------

int
authority_view::
compare(const authority_view& other) const noexcept
{
int comp = has_userinfo() - other.has_userinfo();
if ( comp != 0 )
return comp;

if (has_userinfo())
{
comp = detail::compare_encoded(
encoded_user(),
other.encoded_user());
if ( comp != 0 )
return comp;

comp = has_password() - other.has_password();
if ( comp != 0 )
return comp;

if (has_password())
{
comp = detail::compare_encoded(
encoded_password(),
other.encoded_password());
if ( comp != 0 )
return comp;
}
}

comp = detail::ci_compare_encoded(
encoded_host(),
other.encoded_host());
if ( comp != 0 )
return comp;

comp = has_port() - other.has_port();
if ( comp != 0 )
return comp;

if (has_port())
{
comp = detail::compare(
port(),
other.port());
if ( comp != 0 )
return comp;
}

return 0;
}


} // urls
} // boost

Expand Down
Loading

0 comments on commit 9c40e38

Please sign in to comment.