VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::UrlParser Class Referencefinal

Immutable RFC-3986 URL parser. More...

#include <url_parser.h>

Collaboration diagram for vlink::UrlParser:

Public Types

enum class  Category : uint8_t { kHierarchical = 0 , kNonHierarchical = 1 }
 Distinguishes hierarchical and non-hierarchical URL forms. More...
enum class  Component : uint8_t {
  kTransport = 0 , kContent = 1 , kUsername = 2 , kPassword = 3 ,
  kHost = 4 , kPort = 5 , kPath = 6 , kQuery = 7 ,
  kFragment = 8
}
 Identifies individual URL components for the components-map constructor. More...
enum class  Separator : uint8_t { kAmpersand = 0 , kSemicolon = 1 }
 Query-string key-value pair delimiter. More...

Public Member Functions

 UrlParser (const char *str, Category category=Category::kHierarchical, Separator separator=Separator::kAmpersand)
 Constructs a parser by parsing the given C-string URL.
 UrlParser (const std::string &str, Category category=Category::kHierarchical, Separator separator=Separator::kAmpersand)
 Constructs a parser by parsing the given std::string URL.
 UrlParser (const std::map< Component, std::string > &components, Category category, bool rooted, Separator separator=Separator::kAmpersand)
 Constructs a URL from an explicit component map.
 UrlParser (const UrlParser &other, const std::map< Component, std::string > &replacements)
 Constructs a parser by copying other and overriding specific components.
const std::string & get_transport () const
 Returns the transport string parsed from the URL (e.g. "dds", "intra").
Category get_category () const
 Returns the URL category (hierarchical or non-hierarchical).
const std::string & get_content () const
 Returns the full content portion of the URL (after the scheme separator).
const std::string & get_username () const
 Returns the authentication username component.
const std::string & get_password () const
 Returns the authentication password component.
const std::string & get_host () const
 Returns the host component (hostname or IP address).
int64_t get_port () const
 Returns the port number, or 0 if no port was specified.
const std::string & get_path () const
 Returns the path component of the URL.
const std::string & get_query () const
 Returns the raw query string (without the leading ? character).
const std::map< std::string, std::string > & get_query_dictionary () const
 Returns the parsed query string as a key-value dictionary.
const std::string & get_fragment () const
 Returns the fragment identifier component (without the leading #).
std::string to_string () const
 Reconstructs the URL as a canonical string from parsed components.

Detailed Description

Immutable RFC-3986 URL parser.

Parses the input URL string once at construction time. All accessor methods are const and return references to internally stored strings; the lifetime of the returned references is tied to the lifetime of the UrlParser object.

Member Enumeration Documentation

◆ Category

enum class vlink::UrlParser::Category : uint8_t
strong

Distinguishes hierarchical and non-hierarchical URL forms.

Enumerator
kHierarchical 

Standard scheme://authority/path form (most VLink transports).

kNonHierarchical 

Opaque scheme:content form (e.g. mailto:).

◆ Component

enum class vlink::UrlParser::Component : uint8_t
strong

Identifies individual URL components for the components-map constructor.

Enumerator
kTransport 

URI scheme / VLink transport prefix (e.g. dds, intra).

kContent 

Full content string after the scheme separator.

kUsername 

Optional authentication username.

kPassword 

Optional authentication password.

kHost 

Hostname or IP address.

kPort 

Port number (stored as string in the components map).

kPath 

Resource path (e.g. /vehicle/speed).

kQuery 

Raw query string (without the leading ?).

kFragment 

Fragment identifier (without the leading #).

◆ Separator

enum class vlink::UrlParser::Separator : uint8_t
strong

Query-string key-value pair delimiter.

Enumerator
kAmpersand 

& separator (default; key=val&key2=val2).

kSemicolon 

; separator (alternative; key=val;key2=val2).

Constructor & Destructor Documentation

◆ UrlParser() [1/4]

vlink::UrlParser::UrlParser ( const char * str,
Category category = Category::kHierarchical,
Separator separator = Separator::kAmpersand )
explicit

Constructs a parser by parsing the given C-string URL.

Parameters
strNull-terminated URL string to parse.
categoryHierarchical or non-hierarchical form; default hierarchical.
separatorQuery key-value delimiter; default ampersand (&).
Here is the caller graph for this function:

◆ UrlParser() [2/4]

vlink::UrlParser::UrlParser ( const std::string & str,
Category category = Category::kHierarchical,
Separator separator = Separator::kAmpersand )
explicit

Constructs a parser by parsing the given std::string URL.

Parameters
strURL string to parse.
categoryHierarchical or non-hierarchical form; default hierarchical.
separatorQuery key-value delimiter; default ampersand (&).

◆ UrlParser() [3/4]

vlink::UrlParser::UrlParser ( const std::map< Component, std::string > & components,
Category category,
bool rooted,
Separator separator = Separator::kAmpersand )
explicit

Constructs a URL from an explicit component map.

Builds the internal state from a pre-decomposed set of components rather than parsing a raw URL string. Useful when constructing a modified URL from an existing UrlParser instance.

Parameters
componentsMap of Component to string value for each component present.
categoryHierarchical or non-hierarchical form.
rootedtrue if the path begins with / (hierarchical URLs only).
separatorQuery key-value delimiter; default ampersand.

◆ UrlParser() [4/4]

vlink::UrlParser::UrlParser ( const UrlParser & other,
const std::map< Component, std::string > & replacements )
explicit

Constructs a parser by copying other and overriding specific components.

Copies all components from other, then replaces those present in replacements. Equivalent to creating a modified copy of an existing URL.

Parameters
otherSource UrlParser to copy from.
replacementsComponents to override in the copy.
Here is the call graph for this function:

Member Function Documentation

◆ get_category()

Category vlink::UrlParser::get_category ( ) const
nodiscard

Returns the URL category (hierarchical or non-hierarchical).

Returns
The Category value supplied at construction.

◆ get_content()

const std::string & vlink::UrlParser::get_content ( ) const
nodiscard

Returns the full content portion of the URL (after the scheme separator).

Returns
Reference to the parsed content string; empty if not present.

◆ get_fragment()

const std::string & vlink::UrlParser::get_fragment ( ) const
nodiscard

Returns the fragment identifier component (without the leading #).

Returns
Reference to the parsed fragment; empty if not present.

◆ get_host()

const std::string & vlink::UrlParser::get_host ( ) const
nodiscard

Returns the host component (hostname or IP address).

Returns
Reference to the parsed host string; empty if not present.

◆ get_password()

const std::string & vlink::UrlParser::get_password ( ) const
nodiscard

Returns the authentication password component.

Returns
Reference to the parsed password; empty if not present.

◆ get_path()

const std::string & vlink::UrlParser::get_path ( ) const
nodiscard

Returns the path component of the URL.

Returns
Reference to the parsed path string; empty if not present.

◆ get_port()

int64_t vlink::UrlParser::get_port ( ) const
nodiscard

Returns the port number, or 0 if no port was specified.

Returns
Parsed port as int64_t; 0 if absent.

◆ get_query()

const std::string & vlink::UrlParser::get_query ( ) const
nodiscard

Returns the raw query string (without the leading ? character).

Returns
Reference to the raw query; empty if no query was present.

◆ get_query_dictionary()

const std::map< std::string, std::string > & vlink::UrlParser::get_query_dictionary ( ) const
nodiscard

Returns the parsed query string as a key-value dictionary.

Built by splitting the raw query on the configured Separator and then splitting each token on the first = character. Keys without a = are stored with an empty-string value.

Returns
Reference to the std::map<string,string> query dictionary.

◆ get_transport()

const std::string & vlink::UrlParser::get_transport ( ) const
nodiscard

Returns the transport string parsed from the URL (e.g. "dds", "intra").

Returns
Reference to the parsed transport component; empty if not present.

◆ get_username()

const std::string & vlink::UrlParser::get_username ( ) const
nodiscard

Returns the authentication username component.

Returns
Reference to the parsed username; empty if not present.

◆ to_string()

std::string vlink::UrlParser::to_string ( ) const
nodiscard

Reconstructs the URL as a canonical string from parsed components.

Re-assembles the parsed URI into a canonical string. Hierarchical URLs are emitted as scheme://authority/path?query#fragment, while non-hierarchical URLs are emitted as scheme:content?query#fragment. The output may differ slightly from the original input if the input had unusual whitespace or encoding.

Returns
Reconstructed URL string.

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