pub fn writeSplat(w: *Writer, data: []const []const u8, splat: usize) Error!usize w: *Writerdata: []const []const u8splat: usizeWriteFailedSee the Writer implementation for detailed diagnostics.
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203pub fn writeSplat(w: *Writer, data: []const []const u8, splat: usize) Error!usize {
assert(data.len > 0);
const buffer = w.buffer;
const count = countSplat(data, splat);
if (w.end + count > buffer.len) return w.vtable.drain(w, data, splat);
for (data[0 .. data.len - 1]) |bytes| {
@memcpy(buffer[w.end..][0..bytes.len], bytes);
w.end += bytes.len;
}
const pattern = data[data.len - 1];
switch (pattern.len) {
0 => {},
1 => {
@memset(buffer[w.end..][0..splat], pattern[0]);
w.end += splat;
},
else => for (0..splat) |_| {
@memcpy(buffer[w.end..][0..pattern.len], pattern);
w.end += pattern.len;
},
}
return count;
}
If the number of bytes to write based on
dataandsplatfits insideunusedCapacitySlice, this function is guaranteed to not fail, not call intoVTable, and return the full number of bytes.