#include <uri.h>
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.
Fields | |
static const xtd::ustring | scheme_delimiter = "://" |
Specifies the characters that separate the communication protocol scheme from the address portion of the URI. This field is read-only. More... | |
static const xtd::ustring | uri_scheme_file = "file" |
Specifies that the URI is a pointer to a file. This field is read-only. More... | |
static const xtd::ustring | uri_scheme_ftp = "ftp" |
Specifies that the URI is accessed through the File Transfer Protocol (FTP). This field is read-only. More... | |
static const xtd::ustring | uri_scheme_gopher = "gopher" |
Specifies that the URI is accessed through the Gopher protocol. This field is read-only. More... | |
static const xtd::ustring | uri_scheme_http = "http" |
Specifies that the URI is accessed through the Hypertext Transfer Protocol (HTTP). This field is read-only. More... | |
static const xtd::ustring | uri_scheme_https = "https" |
Specifies that the URI is accessed through the Hypertext Transfer Protocol (HTTPS). This field is read-only. More... | |
static const xtd::ustring | uri_scheme_mailto = "mailto" |
Specifies that the URI is an e-mail address and is accessed through the Simple Mail Transport Protocol (SMTP). This field is read-only. More... | |
static const xtd::ustring | uri_scheme_net_pipe = "net.pipe" |
Specifies that the URI is accessed through the NetPipe scheme used by Windows Communication Foundation (WCF). This field is read-only. More... | |
static const xtd::ustring | uri_scheme_net_tcp = "net.tcp" |
Specifies that the URI is accessed through the NetTcp scheme used by Windows Communication Foundation (WCF). This field is read-only. More... | |
static const xtd::ustring | uri_scheme_news = "news" |
Specifies that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). This field is read-only. More... | |
static const xtd::ustring | uri_scheme_nntp = "nntp" |
Specifies that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). This field is read-only. More... | |
Constructors | |
uri ()=default | |
Initializes a new instance of the xtd::uri class. More... | |
uri (const xtd::ustring &uri_string) | |
Initializes a new instance of the xtd::uri class with the specified URI. More... | |
uri (const xtd::ustring &uri, xtd::uri_kind uri_kind) | |
Initializes a new instance of the xtd::uri class with the specified URI. This constructor allows you to specify if the URI string is a relative URI, absolute URI, or is indeterminate. More... | |
uri (const uri &base_uri, const xtd::ustring &relative_uri) | |
Initializes a new instance of the xtd::uri class based on the specified base URI and relative URI string. More... | |
uri (const uri &base_uri, const uri &relative_uri) | |
Initializes a new instance of the xtd::uri class based on the combination of a specified base xtd::uri instance and a relative xtd::uri instance. More... | |
Properties | |
xtd::ustring | absolute_path () const |
Gets the absolute path of the URI. More... | |
xtd::ustring | absolute_uri () |
Gets the absolute URI. More... | |
xtd::ustring | authority () const |
Gets the Domain Name System (DNS) host name or IP address and the port number for a server. More... | |
xtd::ustring | dns_safe_host () const |
Gets an unescaped host name that is safe to use for DNS resolution. More... | |
xtd::ustring | fragment () const |
Gets the escaped URI fragment. More... | |
xtd::ustring | host () const |
Gets the host component of this instance. More... | |
xtd::uri_host_name_type | host_name_type () const |
Gets the type of the host name specified in the URI. More... | |
xtd::ustring | idn_host () const |
Gets the RFC 3490 compliant International Domain Name of the host, using Punycode as appropriate. This string, after being unescaped if necessary, is safe to use for DNS resolution. More... | |
bool | is_absolute_uri () const |
Gets whether the xtd::uri instance is absolute. More... | |
bool | is_default_port () const |
Gets whether the port value of the URI is the default for this scheme. More... | |
bool | is_file () const |
Gets a value indicating whether the specified xtd::uri is a file URI. More... | |
bool | is_loopback () const |
Gets whether the specified xtd::uri references the local host. More... | |
bool | is_unc () const |
Gets whether the specified xtd::uri is a universal naming convention (UNC) path. More... | |
xtd::ustring | local_path () const |
Gets the original URI string that was passed to the xtd::uri constructor. More... | |
const xtd::ustring & | original_string () const |
Gets the original URI string that was passed to the xtd::uri constructor. More... | |
xtd::ustring | path_and_query () const |
Gets the absolute_path and query properties separated by a question mark (?). More... | |
int32 | port () const |
Gets the port number of this URI. More... | |
xtd::ustring | query () const |
Gets any query information included in the specified URI. More... | |
xtd::ustring | scheme () const |
Gets the scheme name for this URI. More... | |
std::vector< xtd::ustring > | segments () const |
Gets an array containing the path segments that make up the specified URI. More... | |
xtd::ustring | user_info () const |
Gets the user name, password, or other user-specific information associated with the specified URI. More... | |
Methods | |
xtd::ustring | get_components (xtd::uri_components components, xtd::uri_format format) const |
Gets the specified components of the current instance using the specified escaping for special characters. More... | |
xtd::ustring | get_left_part (xtd::uri_partial part) const |
Gets the specified portion of a xtd::uri instance. More... | |
bool | is_base_of (const xtd::uri &uri) const |
Determines whether the current xtd::uri instance is a base of the specified xtd::uri instance. More... | |
bool | is_well_formed_original_string () |
Indicates whether the string used to construct this xtd::uri was well-formed and is not required to be further escaped. More... | |
bool | equals (const xtd::uri &uri) const noexcept override |
Indicates whether the current object is equal to another object of the same type. More... | |
xtd::ustring | to_string () const noexcept override |
Gets a canonical string representation for the specified xtd::uri instance. More... | |
static bool | check_scheme_name (const xtd::ustring &scheme) |
Determines whether the specified scheme name is valid. More... | |
static xtd::ustring | escape_data_string (const xtd::ustring &value) |
Converts a string to its escaped representation. More... | |
static xtd::ustring | escape_uri_string (const xtd::ustring &value) |
Converts a URI string to its escaped representation. More... | |
static int32 | from_hex (char digit) |
Gets the decimal value of a hexadecimal digit. More... | |
static xtd::ustring | hex_escape (char character) |
Converts a specified character into its hexadecimal equivalent. More... | |
static char | hex_unescape (const xtd::ustring &pattern, size_t &index) |
Converts a specified hexadecimal representation of a character to the character. More... | |
static bool | is_hex_digit (char character) |
Determines whether a specified character is a valid hexadecimal digit. More... | |
static bool | is_hex_encoding (const xtd::ustring &pattern, size_t index) |
Determines whether a character in a string is hexadecimal encoded. More... | |
static bool | is_well_formed_uri_string (const xtd::ustring &uri_string, xtd::uri_kind uri_kind) |
Indicates whether the string is well-formed by attempting to construct a URI with the string and ensures that the string does not require further escaping. More... | |
static xtd::ustring | unescape_data_string (const xtd::ustring &value) |
Converts a string to its unescaped representation. More... | |
Additional Inherited Members | |
![]() | |
![]() | |
object ()=default | |
Create a new instance of the ultimate base class object. More... | |
bool | equals (const object &obj) const noexcept |
Determines whether the specified object is equal to the current object. More... | |
virtual size_t | get_hash_code () const noexcept |
Serves as a hash function for a particular type. More... | |
template<typename object_t > | |
std::unique_ptr< object_t > | memberwise_clone () const noexcept |
Gets the type of the current instance. More... | |
![]() | |
static bool | equals (const object &object_a, const object &object_b) noexcept |
Determines whether the specified object instances are considered equal. More... | |
static bool | reference_equals (const object &object_a, const object &object_b) noexcept |
Determines whether the specified object instances are the same instance. More... | |
|
default |
Initializes a new instance of the xtd::uri class.
|
explicit |
Initializes a new instance of the xtd::uri class with the specified URI.
uri_string | : A string that identifies the resource to be represented by the xtd::uri instance. Note that an IPv6 address in string form must be enclosed within brackets. For example, "http://[2607:f8b0:400d:c06::69]". |
xtd::uri_format_exception | uri_string is empty. -or- The scheme specified in uri_string is not correctly formed. See xtd::uricheck_scheme_name. -or- The password specified in uri_string is not valid. -or- The host name specified in uri_string is not valid. -or- The file name specified in uri_string is not valid. -or- The user name specified in uri_string is not valid. -or-<or>The host or authority name specified in uri_string cannot be terminated by backslashes. -or- The port number specified in uri_string is not valid or cannot be parsed. -or- The length of uri_string exceeds 65519 characters. -or- The length of the scheme specified in uri_string exceeds 1023 characters. -or- There is an invalid character sequence in uri_string. -or- The MS-DOS path specified in uri_string must start with c:\. |
xtd::uri::uri | ( | const xtd::ustring & | uri, |
xtd::uri_kind | uri_kind | ||
) |
Initializes a new instance of the xtd::uri class with the specified URI. This constructor allows you to specify if the URI string is a relative URI, absolute URI, or is indeterminate.
uri_string | : A string that identifies the resource to be represented by the xtd::uri instance. Note that an IPv6 address in string form must be enclosed within brackets. For example, "http://[2607:f8b0:400d:c06::69]". |
uri_kind | : Specifies whether the URI string is a relative URI, absolute URI, or is indeterminate. |
xtd::uri_format_exception | uri_string contains a relative URI and uri_kind is xtd::uri_kind::absolute. -or- uri_string contains an absolute URI and uri_kind is xtd::uri_kind::relative. -or- uri_string is empty. -or- The scheme specified in uri_string is not correctly formed. See CheckSchemeName(String). -or- uri_string contains too many slashes. -or- The password specified in uri_string is not valid. -or- The host name specified in uri_string is not valid. -or- The file name specified in uri_string is not valid. -or- The user name specified in uri_string is not valid. -or- The host or authority name specified in uri_string cannot be terminated by backslashes. -or- The port number specified in uri_string is not valid or cannot be parsed. -or- The length of uri_string exceeds 65519 characters. -or- The length of the scheme specified in uri_string exceeds 1023 characters. -or- There is an invalid character sequence in uri_string. -or- The MS-DOS path specified in uri_string must start with c:\. |
xtd::uri::uri | ( | const uri & | base_uri, |
const xtd::ustring & | relative_uri | ||
) |
Initializes a new instance of the xtd::uri class based on the specified base URI and relative URI string.
base_uri | : The base URI. |
relative_uri | : The relative URI to add to the base URI. |
xtd::uri_format_exception | The URI formed by combining base_uri and relative_uri is empty or contains only spaces. -or- The scheme specified in the URI formed by combining base_uri and relative_uri is not valid. -or- The URI formed by combining base_uri and relative_uri contains too many slashes. -or- The password specified in the URI formed by combining base_uri and relative_uri is not valid. -or- The host name specified in the URI formed by combining base_uri and relative_uri is not valid. -or- The file name specified in the URI formed by combining base_uri and relative_uri is not valid. -or- The user name specified in the URI formed by combining base_uri and relative_uri is not valid. -or- The host or authority name specified in the URI formed by combining base_uri and relative_uri cannot be terminated by backslashes. -or- The port number specified in the URI formed by combining base_uri and relative_uri is not valid or cannot be parsed. -or- The length of the URI formed by combining base_uri and relative_uri exceeds 65519 characters. -or- The length of the scheme specified in the URI formed by combining base_uri and relative_uri exceeds 1023 characters. -or- There is an invalid character sequence in the URI formed by combining base_uri and relative_uri. -or- The MS-DOS path specified in uriString must start with c:\. |
Initializes a new instance of the xtd::uri class based on the combination of a specified base xtd::uri instance and a relative xtd::uri instance.
base_uri | : An absolute xtd::uri that is the base for the new xtd::uri instance. |
relative_uri | : A relative xtd::uri instance that is combined with base_uri. |
xtd::uri_format_exception | The URI formed by combining base_uri and relative_uri is empty or contains only spaces. -or- The scheme specified in the URI formed by combining base_uri and relative_uri is not valid. -or- The URI formed by combining base_uri and relative_uri contains too many slashes. -or- The password specified in the URI formed by combining base_uri and relative_uri is not valid. -or- The host name specified in the URI formed by combining base_uri and relative_uri is not valid. -or- The file name specified in the URI formed by combining base_uri and relative_uri is not valid. -or- The user name specified in the URI formed by combining base_uri and relative_uri is not valid. -or- The host or authority name specified in the URI formed by combining base_uri and relative_uri cannot be terminated by backslashes. -or- The port number specified in the URI formed by combining base_uri and relative_uri is not valid or cannot be parsed. -or- The length of the URI formed by combining base_uri and relative_uri exceeds 65519 characters. -or- The length of the scheme specified in the URI formed by combining base_uri and relative_uri exceeds 1023 characters. -or- There is an invalid character sequence in the URI formed by combining base_uri and relative_uri. -or- The MS-DOS path specified in uriString must start with c:\. |
xtd::ustring xtd::uri::absolute_path | ( | ) | const |
Gets the absolute path of the URI.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
xtd::ustring xtd::uri::absolute_uri | ( | ) |
Gets the absolute URI.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
xtd::ustring xtd::uri::authority | ( | ) | const |
Gets the Domain Name System (DNS) host name or IP address and the port number for a server.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
|
static |
Determines whether the specified scheme name is valid.
scheme | The scheme name to validate. |
xtd::ustring xtd::uri::dns_safe_host | ( | ) | const |
Gets an unescaped host name that is safe to use for DNS resolution.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
|
overridevirtualnoexcept |
Indicates whether the current object is equal to another object of the same type.
obj | An object to compare with this object. |
Implements xtd::iequatable< uri >.
|
static |
Converts a string to its escaped representation.
value | The string to escape. |
ArgumentNullException | value is null. |
UriFormatException | The length of value exceeds 32766 characters. |
|
static |
Converts a URI string to its escaped representation.
value | The string to escape. |
ArgumentNullException | value is null. |
UriFormatException | The length of value exceeds 32766 characters. |
xtd::ustring xtd::uri::fragment | ( | ) | const |
Gets the escaped URI fragment.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
|
static |
Gets the decimal value of a hexadecimal digit.
digit | The hexadecimal digit (0-9, a-f, A-F) to convert. |
ArgumentException | digit is not a valid hexadecimal digit (0-9, a-f, A-F). |
xtd::ustring xtd::uri::get_components | ( | xtd::uri_components | components, |
xtd::uri_format | format | ||
) | const |
Gets the specified components of the current instance using the specified escaping for special characters.
components | A bitwise combination of the xtd::uri_components values that specifies which parts of the current instance to return to the caller. |
format | One of the xtd::uri_format values that controls how special characters are escaped. |
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
xtd::ustring xtd::uri::get_left_part | ( | xtd::uri_partial | part | ) | const |
Gets the specified portion of a xtd::uri instance.
part | = One of the xtd::uri_partial values that specifies the end of the URI portion to return. |
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
ArgumentException | The specified part is not valid. |
URI | Scheme | Autority | Path | Query |
---|---|---|---|---|
http://www.contoso.com/index.htm?date=today | http:// | http://www.contoso.com | http://www.contoso.com/index.htm | http://www.contoso.com/index.htm?date=today |
http://www.contoso.com/index.htm#main | http:// | http://www.contoso.com | http://www.contoso.com/index.htm | http://www.contoso.com/index.htm |
user@?subject=uri cont oso.c om | mailto: | user@ cont oso.c om | user@?subject=uri cont oso.c om | <None> |
nntp://news.contoso.com/123456.com | nntp:// | nntp://news.contoso.com | nntp://news.contoso.com/123456.com | nntp://news.contoso.com/123456.com |
news:123456@contoso.com | news: | news:123456@contoso.com | news:123456@contoso.com | <None> |
file://server/filename.ext | file:// | file://server | file://server/filename.ext | file://server/filename.ext |
|
static |
Converts a specified character into its hexadecimal equivalent.
character | The character to convert to hexadecimal representation. |
ArgumentOutOfRangeException | character is greater than 255. |
|
static |
Converts a specified hexadecimal representation of a character to the character.
pattern | The hexadecimal representation of a character. |
index | The location in pattern where the hexadecimal representation of a character begins. |
ArgumentOutOfRangeException | index is less than 0 or greater than or equal to the number of characters in pattern. |
xtd::ustring xtd::uri::host | ( | ) | const |
Gets the host component of this instance.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
xtd::uri_host_name_type xtd::uri::host_name_type | ( | ) | const |
Gets the type of the host name specified in the URI.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
xtd::ustring xtd::uri::idn_host | ( | ) | const |
Gets the RFC 3490 compliant International Domain Name of the host, using Punycode as appropriate. This string, after being unescaped if necessary, is safe to use for DNS resolution.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
bool xtd::uri::is_absolute_uri | ( | ) | const |
Gets whether the xtd::uri instance is absolute.
bool xtd::uri::is_base_of | ( | const xtd::uri & | uri | ) | const |
Determines whether the current xtd::uri instance is a base of the specified xtd::uri instance.
uri | The specified xtd::uri instance to test. |
ArgumentNullException | uri is null. |
bool xtd::uri::is_default_port | ( | ) | const |
Gets whether the port value of the URI is the default for this scheme.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
bool xtd::uri::is_file | ( | ) | const |
Gets a value indicating whether the specified xtd::uri is a file URI.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
|
static |
Determines whether a specified character is a valid hexadecimal digit.
character | The character to validate. |
|
static |
Determines whether a character in a string is hexadecimal encoded.
pattern | The string to check. |
index | The location in pattern to check for hexadecimal encoding. |
bool xtd::uri::is_loopback | ( | ) | const |
Gets whether the specified xtd::uri references the local host.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
bool xtd::uri::is_unc | ( | ) | const |
Gets whether the specified xtd::uri is a universal naming convention (UNC) path.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
bool xtd::uri::is_well_formed_original_string | ( | ) |
Indicates whether the string used to construct this xtd::uri was well-formed and is not required to be further escaped.
Error | Example |
---|---|
The string is not correctly escaped. | http://www.contoso.com/path???/file name |
The string is an absolute xtd::uri that represents an implicit file xtd::uri. | c:\directory |
The string is an absolute URI that is missing a slash before the path. | file://c:/directory/filename |
The string contains unescaped backslashes even if they are treated as forward slashes. | http:\host/path/file |
The string represents a hierarchical absolute xtd::uri and does not contain "://". | www.contoso.com/path/file |
The parser for the xtd::uri.scheme indicates that the original string was not well-formed. | The example depends on the scheme of the URI. |
|
static |
Indicates whether the string is well-formed by attempting to construct a URI with the string and ensures that the string does not require further escaping.
uri_string | The string used to attempt to construct a xtd::uri. |
uri_kind | The type of the xtd::uri in uri_string. |
Error | Example |
---|---|
The string is not correctly escaped. | http://www.contoso.com/path???/file name |
The string is an absolute xtd::uri that represents an implicit file xtd::uri. | c:\directory |
The string is an absolute URI that is missing a slash before the path. | file://c:/directory/filename |
The string contains unescaped backslashes even if they are treated as forward slashes. | http:\host/path/file |
The string represents a hierarchical absolute xtd::uri and does not contain "://". | www.contoso.com/path/file |
The parser for the xtd::uri.scheme indicates that the original string was not well-formed. | The example depends on the scheme of the URI. |
xtd::ustring xtd::uri::local_path | ( | ) | const |
Gets the original URI string that was passed to the xtd::uri constructor.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
const xtd::ustring& xtd::uri::original_string | ( | ) | const |
Gets the original URI string that was passed to the xtd::uri constructor.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
xtd::ustring xtd::uri::path_and_query | ( | ) | const |
Gets the absolute_path and query properties separated by a question mark (?).
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
int32 xtd::uri::port | ( | ) | const |
Gets the port number of this URI.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
xtd::ustring xtd::uri::query | ( | ) | const |
Gets any query information included in the specified URI.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
xtd::ustring xtd::uri::scheme | ( | ) | const |
Gets the scheme name for this URI.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
Scheme | Description |
---|---|
file | The resource is a file on the local computer. |
ftp | The resource is accessed through FTP. |
gopher | The resource is accessed through the Gopher protocol. |
http | The resource is accessed through HTTP. |
https | The resource is accessed through SSL-encrypted HTTP. |
ldap | The resource is accessed through the LDAP protocol. |
mailto | The resource is an e-mail address and accessed through the SMTP protocol. |
net.pipe | The resource is accessed through a named pipe. |
net.tcp | The resource is accessed from TCP endpoint. |
news | The resource is accessed through the NNTP protocol. |
nntp | The resource is accessed through the NNTP protocol. |
telnet | The resource is accessed through the TELNET protocol. |
uuid | The resource is accessed through a unique UUID endpoint name for communicating with a service. |
std::vector<xtd::ustring> xtd::uri::segments | ( | ) | const |
Gets an array containing the path segments that make up the specified URI.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
|
overridevirtualnoexcept |
Gets a canonical string representation for the specified xtd::uri instance.
Reimplemented from xtd::object.
|
static |
Converts a string to its unescaped representation.
value | The string to unescape. |
ArgumentNullException | value is null. |
xtd::ustring xtd::uri::user_info | ( | ) | const |
Gets the user name, password, or other user-specific information associated with the specified URI.
xtd::invalid_operation_exception | This instance represents a relative URI, and this property is valid only for absolute URIs. |
|
inlinestatic |
Specifies the characters that separate the communication protocol scheme from the address portion of the URI. This field is read-only.
|
inlinestatic |
Specifies that the URI is a pointer to a file. This field is read-only.
|
inlinestatic |
Specifies that the URI is accessed through the File Transfer Protocol (FTP). This field is read-only.
|
inlinestatic |
Specifies that the URI is accessed through the Gopher protocol. This field is read-only.
|
inlinestatic |
Specifies that the URI is accessed through the Hypertext Transfer Protocol (HTTP). This field is read-only.
|
inlinestatic |
Specifies that the URI is accessed through the Hypertext Transfer Protocol (HTTPS). This field is read-only.
|
inlinestatic |
Specifies that the URI is an e-mail address and is accessed through the Simple Mail Transport Protocol (SMTP). This field is read-only.
|
inlinestatic |
Specifies that the URI is accessed through the NetPipe scheme used by Windows Communication Foundation (WCF). This field is read-only.
|
inlinestatic |
Specifies that the URI is accessed through the NetTcp scheme used by Windows Communication Foundation (WCF). This field is read-only.
|
inlinestatic |
Specifies that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). This field is read-only.
|
inlinestatic |
Specifies that the URI is an Internet news group and is accessed through the Network News Transport Protocol (NNTP). This field is read-only.