| ... | ... | @@ -1373,6 +1373,20 @@ test "mem.tokenize (multibyte)" { |
| 1373 | 1373 | testing.expect(it.next() == null); |
| 1374 | 1374 | } |
| 1375 | 1375 | |
| 1376 | test "mem.tokenize (reset)" { |
| 1377 | var it = tokenize(" abc def ghi ", " "); |
| 1378 | testing.expect(eql(u8, it.next().?, "abc")); |
| 1379 | testing.expect(eql(u8, it.next().?, "def")); |
| 1380 | testing.expect(eql(u8, it.next().?, "ghi")); |
| 1381 | |
| 1382 | it.reset(); |
| 1383 | |
| 1384 | testing.expect(eql(u8, it.next().?, "abc")); |
| 1385 | testing.expect(eql(u8, it.next().?, "def")); |
| 1386 | testing.expect(eql(u8, it.next().?, "ghi")); |
| 1387 | testing.expect(it.next() == null); |
| 1388 | } |
| 1389 | |
| 1376 | 1390 | /// Returns an iterator that iterates over the slices of `buffer` that |
| 1377 | 1391 | /// are separated by bytes in `delimiter`. |
| 1378 | 1392 | /// split("abc|def||ghi", "|") |
| ... | ... | @@ -1471,6 +1485,11 @@ pub const TokenIterator = struct { |
| 1471 | 1485 | return self.buffer[index..]; |
| 1472 | 1486 | } |
| 1473 | 1487 | |
| 1488 | /// Resets the iterator to the initial token. |
| 1489 | pub fn reset(self: *TokenIterator) void { |
| 1490 | self.index = 0; |
| 1491 | } |
| 1492 | |
| 1474 | 1493 | fn isSplitByte(self: TokenIterator, byte: u8) bool { |
| 1475 | 1494 | for (self.delimiter_bytes) |delimiter_byte| { |
| 1476 | 1495 | if (byte == delimiter_byte) { |