accept_lang.nx
buildroot/runtime/accept_lang.nx
about
accept_lang.nx -- parse HTTP Accept-Language header.
RFC 7231 ยง5.3.5. Clients send a comma-separated list of
language tags with optional quality values:
Accept-Language: en-US,en;q=0.9,fr;q=0.8,*;q=0.1
We parse this into a sorted array of (tag, quality_thousandths)
and expose a lookup helper that picks the best match from a
server-supported-languages list.
Quality values:
- Default q = 1.0 if omitted
- Range 0.0..1.0; anything else clamped
- Stored as integer thousandths (0..1000) to avoid FP math
Sorting: higher quality first; ties preserve input order
(stable). Caller walks sorted list first-match against their
supported set.
Invariants:
AL1 Zero-alloc: offsets into caller's buffer.
AL2 \"*\" wildcard accepted as a language tag; it matches
any language that hasn't been explicitly excluded.
AL3 Language tag byte ranges preserved as-is (case-sensitive
in the buffer); caller does ASCII-lowercase compare if
they need RFC-correct case-insensitive matching.
dependencies 1 imports · 0 importers
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 32 | struct AcceptLang { |
consts
| 30 | const AL_ERR_OVERFLOW: i64 = -1 |
functions
| 38 | func al_is_ws(b: i64) -> i64 { |
| 44 | func al_ltrim(buf: *u8, off: i64, end: i64) -> i64 { |
| 53 | func al_rtrim(buf: *u8, start: i64, end: i64) -> i64 { |
| 64 | func al_parse_q(buf: *u8, pos: *i64, end: i64) -> i64 { |
| 111 | func accept_lang_parse(buf: *u8, n: i64, |
| 159 | func accept_lang_sort(entries: *AcceptLang, count: i64) -> i64 {
called by 1: main |
| 186 | func main() -> i64 { |