#pragma once #include #include #include #include namespace jvalidate { class URI { private: std::string uri_; std::string_view resource_; std::string_view scheme_; public: URI() = default; explicit URI(std::string_view uri) : uri_(uri), resource_(uri_) { if (uri_.back() == '#') { uri_.pop_back(); } if (size_t n = uri_.find("://"); n != std::string::npos) { scheme_ = {uri_.c_str(), n}; resource_.remove_prefix(n + 3); } } URI parent() const { return URI(std::string_view(uri_).substr(0, uri_.rfind('/'))); } URI operator/(URI const & relative) const { return URI(uri_ + relative.uri_); } std::string_view scheme() const { return scheme_; } std::string_view resource() const { return resource_; } explicit operator std::string const &() const { return uri_; } bool empty() const { return uri_.empty(); } friend std::ostream & operator<<(std::ostream & os, URI const & self) { return os << self.uri_; } auto operator<=>(URI const & lhs) const = default; }; }