Uiua implementation for parsing Uniform Resource Identifiers into it's components for further manipulation. This library also includes a method for building the URI back from the parsed data.
This implementation doesn't follow any spec, it's only my best attempt.
The parser just matches a URI to hand-written regular expression instead of properly tokenizing and rigorously parsing input. That means that the parser is relatively lax and may parse what is a technically invalid URI.
It may also be incomplete and fail to match URIs with some edge cases. Please create an issue for such cases.
Requires at least Uiua v0.10.0-dev.1
.
# Experimental!
# Import the library
URI ~ "git: github.com/ekgame/uiua-uri-parser"
# Parse URI to it's components
URI~Parse "https://google.com/search?q=hello+world"
# The components are just a map that can be modified
# For example, we can change the domain for the URI
insert "domain" "bing.com"
# We can then build the URI back into string with the changes
URI~Build
Try the code in the online editor
Take this URI for example:
ftp://username:password@ftp.example.com:21/path/to/file?key=value&key2[]=value2#fragment-test
It will be split into a map with these components:
Key | Value |
---|---|
schema | ftp |
userinfo | username:password |
domain | ftp.example.com |
port | 21 |
path | /path/to/file |
query | key=value&key2[]=value2 |
fragment | fragment-test |
Any parsed URI will have all keys in the map, but the values may be empty strings if the component is not present.
- Test cases adapted from this comment in StackOverflow.