Function takeSentinel [src]
Returns a slice of the next bytes of buffered data from the stream until
sentinel is found, advancing the seek position.
Returned slice has a sentinel.
Invalidates previously returned values from peek.
See also:
peekSentinel
takeDelimiterExclusive
takeDelimiterInclusive
Prototype
pub fn takeSentinel(r: *Reader, comptime sentinel: u8) DelimiterError![:sentinel]u8
Parameters
r: *Reader
sentinel: u8
Possible Errors
For "inclusive" functions, stream ended before the delimiter was found. For "exclusive" functions, stream ended and there are no more bytes to return.
See the Reader
implementation for detailed diagnostics.
The delimiter was not found within a number of bytes matching the
capacity of the Reader
.
Example
test takeSentinel {
var r: Reader = .fixed("ab\nc");
try testing.expectEqualStrings("ab", try r.takeSentinel('\n'));
try testing.expectError(error.EndOfStream, r.takeSentinel('\n'));
try testing.expectEqualStrings("c", try r.peek(1));
}
Source
pub fn takeSentinel(r: *Reader, comptime sentinel: u8) DelimiterError![:sentinel]u8 {
const result = try r.peekSentinel(sentinel);
r.toss(result.len + 1);
return result;
}