Function splatBytesAll [src]
Writes the same slice many times, performing the underlying write call as
many times as necessary.
Prototype
pub fn splatBytesAll(w: *Writer, bytes: []const u8, splat: usize) Error!void
Parameters
w: *Writer
bytes: []const u8
splat: usize
Possible Errors
See the Writer
implementation for detailed diagnostics.
Example
test splatBytesAll {
var aw: Writer.Allocating = .init(testing.allocator);
defer aw.deinit();
try aw.writer.splatBytesAll("hello", 3);
try testing.expectEqualStrings("hellohellohello", aw.writer.buffered());
}
Source
pub fn splatBytesAll(w: *Writer, bytes: []const u8, splat: usize) Error!void {
var remaining_bytes: usize = bytes.len * splat;
remaining_bytes -= try w.splatBytes(bytes, splat);
while (remaining_bytes > 0) {
const leftover_splat = remaining_bytes / bytes.len;
const leftover_bytes = remaining_bytes % bytes.len;
const buffers: [2][]const u8 = .{ bytes[bytes.len - leftover_bytes ..], bytes };
remaining_bytes -= try w.writeSplat(&buffers, leftover_splat);
}
}