| author | |
| committer | |
| log | 5db3ab392d43e25bc7fc0243fd7b131399cae7c8 |
| tree | bdcf5ef925bf0e4b8e8986aa905a7be0b1f6c0a3 |
| parent | cc1a96881c7b15d850f9cd4b32019fd66fc8d3b0 |
| signature |
4 files changed, 16 insertions(+), 0 deletions(-)
AnyReadable.zig+1| ... | @@ -23,6 +23,7 @@ pub const readUntilDelimitersArrayList = R.readUntilDelimitersArrayList; | ... | @@ -23,6 +23,7 @@ pub const readUntilDelimitersArrayList = R.readUntilDelimitersArrayList; |
| 23 | pub const readAlloc = R.readAlloc; | 23 | pub const readAlloc = R.readAlloc; |
| 24 | pub const readInt = R.readInt; | 24 | pub const readInt = R.readInt; |
| 25 | pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; | 25 | pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; |
| 26 | pub const readUntilDelimiterOrEof = R.readUntilDelimiterOrEof; | ||
| 26 | 27 | ||
| 27 | pub const Error = ReadError; // std compat | 28 | pub const Error = ReadError; // std compat |
| 28 | pub const ReadError = anyerror; | 29 | pub const ReadError = anyerror; |
buffered_reader.zig+1| ... | @@ -34,6 +34,7 @@ pub fn BufferedReader(comptime buffer_size: usize, comptime ReaderType: type) ty | ... | @@ -34,6 +34,7 @@ pub fn BufferedReader(comptime buffer_size: usize, comptime ReaderType: type) ty |
| 34 | pub const readAlloc = R.readAlloc; | 34 | pub const readAlloc = R.readAlloc; |
| 35 | pub const readInt = R.readInt; | 35 | pub const readInt = R.readInt; |
| 36 | pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; | 36 | pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; |
| 37 | pub const readUntilDelimiterOrEof = R.readUntilDelimiterOrEof; | ||
| 37 | 38 | ||
| 38 | pub const ReadError = ReaderType.ReadError; | 39 | pub const ReadError = ReaderType.ReadError; |
| 39 | pub fn read(self: *Self, dest: []u8) ReadError!usize { | 40 | pub fn read(self: *Self, dest: []u8) ReadError!usize { |
fixed_buffer_stream.zig+1| ... | @@ -43,6 +43,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type { | ... | @@ -43,6 +43,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type { |
| 43 | pub const readAlloc = R.readAlloc; | 43 | pub const readAlloc = R.readAlloc; |
| 44 | pub const readInt = R.readInt; | 44 | pub const readInt = R.readInt; |
| 45 | pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; | 45 | pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; |
| 46 | pub const readUntilDelimiterOrEof = R.readUntilDelimiterOrEof; | ||
| 46 | 47 | ||
| 47 | pub const ReadError = error{}; | 48 | pub const ReadError = error{}; |
| 48 | pub fn read(self: *Self, dest: []u8) ReadError!usize { | 49 | pub fn read(self: *Self, dest: []u8) ReadError!usize { |
nio.zig+13| ... | @@ -181,6 +181,19 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { | ... | @@ -181,6 +181,19 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 181 | _ = try readUntilDelimitersArrayList(self, &list, needle, max_size); | 181 | _ = try readUntilDelimitersArrayList(self, &list, needle, max_size); |
| 182 | return list.toOwnedSlice(); | 182 | return list.toOwnedSlice(); |
| 183 | } | 183 | } |
| 184 | |||
| 185 | /// Returned slice is not suffixed by needle but buf will contain it. | ||
| 186 | pub fn readUntilDelimiterOrEof(self: Self, buf: []u8, needle: u8) !?[]u8 { | ||
| 187 | for (buf, 0..) |*c, i| { | ||
| 188 | const b = try readByte(self); | ||
| 189 | c.* = b; | ||
| 190 | if (b == needle) { | ||
| 191 | if (i == 0) return null; | ||
| 192 | return buf[0..i]; | ||
| 193 | } | ||
| 194 | } | ||
| 195 | return error.StreamTooLong; | ||
| 196 | } | ||
| 184 | }; | 197 | }; |
| 185 | } | 198 | } |
| 186 | 199 |