Module: io.path
Source: ./io/path.reef
Overview
io/path - Path manipulation utilities
Provides functions for working with file system paths. All paths use forward slashes (/) as separator.
Functions
fn join_path(a: string, b: string): string
Joins two path components with a separator Handles trailing/leading slashes correctly
fn dirname(path: string): string
Returns the directory portion of a path "/home/user/file.txt" -> "/home/user" "file.txt" -> ""
fn basename(path: string): string
Returns the filename portion of a path (after the last /) "/home/user/file.txt" -> "file.txt" "file.txt" -> "file.txt"
fn extension(path: string): string
Returns the file extension (without the dot) "file.txt" -> "txt" "file.tar.gz" -> "gz" "file" -> ""
fn strip_extension(path: string): string
Removes the file extension from a path "file.txt" -> "file" "/home/user/file.txt" -> "/home/user/file"
fn is_absolute(path: string): bool
Returns true if path is absolute (starts with /)
fn is_relative(path: string): bool
Returns true if path is relative (does not start with /)
fn has_extension(path: string): bool
Returns true if path has an extension
fn normalize(path: string): string
Normalizes a path:
- collapses repeated
/ - resolves
.segments (drop) - resolves
..by popping the prior segment (absolute paths never climb above root; relative paths may keep leading..) - preserves absolute vs relative (leading
/) - root
/stays/; empty stays"" - trailing
/is trimmed except for root POSIX-inspired segment stack, written into a single output buffer.
fn join(a: string, b: string): string
Preferred name for joining two path components. Equivalent to join_path; the longer name is retained for backward compatibility.
fn expand_home(p: string): string
Expands a leading tilde to the value of $HOME.
"" -> $HOME
"/foo" -> $HOME/foo
"/abs/foo" -> "/abs/foo" (passthrough)
"rel/foo" -> "rel/foo" (passthrough)
"~user/foo" -> "user/foo" (passthrough; expand_user not yet implemented)
If $HOME is unset, the path is returned unchanged (substituting empty
would silently turn "/foo" into "/foo").
Returns the value of $HOME, or "" if unset.
fn expand_user(p: string): string
Expands a leading user or /", and "~/foo" (these don't carry a username). On unknown
user or empty path, returns the input unchanged.user/foo using getpwnam to look up the
named user's home directory. Falls back to expand_home behavior for
"", "
"root" -> /root (via getpwnam("root"))
"" -> $HOME (delegates to expand_home)
"~nope/foo" -> "~nope/foo" (unknown user, passthrough)
"/abs" -> "/abs" (passthrough)root/foo" -> /root/foo
"/foo" -> $HOME/foo (delegates to expand_home)
"
Generated by reefc doc