Represents a Host part of a URL. More...
#include <urlparser.h>
Public Member Functions | |
Host ()=default | |
Default constructor for the Host class. Creates an empty Host object. | |
Host (const std::string &host, const bool ignore_www=DEFAULT_IGNORE_WWW) | |
Construct a Host object from a hostname string. | |
const std::string & | domain () const noexcept |
Get the domain of the host. | |
std::string | domainName () const noexcept |
Get the domain name of the host. | |
const std::string & | fulldomain () const noexcept |
Get the full domain of the host. | |
bool | operator== (const Host &other) const |
Equality operator for comparing two Host objects. | |
bool | operator== (const std::string &other) const |
Equality operator for comparing a Host object with a string. | |
const std::string & | str () const noexcept |
Get the complete host as a string. | |
const std::string & | subdomain () const noexcept |
Get the subdomain of the host. | |
const std::string & | suffix () const noexcept |
Get the suffix of the host. | |
Static Public Member Functions | |
static Host | fromUrl (const std::string &url, const bool ignore_www=DEFAULT_IGNORE_WWW) |
Create a Host object from a URL string. | |
static bool | isPslLoaded () noexcept |
Check if the Public Suffix List (PSL) is loaded. | |
static void | loadPslFromPath (const std::string &filepath) |
Load the Public Suffix List from a file. | |
static void | loadPslFromString (const std::string &filestr) |
Load the Public Suffix List from a string. | |
static std::string_view | removeWWW (const std::string_view &host) noexcept |
Remove "www." from the beginning of a hostname. | |
Represents a Host part of a URL.
The Host class encapsulates functionalities for handling the host component of a URL. It provides methods to extract domain-specific details such as suffix, domain, subdomain, and the full domain.
TLD::Host::Host | ( | const std::string & | host, |
const bool | ignore_www = DEFAULT_IGNORE_WWW |
||
) |
Construct a Host object from a hostname string.
host | The hostname to parse. |
ignore_www | Whether to ignore the "www" subdomain. Default is false. |
std::invalid_argument | If the hostname is malformed or cannot be parsed. |
|
noexcept |
Get the domain of the host.
|
noexcept |
Get the domain name of the host.
|
static |
|
noexcept |
Get the full domain of the host.
|
staticnoexcept |
Check if the Public Suffix List (PSL) is loaded.
|
static |
Load the Public Suffix List from a file.
filepath | Path to the PSL file. |
std::runtime_error | If the file cannot be opened or parsed. |
|
static |
Load the Public Suffix List from a string.
filestr | The PSL content as a string. |
std::runtime_error | If the content cannot be parsed. |
bool TLD::Host::operator== | ( | const Host & | other | ) | const |
bool TLD::Host::operator== | ( | const std::string & | other | ) | const |
Equality operator for comparing a Host object with a string.
other | The string to compare with. |
|
staticnoexcept |
Remove "www." from the beginning of a hostname.
host | The hostname to process. |
|
noexcept |
Get the complete host as a string.
|
noexcept |
Get the subdomain of the host.
|
noexcept |
Get the suffix of the host.