Classes | Static Public Member Functions | List of all members
kvikio::detail::UrlParser Class Reference

URL parsing utility using libcurl's URL API. More...

#include <url.hpp>

Classes

struct  UrlComponents
 Container for parsed URL components. More...
 

Static Public Member Functions

static UrlComponents parse (std::string const &url, std::optional< unsigned int > bitmask_url_flags=std::nullopt, std::optional< unsigned int > bitmask_component_flags=std::nullopt)
 Parses the given URL according to RFC 3986 plus and extracts its components. More...
 
static std::optional< std::string > extract_component (CurlUrlHandle const &handle, CURLUPart part, std::optional< unsigned int > bitmask_component_flags=std::nullopt, std::optional< CURLUcode > allowed_err_code=std::nullopt)
 Extract a specific component from a CurlUrlHandle. More...
 
static std::optional< std::string > extract_component (std::string const &url, CURLUPart part, std::optional< unsigned int > bitmask_url_flags=std::nullopt, std::optional< unsigned int > bitmask_component_flags=std::nullopt, std::optional< CURLUcode > allowed_err_code=std::nullopt)
 Extract a specific component from a URL string. More...
 

Detailed Description

URL parsing utility using libcurl's URL API.

This class provides static methods for parsing URLs into their constituent components (scheme, host, port, path, query, fragment).

Note
This class uses libcurl's URL parsing which follows RFC 3986 plus. See https://curl.se/docs/url-syntax.html

Example:

auto components = UrlParser::parse("https://example.com:8080/path?query=1#frag");
if (components.scheme.has_value()) {
std::cout << "Scheme: " << components.scheme.value() << std::endl;
}
if (components.host.has_value()) {
std::cout << "Host: " << components.host.value() << std::endl;
}
static UrlComponents parse(std::string const &url, std::optional< unsigned int > bitmask_url_flags=std::nullopt, std::optional< unsigned int > bitmask_component_flags=std::nullopt)
Parses the given URL according to RFC 3986 plus and extracts its components.

Definition at line 84 of file url.hpp.

Member Function Documentation

◆ extract_component() [1/2]

static std::optional<std::string> kvikio::detail::UrlParser::extract_component ( CurlUrlHandle const &  handle,
CURLUPart  part,
std::optional< unsigned int >  bitmask_component_flags = std::nullopt,
std::optional< CURLUcode >  allowed_err_code = std::nullopt 
)
static

Extract a specific component from a CurlUrlHandle.

Parameters
handleThe CurlUrlHandle containing the parsed URL
partThe URL part to extract (e.g., CURLUPART_SCHEME)
bitmask_component_flagsFlags controlling extraction behavior
allowed_err_codeOptional error code to treat as valid (e.g., CURLUE_NO_SCHEME)
Returns
The extracted component as a string, or std::nullopt if not present
Exceptions
std::runtime_errorif extraction fails with an unexpected error

◆ extract_component() [2/2]

static std::optional<std::string> kvikio::detail::UrlParser::extract_component ( std::string const &  url,
CURLUPart  part,
std::optional< unsigned int >  bitmask_url_flags = std::nullopt,
std::optional< unsigned int >  bitmask_component_flags = std::nullopt,
std::optional< CURLUcode >  allowed_err_code = std::nullopt 
)
static

Extract a specific component from a URL string.

Parameters
urlThe URL string from which to extract a component
partThe URL part to extract
bitmask_url_flagsOptional flags for URL parsing.
bitmask_component_flagsFlags controlling extraction behavior
allowed_err_codeOptional error code to treat as valid
Returns
The extracted component as a string, or std::nullopt if not present
Exceptions
std::runtime_errorif extraction fails with an unexpected error

◆ parse()

static UrlComponents kvikio::detail::UrlParser::parse ( std::string const &  url,
std::optional< unsigned int >  bitmask_url_flags = std::nullopt,
std::optional< unsigned int >  bitmask_component_flags = std::nullopt 
)
static

Parses the given URL according to RFC 3986 plus and extracts its components.

Parameters
urlThe URL string to parse
bitmask_url_flagsOptional flags for URL parsing. Common flags include:
  • CURLU_DEFAULT_SCHEME: Allows URLs without schemes
  • CURLU_NON_SUPPORT_SCHEME: Accept non-supported schemes
  • CURLU_URLENCODE: URL encode the path
bitmask_component_flagsOptional flags for component extraction. Common flags include:
  • CURLU_URLDECODE: URL decode the component
  • CURLU_PUNYCODE: Return host as punycode
Returns
UrlComponents structure containing the parsed URL components
Exceptions
std::runtime_errorif the URL cannot be parsed or if component extraction fails

Example:

// Basic parsing
auto components = UrlParser::parse("https://api.example.com/v1/users?page=1");
// Parsing with URL decoding
auto decoded = UrlParser::parse(
"https://example.com/hello%20world",
std::nullopt,
CURLU_URLDECODE
);
// Allow non-standard schemes
auto custom = UrlParser::parse(
"myscheme://example.com",
CURLU_NON_SUPPORT_SCHEME
);

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