// Copyright (c) 2014-2018 Thomas Fussell // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE // // @license: http://www.opensource.org/licenses/mit-license.php // @author: see AUTHORS file #pragma once #include #include #include namespace xlnt { /// /// Encapsulates a uniform resource identifier (URI) as described /// by RFC 3986. /// class XLNT_API uri { public: /// /// Constructs an empty URI. /// uri(); /// /// Constructs a URI by combining base with relative. /// uri(const uri &base, const uri &relative); /// /// Constructs a URI by combining base with relative path. /// uri(const uri &base, const path &relative); /// /// Constructs a URI by parsing the given uri_string. /// uri(const std::string &uri_string); /// /// Returns true if this URI is relative. /// bool is_relative() const; /// /// Returns true if this URI is not relative (i.e. absolute). /// bool is_absolute() const; /// /// Returns the scheme of this URI. /// E.g. the scheme of http://user:pass@example.com is "http" /// std::string scheme() const; /// /// Returns the authority of this URI. /// E.g. the authority of http://user:pass@example.com:80/document is "user:pass@example.com:80" /// std::string authority() const; /// /// Returns true if an authentication section is specified for this URI. /// bool has_authentication() const; /// /// Returns the authentication of this URI. /// E.g. the authentication of http://user:pass@example.com is "user:pass" /// std::string authentication() const; /// /// Returns the username of this URI. /// E.g. the username of http://user:pass@example.com is "user" /// std::string username() const; /// /// Returns the password of this URI. /// E.g. the password of http://user:pass@example.com is "pass" /// std::string password() const; /// /// Returns the host of this URI. /// E.g. the host of http://example.com:80/document is "example.com" /// std::string host() const; /// /// Returns true if a non-default port is specified for this URI. /// bool has_port() const; /// /// Returns the port of this URI. /// E.g. the port of https://example.com:443/document is "443" /// std::size_t port() const; /// /// Returns the path of this URI. /// E.g. the path of http://example.com/document is "/document" /// class path path() const; /// /// Returns true if this URI has a non-null query string section. /// bool has_query() const; /// /// Returns the query string of this URI. /// E.g. the query of http://example.com/document?v=1&x=3#abc is "v=1&x=3" /// std::string query() const; /// /// Returns true if this URI has a non-empty fragment section. /// bool has_fragment() const; /// /// Returns the fragment section of this URI. /// E.g. the fragment of http://example.com/document#abc is "abc" /// std::string fragment() const; /// /// Returns a string representation of this URI. /// std::string to_string() const; /// /// If this URI is relative, an absolute URI will be returned by appending /// the path to the given absolute base URI. /// uri make_absolute(const uri &base); /// /// If this URI is absolute, a relative URI will be returned by removing the /// common base path from the given absolute base URI. /// uri make_reference(const uri &base); /// /// Returns true if this URI is equivalent to other. /// bool operator==(const uri &other) const; private: /// /// True if this URI is absolute. /// bool absolute_ = false; /// /// The scheme, like "http" /// std::string scheme_; /// /// True if this URI has an authentication section. /// bool has_authentication_ = false; /// /// The username /// std::string username_; /// /// The password /// std::string password_; /// /// The host /// std::string host_; /// /// True if this URI has a non-default port specified /// bool has_port_ = false; /// /// The numeric port /// std::size_t port_ = 0; /// /// True if this URI has a query section /// bool has_query_ = false; /// /// The query section /// std::string query_; /// /// True if this URI has a fragment section /// bool has_fragment_ = false; /// /// The fragment section /// std::string fragment_; /// /// The path section /// class path path_; }; } // namespace xlnt