// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie // SPDX-License-Identifier: MIT //! A URI parser and formatter, modelled on Python's `hyperlink` package. //! //! Source, issues and the README are at //! [git.jcollie.dev/jeff/zig-uri](https://git.jcollie.dev/jeff/zig-uri), //! mirrored to [codeberg.org/jcollie/zig-uri](https://codeberg.org/jcollie/zig-uri) //! and published on Radicle as `rad:zrcnvxgQxKm2DSmX3Q9VSF2dHJ8m`. //! //! ```zig //! const uri = @import("uri"); //! //! const u = try uri.Uri.parse(alloc, "https://example.com/a/b?q=1#top"); //! defer u.deinit(); //! //! u.scheme.? // "https" //! u.host.?.hostname // "example.com" //! u.path // .{ "a", "b" }, with u.rooted == true //! u.first("q").? // .{ .key = "q", .value = "1" } //! //! const link = try u.click(alloc, "../c/"); //! defer link.deinit(); //! // link is https://example.com/c/ //! ``` //! //! Components are stored decoded and re-escaped on output; see `Uri` for what //! that means for round-tripping. //! //! `src/wasm.zig` wraps all of this in a flat ABI for WebAssembly, which //! `web/uri.js` drives from a browser; `zig build wasm` builds the pair. It is //! not part of this module, so it does not appear in these docs — see the //! README. const std = @import("std"); const build_options = @import("build_options"); /// Whether this build has Unicode support compiled in, i.e. whether it was /// built with `-Dunicode=true`. When false, `idna`, `normalization` and /// `Uri.toUri`/`Uri.toIri` are unavailable and the library has no /// dependencies at all. pub const unicode_enabled = build_options.unicode; pub const components = @import("components.zig"); /// `data:` URLs (RFC 2397), which carry a document in the URL and have no /// hierarchy -- a base64 body is full of `/` -- and so need a parser of /// their own. Always available. pub const data = @import("data.zig"); /// `file:` URIs (RFC 8089) and the filesystem paths they name. See /// `Uri.fromPath` and `Uri.toPath`. Always available. pub const file = @import("file.zig"); pub const format = @import("format.zig"); /// LDAP URLs (RFC 4516), which are positional rather than query-shaped and so /// need a parser of their own. Always available. pub const ldap = @import("ldap.zig"); pub const normalize = @import("normalize.zig"); pub const parse = @import("parse.zig"); pub const percent = @import("percent.zig"); pub const query = @import("query.zig"); pub const relativize = @import("relativize.zig"); pub const schemes = @import("schemes.zig"); /// DNS stamps: `sdns://`, the one-string form a DNS resolver is published as. /// A parser of its own rather than a view over `Uri`, for the reason /// `stamp.zig` gives -- the body is base64url of a binary structure, and a /// generic parser reads it as an authority and lowercases it. pub const stamp = @import("stamp.zig"); /// Punycode (RFC 3492). Always available: it needs no Unicode tables. pub const punycode = @import("punycode.zig"); /// IDNA per UTS #46. Only present when built with `-Dunicode=true`. pub const idna = if (unicode_enabled) @import("idna.zig") else struct {}; /// Unicode Normalization Form C. Only present with `-Dunicode=true`. pub const normalization = if (unicode_enabled) @import("normalization.zig") else struct {}; pub const Components = components.Components; pub const Host = components.Host; pub const QueryParam = components.QueryParam; pub const Uri = @import("uri.zig").Uri; /// A parsed LDAP URL. See `ldap`. pub const LdapUrl = ldap.Url; /// A parsed data URL. See `data`. pub const DataUrl = data.Url; pub const Stamp = stamp.Stamp; pub const Error = @import("uri.zig").Error; /// The IANA-registered default port for a scheme, if it has one. pub const defaultPort = schemes.defaultPort; /// Whether a scheme is written `scheme://host/...` rather than `scheme:body`. pub const usesNetloc = schemes.usesNetloc; /// Decode `%XX` escapes. See `percent.decode`. pub const percentDecode = percent.decode; /// Percent-encode everything outside a character set. See `percent.encode`. pub const percentEncode = percent.encode; test { std.testing.refAllDecls(@This()); inline for (.{ components, data, file, format, ldap, normalize, parse, percent, query, relativize, schemes, stamp, punycode }) |m| { std.testing.refAllDecls(m); } if (unicode_enabled) { inline for (.{ idna, normalization }) |m| std.testing.refAllDecls(m); } _ = @import("tests.zig"); _ = @import("tests_hyperlink.zig"); _ = @import("tests_ldap.zig"); _ = @import("tests_file.zig"); _ = @import("tests_relativize.zig"); _ = @import("tests_stamp.zig"); _ = @import("fuzz.zig"); if (unicode_enabled) { _ = @import("tests_unicode.zig"); _ = @import("fuzz_unicode.zig"); } }