#question about toOwnedSliceSentinel

1 messages · Page 1 of 1 (latest)

upper merlin
#

I just want to ask what i have to pass to this function?
and also, what is a sentine?

I tried to pass u8 type but it doesnt work, any idea?

upper merlin
#

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);
    }
};
vale zinc
#

toOwnedSlice clears the arraylist so your call to toOwnedSliceSentinel is just returning an empty slice

upper merlin
#

ow.... I see.