Remove ciutf8

This commit is contained in:
jaina heartles 2022-12-01 19:46:51 -08:00
parent 04c593ffdd
commit b2093128de
3 changed files with 0 additions and 108 deletions

View file

@ -1,5 +1,4 @@
const std = @import("std");
const ciutf8 = @import("util").ciutf8;
const request = @import("./request.zig");

View file

@ -1,106 +0,0 @@
const std = @import("std");
const Hash = std.hash.Wyhash;
const View = std.unicode.Utf8View;
const toLower = std.ascii.toLower;
const isAscii = std.ascii.isASCII;
const hash_seed = 1;
pub fn hash(str: []const u8) u64 {
// fallback to regular hash on invalid utf8
const view = View.init(str) catch return Hash.hash(hash_seed, str);
var iter = view.iterator();
var h = Hash.init(hash_seed);
var it = iter.nextCodepointSlice();
while (it != null) : (it = iter.nextCodepointSlice()) {
if (it.?.len == 1 and isAscii(it.?[0])) {
const ch = [1]u8{toLower(it.?[0])};
h.update(&ch);
} else {
h.update(it.?);
}
}
return h.final();
}
pub fn eql(a: []const u8, b: []const u8) bool {
if (a.len != b.len) return false;
const va = View.init(a) catch return std.mem.eql(u8, a, b);
const vb = View.init(b) catch return false;
var iter_a = va.iterator();
var iter_b = vb.iterator();
var it_a = iter_a.nextCodepointSlice();
var it_b = iter_b.nextCodepointSlice();
while (it_a != null and it_b != null) : ({
it_a = iter_a.nextCodepointSlice();
it_b = iter_b.nextCodepointSlice();
}) {
if (it_a.?.len != it_b.?.len) return false;
if (it_a.?.len == 1) {
if (isAscii(it_a.?[0]) and isAscii(it_b.?[0])) {
const ch_a = toLower(it_a.?[0]);
const ch_b = toLower(it_b.?[0]);
if (ch_a != ch_b) return false;
} else if (it_a.?[0] != it_b.?[0]) return false;
} else if (!std.mem.eql(u8, it_a.?, it_b.?)) return false;
}
return it_a == null and it_b == null;
}
test "case insensitive eql with utf-8 chars" {
const t = std.testing;
try t.expectEqual(true, eql("abc 💯 def", "aBc 💯 DEF"));
try t.expectEqual(false, eql("xyz 💯 ijk", "aBc 💯 DEF"));
try t.expectEqual(false, eql("abc 💯 def", "aBc x DEF"));
try t.expectEqual(true, eql("💯", "💯"));
try t.expectEqual(false, eql("💯", "a"));
try t.expectEqual(false, eql("💯", "💯 continues"));
try t.expectEqual(false, eql("💯 fsdfs", "💯"));
try t.expectEqual(false, eql("💯", ""));
try t.expectEqual(false, eql("", "💯"));
try t.expectEqual(true, eql("abc x def", "aBc x DEF"));
try t.expectEqual(false, eql("xyz x ijk", "aBc x DEF"));
try t.expectEqual(true, eql("x", "x"));
try t.expectEqual(false, eql("x", "a"));
try t.expectEqual(false, eql("x", "x continues"));
try t.expectEqual(false, eql("x fsdfs", "x"));
try t.expectEqual(false, eql("x", ""));
try t.expectEqual(false, eql("", "x"));
try t.expectEqual(true, eql("", ""));
}
test "case insensitive hash with utf-8 chars" {
const t = std.testing;
try t.expect(hash("abc 💯 def") == hash("aBc 💯 DEF"));
try t.expect(hash("xyz 💯 ijk") != hash("aBc 💯 DEF"));
try t.expect(hash("abc 💯 def") != hash("aBc x DEF"));
try t.expect(hash("💯") == hash("💯"));
try t.expect(hash("💯") != hash("a"));
try t.expect(hash("💯") != hash("💯 continues"));
try t.expect(hash("💯 fsdfs") != hash("💯"));
try t.expect(hash("💯") != hash(""));
try t.expect(hash("") != hash("💯"));
try t.expect(hash("abc x def") == hash("aBc x DEF"));
try t.expect(hash("xyz x ijk") != hash("aBc x DEF"));
try t.expect(hash("x") == hash("x"));
try t.expect(hash("x") != hash("a"));
try t.expect(hash("x") != hash("x continues"));
try t.expect(hash("x fsdfs") != hash("x"));
try t.expect(hash("x") != hash(""));
try t.expect(hash("") != hash("x"));
try t.expect(hash("") == hash(""));
}

View file

@ -1,7 +1,6 @@
const std = @import("std");
const iters = @import("./iters.zig");
pub const ciutf8 = @import("./ciutf8.zig");
pub const Uuid = @import("./Uuid.zig");
pub const DateTime = @import("./DateTime.zig");
pub const Url = @import("./Url.zig");