summaryrefslogtreecommitdiff
path: root/src/utils.zig
diff options
context:
space:
mode:
authorGravatar Uko Kokņevičs2025-08-03 03:23:26 +0300
committerGravatar Uko Kokņevičs2025-08-03 03:23:26 +0300
commit0a0cff51b27ce35c4fa5d8fd56f60d2b7a89c90a (patch)
tree6724a6204584153044301489a6dae364886c7867 /src/utils.zig
parentAdd @crabravebot to the list of allowed inline bots (diff)
downloadukkobot-0a0cff51b27ce35c4fa5d8fd56f60d2b7a89c90a.tar.gz
ukkobot-0a0cff51b27ce35c4fa5d8fd56f60d2b7a89c90a.tar.xz
ukkobot-0a0cff51b27ce35c4fa5d8fd56f60d2b7a89c90a.zip
Moved inline bot handling to a new file
Diffstat (limited to 'src/utils.zig')
-rw-r--r--src/utils.zig14
1 files changed, 14 insertions, 0 deletions
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 {
38 return lc_global.?; 38 return lc_global.?;
39} 39}
40 40
41// arr should be sorted as according to isSorted.
42pub inline fn isIn(comptime T: type, val: T, arr: []const T) bool {
43 const order = struct {
44 pub fn f(a: T, b: T) std.math.Order {
45 return std.math.order(a, b);
46 }
47 }.f;
48 return std.sort.binarySearch(T, arr, val, order) != null;
49}
50
41pub inline fn isNull(value: anytype) bool { 51pub inline fn isNull(value: anytype) bool {
42 return switch (@typeInfo(@TypeOf(value))) { 52 return switch (@typeInfo(@TypeOf(value))) {
43 .null => true, 53 .null => true,
@@ -46,6 +56,10 @@ pub inline fn isNull(value: anytype) bool {
46 }; 56 };
47} 57}
48 58
59pub inline fn isSorted(comptime T: type, arr: []const T) bool {
60 return std.sort.isSorted(T, arr, {}, std.sort.asc(T));
61}
62
49pub fn isTgWhitespaceStr(str: []const u8) !bool { 63pub fn isTgWhitespaceStr(str: []const u8) !bool {
50 const view = try Utf8View.init(str); 64 const view = try Utf8View.init(str);
51 const gc = try getGC(); 65 const gc = try getGC();