From d7c69d3b783d7dff7f3f44fce7d38d7dde4ecfcc Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Fri, 31 Dec 2021 15:07:14 -0800 Subject: Add unrolled case insensitive string comparison --- src/string_immutable.zig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/string_immutable.zig') diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 8b6215606..2796f59b8 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -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) { -- cgit v1.2.3