pub fn starts_with(self: text, value: text) -> boolean
Returns true if self begins with value. Use for prefix matching (e.g., protocol detection).
pub fn ends_with(self: text, value: text) -> boolean
Returns true if self ends with value. Use for suffix matching (e.g., file extension checks).
pub fn path_inside(root: text, path: text) -> text?
Where path lies under root, or null when it would lie outside it. Use it for a path a program did not write itself — the path of a request, a name out of an archive, a file name a user typed — before handing it to file, read_bytes or delete: loft opens whatever path it is given (../../etc/passwd and /etc/passwd included), and this is the check that keeps such a path inside the directory it was meant for. at = path_inside("public", request_path); if at == null { respond(403, "outside") } else { serve(file(at)) } The path is read as loft reads every path: / and \ both separate, . stays where it is and .. steps up. A .. that stays inside is fine (a/../b is root/b); one that steps above the root is null, as are an absolute path and one naming a drive (C:). Null means OUTSIDE, which is not "no such file": answer it as a refusal. A symbolic link inside the root is followed where it leads, as the file system does.
pub fn dir(self: text) -> text
Directory part of a path — strips the trailing /<segment>. Paths are plain slash-separated text: a \ is not a separator here, on any platform. "doc/claude/PROBLEMS.md".dir() → "doc/claude" "CLAUDE.md".dir() → "" (no /) "/etc/passwd".dir() → "/etc" "".dir() → ""
pub fn basename(self: text) -> text
Last segment of a path — the part after the trailing /. "doc/claude/PROBLEMS.md".basename() → "PROBLEMS.md" "CLAUDE.md".basename() → "CLAUDE.md" "/foo/".basename() → "" (trailing slash) "".basename() → ""
pub fn join(self: text, other: text) -> text
Join two paths — self/other with a single / separator. Special cases: - other starts with / (absolute) → return other unchanged - self is empty → return other - self ends with / → no extra separator inserted
pub fn resolve(self: text, target: text) -> text
Resolve target against self (where self is a base directory). Strips leading ./ repeatedly; each ../ segment trims the last component from self. Mirrors scan.loft's resolve_link_path. "doc/claude".resolve("../README.md") → "doc/README.md" "doc/claude".resolve("./PROBLEMS.md") → "doc/claude/PROBLEMS.md" "a/b/c".resolve("../../x") → "a/x" "".resolve("foo") → "foo"