4.5. 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.5.1. Handled structures
- UriIp6Struct
IPv6 address portion of the URI.
- Fields:
data : uint8[16] - IPv6 address data.
- 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.
- 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.
- UriIp4Struct
IPv4 address portion of the URI.
- Fields:
data : uint8[4] - IPv4 address data.
- UriTextRangeA
Range of text in the URI.
- 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.
- 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.
4.5.2. Initialization and finalization
4.5.2.1. Uri
- Uri(arg0: string): Uri
Constructs a new Uri object by parsing the given URI string.
- Arguments:
arg0 : string implicit
- Uri(): Uri
- clone(dest: Uri; src: Uri)
Creates a deep copy of the given Uri object.
- finalize(uri: Uri)
Releases all resources held by the Uri object.
- Arguments:
uri : Uri implicit
4.5.2.2. using
- using(arg0: string; arg1: block<(Uri#):void>)
Creates a scoped Uri variable that is automatically finalized at end of block.
- Arguments:
arg0 : string implicit
arg1 : block<( Uri#):void> implicit
- using(arg0: block<(Uri#):void>)
4.5.3. Escape and unescape
- 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
- unescape_uri(uriStr: string): string
Decodes percent-encoded characters in the URI string.
- Arguments:
uriStr : string implicit
4.5.4. Uri manipulations
- add_base_uri(base: Uri; relative: Uri): Uri
Resolves a relative URI against a base URI, producing an absolute URI.
- normalize(uri: Uri): bool
Normalizes a Uri in place, removing redundant /, ., and .. path segments.
- Arguments:
uri : Uri implicit
- normalize_uri(uriStr: string): string
Returns a normalized copy of the URI string with redundant /, ., and .. segments removed.
- Arguments:
uriStr : string implicit
- remove_base_uri(base: Uri; relative: Uri): Uri
Computes a relative URI by removing the base URI prefix from an absolute URI.
4.5.4.1. string
- string(uri: Uri): string
Converts a Uri object to its string representation.
- Arguments:
uri : Uri implicit
- string(range: UriTextRangeA): string
- 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
- 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.5.5. File name conversions
- file_name_to_uri(uriStr: string): string
Converts a platform-native file path to a file:// URI string.
- Arguments:
uriStr : string implicit
- to_file_name(uri: Uri): string
Converts a Uri to a platform-native file path.
- Arguments:
uri : Uri implicit
- to_unix_file_name(uri: Uri): string
Converts a Uri to a Unix-style file path.
- Arguments:
uri : Uri implicit
- to_windows_file_name(uri: Uri): string
Converts a Uri to a Windows-style file path.
- Arguments:
uri : Uri implicit
- unix_file_name_to_uri(uriStr: string): string
Converts a Unix-style file path to a file:// URI string.
- Arguments:
uriStr : string implicit
- uri_from_file_name(filename: string): Uri
Converts a platform-native file path to a file:// URI string.
- Arguments:
filename : string implicit
- uri_from_unix_file_name(filename: string): Uri
Converts a Unix-style file path to a file:// URI string.
- Arguments:
filename : string implicit
- uri_from_windows_file_name(filename: string): Uri
Converts a Windows-style file path to a file:// URI string.
- Arguments:
filename : string implicit
- uri_to_file_name(uriStr: string): string
Converts a URI string to a platform-native file path.
- Arguments:
uriStr : string implicit
- uri_to_unix_file_name(uriStr: string): string
Converts a URI string to a Unix-style file path.
- Arguments:
uriStr : string implicit
- uri_to_windows_file_name(uriStr: string): string
Converts a URI string to a Windows-style file path.
- Arguments:
uriStr : string implicit
- windows_file_name_to_uri(uriStr: string): string
Converts a Windows-style file path to a file:// URI string.
- Arguments:
uriStr : string implicit
4.5.6. GUID
- make_new_guid(): string
Generates a new random GUID/UUID string.