lib: remove backported cutPrefix implementation (#13658)

We can use std.mem.cutPrefix directly now that we're on Zig 0.16.
This commit is contained in:
Mitchell Hashimoto
2026-08-05 20:47:26 -07:00
committed by GitHub
4 changed files with 5 additions and 23 deletions

View File

@@ -26,7 +26,6 @@ const xev = global.xev;
const Binding = @import("../../../input.zig").Binding;
const CoreConfig = configpkg.Config;
const CoreSurface = @import("../../../Surface.zig");
const lib = @import("../../../lib/main.zig");
const ext = @import("../ext.zig");
const key = @import("../key.zig");
@@ -1878,7 +1877,7 @@ pub const Application = extern struct {
continue;
}
if (lib.cutPrefix(u8, str, "--command=")) |v| {
if (std.mem.cutPrefix(u8, str, "--command=")) |v| {
var cmd: configpkg.Command = undefined;
cmd.parseCLI(alloc, v) catch |err| {
log.warn("unable to parse command: {t}", .{err});
@@ -1887,14 +1886,14 @@ pub const Application = extern struct {
command = cmd;
continue;
}
if (lib.cutPrefix(u8, str, "--working-directory=")) |v| {
if (std.mem.cutPrefix(u8, str, "--working-directory=")) |v| {
working_directory = alloc.dupeZ(u8, std.mem.trim(u8, v, &std.ascii.whitespace)) catch |err| wd: {
log.warn("unable to duplicate working directory: {t}", .{err});
break :wd null;
};
continue;
}
if (lib.cutPrefix(u8, str, "--title=")) |v| {
if (std.mem.cutPrefix(u8, str, "--title=")) |v| {
title = alloc.dupeZ(u8, std.mem.trim(u8, v, &std.ascii.whitespace)) catch |err| t: {
log.warn("unable to duplicate title: {t}", .{err});
break :t null;

View File

@@ -5,7 +5,6 @@ const Action = @import("../cli.zig").ghostty.Action;
const apprt = @import("../apprt.zig");
const args = @import("args.zig");
const diagnostics = @import("diagnostics.zig");
const lib = @import("../lib/main.zig");
const homedir = @import("../os/homedir.zig");
const global = @import("../global.zig");
@@ -70,12 +69,12 @@ pub const Options = struct {
Allocator.Error;
fn checkArg(self: *Options, alloc: Allocator, arg: []const u8) CheckArgError!?[:0]const u8 {
if (lib.cutPrefix(u8, arg, "--class=")) |rest| {
if (std.mem.cutPrefix(u8, arg, "--class=")) |rest| {
self.class = try alloc.dupeZ(u8, std.mem.trim(u8, rest, &std.ascii.whitespace));
return null;
}
if (lib.cutPrefix(u8, arg, "--working-directory=")) |rest| {
if (std.mem.cutPrefix(u8, arg, "--working-directory=")) |rest| {
const stripped = std.mem.trim(u8, rest, &std.ascii.whitespace);
if (std.mem.eql(u8, stripped, "home")) return try alloc.dupeZ(u8, arg);
if (std.mem.eql(u8, stripped, "inherit")) return try alloc.dupeZ(u8, arg);

View File

@@ -13,7 +13,6 @@ pub const Struct = structpkg.Struct;
pub const structSizedFieldFits = structpkg.sizedFieldFits;
pub const Target = @import("target.zig").Target;
pub const TaggedUnion = unionpkg.TaggedUnion;
pub const cutPrefix = @import("string.zig").cutPrefix;
test {
std.testing.refAllDecls(@This());

View File

@@ -1,15 +0,0 @@
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="));
}