DoxigAlpha

first

Returns the first component (from the beginning of the path). For example, if the path is /a/b/c then this will return the a component. After calling first, previous will always return null, and next will return the component to the right of the one returned by first, if any exist.

Function parameters

Parameters

#
self:*Self

Type definitions in this namespace

Types

#

Returns if the given byte is a valid path separator

Functions

#
isSep
Returns if the given byte is a valid path separator
join
Naively combines a series of paths with the native path separator.
joinZ
Naively combines a series of paths with the native path separator and null terminator.
resolve
On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`.
resolveWindows
This function is like a series of `cd` statements executed one after another.
resolvePosix
This function is like a series of `cd` statements executed one after another.
dirname
Strip the last component from a file path.
relative
Returns the relative path from `from` to `to`.
extension
Searches for a file extension separated by a `.` and returns the string after that `.`.
stem
Returns the last component of this path without its extension (if any):
ComponentIterator
A path component iterator that can move forwards and backwards.
fmtAsUtf8Lossy
Format a path encoded as bytes for display as UTF-8.
fmtWtf16LeAsUtf8Lossy
Format a path encoded as WTF-16 LE for display as UTF-8.

= '\\'

Values

#
sep
= switch (native_os) { .windows, .uefi => sep_windows, else => sep_posix, }
sep_str
= switch (native_os) { .windows, .uefi => sep_str_windows, else => sep_str_posix, }
delimiter
= if (native_os == .windows) delimiter_windows else delimiter_posix

Source

Implementation

#
pub fn first(self: *Self) ?Component {
    self.start_index = self.root_end_index;
    self.end_index = self.start_index;
    while (self.end_index < self.path.len and !path_type.isSep(T, self.path[self.end_index])) {
        self.end_index += 1;
    }
    if (self.end_index == self.start_index) return null;
    return .{
        .name = self.path[self.start_index..self.end_index],
        .path = self.path[0..self.end_index],
    };
}