Asserts that path starts with two path separators
fn parseUNC(comptime T: type, path: []const T) WindowsUNC(T)
fn parseUNC(comptime T: type, path: []const T) WindowsUNC(T) {
assert(path.len >= 2 and PathType.windows.isSep(T, path[0]) and PathType.windows.isSep(T, path[1]));
const any_sep = switch (T) {
u8 => "/\\",
u16 => std.unicode.wtf8ToWtf16LeStringLiteral("/\\"),
else => @compileError("only u8 (WTF-8) and u16 (WTF-16LE) are supported"),
};
// For the server, the first path separator after the initial two is always
// the terminator of the server name, even if that means the server name is
// zero-length.
const server_end = mem.findAnyPos(T, path, 2, any_sep) orelse return .{
.server = path[2..path.len],
.sep_after_server = false,
.share = path[path.len..path.len],
.sep_after_share = false,
};
// For the share, there can be any number of path separators between the server
// and the share, so we want to skip over all of them instead of just looking for
// the first one.
var it = mem.tokenizeAny(T, path[server_end + 1 ..], any_sep);
const share = it.next() orelse return .{
.server = path[2..server_end],
.sep_after_server = true,
.share = path[server_end + 1 .. server_end + 1],
.sep_after_share = false,
};
return .{
.server = path[2..server_end],
.sep_after_server = true,
.share = share,
.sep_after_share = it.index != it.buffer.len,
};
}