unescape_segment


Description:

[ Version ( since = "2.16" ) ]
public static string? unescape_segment (string? escaped_string, string? escaped_string_end, string? illegal_characters = null)

Unescapes a segment of an escaped string.

If any of the characters in illegal_characters or the NUL character appears as an escaped character in escaped_string , then that is an error and null will be returned. This is useful if you want to avoid for instance having a slash being expanded in an escaped path element, which might confuse pathname handling.

Note: `NUL` byte is not accepted in the output, in contrast to unescape_bytes.

Example: Unescape segments:

public static int main (string[] args) {
string ressource = "foo/my%2F1.%20ressource.txt";
// ^-----------------^
// start end

unowned string start = (string) ((char*)ressource + 4);
unowned string end = (string) ((char*)ressource + 27);

// Output:
// ``start: "my%2F1.%20ressource.txt"``
// ``end: ""``
print ("start: \"%s\"\n", start);
print ("end: \"%s\"\n", end);


// Output: ``Unescaped segment: "my/1. ressource.txt"``
string? segment = Uri.unescape_segment (start, end);
print ("Unescaped segment: \"%s\"\n", segment);

// Output: ``Unescaped segment: "(null)"``
segment = Uri.unescape_segment (start, end, "/");
print ("Unescaped segment: \"%s\"\n", segment);


// Output: ``Unescaped segment: "(null)"``
segment = Uri.unescape_segment (null, null);
print ("Unescaped segment: \"%s\"\n", segment);

return 0;
}

valac --pkg glib-2.0 GLib.Uri.unescape_segment.vala

Parameters:

escaped_string

A string, may be null

escaped_string_end

Pointer to end of escaped_string, may be null

illegal_characters

An optional string of illegal characters not to be allowed, may be null

Returns:

an unescaped version of escaped_string, or null on error. The returned string should be freed when no longer needed. As a special case if null is given for escaped_string, this function will return null.