code wiki / (root) / url.nx

url.nx

buildroot/runtime/url.nx

5412 B149 linesdepth 3pulls 3 transitivereach 1 importersview sourcekind tooltopic url
docsdependenciesstructsconstsfunctions

about

url.nx -- URL percent-encoding + decoding (RFC 3986). Used by: HTTP query strings, path segments, form-urlencoded POST bodies, JWT segments. Complements base64.nx / hex.nx for the URL-safe text-encoding niche. Encoding rules (RFC 3986 ยง2.3): Unreserved: A-Z a-z 0-9 - . _ ~ (encoded as-is) Reserved: : / ? # [ ] @ ! $ & ' ( ) * + , ; = -- reserved chars DEPEND on context. We offer two encoders: url_encode_component -- encodes everything reserved url_encode_path -- preserves / for path segments All other bytes: encoded as %HH (two uppercase hex digits). Invariants: UR1 Output is deterministic: same input -> same bytes. UR2 Decoder rejects malformed sequences (%X or %XY where Y isn't hex) with a negative return. No silent skip. UR3 Decoder accepts both upper and lower case hex digits. UR4 Round-trip exact for any byte sequence: decode(encode(x)) == x UR5 Encoder never outputs non-ASCII; caller always gets 7-bit safe text.

dependencies 1 imports · 1 importers

syscalls.nx url.nx totp_uri.nx

imports: syscalls.nx

imported by: totp_uri.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main url_encode_component url_unreserved url_hex_upper url_decode url_hex_val

structs

none

consts

27const URL_ERR_BAD_ESCAPE: i64 = -1
28const URL_ERR_TRUNCATED: i64 = -2

functions

31func url_unreserved(c: i64) -> i64 {
43func url_hex_upper(n: i64) -> i64 {
49func url_hex_val(c: i64) -> i64 {
called by 1: url_decode
59func url_encode_component(in_bytes: *u8, n: i64, out: *u8) -> i64 {
80func url_encode_path(in_bytes: *u8, n: i64, out: *u8) -> i64 {
107func url_decode(in_bytes: *u8, n: i64, out: *u8) -> i64 {
called by 1: main calls 1: url_hex_val
132func main() -> i64 {