aboutsummaryrefslogtreecommitdiff
path: root/src/string_immutable.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/string_immutable.zig')
-rw-r--r--src/string_immutable.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index 409ded4f1..a5e3e7104 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -12,6 +12,19 @@ pub inline fn containsChar(self: string, char: u8) bool {
pub inline fn contains(self: string, str: string) bool {
return std.mem.indexOf(u8, self, str) != null;
}
+pub inline fn containsComptime(self: string, comptime str: string) bool {
+ var remain = self;
+ const Int = std.meta.Int(.unsigned, str.len * 8);
+
+ while (remain.len >= comptime str.len) {
+ if (@bitCast(Int, remain.ptr[0..str.len].*) == @bitCast(Int, str.ptr[0..str.len].*)) {
+ return true;
+ }
+ remain = remain[str.len..];
+ }
+
+ return false;
+}
pub const includes = contains;
pub inline fn containsAny(in: anytype, target: string) bool {