From b735c32c1a06be7532d500231ef10faf988f65db Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Fri, 27 Aug 2021 01:13:17 -0700 Subject: [PATCH] move addSentinel into zig-extras --- src/db/_.zig | 11 ++--------- zigmod.lock | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/db/_.zig b/src/db/_.zig index 09c1b7d..8e4fd1b 100644 --- a/src/db/_.zig +++ b/src/db/_.zig @@ -1,5 +1,6 @@ const std = @import("std"); const zorm = @import("zorm"); +const extras = @import("extras"); const _internal = @import("./_internal.zig"); const db = &_internal.db; @@ -7,7 +8,7 @@ const Engine = _internal.Engine; pub fn connect(alloc: *std.mem.Allocator, path: []const u8) !void { const abspath = try std.fs.realpathAlloc(alloc, path); - const nulpath = try addSentinel(alloc, u8, abspath, 0); + const nulpath = try extras.addSentinel(alloc, u8, abspath, 0); db.* = try Engine.connect(nulpath); } @@ -15,14 +16,6 @@ pub fn close() void { db.close(); } -fn addSentinel(alloc: *std.mem.Allocator, comptime T: type, input: []const T, comptime sentinel: T) ![:sentinel]const T { - var list = try std.ArrayList(T).initCapacity(alloc, input.len + 1); - try list.appendSlice(input); - try list.append(sentinel); - const str = list.toOwnedSlice(); - return str[0 .. str.len - 1 :sentinel]; -} - pub const Remote = @import("./Remote.zig").Remote; pub const User = @import("./User.zig").User; pub const Package = @import("./Package.zig").Package; diff --git a/zigmod.lock b/zigmod.lock index 5ea9510..d6d868c 100644 --- a/zigmod.lock +++ b/zigmod.lock @@ -5,4 +5,4 @@ git https://github.com/nektro/zig-range commit-890ca308fe09b3d5c866d5cfb3b3d7a95 git https://github.com/kivikakk/htmlentities.zig commit-c3cbe4cb3a9a9bd60e7c9fedcf9b97e087b98d6c git https://github.com/nektro/zig-zorm commit-38a255e5698796eb13a171a6ce6f33b98d65cfe2 git https://github.com/vrischmann/zig-sqlite commit-e9966b721515864ce6397aa8f35038ed318c97e7 -git https://github.com/nektro/zig-extras commit-8691b110468d7b6d170e6fec0e0ecfe7ede6372c +git https://github.com/nektro/zig-extras commit-4d2b9a70c8347fd5ce877eb087e1b3cad54e3cae