pub fn SplitBackwardsIterator(comptime T: type, comptime delimiter_type: DelimiterType) type buffer: []const Tindex: ?usizedelimiter: switch (delimiter_type) { .sequence, .any => []const T, .scalar => T, }pub fn first(self: *Self) []const TReturns a slice of the first field. Call this only to get the first field and then use next to get all subsequent fields. Asserts that iteration has not begun.
pub fn next(self: *Self) ?[]const TReturns a slice of the next field, or null if splitting is complete.
pub fn rest(self: Self) []const TReturns a slice of the remaining bytes. Does not affect iterator state.
pub fn reset(self: *Self) voidResets the iterator to the initial slice.
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517pub fn SplitBackwardsIterator(comptime T: type, comptime delimiter_type: DelimiterType) type {
return struct {
buffer: []const T,
index: ?usize,
delimiter: switch (delimiter_type) {
.sequence, .any => []const T,
.scalar => T,
},
const Self = @This();
/// Returns a slice of the first field.
/// Call this only to get the first field and then use `next` to get all subsequent fields.
/// Asserts that iteration has not begun.
pub fn first(self: *Self) []const T {
assert(self.index.? == self.buffer.len);
return self.next().?;
}
/// Returns a slice of the next field, or null if splitting is complete.
pub fn next(self: *Self) ?[]const T {
const end = self.index orelse return null;
const start = if (switch (delimiter_type) {
.sequence => findLast(T, self.buffer[0..end], self.delimiter),
.any => findLastAny(T, self.buffer[0..end], self.delimiter),
.scalar => findScalarLast(T, self.buffer[0..end], self.delimiter),
}) |delim_start| blk: {
self.index = delim_start;
break :blk delim_start + switch (delimiter_type) {
.sequence => self.delimiter.len,
.any, .scalar => 1,
};
} else blk: {
self.index = null;
break :blk 0;
};
return self.buffer[start..end];
}
/// Returns a slice of the remaining bytes. Does not affect iterator state.
pub fn rest(self: Self) []const T {
const end = self.index orelse 0;
return self.buffer[0..end];
}
/// Resets the iterator to the initial slice.
pub fn reset(self: *Self) void {
self.index = self.buffer.len;
}
};
}
Iterator type for splitting operations from the end backwards, including empty sequences.