Commit 11c8986e authored by Dominik Charousset's avatar Dominik Charousset

Add function to get an URI with the authority only

parent fb2c9831
......@@ -109,6 +109,11 @@ public:
/// Returns a hash code over all components.
size_t hash_code() const noexcept;
/// Returns a new URI with the `authority` component only.
/// @returns A new URI in the form `scheme://authority` if the authority
/// exists, otherwise `none`.`
optional<uri> authority_only() const;
// -- comparison -------------------------------------------------------------
int compare(const uri& other) const noexcept;
......
......@@ -28,6 +28,7 @@
#include "caf/error.hpp"
#include "caf/expected.hpp"
#include "caf/make_counted.hpp"
#include "caf/optional.hpp"
#include "caf/serializer.hpp"
namespace caf {
......@@ -72,6 +73,19 @@ size_t uri::hash_code() const noexcept {
return detail::fnv_hash(str());
}
optional<uri> uri::authority_only() const {
if (empty() || authority().empty())
return none;
auto result = make_counted<detail::uri_impl>();
result->scheme = impl_->scheme;
result->authority = impl_->authority;
auto& str = result->str;
str = impl_->scheme;
str += "://";
str += to_string(impl_->authority);
return uri{std::move(result)};
}
// -- comparison ---------------------------------------------------------------
int uri::compare(const uri& other) const noexcept {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment