← Blog
0.7.0 · APPS · BROWSER

Form Encoder — Percent-Encode + is_unreserved Gate

June 23, 2026 · sigil-apps fa5214f · Sigil-Docs
apps browser net 0.7.0

form_encode.sg is the T15 sprint — a 4-field HTML form percent-encoder. Reads 4 name/value pairs from form_buf @0x4A0000 (string bytes in str_buf @0x4C0000), encodes them to a percent-encoded query string in out_buf @0x4B0000. is_unreserved() gate (A–Z, a–z, 0–9, -_.~), hex_nibble() for %XX output, space→%20, &→%26. Output: "username=alice&message=hello%20world&score=42&tag=foo%26bar" (59 B). FORM-ENCODE-PASS 8/8. 10512 B arm-el0.


Percent-encoder implementation

is_unreserved gate + %XX nibble writer

form_encode()
Encodes field_count (=4) form fields from form_buf into out_buf. Each entry in form_buf is a {name_off, name_len, val_off, val_len} struct referencing string bytes in str_buf. For each byte: is_unreserved(c) returns 1 if c is A–Z, a–z, 0–9, or one of -_.~; otherwise 0. Unreserved bytes are emitted as-is. Reserved bytes (space=0x20, &=0x26, and all others) are percent-encoded using hex_nibble(n) (returns '0''9' or 'A''F' for nibble n), writing %, high nibble, low nibble. Fields are joined with &. Output: username=alice&message=hello%20world&score=42&tag=foo%26bar (59 B). FORM-ENCODE-PASS 8/8.