![]() |
libtld 2.0.14
A library to determine the Top-Level Domain name of any Internet URI.
|
Class used to ease the use o the tld() function in C++. More...
Public Member Functions | |
tld_object (const char *domain_name=NULL) | |
Initialize a tld object with the specified domain. | |
tld_object (const std::string &domain_name) | |
Initialize a tld object with the specified domain. | |
tld_category | category () const |
Retrieve the category of this URI. | |
std::string | country () const |
The name of the country linked to that TLD. | |
std::string | domain () const |
Retrieve the domain name of this TLD object. | |
std::string | domain_only () const |
Retrieve the domain name only. | |
std::string | full_domain () const |
Full domain name: domain and TLD. | |
bool | is_valid () const |
Check whether this TLD object is valid. | |
tld_result | result () const |
Check the result of the tld() command. | |
void | set_domain (const char *domain_name) |
Change the domain of a tld object with the newly specified domain. | |
void | set_domain (const std::string &domain_name) |
Change the domain of a tld object with the newly specified domain. | |
tld_status | status () const |
Retrieve the current status of the TLD. | |
std::string | sub_domains () const |
Retrieve the sub-domains of the URI. | |
std::string | tld_only () const |
Return the TLD of the URI. | |
Private Attributes | |
std::string | f_domain = std::string() |
The domain or URI as specified in the constructor or set_domain() function. | |
tld_info | f_info = tld_info() |
The information of the domain of this tld_object. | |
tld_result | f_result = TLD_RESULT_INVALID |
The result of the tld() function call. | |
The tld_object class allows you to query the tld library and then check each part of the URI with simple calls instead of you having to determine the location of each part.
This function initializes a TLD object with the specified domain
name. This function accepts a null terminated C string pointer. The pointer can be set to NULL or point to an empty string in which case the constructor creates an empty TLD object. Note that an empty TLD object is considered invalid and if called some functions throw the invalid_domain exception.
[in] | domain_name | The domain to parse by this object. |
Definition at line 56 of file tld_object.cpp.
References domain(), and set_domain().
tld_object::tld_object | ( | const std::string & | domain_name | ) |
This function initializes a TLD object with the specified domain
name. This function accepts standard C++ strings. The string can be empty to create an empty TLD object. Note that an empty TLD object is considered invalid and if called some functions throw the invalid_domain exception.
[in] | domain_name | The domain to parse by this object. |
Definition at line 74 of file tld_object.cpp.
References domain(), and set_domain().
tld_category tld_object::category | ( | ) | const |
This function is used to retrieve the category of the URI. The category is just informative and has no special bearing on the TLD, domain, and sub-domain parts.
The existing categories are:
Definition at line 326 of file tld_object.cpp.
References tld_info::f_category, and f_info.
std::string tld_object::country | ( | ) | const |
This TLD represents a country and this is its name.
If the TLD does not represent a country then this function returns an empty string. If category() returns TLD_CATEGORY_COUNTRY then this function should always return a valid name.
Definition at line 346 of file tld_object.cpp.
References tld_info::f_country, and f_info.
std::string tld_object::domain | ( | ) | const |
The TLD object keeps a copy of the domain name as specified with the constructor. This copy can be retrieved by this function. This is an exact copy of the input (i.e. no canonicalization.)
Definition at line 188 of file tld_object.cpp.
References f_domain.
Referenced by tld_object(), tld_object(), domain_only(), full_domain(), set_domain(), set_domain(), and sub_domains().
std::string tld_object::domain_only | ( | ) | const |
This function returns the domain name without the TLD nor any sub-domains.
A domain name never includes any period.
invalid_domain | This exception is raised when this function is called with an invalid TLD object. This happens whenever you create the object or call set_domain() with an invalid URI. You should call is_valid() and if false, avoid calling this function. |
Definition at line 266 of file tld_object.cpp.
References domain(), f_domain, f_info, tld_info::f_tld, and is_valid().
std::string tld_object::full_domain | ( | ) | const |
This function returns the domain name and the TLD as a string.
The result includes the domain name but no sub-domains.
To get the domain name with the sub-domains, call the domain() function instead. That function returns the domain as passed to this object (set_domain() or constructor).
invalid_domain | This exception is raised when this function is called with an invalid TLD object. This happens whenever you create the object or call set_domain() with an invalid URI. You should call is_valid() and if false, avoid calling this function. |
Definition at line 241 of file tld_object.cpp.
References domain(), f_domain, f_info, tld_info::f_tld, and is_valid().
bool tld_object::is_valid | ( | ) | const |
This function checks the result and status returned by the last call to the tld() function. This object is considered valid if and only if the result is TLD_RESULT_SUCCESS and the status is TLD_STATUS_VALID. At this point, any other result returns invalid and that prevents you from checking the object further (i.e. call the tld_only() function to retrieve the TLD of the specified URI.)
Definition at line 175 of file tld_object.cpp.
References f_info, f_result, tld_info::f_status, TLD_RESULT_SUCCESS, and TLD_STATUS_VALID.
Referenced by domain_only(), full_domain(), sub_domains(), and tld_only().
tld_result tld_object::result | ( | ) | const |
This function returns the result that the tld() command produced when called with the domain as specified in a constructor or the set_domain() functions.
Valid resutls are:
Definition at line 136 of file tld_object.cpp.
References f_result.
This function initializes this TLD object with the specified domain
name. This function accepts a null terminated C string pointer. The pointer can be set to NULL or point to an empty string in which case the constructor creates an empty TLD object. Note that an empty TLD object is considered invalid and if called some functions throw the invalid_domain exception.
[in] | domain_name | The domain to parse by this object. |
Definition at line 93 of file tld_object.cpp.
References domain(), and set_domain().
Referenced by tld_object(), tld_object(), and set_domain().
This function initializes a TLD object with the specified domain
name. This function accepts standard C++ strings. The string can be empty to create an empty TLD object. Note that an empty TLD object is considered invalid and if called some functions throw the invalid_domain exception.
[in] | domain_name | The domain to parse by this object. |
Definition at line 111 of file tld_object.cpp.
tld_status tld_object::status | ( | ) | const |
This function returns the status that the last tld() call generated. status() along with result() are used to determine whether a call to the TLD succeeded or not. See the is_valid() function too.
This function can be used to know why a domain name failed when parsed by the tld() function.
Definition at line 159 of file tld_object.cpp.
References f_info, and tld_info::f_status.
std::string tld_object::sub_domains | ( | ) | const |
This function returns the sub-domains found in the URI. This may be the empty string.
invalid_domain | This exception is raised when this function is called with an invalid TLD object. This happens whenever you create the object or call set_domain() with an invalid URI. You should call is_valid() and if false, avoid calling this function. |
Definition at line 206 of file tld_object.cpp.
References domain(), f_domain, f_info, tld_info::f_tld, and is_valid().
std::string tld_object::tld_only | ( | ) | const |
This function returns the TLD part of the URI specified in the constructor or the set_domain() function.
The TLD is the part that represents a country, a region, a general TLD, etc. Generic TLDs have one period (.com, .info,) but in general you must expect TLDs with several period characters (.ca.us, .indiana.museum, .yawatahama.ehime.jp).
invalid_domain | This exception is raised when this function is called with an invalid TLD object. This happens whenever you create the object or call set_domain() with an invalid URI. You should call is_valid() and if false, avoid calling this function. |
Definition at line 295 of file tld_object.cpp.
References f_info, tld_info::f_tld, and is_valid().
|
private |
This variable holds the original domain (URI) as passed to the tld_object constructor or set_domain() function.
You can retrieve that value with the domain() function. The tld_object never modifies that string.
Note that it can be an empty string.
Definition at line 216 of file tld.h.
Referenced by domain(), domain_only(), full_domain(), set_domain(), and sub_domains().
|
private |
This variable holds the information as defined by a call to the tld() function. It holds information whether or not the domain is valid, empty, etc.
The structure gets reinitialized each time a call to set_domain() is made and those values are considered cached.
Definition at line 217 of file tld.h.
Referenced by category(), country(), domain_only(), full_domain(), is_valid(), set_domain(), status(), sub_domains(), and tld_only().
|
private |
This variable caches the result of the last tld() call with the URI as defined in the f_domain variable. The f_info also corresponds to this f_result.
The result is always initialized to a value or another by constructors and set_domain() methods.
Definition at line 218 of file tld.h.
Referenced by is_valid(), result(), and set_domain().
This document is part of the Snap! Websites Project.
Copyright by Made to Order Software Corp.