Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Type Function

SplitBackwardsIterator

Public Type Function
std.mem.SplitBackwardsIterator
pub fn SplitBackwardsIterator(comptime T: type, comptime delimiter_type: DelimiterType) type

Iterator type for splitting operations from the end backwards, including empty sequences.

Fields

buffer: []const T
index: ?usize
delimiter: switch (delimiter_type) { .sequence, .any => []const T, .scalar => T, }

Types

Functions

pub fn first(self: *Self) []const T

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 next(self: *Self) ?[]const T

Returns a slice of the next field, or null if splitting is complete.

pub fn rest(self: Self) []const T

Returns a slice of the remaining bytes. Does not affect iterator state.

pub fn reset(self: *Self) void

Resets the iterator to the initial slice.

File

mem.zig:3467
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
3517
pub 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;
        }
    };
}