struct EnvNameHashContext [src]

Members

Source

pub const EnvNameHashContext = struct { fn upcase(c: u21) u21 { if (c <= std.math.maxInt(u16)) return windows.ntdll.RtlUpcaseUnicodeChar(@as(u16, @intCast(c))); return c; } pub fn hash(self: @This(), s: []const u8) u64 { _ = self; if (native_os == .windows) { var h = std.hash.Wyhash.init(0); var it = unicode.Wtf8View.initUnchecked(s).iterator(); while (it.nextCodepoint()) |cp| { const cp_upper = upcase(cp); h.update(&[_]u8{ @as(u8, @intCast((cp_upper >> 16) & 0xff)), @as(u8, @intCast((cp_upper >> 8) & 0xff)), @as(u8, @intCast((cp_upper >> 0) & 0xff)), }); } return h.final(); } return std.hash_map.hashString(s); } pub fn eql(self: @This(), a: []const u8, b: []const u8) bool { _ = self; if (native_os == .windows) { var it_a = unicode.Wtf8View.initUnchecked(a).iterator(); var it_b = unicode.Wtf8View.initUnchecked(b).iterator(); while (true) { const c_a = it_a.nextCodepoint() orelse break; const c_b = it_b.nextCodepoint() orelse return false; if (upcase(c_a) != upcase(c_b)) return false; } return if (it_b.nextCodepoint()) |_| false else true; } return std.hash_map.eqlString(a, b); } }