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

splatBytePreserve

Public Function
std.Io.Writer.splatBytePreserve
pub fn splatBytePreserve(w: *Writer, preserve: usize, byte: u8, n: usize) Error!void

Writes the same byte many times, performing the underlying write call as many times as necessary.

On success, at least preserve bytes will remain buffered if there are enough buffered bytes to do so. The amount buffered by the writer after the call will only be less than preserve if w.end + n is less than preserve before the call. The intentionally preserved bytes will include up to preserve -| n bytes from the previously buffered bytes, plus @min(n, preserve_len) of the newly written bytes.

Asserts buffer capacity is at least preserve. n can be greater than the buffer capacity.

Params

  • w: *Writer
  • preserve: usize
  • byte: u8
  • n: usize

Errors

WriteFailed

See the Writer implementation for detailed diagnostics.

File

Io/Writer.zig:884
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
pub fn splatBytePreserve(w: *Writer, preserve: usize, byte: u8, n: usize) Error!void {
    const new_end = w.end + n;
    if (new_end <= w.buffer.len) {
        @memset(w.buffer[w.end..][0..n], byte);
        w.end = new_end;
        return;
    }
    // If `n` is large, we can ignore `preserve` up to a point.
    var remaining = n;
    while (remaining > preserve) {
        assert(remaining != 0);
        remaining -= try splatByte(w, byte, remaining - preserve);
        if (w.end + remaining <= w.buffer.len) {
            @memset(w.buffer[w.end..][0..remaining], byte);
            w.end += remaining;
            return;
        }
    }
    // Ensure the contract of `rebase` is upheld.
    assert(w.end + remaining > w.buffer.len);
    // Offset the amount preserved by the amount we have left to splat
    // since the remaining splat is always going to be part of that
    // preservation.
    try w.vtable.rebase(w, preserve -| remaining, remaining);
    @memset(w.buffer[w.end..][0..remaining], byte);
    w.end += remaining;
}