xtd 0.2.0
Loading...
Searching...
No Matches

◆ uri() [5/5]

xtd::uri::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.

Parameters
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.
Exceptions
xtd::uri_format_exceptionThe 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:\.
Examples
This example creates an absolute xtd::uri instance, absolute_uri, and a relative xtd::uri instance, relative_uri. A new xtd::uri instance, combined_uri, is then created from these two instances.
// Create an absolute xtd::ri from a string.
auti absolute_uri = uri("http://www.contoso.com/");
// Create a relative xtd::uri from a string and uri_kind::relative for
// creating a relative xtd::uri.
auto relative_uri = uri("/catalog/shownew.htm?date=today", uri_kind::relative);
// Check whether the new xtd::uri is absolute or relative.
if (!relative_uri.is_absolute_uri())
console::write_line("{0} is a relative xtd::uri.", relative_uri);
// Create a new xtd::uri from an absolute xtd::uri and a relative xtd::uri.
auto combined_uri = uri(absolute_uri, relative_uri);
console::write_line(combined_uri.absolute_uri());
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
uri()=default
Initializes a new instance of the xtd::uri class.
xtd::string absolute_uri()
Gets the absolute URI.
@ relative
The xtd::uri is a relative xtd::uri.
Remarks
This constructor creates a new xtd::uri instance by combining an absolute xtd::uri instance, base_uri, with a relative xtd::uri instance, relative_uri. If relative_uri is an absolute xtd::uri instance (containing a scheme, host name, and optionally a port number), the xtd::uri instance is created using only relative_uri.
If the base_uri has relative parts (like /api), then the relative part must be terminated with a slash, (like /api/), if the relative part of base_uri is to be preserved in the constructed xtd::uri.
Additionally, if the relative_uri begins with a slash, then it will replace any relative part of the base_uri
This constructor does not ensure that the xtd::uri refers to an accessible resource.