4.3. URI manipulation library based on UriParser
The URIPARSER module provides URI parsing and manipulation based on the uriparser library. It supports parsing URI strings into components (scheme, host, path, query, fragment), normalization, resolution of relative URIs, and GUID generation.
All functions and symbols are in “uriparser” module, use require to get access to it.
require uriparser
4.3.1. Handled structures
- uriparser::UriTextRangeA
Range of text in the URI.
- uriparser::UriIp4Struct
IPv4 address portion of the URI.
- Fields
data : uint8[4] - IPv4 address data.
- uriparser::UriIp6Struct
IPv6 address portion of the URI.
- Fields
data : uint8[16] - IPv6 address data.
- uriparser::UriHostDataA
Host data portion of the URI (IPv4 or IPv6, or some future data).
- Fields
ip4 : UriIp4Struct? - IPv4 address data.
ip6 : UriIp6Struct? - IPv6 address data.
ipFuture : UriTextRangeA - Future host address data.
- uriparser::UriPathSegmentStructA
Part of the path portion of the URI.
- Fields
text : UriTextRangeA - Text of the path segment.
next : UriPathSegmentStructA? - Next path segment, or null if this is the last segment.
- uriparser::UriUriA
URI base class, contains all URI data.
- Fields
scheme : UriTextRangeA - Scheme of the URI.
userInfo : UriTextRangeA - User information.
hostText : UriTextRangeA - Host text.
hostData : UriHostDataA - Host data portion of the URI (IPv4 or IPv6, or some future data).
portText : UriTextRangeA - Port text.
pathHead : UriPathSegmentStructA? - Head of the path.
pathTail : UriPathSegmentStructA? - Tail of the path.
query : UriTextRangeA - Query portion of the URI.
fragment : UriTextRangeA - Fragment portion of the URI.
absolutePath : int - Whether the path is absolute.
owner : int - Whether the URI is owned by the parser.
- uriparser::Uri
- Uri.empty() : bool()
Returns true if the Uri object contains no URI data.
- Uri.size() : int()
Returns the string length of the URI.
- Uri.status() : int()
Returns the parse status code of the Uri object.
- Properties
empty : bool
size : int
status : int
- Fields
uri : UriUriA - URI implementation.
4.3.2. Initialization and finalization
4.3.2.1. Uri
- uriparser::Uri(arg0: string) : Uri()
Constructs a new Uri object by parsing the given URI string.
- Arguments
arg0 : string implicit
- uriparser::Uri() : Uri()
- uriparser::clone(dest: Uri; src: Uri)
Creates a deep copy of the given Uri object.
- uriparser::finalize(uri: Uri)
Releases all resources held by the Uri object.
- Arguments
uri : Uri implicit
4.3.3. Escape and unescape
- uriparser::escape_uri(uriStr: string; spaceToPlus: bool; normalizeBreaks: bool) : string()
Percent-encodes reserved and special characters in the URI string.
- Arguments
uriStr : string implicit
spaceToPlus : bool
normalizeBreaks : bool
- uriparser::unescape_uri(uriStr: string) : string()
Decodes percent-encoded characters in the URI string.
- Arguments
uriStr : string implicit
4.3.4. Uri manipulations
- uriparser::add_base_uri(base: Uri; relative: Uri) : Uri()
Resolves a relative URI against a base URI, producing an absolute URI.
- uriparser::normalize(uri: Uri) : bool()
Normalizes a Uri in place, removing redundant /, ., and .. path segments.
- Arguments
uri : Uri implicit
- uriparser::normalize_uri(uriStr: string) : string()
Returns a normalized copy of the URI string with redundant /, ., and .. segments removed.
- Arguments
uriStr : string implicit
- uriparser::remove_base_uri(base: Uri; relative: Uri) : Uri()
Computes a relative URI by removing the base URI prefix from an absolute URI.
4.3.4.1. string
- uriparser::string(uri: Uri) : string()
Converts a Uri object to its string representation.
- Arguments
uri : Uri implicit
- uriparser::string(range: UriTextRangeA) : string()
- uriparser::strip_uri(uri: Uri; query: bool; fragment: bool) : Uri()
Removes the query string and fragment from the URI.
- Arguments
uri : Uri implicit
query : bool
fragment : bool
- uriparser::uri_for_each_query_kv(uri: Uri; block: block<(string#;string#):void>)
Iterates over each key-value pair in the URI’s query string, invoking a block for each.
- Arguments
uri : Uri implicit
block : block<(string#;string#):void> implicit
4.3.5. File name conversions
- uriparser::file_name_to_uri(uriStr: string) : string()
Converts a platform-native file path to a file:// URI string.
- Arguments
uriStr : string implicit
- uriparser::to_file_name(uri: Uri) : string()
Converts a Uri to a platform-native file path.
- Arguments
uri : Uri implicit
- uriparser::to_unix_file_name(uri: Uri) : string()
Converts a Uri to a Unix-style file path.
- Arguments
uri : Uri implicit
- uriparser::to_windows_file_name(uri: Uri) : string()
Converts a Uri to a Windows-style file path.
- Arguments
uri : Uri implicit
- uriparser::unix_file_name_to_uri(uriStr: string) : string()
Converts a Unix-style file path to a file:// URI string.
- Arguments
uriStr : string implicit
- uriparser::uri_from_file_name(filename: string) : Uri()
Converts a platform-native file path to a file:// URI string.
- Arguments
filename : string implicit
- uriparser::uri_from_unix_file_name(filename: string) : Uri()
Converts a Unix-style file path to a file:// URI string.
- Arguments
filename : string implicit
- uriparser::uri_from_windows_file_name(filename: string) : Uri()
Converts a Windows-style file path to a file:// URI string.
- Arguments
filename : string implicit
- uriparser::uri_to_file_name(uriStr: string) : string()
Converts a URI string to a platform-native file path.
- Arguments
uriStr : string implicit
- uriparser::uri_to_unix_file_name(uriStr: string) : string()
Converts a URI string to a Unix-style file path.
- Arguments
uriStr : string implicit
- uriparser::uri_to_windows_file_name(uriStr: string) : string()
Converts a URI string to a Windows-style file path.
- Arguments
uriStr : string implicit
- uriparser::windows_file_name_to_uri(uriStr: string) : string()
Converts a Windows-style file path to a file:// URI string.
- Arguments
uriStr : string implicit