From 0a0cff51b27ce35c4fa5d8fd56f60d2b7a89c90a Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Sun, 3 Aug 2025 03:23:26 +0300 Subject: Moved inline bot handling to a new file --- src/utils.zig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/utils.zig') diff --git a/src/utils.zig b/src/utils.zig index b5d9f19..f771337 100644 --- a/src/utils.zig +++ b/src/utils.zig @@ -38,6 +38,16 @@ pub fn getLetterCasing() !LetterCasing { return lc_global.?; } +// arr should be sorted as according to isSorted. +pub inline fn isIn(comptime T: type, val: T, arr: []const T) bool { + const order = struct { + pub fn f(a: T, b: T) std.math.Order { + return std.math.order(a, b); + } + }.f; + return std.sort.binarySearch(T, arr, val, order) != null; +} + pub inline fn isNull(value: anytype) bool { return switch (@typeInfo(@TypeOf(value))) { .null => true, @@ -46,6 +56,10 @@ pub inline fn isNull(value: anytype) bool { }; } +pub inline fn isSorted(comptime T: type, arr: []const T) bool { + return std.sort.isSorted(T, arr, {}, std.sort.asc(T)); +} + pub fn isTgWhitespaceStr(str: []const u8) !bool { const view = try Utf8View.init(str); const gc = try getGC(); -- cgit v1.2.3