aboutsummaryrefslogtreecommitdiff
path: root/mirai.old/utils/string/compare.zig
blob: 8fc326665633b99b8385ef170107e574eb8580b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//! String comparison utilities

pub inline fn equals(a: []const u8, b: []const u8) bool {
    if (a.len != b.len) return false;
    for (a, b) |ac, bc| {
        if (ac != bc) return false;
    }
    return true;
}

pub inline fn equals_bytes(a: []const u8, b: anytype) bool {
    if (a.len != b.len) return false;
    for (a, 0..) |ac, i| {
        if (ac != b[i]) return false;
    }
    return true;
}

pub inline fn starts_with(str: []const u8, prefix: []const u8) bool {
    if (str.len < prefix.len) return false;
    return equals(str[0..prefix.len], prefix);
}