Loading...
Searching...
No Matches
urlparser.h File Reference

Defines classes for parsing and handling URLs and hosts. More...

#include <iostream>
#include <memory>
#include <string>
#include <vector>
+ Include dependency graph for urlparser.h:

Go to the source code of this file.

Classes

class  TLD::Host
 Represents a Host part of a URL. More...
 
class  TLD::Url
 Represents a URL. More...
 

Namespaces

namespace  TLD
 

Macros

#define PUBLIC_SUFFIX_LIST_DAT   "public_suffix_list.dat"
 

Typedefs

using TLD::QueryParams = std::vector< std::string >
 A vector of strings representing query parameters in a URL.
 

Functions

std::ostream & operator<< (std::ostream &os, const TLD::Host &dt)
 Output stream operator for Host.
 
std::ostream & operator<< (std::ostream &os, const TLD::QueryParams &dt)
 Output stream operator for QueryParams.
 
std::ostream & operator<< (std::ostream &os, const TLD::Url &dt)
 Output stream operator for Url.
 

Variables

constexpr bool TLD::DEFAULT_IGNORE_WWW = false
 

Detailed Description

Defines classes for parsing and handling URLs and hosts.

This file contains the declaration of the Url and Host classes, which provide functionality for parsing and managing URLs and hosts within them. The Url class allows extraction and manipulation of various components of a URL, while the Host class focuses on handling and extracting domain-related information from a host.

The Url class encapsulates a URL and provides methods to access its components such as protocol, subdomain, domain, suffix, query, fragment, userinfo, port, and parameters. Additionally, it offers methods for constructing a URL string and obtaining specific parts of the URL.

The Host class represents a host part of a URL and offers functionalities for extracting domain-related details such as suffix, domain, subdomain, and the full domain. It also supports the removal of 'www' from the host and provides methods to obtain domain-specific information.

Example Usage:

// Creating a URL object and accessing its methods
TLD::Url url("https://www.example.com/path/to/resource");
std::cout << "URL Protocol: " << url.protocol() << std::endl;
std::cout << "URL Domain: " << url.domain() << std::endl;
std::cout << "URL Suffix: " << url.suffix() << std::endl;
std::cout << "URL Query: " << url.query() << std::endl;
// Creating a Host object and calling its methods
TLD::Host host("www.example.com");
std::cout << "Host Domain: " << host.domain() << std::endl;
std::cout << "Host Suffix: " << host.suffix() << std::endl;
std::cout << "Host Subdomain: " << host.subdomain() << std::endl;
Represents a Host part of a URL.
Definition urlparser.h:200
Represents a URL.
Definition urlparser.h:67

Macro Definition Documentation

◆ PUBLIC_SUFFIX_LIST_DAT

#define PUBLIC_SUFFIX_LIST_DAT   "public_suffix_list.dat"

Function Documentation

◆ operator<<() [1/3]

std::ostream & operator<< ( std::ostream &  os,
const TLD::Host dt 
)

Output stream operator for Host.

Parameters
osThe output stream.
dtThe Host object to output.
Returns
The output stream.

◆ operator<<() [2/3]

std::ostream & operator<< ( std::ostream &  os,
const TLD::QueryParams dt 
)

Output stream operator for QueryParams.

Parameters
osThe output stream.
dtThe QueryParams to output.
Returns
The output stream.

◆ operator<<() [3/3]

std::ostream & operator<< ( std::ostream &  os,
const TLD::Url dt 
)

Output stream operator for Url.

Parameters
osThe output stream.
dtThe Url object to output.
Returns
The output stream.