struct Uri {
scheme : String? // URI scheme (http, https, etc.)
authority : Authority?// Authority component
path : String // Path component
query : String? // Query component
fragment : String? // Fragment component
}struct Authority {
userinfo : String? // User information (user:pass)
host : String // Host name or IP address
port : Int? // Port number
}let uri = parse_uri("http://www.example.com/path?query=value#fragment")
println("Scheme: \{uri.scheme.unwrap()}") // "http"
println("Host: \{uri.authority.unwrap().host}") // "www.example.com"
println("Path: \{uri.path}") // "/path"
println("Query: \{uri.query.unwrap()}") // "query=value"
println("Fragment: \{uri.fragment.unwrap()}") // "fragment"let uri = parse_uri("https://user:pass@example.com:8080/secure/path")
let auth = uri.authority.unwrap()
println("Userinfo: \{auth.userinfo.unwrap()}") // "user:pass"
println("Host: \{auth.host}") // "example.com"
println("Port: \{auth.port.unwrap()}") // 8080let uri = parse_uri("http://[2001:db8::1]:8080/path")
let auth = uri.authority.unwrap()
println("Host: \{auth.host}") // "[2001:db8::1]"
println("Port: \{auth.port.unwrap()}") // 8080let uri = parse_uri("HTTP://EXAMPLE.COM:80/path")
let normalized = normalize_uri(uri)
println("Normalized: \{normalized.to_string()}") // "http://example.com/path"let encoded = percent_encode("hello world!", is_unreserved)
println("Encoded: \{encoded}") // "hello%20world%21"
let decoded = percent_decode("hello%20world%21")
println("Decoded: \{decoded}") // "hello world!"let relative = parse_uri_reference("/path/to/resource?query=val")
println("Scheme: None (relative reference)")
println("Path: \{relative.path}") // "/path/to/resource"
println("Query: \{relative.query.unwrap()}") // "query=val"moon run src