alternate fix using the rest() function

This commit is contained in:
Andrew Kelley
2018-09-13 11:24:57 -04:00
parent 6d0a122816
commit e3f0ba4984
3 changed files with 15 additions and 14 deletions

View File

@@ -78,6 +78,16 @@ Optional<Slice<uint8_t>> SplitIterator_next(SplitIterator *self) {
return Optional<Slice<uint8_t>>::some(self->buffer.slice(start, end));
}
// Ported from std/mem.zig
Slice<uint8_t> SplitIterator_rest(SplitIterator *self) {
// move to beginning of token
size_t index = self->index;
while (index < self->buffer.len && SplitIterator_isSplitByte(self, self->buffer.ptr[index])) {
index += 1;
}
return self->buffer.sliceFrom(index);
}
// Ported from std/mem.zig
SplitIterator memSplit(Slice<uint8_t> buffer, Slice<uint8_t> split_bytes) {
return SplitIterator{0, buffer, split_bytes};