Module path
path
Cross-platform filesystem path manipulation.
Types
PathError
enum
PathError
Path parsing error variants.
Variants
| Variant | Fields | Description |
|---|---|---|
EmptyPath | The path string was empty. | |
InvalidPath | message: String | The path string was malformed. |
Path
object
Path
Filesystem path with segment-based operations.
Paths are normalized on construction: . segments are removed, .. pops the parent.
Fields
| Name | Type | Description |
|---|---|---|
_segments | ArrayList(String) | |
_is_absolute | bool |
Trait Implementations
impl(Path, ...)
new : (Path) fn(path_str : String) -> Pathfrom_cstr : (Path) fn(cstr : *(u8)) -> Pathjoin : (Path) fn(self : Path, other : Path) -> Pathparent : (Path) fn(self : Path) -> Option(Path)file_name : (Path) fn(self : Path) -> Option(String)file_stem : (Path) fn(self : Path) -> Option(String)extension : (Path) fn(self : Path) -> Option(String)with_extension : (Path) fn(self : Path, ext : String) -> Pathwith_file_name : (Path) fn(self : Path, name : String) -> Pathstarts_with : (Path) fn(self : Path, base : Path) -> boolends_with : (Path) fn(self : Path, suffix : Path) -> boolcomponents : (Path) fn(self : Path) -> ArrayList(String)is_absolute : (Path) fn(self : Path) -> boolis_relative : (Path) fn(self : Path) -> boolimpl(Path, ToString(...))
to_string : (self -> {
segments := self._segments;
sep := String.from("/");
result := String.new();
// Check if first segment is a Windows drive letter (e.g., "C:")
has_drive_letter := cond(
(segments.len() > usize(0)) => {
first_seg_opt := segments.get(usize(0));
match(first_seg_opt,
.Some(first_seg) =>
// Check if it's a drive letter like "C:"
cond(
(first_seg.len() == usize(2)) => {
b0_opt := first_seg.as_bytes().get(usize(0));
b1_opt := first_seg.as_bytes().get(usize(1));
match(b0_opt,
.Some(b0) => match(b1_opt,
.Some(b1) => {
is_letter := (((b0 >= u8(65)) && (b0 <= u8(90))) || ((b0 >= u8(97)) && (b0 <= u8(122))));
is_colon := (b1 == u8(58));
(is_letter && is_colon)
},
.None => false
),
.None => false
)
},
true => false
),
.None => false
)
},
true => false
);
// For Unix absolute paths, prepend /
// For Windows paths with drive letter, don't prepend /
cond(
(self._is_absolute && !has_drive_letter) => {
result = result.concat(sep);
},
true => ()
);
i := usize(0);
segments_len := segments.len();
while ((i < segments_len)),
(i = (i + usize(1))),
{
seg := segments.get(i);
match(seg,
.Some(s) => {
result = result.concat(s);
cond(
((i < (segments_len - usize(1)))) => {
result = result.concat(sep);
},
true => ()
);
},
.None => ()
);
};
return result;
})impl(Path, Eq(Path))
Constants
Platform-specific path separator: '/' on Unix, '\\' on Windows.
Value: 47
Platform-specific path list delimiter: ':' on Unix, ';' on Windows.
Value: 58