IriUtils

object IriUtils

Utilities for working with IRIs (Internationalized Resource Identifiers) in the context of the Solid protocol.

Java's URI class only handles a subset of valid IRIs (ASCII-range). These helpers provide basic normalization and validation aligned with the Solid Protocol's IRI requirements.

Spec: https://solidproject.org/TR/protocol — IRI handling

Functions

Link copied to clipboard

Returns the canonical form of iri for equivalence comparison: lower-cases the scheme and host, removes ./.. dot-segments, and normalizes percent-encoding via URI. Path case, the trailing slash, and any fragment are preserved — a file x and a container x/, or two different #fragments, are genuinely distinct resources/agents and must NOT be unified. Falls back to the raw string if iri doesn't parse.

Link copied to clipboard

Escapes iri for safe emission inside <...> angle brackets in N-Triples / Turtle / N3. The IRIREF production forbids control characters (U+0000–U+0020) and < > " { } | ^ \` unescaped; we replace each with a \\uXXXX UCHAR so a hostile or merely unusual IRI can't break out of the term and corrupt the serialized document. Returns the input unchanged when it contains none of those characters.

Link copied to clipboard

Returns true if iri identifies an LDP container (URI ends with /). Per the Solid Protocol, the / character indicates a hierarchical container relationship.

Link copied to clipboard

Returns true if iri is a syntactically valid absolute IRI with an http or https scheme (the only schemes used in Solid).

Link copied to clipboard

Returns the parent container IRI of iri, or null if iri is the storage root (no parent).

Link copied to clipboard
fun resolve(base: String, reference: String): String

Resolves reference against base, returning the resolved IRI string. Handles relative references such as /path/to/resource.

Link copied to clipboard

Returns the last path segment of iri (the resource name), excluding any trailing slash.

Link copied to clipboard

Returns true if a and b denote the same IRI once canonical-ized.

Link copied to clipboard

Strips the trailing slash from iri if present.

Link copied to clipboard

Appends a trailing slash to iri if absent, returning a container IRI.

Link copied to clipboard
fun toUriOrNull(iri: String): URI?

Attempts to parse iri as a URI, returning null on failure instead of throwing.