Function

Coguri_guess_from_user_input

Declaration [src]

char*
cog_uri_guess_from_user_input (
  const char* uri_like,
  gboolean is_cli_arg,
  GError** error
)

Description [src]

Tries to assemble a valid URI from input that resembles a URI.

First, if is_cli_arg is set, the input string is converted to UTF-8. Then, the following heuristics may applied:

  • If the input is already a valid URI with a known scheme, return it as-is.
  • If the input is a relative path, or resembles a local file path, try to resolve it to a full path and return a file:// URI.
  • If a URI does not have any path, set / as the path.
  • As a last resort, try to prepend the http:// scheme.

The main use case for this function is turning some “simpler” version of a URI, as typically entered by a user in a browser URL entry (e.g. wpewebkit.org/release) and turn it into an actual URI (http://wpewebkit.org/release/) which can be then passed to WebKit.WebView.load_uri.

Parameters

uri_like const char*
 

String containing a URI-like value.

 The data is owned by the caller of the function.
 The value is a NUL terminated UTF-8 string.
is_cli_arg gboolean
 

Whether the URI-like string is from a command line option.

error GError **
  The return location for a GError*, or NULL.

Return value

Returns: char*
 

A valid, full URI as a string. If NULL is returned, the error will also be set.

 The caller of the function takes ownership of the data, and is responsible for freeing it.
 The value is a NUL terminated UTF-8 string.