Paths
Module paths
import paths
| Module | paths |
| Source | paths/module-docs.zirr, paths/paths.zirr |
Path strings, independent of the host.
Paths are slash-separated regardless of the host: they describe the filesystem fs presents, not the machine the program runs on. Nothing here touches the disk — these are string operations, and a path that does not exist is manipulated exactly like one that does.
match is the exception to the “returns a plain value” rule: a malformed pattern is a mistake worth reporting, so it returns a prelude.Result rather than silently answering false.
Contents
Functions
base
`paths/paths.zirr:12`
extern fn base(p: String) -> String
Returns the last element of p.
clean
`paths/paths.zirr:9`
extern fn clean(p: String) -> String
Returns p with redundant separators and . or … elements resolved.
dir
`paths/paths.zirr:15`
extern fn dir(p: String) -> String
Returns p without its last element, i.e. its directory.
ext
`paths/paths.zirr:18`
extern fn ext(p: String) -> String
Returns the extension of p’s last element, including the leading dot, or “” if it has none.
isAbs
`paths/paths.zirr:24`
extern fn isAbs(p: String) -> Bool
Returns whether p begins at the root.
join
`paths/paths.zirr:6`
extern fn join(parts: [String]) -> String
Joins every part into a single path, cleaning the result.
match
`paths/paths.zirr:31`
extern fn match(pattern: String, p: String) -> Result
Returns whether p matches pattern, where * matches any run of non-separator characters, ? matches one, and [abc] matches a character class.
Fails with Err when the pattern is malformed, which is why this returns a Result rather than a Bool.
segments
`paths/paths.zirr:27`
extern fn segments(p: String) -> [String]
Returns p’s non-empty elements, in order.
stem
`paths/paths.zirr:21`
extern fn stem(p: String) -> String
Returns the last element of p without its extension.