authorgravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2022-02-04 22:36:24-07:00
committergravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2022-05-11 18:41:23-06:00
loge65d8f82c5f98b20236f571fe4a4e40924ea8dc2
tree8f32cc1f06809c43cce5430e0428bc94d15b6df3
parent69f0a5587d0db07546e91968b21135fdef856136

add unicode support


2 files changed, 28 insertions(+), 8 deletions(-)

lib/std/os/windows/ntdll.zig+4
......@@ -235,6 +235,10 @@ pub extern "NtDll" fn RtlUpcaseUnicodeString(
235235 AllocateDestinationString: BOOLEAN,
236236) callconv(WINAPI) NTSTATUS;
237237
238pub extern "NtDll" fn RtlUpcaseUnicodeChar(
239 SourceCharacter: u16,
240) callconv(WINAPI) u16;
241
238242pub extern "ntdll" fn NtLockFile(
239243 FileHandle: HANDLE,
240244 Event: ?HANDLE,
lib/std/process.zig+24-8
......@@ -63,26 +63,42 @@ pub const EnvMap = struct {
6363 );
6464
6565 pub const EnvNameHashContext = struct {
66 fn upcase(c: u21) u21 {
67 if (c <= std.math.maxInt(u16))
68 return std.os.windows.ntdll.RtlUpcaseUnicodeChar(c);
69 return c;
70 }
71
6672 pub fn hash(self: @This(), s: []const u8) u64 {
6773 _ = self;
6874 if (builtin.os.tag == .windows) {
6975 const h = std.hash.Wyhash.init(0);
70 // TODO: improve this, instead of iterating over ascii,
71 // iterate over with unicode
72 for (s) |c| {
73 var s_upper = [_]u8 { std.ascii.toLower(c) };
74 h.update(s_upper);
76 var it = std.unicode.Utf8View(s).iterator();
77 while (it.nextCodepoint()) |cp| {
78 const cp_upper = upcase(cp);
79 h.update(&[_]u8{
80 @intCast(u8, (cp_upper >> 16) & 0xff),
81 @intCast(u8, (cp_upper >> 8) & 0xff),
82 @intCast(u8, (cp_upper >> 0) & 0xff),
83 });
7584 }
7685 return h.final();
7786 }
7887 return std.hash_map.hashString(s);
7988 }
89
8090 pub fn eql(self: @This(), a: []const u8, b: []const u8) bool {
8191 _ = self;
8292 if (builtin.os.tag == .windows) {
83 // TODO: improve this, instead of comparing ascii
84 // compare with unicode
85 return std.ascii.eqlIgnoreCase(a, b);
93 var it_a = std.unicode.Utf8View(a).iterator();
94 var it_b = std.unicode.Utf8View(b).iterator();
95 while (true) {
96 const c_a = it_a.nextCodepoint() orelse break;
97 const c_b = it_b.nextCodepoint() orelse return false;
98 if (upcase(c_a) != upcase(c_b))
99 return false;
100 }
101 if (it_b.nextCodepoint()) return false;
86102 }
87103 return std.hash_map.eqlString(a, b);
88104 }