mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 07:32:44 +00:00
std: Add reset to TokenIterator
This commit is contained in:
parent
3913332145
commit
0d96a284e8
@ -1373,6 +1373,20 @@ test "mem.tokenize (multibyte)" {
|
||||
testing.expect(it.next() == null);
|
||||
}
|
||||
|
||||
test "mem.tokenize (reset)" {
|
||||
var it = tokenize(" abc def ghi ", " ");
|
||||
testing.expect(eql(u8, it.next().?, "abc"));
|
||||
testing.expect(eql(u8, it.next().?, "def"));
|
||||
testing.expect(eql(u8, it.next().?, "ghi"));
|
||||
|
||||
it.reset();
|
||||
|
||||
testing.expect(eql(u8, it.next().?, "abc"));
|
||||
testing.expect(eql(u8, it.next().?, "def"));
|
||||
testing.expect(eql(u8, it.next().?, "ghi"));
|
||||
testing.expect(it.next() == null);
|
||||
}
|
||||
|
||||
/// Returns an iterator that iterates over the slices of `buffer` that
|
||||
/// are separated by bytes in `delimiter`.
|
||||
/// split("abc|def||ghi", "|")
|
||||
@ -1471,6 +1485,11 @@ pub const TokenIterator = struct {
|
||||
return self.buffer[index..];
|
||||
}
|
||||
|
||||
/// Resets the iterator to the initial token.
|
||||
pub fn reset(self: *TokenIterator) void {
|
||||
self.index = 0;
|
||||
}
|
||||
|
||||
fn isSplitByte(self: TokenIterator, byte: u8) bool {
|
||||
for (self.delimiter_bytes) |delimiter_byte| {
|
||||
if (byte == delimiter_byte) {
|
||||
|
Loading…
Reference in New Issue
Block a user