lib/tldr/src/formats/elf/string.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const std = @import("std");
2
3 const Allocator = std.mem.Allocator;
4
5 pub const Table = struct {
6 data: std.ArrayListUnmanaged(u8) = .empty,
7
8 pub fn init(allocator: Allocator) Allocator.Error!Table {
9 var table = Table{};
10 try table.data.append(allocator, 0);
11 return table;
12 }
13
14 pub fn deinit(self: *Table, allocator: Allocator) void {
15 self.data.deinit(allocator);
16 }
17
18 pub fn add(self: *Table, allocator: Allocator, value: []const u8) Allocator.Error!u32 {
19 const offset: u32 = @intCast(self.data.items.len);
20 try self.data.appendSlice(allocator, value);
21 try self.data.append(allocator, 0);
22 return offset;
23 }
24
25 pub fn bytes(self: Table) []const u8 {
26 return self.data.items;
27 }
28 };