ddn.net.uri¶
RFC 3986 URI implementation with normalization, reference resolution, percent-encoding helpers, IDNA/Punycode hostname support, and RFC 6570 URI Templates.
Module Declaration¶
Classes¶
UriException¶
Base exception type for URI-related errors.
UriParseException¶
Exception type for URI parsing/validation errors.
UriTemplateException¶
Exception type for RFC 6570 URI Template parsing/expansion errors.
Enums¶
Component¶
URI component selector used to apply component-specific rules (notably percent-encoding).
| Member | Description |
|---|---|
Scheme |
Scheme component |
UserInfo |
Authority userinfo subcomponent |
Host |
Authority host subcomponent |
Path |
Path component |
Query |
Query component (without leading ?) |
Fragment |
Fragment component (without leading #) |
Structs¶
Authority¶
Authority component per RFC 3986 (userinfo@host:port).
The host is stored without square brackets even for IP-literals; brackets are added when formatting with toString().
Fields¶
| Field | Type | Description |
|---|---|---|
userinfo |
string |
Optional userinfo (empty if absent) |
host |
string |
Hostname or IP-literal value (IPv6/IPvFuture stored without brackets) |
port |
int |
Port number (-1 means absent) |
Methods¶
hasUserInfo¶
hasPort¶
toString¶
Serialize the authority, adding brackets for IP-literals.
URI¶
Generic Uniform Resource Identifier per RFC 3986.
Represents either an absolute URI (has a non-empty scheme) or a relative reference.
Fields¶
URI stores the parsed components directly:
schemeauthority(guarded byhasAuthority)pathquery(guarded byhasQueryComponent)fragment(guarded byhasFragmentComponent)
Construction & parsing¶
parse¶
Parse an absolute URI or relative reference.
parseStrict¶
Parse s as a URI applying additional strict validations.
Introspection¶
isAbsolute¶
True if this reference is an absolute URI (has a non-empty scheme).
hasAuthority¶
True if an authority component is present (i.e. the reference used the // form).
hasQueryComponent¶
hasFragmentComponent¶
Serialization¶
toString¶
Serialize this URI per RFC 3986 generic syntax.
Normalization¶
normalize¶
Normalize per RFC 3986 Section 6 (scheme/host case-folding, dot-segment removal, percent-encoding normalization, default port elision).
normalizeIDNA¶
Like normalize(), but also converts the host (when present and not an IP-literal) to ASCII using IDNA ToASCII.
hostUnicode¶
Return the Unicode form of the host using IDNA ToUnicode (if applicable).
Reference resolution¶
resolve¶
Resolve a reference against this base URI per RFC 3986 ยง5.2.
URL¶
Convenience wrapper for hierarchical absolute URIs that have an authority.
Construction¶
parse¶
Parses and enforces that the URI is absolute and has an authority.
Methods / properties¶
toString¶
scheme¶
authority¶
path¶
query¶
fragment¶
host¶
port¶
userinfo¶
hostUnicode¶
URN¶
Uniform Resource Name wrapper (scheme == "urn").
Construction¶
parse¶
Methods / properties¶
nss¶
Namespace Specific String (NSS) accessors.
toString¶
UriOptions¶
Options controlling per-call parsing/normalization strictness.
| Field | Type | Meaning |
|---|---|---|
strictParsing |
bool |
Enable stricter parsing validations |
idnaStrict |
bool |
Stricter IDNA label validation during IDNA conversion |
allowNonAsciiHost |
bool |
Allow non-ASCII bytes in reg-name during parsing |
IdnaOptions¶
Options controlling IDNA processing.
| Field | Type | Meaning |
|---|---|---|
enableMappings |
bool |
Apply basic UTS #46-like compatibility mappings |
strict |
bool |
Reject prohibited code points and additional label constraints |
UriTemplate¶
RFC 6570 URI Template (template string parsed into literal/expression parts).
Methods¶
parse¶
Parse an RFC 6570 template string.
expand¶
Expand this template using a variable scope.
UriTemplateVars¶
Expansion scope for URI Templates (maps variable names to values).
Methods¶
set¶
contains¶
get¶
UriTemplateValue¶
URI Template value model (scalar, list, or map).
Common constructors:
static UriTemplateValue fromScalar(string s);
static UriTemplateValue fromList(string[] items);
static UriTemplateValue fromMap(Tuple!(string, string)[] pairs);
static UriTemplateValue fromAA(string[string] aa);
Functions¶
pctEncodeTo¶
Write percent-encoded representation of s for component comp to dst.
pctEncode¶
Percent-encode s according to RFC 3986 rules for a specific component.
pctDecode¶
Decode %HH triplets in s byte-wise (invalid/incomplete escapes are preserved).
pctNormalizeTo¶
Normalize percent-escapes: decode escapes that map to unreserved characters and uppercase hex digits in remaining escapes.
pctNormalize¶
Allocating wrapper around pctNormalizeTo.
isPctAllowed¶
Returns true if code point c is allowed to appear unescaped (literal ASCII byte) in comp.
idnaToASCII¶
Convert a domain name to its ASCII form using IDNA ToASCII (basic version).
idnaToUnicode¶
string idnaToUnicode(string asciiDomain);
string idnaToUnicode(string asciiDomain, IdnaOptions opt);
Convert an ASCII domain containing Punycode labels to its Unicode form (IDNA ToUnicode subset).
punycodeEncodeLabel¶
Encode a single DNS label to Punycode (without adding the xn-- prefix).
punycodeDecodeLabel¶
Decode a single Punycode label (without the xn-- prefix).