Static Public Member Functions | Public Member Functions | Friends | List of all members
UriComponents Struct Reference

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...
 
UriComponentsoperator= (const UriComponents &)=default
 Assign a URI components instance by copying the supplied instance. More...
 
UriComponentsoperator= (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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ UriComponents() [1/4]

UriComponents ( const Uri uri_)
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.

Parameters
uri_the URI to parse
Exceptions
InvalidUriExceptionif the URI is invalid.

◆ UriComponents() [2/4]

UriComponents ( std::string  uri_)
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.

Parameters
uri_the URI string to parse
Exceptions
InvalidUriExceptionif the URI is invalid.

◆ UriComponents() [3/4]

UriComponents ( const UriComponents )
default

Create a URI components instance by copying the supplied instance.

◆ UriComponents() [4/4]

UriComponents ( UriComponents &&  )
default

Create a URI components instance by moving the contents of the supplied instance.

Member Function Documentation

◆ fragment()

std::string_view fragment ( ) const
inline

Obtain a string view to the fragment.

If there is no fragment in the URI, an empty string will be returned.

Returns
a string view to the fragment

◆ getUri()

const std::string& getUri ( ) const
inline

Get the URI string contained within the URI component structure.

◆ hasAuthority()

bool hasAuthority ( ) const
inline

Returns true if the URI has an authority section.

Returns
true if the URI has an authority section

◆ hasFragment()

bool hasFragment ( ) const
inline

Returns true if the URI has a fragment.

Returns
true if the URI has a fragment

◆ hasHost()

bool hasHost ( ) const
inline

Returns true if the URI has a host entry.

Returns
true if the URI has a host entry

◆ hasPort()

bool hasPort ( ) const
inline

Returns true if the URI has port information.

Returns
true if the URI has port information

◆ hasQuery()

bool hasQuery ( ) const
inline

Returns true if the URI has a query.

Returns
true if the URI has a query

◆ hasUserInfo()

bool hasUserInfo ( ) const
inline

Returns true if the URI has user info.

Returns
true if the URI has user info

◆ host()

std::string_view host ( ) const
inline

Obtain a string view to the host.

If there is no host in the URI, an empty string will be returned.

Returns
a string view to the host

◆ normalizePath()

static std::string normalizePath ( std::string_view  path)
static

Remove instances of "." and "blah/.." and remove any trailing slashes.

Parameters
paththe path to normalize
Returns
the normalized path.

◆ operator=() [1/2]

UriComponents& operator= ( const UriComponents )
default

Assign a URI components instance by copying the supplied instance.

Returns
the current object

◆ operator=() [2/2]

UriComponents& operator= ( UriComponents &&  )
default

Assign a URI components instance by moving the contents of the supplied instance.

Returns
the current object

◆ path()

std::string_view path ( ) const
inline

Obtain a string view to the path.

If the path is empty, an empty string will be returned.

Returns
a string view to the path

◆ pathQueryFragment()

std::string_view pathQueryFragment ( ) const
inline

Obtain a string view to the path-query-fragment.

This is the usual string used in a client request call.

Returns
a string view to the path-query-fragment

◆ port()

unsigned short port ( ) const
inline

Obtain the port.

If there is no port in the URI, zero will be returned.

Returns
the port number or zero if the port was not set.

◆ query()

std::string_view query ( ) const
inline

Obtain a string view to the query.

If there is no query in the URI, an empty string will be returned.

Returns
a string view to the query

◆ scheme()

std::string_view scheme ( ) const
inline

Obtain a string view to the scheme.

Returns
a string view to the scheme

◆ userInfo()

std::string_view userInfo ( ) const
inline

Obtain a string view to the user info.

If there is no userinfo in the URI, an empty string will be returned.

Returns
a string view to the user info

Friends And Related Function Documentation

◆ operator==

bool operator== ( const UriComponents lhs,
const UriComponents rhs 
)
friend

Returns true if the two URI component instances are equal.

This function will not normalise the URIs.

Returns
true if the two URI component instances are equal

The documentation for this struct was generated from the following file: