Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

peekDelimiterInclusive

Public Function
std.Io.Reader.peekDelimiterInclusive
pub fn peekDelimiterInclusive(r: *Reader, delimiter: u8) DelimiterError![]u8

Returns a slice of the next bytes of buffered data from the stream until delimiter is found, without advancing the seek position.

Returned slice includes the delimiter as the last byte.

Invalidates previously returned values from peek.

See also:

Params

Errors

ReadFailed

See the Reader implementation for detailed diagnostics.

EndOfStream

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

StreamTooLong

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

File

Io/Reader.zig:823
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
pub fn peekDelimiterInclusive(r: *Reader, delimiter: u8) DelimiterError![]u8 {
    {
        const contents = r.buffer[0..r.end];
        const seek = r.seek;
        if (std.mem.findScalarPos(u8, contents, seek, delimiter)) |end| {
            @branchHint(.likely);
            return contents[seek .. end + 1];
        }
    }
    while (true) {
        const content_len = r.end - r.seek;
        if (r.buffer.len - content_len == 0) break;
        try fillMore(r);
        const seek = r.seek;
        const contents = r.buffer[0..r.end];
        if (std.mem.findScalarPos(u8, contents, seek + content_len, delimiter)) |end| {
            return contents[seek .. end + 1];
        }
    }
    // It might or might not be end of stream. There is no more buffer space
    // left to disambiguate. If `StreamTooLong` was added to `RebaseError` then
    // this logic could be replaced by removing the exit condition from the
    // above while loop. That error code would represent when `buffer` capacity
    // is too small for an operation, replacing the current use of asserts.
    var failing_writer = Writer.failing;
    while (r.vtable.stream(r, &failing_writer, .limited(1))) |n| {
        assert(n == 0);
    } else |err| switch (err) {
        error.WriteFailed => return error.StreamTooLong,
        error.ReadFailed => |e| return e,
        error.EndOfStream => |e| return e,
    }
}