Parses a URI and provides views into the URI's components. More...
#include <UriComponents.hpp>
Static Public Member Functions | |
static std::string | normalizePath (std::string_view path) |
Remove instances of "." and "blah/.." and remove any trailing slashes. More... | |
Public Member Functions | |
UriComponents (const Uri &uri_) | |
Parse the URI into its components. More... | |
UriComponents (std::string uri_) | |
Parse the URI string in the supplied URI into its components. More... | |
UriComponents (const UriComponents &)=default | |
Create a URI components instance by copying the supplied instance. More... | |
UriComponents (UriComponents &&)=default | |
Create a URI components instance by moving the contents of the supplied instance. More... | |
std::string_view | fragment () const |
Obtain a string view to the fragment. More... | |
const std::string & | getUri () const |
Get the URI string contained within the URI component structure. More... | |
bool | hasAuthority () const |
Returns true if the URI has an authority section. More... | |
bool | hasFragment () const |
Returns true if the URI has a fragment. More... | |
bool | hasHost () const |
Returns true if the URI has a host entry. More... | |
bool | hasPort () const |
Returns true if the URI has port information. More... | |
bool | hasQuery () const |
Returns true if the URI has a query. More... | |
bool | hasUserInfo () const |
Returns true if the URI has user info. More... | |
std::string_view | host () const |
Obtain a string view to the host. More... | |
UriComponents & | operator= (const UriComponents &)=default |
Assign a URI components instance by copying the supplied instance. More... | |
UriComponents & | operator= (UriComponents &&)=default |
Assign a URI components instance by moving the contents of the supplied instance. More... | |
std::string_view | path () const |
Obtain a string view to the path. More... | |
std::string_view | pathQueryFragment () const |
Obtain a string view to the path-query-fragment. More... | |
unsigned short | port () const |
Obtain the port. More... | |
std::string_view | query () const |
Obtain a string view to the query. More... | |
std::string_view | scheme () const |
Obtain a string view to the scheme. More... | |
std::string_view | userInfo () const |
Obtain a string view to the user info. More... | |
Friends | |
bool | operator== (const UriComponents &lhs, const UriComponents &rhs) |
Returns true if the two URI component instances are equal. More... | |
Parses a URI and provides views into the URI's components.
A URI has the following syntax:
URI = scheme:[//authority]path[?query][#fragment]
where the authority component divides into three sub-components:
authority = [userinfo@]host[:port]
A constructed UriComponents structure contains indices indicating the start offsets of each component in the parsed URI string. These are used to create string views into the internal URI string. The UriComponents instance also contains the parsed port if one was included in the URI.
The parsing of the URI in the constructor performs some initial validation in order to ensure that the URI is well formed, but, with the exception of the scheme and port, does not perform full validation of each URI component. Such full validation should be performed by the consuming application.
Note that deprecated userinfo passwords are not supported in this URI parser. Hence attempting to parse a URI with the form scheme://usr:pw@example.com will result in an InvalidUriException being thrown.
|
explicit |
Parse the URI into its components.
The parsing performs some initial validation in order to ensure that the URI is well formed, but, with the exception of the scheme and port, does not perform full validation of each component. Such full validation should be performed by the consuming application.
uri_ | the URI to parse |
InvalidUriException | if the URI is invalid. |
|
explicit |
Parse the URI string in the supplied URI into its components.
The parsing performs some initial validation in order to ensure that the URI is well formed, but, with the exception of the scheme and port, does not perform full validation of each component. Such full validation should be performed by the consuming application.
uri_ | the URI string to parse |
InvalidUriException | if the URI is invalid. |
|
default |
Create a URI components instance by copying the supplied instance.
|
default |
Create a URI components instance by moving the contents of the supplied instance.
|
inline |
Obtain a string view to the fragment.
If there is no fragment in the URI, an empty string will be returned.
|
inline |
Get the URI string contained within the URI component structure.
|
inline |
Returns true if the URI has an authority section.
|
inline |
Returns true if the URI has a fragment.
|
inline |
Returns true if the URI has a host entry.
|
inline |
Returns true if the URI has port information.
|
inline |
Returns true if the URI has a query.
|
inline |
Returns true if the URI has user info.
|
inline |
Obtain a string view to the host.
If there is no host in the URI, an empty string will be returned.
|
static |
Remove instances of "." and "blah/.." and remove any trailing slashes.
path | the path to normalize |
|
default |
Assign a URI components instance by copying the supplied instance.
|
default |
Assign a URI components instance by moving the contents of the supplied instance.
|
inline |
Obtain a string view to the path.
If the path is empty, an empty string will be returned.
|
inline |
Obtain a string view to the path-query-fragment.
This is the usual string used in a client request call.
|
inline |
Obtain the port.
If there is no port in the URI, zero will be returned.
|
inline |
Obtain a string view to the query.
If there is no query in the URI, an empty string will be returned.
|
inline |
Obtain a string view to the scheme.
|
inline |
Obtain a string view to the user info.
If there is no userinfo in the URI, an empty string will be returned.
|
friend |
Returns true if the two URI component instances are equal.
This function will not normalise the URIs.