aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/lib/string.zig
blob: 795823c25fd9dfd38d51505f0c4388a3342f1cf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const std = @import("std");

// This is a copy of std.mem.cutPrefix from 0.16. Once Ghostty has been ported
// to 0.16 this can be removed.

/// If slice starts with prefix, returns the rest of slice starting at
/// prefix.len.
pub fn cutPrefix(comptime T: type, slice: []const T, prefix: []const T) ?[]const T {
    return if (std.mem.startsWith(T, slice, prefix)) slice[prefix.len..] else null;
}

test cutPrefix {
    try std.testing.expectEqualStrings("foo", cutPrefix(u8, "--example=foo", "--example=").?);
    try std.testing.expectEqual(null, cutPrefix(u8, "--example=foo", "-example="));
}