#question about toOwnedSliceSentinel
1 messages · Page 1 of 1 (latest)
https://ziglang.org/documentation/master/std/#std.array_list.ArrayListAlignedUnmanaged.toOwnedSliceSentinel
what errors are you getting?
the slice is completely empty
its something weird
sorry. the sentinel is empty
pub const TextBufferType = struct {
content: [:0]const u8,
input: std.ArrayList(u8),
len: usize,
pub fn listen(self: *TextBufferType) !void {
var key = c.GetCharPressed();
while (key > 0) {
if ((key >= 32) and (key <= 125)) {
var keyCasted: u8 = @intCast(key);
try self.input.append(keyCasted);
//const slice = try self.input.toOwnedSlice();
//std.debug.print("{s}\n", .{slice});
//std.debug.print("content:{s}\n", .{self.content});
if (key == 97) {
const slice = try self.input.toOwnedSlice();
const sentinel = try self.input.toOwnedSliceSentinel(0);
std.debug.print("slice:{s}\n", .{slice});
std.debug.print("sentinel:{s}\n", .{sentinel});
}
}
key = c.GetCharPressed();
}
//c.DrawText(p., 250, 20, 20, c.WHITE);
c.DrawText(self.content, 250, 20, 20, c.DARKGRAY);
}
};
toOwnedSlice clears the arraylist so your call to toOwnedSliceSentinel is just returning an empty slice
ow.... I see.