Something went wrong. Try again.
A URI parser and formatter for Zig, modelled on Python's hyperlink package, with LDAP URLs, file: URIs and sdns:// DNS stamps beside it.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// 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.//!//! IDNA, Unicode normalization and converting a host between its `xn--` and//! Unicode forms need Unicode tables, and live in a second module,//! `uri_unicode`, so that this one depends on nothing but z46. Punycode needs//! no tables and is here as `punycode`.
const std = @import("std");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");
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); } _ = @import("tests.zig"); _ = @import("tests_hyperlink.zig"); _ = @import("tests_ldap.zig"); _ = @import("tests_file.zig"); _ = @import("tests_relativize.zig"); _ = @import("tests_stamp.zig");}