Loading...
Searching...
No Matches
TLD::Url Class Reference

Represents a URL. More...

#include <urlparser.h>

+ Collaboration diagram for TLD::Url:

Public Member Functions

 Url () noexcept=default
 Default constructor for the Url class. Creates an empty URL object.
 
 Url (const std::string &url, const bool ignore_www=DEFAULT_IGNORE_WWW)
 Construct a Url object from a given URL string.
 
std::string abspath () const noexcept
 Get the absolute path of the URL.
 
const std::string & domain () const noexcept
 Get the domain of the URL.
 
std::string domainName () const noexcept
 Get the domain name of the URL.
 
const std::string & fragment () const noexcept
 Get the fragment part of the URL.
 
const std::string & fulldomain () const noexcept
 Get the full domain of the URL.
 
const Hosthost () const
 Get the host object of the URL.
 
bool operator== (const Url &other) const
 Equality operator for comparing two Url objects.
 
QueryParams params () const noexcept
 Get the parameters of the URL.
 
const int port () const noexcept
 Get the port of the URL.
 
const std::string & protocol () const noexcept
 Get the protocol of the URL.
 
const std::string & query () const noexcept
 Get the query part of the URL.
 
std::string str () const noexcept
 Get the complete URL as a string.
 
const std::string & subdomain () const noexcept
 Get the subdomain of the URL.
 
const std::string & suffix () const noexcept
 Get the suffix of the URL.
 
const std::string & userinfo () const noexcept
 Get the userinfo part of the URL.
 

Static Public Member Functions

static std::string extractHost (const std::string &url) noexcept
 Extract the host from a given URL.
 
static bool isPslLoaded () noexcept
 Check if the Public Suffix List (PSL) is loaded.
 

Detailed Description

Represents a URL.

The Url class provides functionalities for parsing and managing URLs. It allows access to various components of a URL such as protocol, subdomain, domain, suffix, query, fragment, userinfo, port, and parameters.

Constructor & Destructor Documentation

◆ Url() [1/2]

TLD::Url::Url ( const std::string &  url,
const bool  ignore_www = DEFAULT_IGNORE_WWW 
)

Construct a Url object from a given URL string.

Parameters
urlThe URL string to parse.
ignore_wwwWhether to ignore the "www" subdomain. Default is false.
Exceptions
std::invalid_argumentIf the URL is malformed or cannot be parsed.

◆ Url() [2/2]

TLD::Url::Url ( )
defaultnoexcept

Default constructor for the Url class. Creates an empty URL object.

Member Function Documentation

◆ abspath()

std::string TLD::Url::abspath ( ) const
noexcept

Get the absolute path of the URL.

Returns
The absolute path of the URL (the part after the host and before the query).

◆ domain()

const std::string & TLD::Url::domain ( ) const
noexcept

Get the domain of the URL.

Returns
The domain of the URL (e.g., "example" in "www.example.com").

◆ domainName()

std::string TLD::Url::domainName ( ) const
noexcept

Get the domain name of the URL.

Returns
The domain name, which is the same as domain().

◆ extractHost()

static std::string TLD::Url::extractHost ( const std::string &  url)
staticnoexcept

Extract the host from a given URL.

Parameters
urlThe URL from which to extract the host.
Returns
The extracted host as a string.

◆ fragment()

const std::string & TLD::Url::fragment ( ) const
noexcept

Get the fragment part of the URL.

Returns
The fragment of the URL (the part after #).

◆ fulldomain()

const std::string & TLD::Url::fulldomain ( ) const
noexcept

Get the full domain of the URL.

Returns
The full domain of the URL (e.g., "example.com").

◆ host()

const Host & TLD::Url::host ( ) const

Get the host object of the URL.

Returns
A Host object representing the host part of the URL.

◆ isPslLoaded()

static bool TLD::Url::isPslLoaded ( )
staticnoexcept

Check if the Public Suffix List (PSL) is loaded.

Returns
true if the PSL is loaded, false otherwise.

◆ operator==()

bool TLD::Url::operator== ( const Url other) const

Equality operator for comparing two Url objects.

Parameters
otherThe Url object to compare with.
Returns
true if the URLs are equal, false otherwise.

◆ params()

QueryParams TLD::Url::params ( ) const
noexcept

Get the parameters of the URL.

Returns
A vector of strings containing the query parameters.

◆ port()

const int TLD::Url::port ( ) const
noexcept

Get the port of the URL.

Returns
The port number of the URL, or -1 if not specified.

◆ protocol()

const std::string & TLD::Url::protocol ( ) const
noexcept

Get the protocol of the URL.

Returns
The protocol of the URL (e.g., "http", "https", "ftp").

◆ query()

const std::string & TLD::Url::query ( ) const
noexcept

Get the query part of the URL.

Returns
The query string of the URL (e.g., "param1=value1&param2=value2").

◆ str()

std::string TLD::Url::str ( ) const
noexcept

Get the complete URL as a string.

Returns
The complete URL string.

◆ subdomain()

const std::string & TLD::Url::subdomain ( ) const
noexcept

Get the subdomain of the URL.

Returns
The subdomain of the URL (e.g., "www" in "www.example.com").

◆ suffix()

const std::string & TLD::Url::suffix ( ) const
noexcept

Get the suffix of the URL.

Returns
The suffix of the URL (e.g., "com" in "www.example.com").

◆ userinfo()

const std::string & TLD::Url::userinfo ( ) const
noexcept

Get the userinfo part of the URL.

Returns
The userinfo of the URL (e.g., "username:password").

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