|
Ultralight C API 2.0.0
|
Parsed web addresses for C.
#include <Ultralight/CAPI/CAPI_URL.h>
ULURL represents a parsed web address conforming to the WHATWG specification. You'll use it to validate web links and resolve relative paths before loading them into a View.
Parse an address string and load it into a View:
Ownership rules for URL handles and returned strings:
Resolve a relative path against the View's current URL and load the resolved address:
URL parsing, component access, and query building follow the same rules as the C++ interface (see <Ultralight/URL.h>).
Functions | |
| ULURL | ulCreateURL (ULString url_string) |
| Parse a string as an absolute URL (WHATWG-standard parsing). | |
| ULURL | ulCreateURLRelative (ULURL base, ULString relative) |
| Resolve a (possibly relative) reference against a base URL, following the same rules a browser uses to resolve links on a page. | |
| ULURL | ulCreateURLFromFilePath (ULString file_path) |
| Create a file: URL from a native file-system path. | |
| ULURL | ulCreateURLCopy (ULURL url) |
| Create a copy of an existing URL. | |
| void | ulDestroyURL (ULURL url) |
| Destroy a URL previously created with ulCreateURL(), ulCreateURLRelative(), ulCreateURLFromFilePath(), or ulCreateURLCopy(). | |
| bool | ulURLIsValid (ULURL url) |
| Whether or not the URL parsed successfully. | |
| bool | ulURLIsEmpty (ULURL url) |
| Whether or not the URL holds nothing (equivalent to !ulURLIsValid()). | |
| ULString | ulURLGetString (ULURL url) |
| Get the canonical serialization of the whole URL ("" if invalid). | |
| bool | ulURLEquals (ULURL url, ULURL other) |
| Whether two URLs have the same canonical serialization. | |
| ULString | ulURLGetOrigin (ULURL url) |
| Get the origin serialization, like JavaScript's URL.origin. | |
| ULString | ulURLGetScheme (ULURL url) |
| Get the scheme, lowercased, without the trailing colon (eg, "https"; "" if invalid). | |
| ULString | ulURLGetHost (ULURL url) |
| Get the host, without the port (eg, "example.com"; "" if invalid or hostless). | |
| ULString | ulURLGetHostWithPort (ULURL url) |
| Get the host with the explicit port appended, if one is present (eg, "example.com:8080"). | |
| bool | ulURLHasPort (ULURL url) |
| Whether or not the URL has an explicit port. | |
| unsigned short | ulURLGetPort (ULURL url) |
| Get the explicit port number (0 when ulURLHasPort() is false). | |
| ULString | ulURLGetUsername (ULURL url) |
| Get the username portion of the URL's credentials, percent-decoded ("" if none). | |
| ULString | ulURLGetPassword (ULURL url) |
| Get the password portion of the URL's credentials, percent-decoded ("" if none). | |
| ULString | ulURLGetPath (ULURL url) |
| Get the path (eg, "/a/b"; "" if invalid). | |
| ULString | ulURLGetQuery (ULURL url) |
| Get the query string, without the leading '? | |
| ULString | ulURLGetFragment (ULURL url) |
| Get the fragment, without the leading '#' ("" if none). | |
| bool | ulURLSetScheme (ULURL url, ULString scheme) |
| Set the scheme (with or without the trailing colon). | |
| void | ulURLSetHost (ULURL url, ULString host) |
| Set the host (without port). | |
| void | ulURLSetPort (ULURL url, unsigned short port) |
| Set an explicit port. | |
| void | ulURLClearPort (ULURL url) |
| Remove the explicit port, if any. | |
| void | ulURLSetUsername (ULURL url, ULString username) |
| Set the username portion of the URL's credentials (percent-encoded as needed). | |
| void | ulURLSetPassword (ULURL url, ULString password) |
| Set the password portion of the URL's credentials (percent-encoded as needed). | |
| void | ulURLSetPath (ULURL url, ULString path) |
| Set the path. | |
| void | ulURLSetQuery (ULURL url, ULString query) |
| Set the raw query string (without the leading '? | |
| void | ulURLSetFragment (ULURL url, ULString fragment) |
| Set the fragment (without the leading '#'). | |
| bool | ulURLHasQueryParameter (ULURL url, ULString key) |
| Whether or not the query contains a parameter with the given key (form-decoded match). | |
| ULString | ulURLGetQueryParameter (ULURL url, ULString key) |
| Get the first query-parameter value for the given key, form-decoded ("" if absent). | |
| void | ulURLAppendQueryParameter (ULURL url, ULString key, ULString value) |
| Append a key/value pair to the query, form-encoding both. | |
| ULString | ulURLGetFilePath (ULURL url) |
| Get the native file-system path for a file: URL. | |
| ULString | ulURLEncodeComponent (ULString component) |
| Percent-encode a string for safe embedding inside a URL component. | |
| ULString | ulURLDecodeComponent (ULString encoded) |
| Decode a percent-encoded URL component. | |
Typedefs | |
| typedef struct C_URL * | ULURL |
| Opaque handle to a URL object. | |
Parse a string as an absolute URL (WHATWG-standard parsing).
Input without a scheme (eg, "example.com") does not parse. The result is then an invalid URL object, which you can test with ulURLIsValid().
| url_string | The string to parse. |
Create a copy of an existing URL.
Create a file: URL from a native file-system path.
Platform path conventions are handled for you (eg, Windows drive letters and backslashes). Use ulURLGetFilePath() for the reverse conversion.
| file_path | An absolute native file-system path. |
Resolve a (possibly relative) reference against a base URL, following the same rules a browser uses to resolve links on a page.
| base | The base URL to resolve against. |
| relative | The reference to resolve: a path, an absolute path, a fragment, or a full absolute URL (which ignores the base). |
| void ulDestroyURL | ( | ULURL | url | ) |
Destroy a URL previously created with ulCreateURL(), ulCreateURLRelative(), ulCreateURLFromFilePath(), or ulCreateURLCopy().
Append a key/value pair to the query, form-encoding both.
Spaces become + and reserved characters are percent-encoded, so this is the safe way to build search or query URLs from arbitrary text.
| url | The URL handle. |
| key | The parameter name (unencoded). |
| value | The parameter value (unencoded). |
| void ulURLClearPort | ( | ULURL | url | ) |
Remove the explicit port, if any.
Decode a percent-encoded URL component.
This matches JavaScript's decodeURIComponent for well-formed input. Unlike its JavaScript counterpart this function never fails: a malformed escape is passed through unchanged.
Percent-encode a string for safe embedding inside a URL component.
This matches JavaScript's encodeURIComponent: every character except letters, digits, and - _ . ! ~ * ' ( ) is replaced by the percent-encoding of its UTF-8 bytes.
Whether two URLs have the same canonical serialization.
Get the native file-system path for a file: URL.
Get the fragment, without the leading '#' ("" if none).
Get the host, without the port (eg, "example.com"; "" if invalid or hostless).
Get the host with the explicit port appended, if one is present (eg, "example.com:8080").
Get the origin serialization, like JavaScript's URL.origin.
Get the password portion of the URL's credentials, percent-decoded ("" if none).
Get the path (eg, "/a/b"; "" if invalid).
| unsigned short ulURLGetPort | ( | ULURL | url | ) |
Get the explicit port number (0 when ulURLHasPort() is false).
Get the query string, without the leading '?
' ("" if none).
Values inside the query are stored encoded. Use ulURLGetQueryParameter() to read a decoded value.
Get the first query-parameter value for the given key, form-decoded ("" if absent).
Get the scheme, lowercased, without the trailing colon (eg, "https"; "" if invalid).
Get the canonical serialization of the whole URL ("" if invalid).
Get the username portion of the URL's credentials, percent-decoded ("" if none).
| bool ulURLHasPort | ( | ULURL | url | ) |
Whether or not the URL has an explicit port.
Whether or not the query contains a parameter with the given key (form-decoded match).
| bool ulURLIsEmpty | ( | ULURL | url | ) |
Whether or not the URL holds nothing (equivalent to !ulURLIsValid()).
| bool ulURLIsValid | ( | ULURL | url | ) |
Whether or not the URL parsed successfully.
Set the fragment (without the leading '#').
Pass an empty string to remove the fragment entirely.
Set the host (without port).
Invalid input (eg, a stray colon) and empty input are ignored, leaving the URL unchanged.
Set the password portion of the URL's credentials (percent-encoded as needed).
Pass an empty string to remove it.
Set the path.
The path is encoded as needed. On http(s) URLs an empty path becomes "/".
| void ulURLSetPort | ( | ULURL | url, |
| unsigned short | port ) |
Set an explicit port.
A scheme-default port (eg, 443 for https) is elided from the serialization.
Set the raw query string (without the leading '?
').
Pass an empty string to remove the query entirely. The value is used as-is, so you are responsible for encoding it. To build a query from arbitrary text safely, use ulURLAppendQueryParameter() instead.
Set the scheme (with or without the trailing colon).
The new scheme is validated and canonicalized (lowercased).
Set the username portion of the URL's credentials (percent-encoded as needed).
Pass an empty string to remove it.
| typedef struct C_URL* ULURL |
Opaque handle to a URL object.