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. Private Function

writeSplatHeaderLimitFinish

Private Function
std.Io.Writer.writeSplatHeaderLimitFinish
fn writeSplatHeaderLimitFinish(
    w: *Writer,
    header: []const u8,
    data: []const []const u8,
    splat: usize,
    limit: usize,
) Error!usize

Params

  • w: *Writer
  • header: []const u8
  • data: []const []const u8
  • splat: usize
  • limit: usize

Errors

WriteFailed

See the Writer implementation for detailed diagnostics.

File

Io/Writer.zig:264
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
fn writeSplatHeaderLimitFinish(
    w: *Writer,
    header: []const u8,
    data: []const []const u8,
    splat: usize,
    limit: usize,
) Error!usize {
    var remaining = limit;
    var total: usize = 0;
    var vecs: [8][]const u8 = undefined;
    var i: usize = 0;
    if (header.len != 0) {
        const copy_len = @min(header.len, remaining);
        vecs[i] = header[0..copy_len];
        i += 1;
        remaining -= copy_len;
        if (remaining == 0) {
            return w.vtable.drain(w, (&vecs)[0..i], 1);
        }
    }
    for (data[0 .. data.len - 1]) |buf| {
        if (buf.len == 0) continue;
        const copy_len = @min(buf.len, remaining);
        vecs[i] = buf[0..copy_len];
        i += 1;
        remaining -= copy_len;
        if (remaining == 0) {
            return w.vtable.drain(w, (&vecs)[0..i], 1);
        }
        if (i == vecs.len) {
            total += try w.vtable.drain(w, &vecs, 1);
            i = 0;
        }
    }
    const pattern = data[data.len - 1];
    if (splat == 1 or remaining < pattern.len) {
        vecs[i] = pattern[0..@min(remaining, pattern.len)];
        i += 1;
        total += try w.vtable.drain(w, (&vecs)[0..i], 1);
        return total;
    }
    vecs[i] = pattern;
    i += 1;
    total += try w.vtable.drain(w, (&vecs)[0..i], @min(remaining / pattern.len, splat));
    return total;
}