Function getUnprefixedPathType [src]

Get the path type of a path that is known to not have any namespace prefixes (\\?\, \\.\, \??\). If T is u16, then path should be encoded as WTF-16LE.

Prototype

pub fn getUnprefixedPathType(comptime T: type, path: []const T) UnprefixedPathType

Parameters

T: typepath: []const T

Example

test getUnprefixedPathType { try std.testing.expectEqual(UnprefixedPathType.relative, getUnprefixedPathType(u8, "")); try std.testing.expectEqual(UnprefixedPathType.relative, getUnprefixedPathType(u8, "x")); try std.testing.expectEqual(UnprefixedPathType.relative, getUnprefixedPathType(u8, "x\\")); try std.testing.expectEqual(UnprefixedPathType.root_local_device, getUnprefixedPathType(u8, "//.")); try std.testing.expectEqual(UnprefixedPathType.root_local_device, getUnprefixedPathType(u8, "/\\?")); try std.testing.expectEqual(UnprefixedPathType.root_local_device, getUnprefixedPathType(u8, "\\\\?")); try std.testing.expectEqual(UnprefixedPathType.unc_absolute, getUnprefixedPathType(u8, "\\\\x")); try std.testing.expectEqual(UnprefixedPathType.unc_absolute, getUnprefixedPathType(u8, "//x")); try std.testing.expectEqual(UnprefixedPathType.rooted, getUnprefixedPathType(u8, "\\x")); try std.testing.expectEqual(UnprefixedPathType.rooted, getUnprefixedPathType(u8, "/")); try std.testing.expectEqual(UnprefixedPathType.drive_relative, getUnprefixedPathType(u8, "x:")); try std.testing.expectEqual(UnprefixedPathType.drive_relative, getUnprefixedPathType(u8, "x:abc")); try std.testing.expectEqual(UnprefixedPathType.drive_relative, getUnprefixedPathType(u8, "x:a/b/c")); try std.testing.expectEqual(UnprefixedPathType.drive_absolute, getUnprefixedPathType(u8, "x:\\")); try std.testing.expectEqual(UnprefixedPathType.drive_absolute, getUnprefixedPathType(u8, "x:\\abc")); try std.testing.expectEqual(UnprefixedPathType.drive_absolute, getUnprefixedPathType(u8, "x:/a/b/c")); }

Source

pub fn getUnprefixedPathType(comptime T: type, path: []const T) UnprefixedPathType { if (path.len < 1) return .relative; if (std.debug.runtime_safety) { std.debug.assert(getNamespacePrefix(T, path) == .none); } const windows_path = std.fs.path.PathType.windows; if (windows_path.isSep(T, mem.littleToNative(T, path[0]))) { // \x if (path.len < 2 or !windows_path.isSep(T, mem.littleToNative(T, path[1]))) return .rooted; // exactly \\. or \\? with nothing trailing if (path.len == 3 and (mem.littleToNative(T, path[2]) == '.' or mem.littleToNative(T, path[2]) == '?')) return .root_local_device; // \\x return .unc_absolute; } else { // x if (path.len < 2 or mem.littleToNative(T, path[1]) != ':') return .relative; // x:\ if (path.len > 2 and windows_path.isSep(T, mem.littleToNative(T, path[2]))) return .drive_absolute; // x: return .drive_relative; } }