Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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 standard library. Public Function

normalizePath

Public Function
std.os.windows.normalizePath
pub fn normalizePath(comptime T: type, path: []T) RemoveDotDirsError!usize

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.

Params

  • T: type
  • path: []T

Errors

TooManyParentDirs

File

os/windows.zig:3843
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
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]);
}