Function normalizePath [src]

Normalizes a Windows path with the following steps: convert all forward slashes to back slashes collapse duplicate back slashes remove '.' and '..' directory parts Returns the length of the new path.

Prototype

pub fn normalizePath(comptime T: type, path: []T) RemoveDotDirsError!usize

Parameters

T: typepath: []T

Possible Errors

TooManyParentDirs

Source

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]); }