Add unrolled case insensitive string comparison

This commit is contained in:
Jarred Sumner
2021-12-31 15:07:14 -08:00
parent 059aa425b7
commit d7c69d3b78

View File

@@ -413,6 +413,27 @@ inline fn eqlComptimeCheckLen(a: string, comptime b: anytype, comptime check_len
return true;
}
pub fn eqlCaseInsensitiveASCII(a: string, comptime b: anytype, comptime check_len: bool) bool {
if (comptime check_len) {
if (comptime b.len == 0) {
return a.len == 0;
}
switch (a.len) {
b.len => void{},
else => return false,
}
}
// pray to the auto vectorization gods
inline for (b) |c, i| {
const char = comptime std.ascii.toLower(c);
if (char != std.ascii.toLower(a[i])) return false;
}
return true;
}
pub fn eqlLong(a_: string, b: string, comptime check_len: bool) bool {
if (comptime check_len) {
if (a_.len == 0) {