From 1d6bc6829812a448ac6148e7e86e36dff30d19fb Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Wed, 5 Aug 2026 23:07:43 -0400 Subject: [PATCH] lib: remove cutPrefix implementation We can use std.mem.cutPrefix directly now that we're on Zig 0.16. --- src/apprt/gtk/class/application.zig | 7 +++---- src/cli/new_window.zig | 5 ++--- src/lib/main.zig | 1 - src/lib/string.zig | 15 --------------- 4 files changed, 5 insertions(+), 23 deletions(-) delete mode 100644 src/lib/string.zig diff --git a/src/apprt/gtk/class/application.zig b/src/apprt/gtk/class/application.zig index 55d7f4055..6c70d0bb3 100644 --- a/src/apprt/gtk/class/application.zig +++ b/src/apprt/gtk/class/application.zig @@ -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"); @@ -1865,7 +1864,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}); @@ -1874,14 +1873,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; diff --git a/src/cli/new_window.zig b/src/cli/new_window.zig index 333cb06c0..bda8bd6cc 100644 --- a/src/cli/new_window.zig +++ b/src/cli/new_window.zig @@ -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); diff --git a/src/lib/main.zig b/src/lib/main.zig index b22b3d987..d9c35927b 100644 --- a/src/lib/main.zig +++ b/src/lib/main.zig @@ -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()); diff --git a/src/lib/string.zig b/src/lib/string.zig deleted file mode 100644 index 795823c25..000000000 --- a/src/lib/string.zig +++ /dev/null @@ -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=")); -}