Function dirnamePosix [src]

Prototype

pub fn dirnamePosix(path: []const u8) ?[]const u8

Parameters

path: []const u8

Example

test dirnamePosix { try testDirnamePosix("/a/b/c", "/a/b"); try testDirnamePosix("/a/b/c///", "/a/b"); try testDirnamePosix("/a", "/"); try testDirnamePosix("/", null); try testDirnamePosix("//", null); try testDirnamePosix("///", null); try testDirnamePosix("////", null); try testDirnamePosix("", null); try testDirnamePosix("a", null); try testDirnamePosix("a/", null); try testDirnamePosix("a//", null); }

Source

pub fn dirnamePosix(path: []const u8) ?[]const u8 { if (path.len == 0) return null; var end_index: usize = path.len - 1; while (path[end_index] == '/') { if (end_index == 0) return null; end_index -= 1; } while (path[end_index] != '/') { if (end_index == 0) return null; end_index -= 1; } if (end_index == 0 and path[0] == '/') return path[0..1]; if (end_index == 0) return null; return path[0..end_index]; }