mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-08-25 00:21:46 +00:00
lib: remove cutPrefix implementation
We can use std.mem.cutPrefix directly now that we're on Zig 0.16.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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="));
|
||||
}
|
||||
Reference in New Issue
Block a user