Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: add mem.SplitIterator.peek() #15670

Merged
merged 3 commits into from
Jul 10, 2023
Merged

std: add mem.SplitIterator.peek() #15670

merged 3 commits into from
Jul 10, 2023

Conversation

nektro
Copy link
Contributor

@nektro nektro commented May 12, 2023

std.mem.TokenIterator already has a method by this name

@squeek502
Copy link
Collaborator

squeek502 commented Jun 3, 2023

This will need to be rebased now that #15579 has been merged

The updated implementation to handle the other delimiter types could be something like:

        pub fn peek(self: *Self) ?[]const T {
            const start = self.index orelse return null;
            const end = if (switch (delimiter_type) {
                .sequence => indexOfPos(T, self.buffer, start, self.delimiter),
                .any => indexOfAnyPos(T, self.buffer, start, self.delimiter),
                .scalar => indexOfScalarPos(T, self.buffer, start, self.delimiter),
            }) |delim_start| delim_start else self.buffer.len;
            return self.buffer[start..end];
        }

@andrewrk andrewrk merged commit cd0594e into ziglang:master Jul 10, 2023
@nektro nektro deleted the patch-5 branch July 10, 2023 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants