qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::io::uri Class Reference

Class for parsing, manipulating, and representing URIs. More...

#include <uri.h>

Public Member Functions

 uri ()=default
 Default constructor.
 uri (uri &&rhs) noexcept
 Move constructor.
 uri (uri const &rhs)
 Copy constructor.
 uri (std::string const &str, int af=AF_INET)
 Constructor from a string.
 uri (std::string &&str, int af=AF_INET) noexcept
 Constructor from a string (move version)
urioperator= (uri const &rhs)
 Copy assignment operator.
urioperator= (uri &&rhs) noexcept
 Move assignment operator.
urioperator= (std::string const &str)
 String assignment operator.
urioperator= (std::string &&str) noexcept
 String move assignment operator.
auto af () const
 Returns the address family of this URI.
const auto & source () const
 Returns the source string of this URI.
auto scheme () const
 Returns the scheme of this URI.
auto user_info () const
 Returns the user information of this URI.
auto host () const
 Returns the host name or IP address of this URI.
auto port () const
 Returns the port number of this URI.
uint16_t u_port () const
 Returns the port number of this URI as a numeric value.
auto path () const
 Returns the path of this URI.
const auto & encoded_queries () const
 Returns the raw query string of this URI.
const auto & queries () const
 Returns the parsed query parameters of this URI.
auto & queries ()
 Returns the parsed query parameters of this URI (non-const version)
template<typename T>
std::string const & query (T &&name, std::size_t const index=0, std::string const &not_found="") const
 Returns the value of a specific query parameter.
auto fragment () const
 Returns the fragment of this URI.

Static Public Member Functions

template<typename _IT>
static std::string decode (_IT begin, _IT end) noexcept
 Decodes a sequence of URI-encoded characters.
template<typename _IT>
static std::string encode (_IT begin, _IT end) noexcept
 Encodes a sequence of characters in URI format.
static std::string decode (std::string_view input) noexcept
 Decodes a URI-encoded string view.
static std::string encode (std::string_view input) noexcept
 Encodes a string view in URI format.
static std::string decode (const char *input, std::size_t size) noexcept
 Decodes a URI-encoded memory block.
static std::string encode (const char *input, std::size_t size) noexcept
 Encodes a memory block in URI format.
static uri parse (std::string const &str, int af=AF_INET) noexcept
 Creates and parses a URI from a string.
static bool is_valid_scheme (std::string_view scheme) noexcept
 Validates if a string is a valid URI scheme.
static bool is_valid_host (std::string_view host) noexcept
 Validates if a string is a valid URI host.
static bool normalize_path (std::string &path) noexcept
 Normalizes a path by resolving '.

Static Public Attributes

static const char tbl [256]
 Conversion table for hexadecimal characters Used for decoding XX sequences to characters.
static constexpr const char hex [] = "0123456789ABCDEF"
 Hexadecimal characters for encoding.

Detailed Description

Class for parsing, manipulating, and representing URIs.

This class implements URIs according to RFC 3986 and supports URI components such as scheme, authority (including host and port), path, query, and fragment. It also handles encoding and decoding of special characters and supports IPv4 and IPv6 addressing formats.

Constructor & Destructor Documentation

◆ uri() [1/4]

qb::io::uri::uri ( uri && rhs)
noexcept

Move constructor.

Parameters
rhsSource URI to move from

◆ uri() [2/4]

qb::io::uri::uri ( uri const & rhs)

Copy constructor.

Parameters
rhsSource URI to copy from

◆ uri() [3/4]

qb::io::uri::uri ( std::string const & str,
int af = AF_INET )

Constructor from a string.

Parameters
strThe source string for the URI
afThe address family (defaults to AF_INET)

◆ uri() [4/4]

qb::io::uri::uri ( std::string && str,
int af = AF_INET )
noexcept

Constructor from a string (move version)

Parameters
strThe source string for the URI (will be moved)
afThe address family (defaults to AF_INET)

Member Function Documentation

◆ decode() [1/3]

template<typename _IT>
std::string qb::io::uri::decode ( _IT begin,
_IT end )
inlinestaticnoexcept

Decodes a sequence of URI-encoded characters.

Converts XX sequences to corresponding characters

Template Parameters
_ITIterator type
Parameters
beginBegin iterator
endEnd iterator
Returns
The decoded string

◆ encode() [1/3]

template<typename _IT>
std::string qb::io::uri::encode ( _IT begin,
_IT end )
inlinestaticnoexcept

Encodes a sequence of characters in URI format.

Converts special characters to XX sequences

Template Parameters
_ITIterator type
Parameters
beginBegin iterator
endEnd iterator
Returns
The encoded string

◆ decode() [2/3]

std::string qb::io::uri::decode ( std::string_view input)
staticnoexcept

Decodes a URI-encoded string view.

Parameters
inputThe string view to decode
Returns
The decoded string

◆ encode() [2/3]

std::string qb::io::uri::encode ( std::string_view input)
staticnoexcept

Encodes a string view in URI format.

Parameters
inputThe string view to encode
Returns
The encoded string

◆ decode() [3/3]

std::string qb::io::uri::decode ( const char * input,
std::size_t size )
staticnoexcept

Decodes a URI-encoded memory block.

Parameters
inputPointer to the data to decode
sizeSize of the data
Returns
The decoded string

◆ encode() [3/3]

std::string qb::io::uri::encode ( const char * input,
std::size_t size )
staticnoexcept

Encodes a memory block in URI format.

Parameters
inputPointer to the data to encode
sizeSize of the data
Returns
The encoded string

◆ parse()

uri qb::io::uri::parse ( std::string const & str,
int af = AF_INET )
staticnoexcept

Creates and parses a URI from a string.

Parameters
strThe source string for the URI
afThe address family (defaults to AF_INET)
Returns
A parsed URI instance

◆ operator=() [1/4]

uri & qb::io::uri::operator= ( uri const & rhs)

Copy assignment operator.

Parameters
rhsSource URI to copy from
Returns
Reference to this URI

◆ operator=() [2/4]

uri & qb::io::uri::operator= ( uri && rhs)
noexcept

Move assignment operator.

Parameters
rhsSource URI to move from
Returns
Reference to this URI

◆ operator=() [3/4]

uri & qb::io::uri::operator= ( std::string const & str)

String assignment operator.

Parameters
strThe source string for the URI
Returns
Reference to this URI

◆ operator=() [4/4]

uri & qb::io::uri::operator= ( std::string && str)
noexcept

String move assignment operator.

Parameters
strThe source string for the URI (will be moved)
Returns
Reference to this URI

◆ af()

auto qb::io::uri::af ( ) const
inlinenodiscard

Returns the address family of this URI.

Returns
The address family (AF_INET, AF_INET6, AF_UNIX)

◆ source()

const auto & qb::io::uri::source ( ) const
inlinenodiscard

Returns the source string of this URI.

Returns
The source string

◆ scheme()

auto qb::io::uri::scheme ( ) const
inlinenodiscard

Returns the scheme of this URI.

Returns
The scheme (e.g., http, https, ftp)

◆ user_info()

auto qb::io::uri::user_info ( ) const
inlinenodiscard

Returns the user information of this URI.

Returns
The user information

◆ host()

auto qb::io::uri::host ( ) const
inlinenodiscard

Returns the host name or IP address of this URI.

Returns
The host name or IP address

◆ port()

auto qb::io::uri::port ( ) const
inlinenodiscard

Returns the port number of this URI.

Returns
The port number as a string

◆ u_port()

uint16_t qb::io::uri::u_port ( ) const
inlinenodiscard

Returns the port number of this URI as a numeric value.

Returns
The port number as an unsigned 16-bit integer

◆ path()

auto qb::io::uri::path ( ) const
inlinenodiscard

Returns the path of this URI.

Returns
The path

◆ encoded_queries()

const auto & qb::io::uri::encoded_queries ( ) const
inlinenodiscard

Returns the raw query string of this URI.

Returns
The raw query string

◆ queries() [1/2]

const auto & qb::io::uri::queries ( ) const
inlinenodiscard

Returns the parsed query parameters of this URI.

Returns
The query parameters as a map

◆ queries() [2/2]

auto & qb::io::uri::queries ( )
inlinenodiscard

Returns the parsed query parameters of this URI (non-const version)

Returns
Mutable reference to the query parameters map

◆ query()

template<typename T>
std::string const & qb::io::uri::query ( T && name,
std::size_t const index = 0,
std::string const & not_found = "" ) const
inlinenodiscard

Returns the value of a specific query parameter.

Template Parameters
TParameter name type
Parameters
nameName of the parameter to retrieve
indexIndex of the value to retrieve (for multi-value parameters)
not_foundValue to return if the parameter is not found
Returns
The parameter value or not_found if not found

◆ fragment()

auto qb::io::uri::fragment ( ) const
inlinenodiscard

Returns the fragment of this URI.

Returns
The fragment

◆ is_valid_scheme()

bool qb::io::uri::is_valid_scheme ( std::string_view scheme)
staticnoexcept

Validates if a string is a valid URI scheme.

Parameters
schemeThe scheme to validate
Returns
true if valid, false otherwise

◆ is_valid_host()

bool qb::io::uri::is_valid_host ( std::string_view host)
staticnoexcept

Validates if a string is a valid URI host.

Parameters
hostThe host to validate
Returns
true if valid, false otherwise

◆ normalize_path()

bool qb::io::uri::normalize_path ( std::string & path)
staticnoexcept

Normalizes a path by resolving '.

', '..' segments and standardizing slashes

Parameters
pathPath to normalize (will be modified)
Returns
true if successful, false otherwise