Function takeDelimiterExclusive [src]

Returns a slice of the next bytes of buffered data from the stream until delimiter is found, advancing the seek position up to the delimiter. Returned slice excludes the delimiter. End-of-stream is treated equivalent to a delimiter, unless it would result in a length 0 return value, in which case error.EndOfStream is returned instead. If the delimiter is not found within a number of bytes matching the capacity of this Reader, error.StreamTooLong is returned. In such case, the stream state is unmodified as if this function was never called. Invalidates previously returned values from peek. See also: takeDelimiterInclusive peekDelimiterExclusive

Prototype

pub fn takeDelimiterExclusive(r: *Reader, delimiter: u8) DelimiterError![]u8

Parameters

r: *Readerdelimiter: u8

Possible Errors

EndOfStream

For "inclusive" functions, stream ended before the delimiter was found. For "exclusive" functions, stream ended and there are no more bytes to return.

ReadFailed

See the Reader implementation for detailed diagnostics.

StreamTooLong

The delimiter was not found within a number of bytes matching the capacity of the Reader.

Example

test takeDelimiterExclusive { var r: Reader = .fixed("ab\nc"); try testing.expectEqualStrings("ab", try r.takeDelimiterExclusive('\n')); try testing.expectEqualStrings("c", try r.takeDelimiterExclusive('\n')); try testing.expectError(error.EndOfStream, r.takeDelimiterExclusive('\n')); }

Source

pub fn takeDelimiterExclusive(r: *Reader, delimiter: u8) DelimiterError![]u8 { const result = r.peekDelimiterInclusive(delimiter) catch |err| switch (err) { error.EndOfStream => { const remaining = r.buffer[r.seek..r.end]; if (remaining.len == 0) return error.EndOfStream; r.toss(remaining.len); return remaining; }, else => |e| return e, }; r.toss(result.len); return result[0 .. result.len - 1]; }