File system path abstractions for ZZ
Add this to your zz.toml file:
[dependencies] path = "*" [repos] path = "git+ssh://[email protected]/zzmodules/path.git"
using pathAn immutable structure that wraps a char * that is treated as a file path.
Path struct constructor from a given char * pathspec.
using path new p = path::from(".");
ParentPath (Path) struct constructor from a given child Path pointer.
using path new p = path::from("/home/user"); new parent = path::parent(&p);
Returns the length in bytes for the Path string.
using log using path new p = path::from("."); log::info("%lu", p.length()); // 1
Returns a char * string of this Path.
using log using path new p = path::from("./zz.toml"); log::info("%s", p.cstr()); // "./zz.toml"
Returns an Ancestors struct that implements an iterator interface
that will traverse all ancestors in this Path, including itself.
using log using path new p = path::from("/home/user/projects/project/zz.toml"); let mut ancestors = p.ancestors(); while !ancestors.ended { let ancestor = ancestors.next(); log::info("%s", ancestor.cstr()); }
Returns a char * that represents the "extension" part of a Path string.
This function will return an empty string if an extension cannot be found.
using log using path new p = path::from("zz.toml"); log::info("%s", p.extension()); // ".toml"
Returns true if the Path is an absolute path, otherwise false.
using log using path new p = path::from("/files/zz.toml"); if p.is_absolute() { log::info("%s is an absolute path", p.cstr()); }
Returns true if the Path is a relative path, the opposite of an
absolute path, otherwise false.
using log using path new p = path::from("./zz.toml"); if p.is_relative() { log::info("%s is a relative path", p.cstr()); }
Returns true if the path is the root path.
using log using path new p = path::from("/"); // or "c:\\" if p.is_root() { log::info("%s is the root path", p.cstr()); }
Returns true if the path contains the root path in it.
using log using path new p = path::from("/users"); // or "c:\\Users" if p.has_root() { log::info("%s has the root path", p.cstr()); }
Converts this Path to a PathBufferBox , a container for a PathBuffer+
with a fixed size of path::MAX_PATH_BUFFER_BYTES.
using log using path new p = path::from("/home"); let buffer = p.to_path_buffer(); buffer.push("users"); log::info("%s", buffer.cstr()); // "/home/users"
Implements display() to return a safe, nullterm char *.
using log using path new p = path::from("./zz.toml"); log::info("%s", p.display()); // "./zz.toml"
A mutable tail sized structure for path building. The maximum tail size of
this struct can ba path::MAX_PATH_BUFFER_BYTES.
PathBuffer+ constructor from an initial char * pathspec.
using path new+1024 b = path::buffer(".");
PathBufferBox (PathBuffer+) constructor from an initial char * pathspec
that is * canonicalized. An err::Err+ mut error must be given to catch
system errors that may occur during normalization (getcwd(), realpath())
or canonicalization (realpath()).
using err using path new+1024 mut error = err::make(); new b = path::canonicalize("../path/to/resolve", &error); if error.check() { // canonicalization failed, check error trace }
A tail sized String+ container for building the underlying path
string.
A Path with a pointer to the underlying memory in the PathBuffer+
string container.
Normalizes the current pathspec for a PathBuffer+. An err::Err+ mut
error must be given to catch system * errors that may occur during
normalization (getcwd(), realpath()).
using err using path new+1024 mut error = err::make(); new+1024 b = path::buffer("/home/../path/dir"); b.normalize(&error); if error.check() { // normalization failed, check error trace }
Returns the length in bytes for the PathBuffer+ string.
Returns a char * string of this PathBuffer+.
Returns an immutable Path that represents this PathBuffer+
using path new+1024 b = path::buffer("."); let p = b.as_path();
Returns a immutable Path * that represents a pointer to this PathBuffer+
as a Path type.
using path new+1024 b = path::buffer("."); let p = b.as_path_ptr();
Push a char * pathspec component to the buffer returning true
upon success, otherwise false.
using log using path new+1024 b = path::path_buffer(); b.push("path"); b.push("to"); b.push("file"); log::info("%s", b.display()); // "/path/to/file"
Pops a pathspec component from the buffer returning true upon success,
otherwise false.
using log using path new+1024 b = path::path_buffer(); b.push("path"); b.push("to"); b.push("file"); b.pop(); log::info("%s", b.display()); // "/path/to"
Appends a PathBuffer+ components to this PathBuffer+ returning
true upon success, otherwise false.
using log using path new+1024 b = path::path_buffer(); new+1024 joined = path::buffer("/home"); b.push("path"); b.push("to"); b.push("file"); log::info("%s", b.display()); // "/path/to/file" joined.append(&b); log::info("%s", joined.display()); // "/home/path/to/file"
Clears the buffer.
using log using path new+1024 b = path::path_buffer(); b.push("path"); b.push("to"); b.push("file"); b.clear(); log::info("%s", b.display()); // ""
Returns an Ancestors struct that implements an iterator interface
that will traverse all ancestors in this PathBuffer+, at this moment
in time, including itself.
Returns a char * that represents the "extension" part of the
PathBuffer+ string. This function will return an empty string if an
extension cannot be found.
Returns true if the PathBuffer+ is an absolute path, otherwise false.
Returns true if the PathBuffer+ is a relative path, the opposite of an
absolute path, otherwise false.
Returns true if the PathBuffer+ is the root path.
Returns true if the PathBuffer+ contains the root path in it.
Implements display() to return a safe, nullterm char *.
A structure that implements an iterator interface to represent the eventual ancestors of a path.
let mut ancestors = p.ancestors(); while !ancestors.ended { let ancestor = ancestors.next(); // `ancestor` is a `Path` type }
A boolean to indicate if the Ancestors iterator has reached the end of
the path tree.
Return a Path struct with a pointer to the next ancestors path.
Implements display() to return a safe, nullterm char *.
Get the operating system specific path separator as a char *. On
Windows, this will be "\\", otherwise "/".
Get the operating system specific path separator character., On Windows,
this will be '\\', otherwise '/'.
Get the operating system specific PATH delimiter as a char *. On
Windows, this will be ";", otherwise ":".
Get the operating system specific PATH delimiter character. On
Windows, this will be ';', otherwise ':'.
MIT