Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use character-by-character comparison for comparison operators #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/network/uri/uri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ class uri {
*/
std::u32string u32string() const;

/**
* \brief Returns the URI as a string_view object.
* \returns A URI string view.
*/
string_view view() const noexcept;

/**
* \brief Checks if the uri object is empty, i.e. it has no parts.
* \returns \c true if there are no parts, \c false otherwise.
Expand Down
15 changes: 8 additions & 7 deletions src/uri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ std::u32string uri::u32string() const {
return std::u32string(std::begin(*this), std::end(*this));
}

uri::string_view uri::view() const noexcept {
return uri_view_;
}

bool uri::empty() const noexcept { return uri_.empty(); }

bool uri::is_absolute() const noexcept { return has_scheme(); }
Expand Down Expand Up @@ -685,18 +689,15 @@ bool uri::initialize(const string_type &uri) {
void swap(uri &lhs, uri &rhs) noexcept { lhs.swap(rhs); }

bool operator==(const uri &lhs, const uri &rhs) noexcept {
return lhs.compare(rhs, uri_comparison_level::syntax_based) == 0;
return lhs.view() == rhs.view();
}

bool operator==(const uri &lhs, const char *rhs) noexcept {
if (std::strlen(rhs) !=
std::size_t(std::distance(std::begin(lhs), std::end(lhs)))) {
return false;
}
return std::equal(std::begin(lhs), std::end(lhs), rhs);
return lhs.view() == string_view{rhs};
}

bool operator<(const uri &lhs, const uri &rhs) noexcept {
return lhs.compare(rhs, uri_comparison_level::syntax_based) < 0;
return lhs.view() < rhs.view();
}

} // namespace network