Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

normalizePath

Normalizes a Windows path with the following steps:

  1. convert all forward slashes to back slashes
  2. collapse duplicate back slashes
  3. remove '.' and '..' directory parts Returns the length of the new path.
windows.normalizePath
pub fn normalizePath(comptime T: type, path: []T) RemoveDotDirsError!usize

File

lib/std/os/windows.zig:3843

Code

pub fn normalizePath(comptime T: type, path: []T) RemoveDotDirsError!usize {
    mem.replaceScalar(T, path, '/', '\\');
    const new_len = mem.collapseRepeatsLen(T, path, '\\');

    const prefix_len: usize = init: {
        if (new_len >= 1 and path[0] == '\\') break :init 1;
        if (new_len >= 2 and path[1] == ':')
            break :init if (new_len >= 3 and path[2] == '\\') @as(usize, 3) else @as(usize, 2);
        break :init 0;
    };

    return prefix_len + try removeDotDirsSanitized(T, path[prefix_len..new_len]);
}