VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::UrlParser类 参考final

Immutable RFC-3986 URL parser. 更多...

#include <url_parser.h>

vlink::UrlParser 的协作图:

Public 类型

enum class  Category : uint8_t { kHierarchical = 0 , kNonHierarchical = 1 }
 Distinguishes hierarchical and non-hierarchical URL forms. 更多...
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. 更多...
enum class  Separator : uint8_t { kAmpersand = 0 , kSemicolon = 1 }
 Query-string key-value pair delimiter. 更多...

Public 成员函数

 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.

详细描述

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.

成员枚举类型说明

◆ Category

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

Distinguishes hierarchical and non-hierarchical URL forms.

枚举值
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.

枚举值
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.

枚举值
kAmpersand 

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

kSemicolon 

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

构造及析构函数说明

◆ 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.

参数
strNull-terminated URL string to parse.
categoryHierarchical or non-hierarchical form; default hierarchical.
separatorQuery key-value delimiter; default ampersand (&).
这是这个函数的调用关系图:

◆ 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.

参数
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.

参数
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.

参数
otherSource UrlParser to copy from.
replacementsComponents to override in the copy.
函数调用图:

成员函数说明

◆ get_category()

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

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

返回
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).

返回
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 #).

返回
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).

返回
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.

返回
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.

返回
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.

返回
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).

返回
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.

返回
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").

返回
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.

返回
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.

返回
Reconstructed URL string.

该类的文档由以下文件生成: