authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-05 01:59:06 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-05 01:59:06 -08:00
log8dec0da7fbbe80b15c24482125142e172c9a4cf4
tree4a047bbdb44b96fad7c0c076b855856c201434fc
parentdc5a695ba985caab77db4bc568d2fc7c8f5f0c0e

make Readable.readUntilDelimitersArrayList() return the slice it read


1 files changed, 3 insertions(+), 2 deletions(-)

nio.zig+3-2
...@@ -108,10 +108,11 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type {...@@ -108,10 +108,11 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type {
108 return error.StreamTooLong;108 return error.StreamTooLong;
109 }109 }
110110
111 pub fn readUntilDelimitersArrayList(self: Self, array_list: *std.ArrayList(u8), needle: []const u8, max_size: usize) !usize {111 pub fn readUntilDelimitersArrayList(self: Self, array_list: *std.ArrayList(u8), needle: []const u8, max_size: usize) ![]u8 {
112 const initial_len = array_list.items.len;
112 for (0..max_size) |i| {113 for (0..max_size) |i| {
113 try array_list.append(try readByte(self));114 try array_list.append(try readByte(self));
114 if (std.mem.endsWith(u8, array_list.items, needle)) return i + 1 - needle.len;115 if (std.mem.endsWith(u8, array_list.items, needle)) return array_list.items[initial_len..][0 .. i + 1 - needle.len];
115 }116 }
116 return error.StreamTooLong;117 return error.StreamTooLong;
117 }118 }