escape_string
Description:
[ Version ( since = "2.16" ) ]
public static string escape_string (string unescaped, string? reserved_chars_allowed = null, bool allow_utf8 = true)
public static string escape_string (string unescaped, string? reserved_chars_allowed = null, bool allow_utf8 = true)
Escapes a string for use in a URI.
Normally all characters that are not "unreserved" (i.e. ASCII alphanumerical characters plus dash, dot, underscore and tilde) are escaped. But
if you specify characters in reserved_chars_allowed
they are not escaped. This is useful for the "reserved" characters in the URI
specification, since those are allowed unescaped in some portions of a URI.
Example: Escape strings:
public static int main (string[] args) {
string ressource = "foo/my ressource.txt";
// Output: ``Escaped ressource: "foo%2Fmy%20ressource.txt"``
string fragment = Uri.escape_string (ressource);
print ("Escaped ressource: \"%s\"\n", fragment);
// Output: ``Escaped ressource: "foo/my%20ressource.txt"``
fragment = Uri.escape_string (ressource, "/");
print ("Escaped ressource: \"%s\"\n", fragment);
return 0;
}
valac --pkg glib-2.0 GLib.Uri.escape_string.vala
Parameters:
unescaped |
the unescaped input string. |
reserved_chars_allowed |
a string of reserved characters that are allowed to be used, or null. |
allow_utf8 |
true if the result can include UTF-8 characters. |
Returns:
an escaped version of |