diff options
Diffstat (limited to 'ingen/URI.hpp')
-rw-r--r-- | ingen/URI.hpp | 114 |
1 files changed, 14 insertions, 100 deletions
diff --git a/ingen/URI.hpp b/ingen/URI.hpp index cbbfd46a..489b6219 100644 --- a/ingen/URI.hpp +++ b/ingen/URI.hpp @@ -19,8 +19,7 @@ #include "ingen/FilePath.hpp" #include "ingen/ingen.h" -#include "serd/serd.h" -#include "sord/sordmm.hpp" +#include "serd/serd.hpp" #include <boost/utility/string_view.hpp> @@ -31,130 +30,45 @@ namespace ingen { -class INGEN_API URI +class INGEN_API URI : public serd::Node { public: - using Chunk = boost::string_view; + using Slice = serd::StringView; - URI(); explicit URI(const std::string& str); explicit URI(const char* str); - URI(const std::string& str, const URI& base); - URI(const Sord::Node& node); - URI(SerdNode node); + URI(const serd::NodeView& node); + URI(const serd::Node& node); explicit URI(const FilePath& path); - URI(const URI& uri); - URI& operator=(const URI& uri); - - URI(URI&& uri) noexcept; - URI& operator=(URI&& uri) noexcept; - - ~URI(); - URI make_relative(const URI& base) const; - bool empty() const { return !_node.buf; } - - std::string string() const { return std::string(c_str(), _node.n_bytes); } - size_t length() const { return _node.n_bytes; } - const char* c_str() const { return (const char*)_node.buf; } + std::string string() const { return std::string(*this); } + std::string str() const { return std::string(*this); } FilePath file_path() const { return scheme() == "file" ? FilePath(path()) : FilePath(); } - operator std::string() const { return string(); } - - const char* begin() const { return (const char*)_node.buf; } - const char* end() const { return (const char*)_node.buf + _node.n_bytes; } - - Chunk scheme() const { return make_chunk(_uri.scheme); } - Chunk authority() const { return make_chunk(_uri.authority); } - Chunk path() const { return make_chunk(_uri.path); } - Chunk query() const { return make_chunk(_uri.query); } - Chunk fragment() const { return make_chunk(_uri.fragment); } + Slice scheme() const { return serd::URI{*this}.scheme(); } + Slice authority() const { return serd::URI{*this}.authority(); } + Slice path() const { return serd::URI{*this}.path(); } + Slice query() const { return serd::URI{*this}.query(); } + Slice fragment() const { return serd::URI{*this}.fragment(); } static bool is_valid(const char* str) { - return serd_uri_string_has_scheme((const uint8_t*)str); + return serd_uri_string_has_scheme(str); } static bool is_valid(const std::string& str) { return is_valid(str.c_str()); } - -private: - URI(SerdNode node, SerdURI uri); - - static Chunk make_chunk(const SerdChunk& chunk) { - return Chunk((const char*)chunk.buf, chunk.len); - } - - SerdURI _uri; - SerdNode _node; }; -inline bool operator==(const URI& lhs, const URI& rhs) -{ - return lhs.string() == rhs.string(); -} - inline bool operator==(const URI& lhs, const std::string& rhs) { - return lhs.string() == rhs; -} - -inline bool operator==(const URI& lhs, const char* rhs) -{ - return lhs.string() == rhs; -} - -inline bool operator==(const URI& lhs, const Sord::Node& rhs) -{ - return rhs.type() == Sord::Node::URI && lhs.string() == rhs.to_string(); -} - -inline bool operator==(const Sord::Node& lhs, const URI& rhs) -{ - return rhs == lhs; -} - -inline bool operator!=(const URI& lhs, const URI& rhs) -{ - return lhs.string() != rhs.string(); -} - -inline bool operator!=(const URI& lhs, const std::string& rhs) -{ - return lhs.string() != rhs; -} - -inline bool operator!=(const URI& lhs, const char* rhs) -{ - return lhs.string() != rhs; -} - -inline bool operator!=(const URI& lhs, const Sord::Node& rhs) -{ - return !(lhs == rhs); -} - -inline bool operator!=(const Sord::Node& lhs, const URI& rhs) -{ - return !(lhs == rhs); -} - -inline bool operator<(const URI& lhs, const URI& rhs) -{ - return lhs.string() < rhs.string(); -} - -template <typename Char, typename Traits> -inline std::basic_ostream<Char, Traits>& -operator<<(std::basic_ostream<Char, Traits>& os, const URI& uri) -{ - return os << uri.string(); + return lhs.c_str() == rhs; } } // namespace ingen |