diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-07-07 17:06:09 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-07-07 17:56:08 -0400 |
| commit | 7ccf7807b3f12428adc5d9ca0ede4e3f4ec6dbbc (patch) | |
| tree | af8db742f220123b24c3959b6f33173d8b1e619e /src/util.cpp | |
| parent | 3b97940fb384285a8f88088c9e73e582f8bdbf96 (diff) | |
| download | zig-7ccf7807b3f12428adc5d9ca0ede4e3f4ec6dbbc.tar.gz zig-7ccf7807b3f12428adc5d9ca0ede4e3f4ec6dbbc.zip | |
ability to target any glibc version
Diffstat (limited to 'src/util.cpp')
| -rw-r--r-- | src/util.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp index 9a6a382993..65b1fe3082 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -86,6 +86,32 @@ Optional<Slice<uint8_t>> SplitIterator_next(SplitIterator *self) { return Optional<Slice<uint8_t>>::some(self->buffer.slice(start, end)); } +// Ported from std/mem.zig. +// This one won't collapse multiple separators into one, so you could use it, for example, +// to parse Comma Separated Value format. +Optional<Slice<uint8_t>> SplitIterator_next_separate(SplitIterator *self) { + // move to beginning of token + if (self->index < self->buffer.len && + SplitIterator_isSplitByte(self, self->buffer.ptr[self->index])) + { + self->index += 1; + } + size_t start = self->index; + if (start == self->buffer.len) { + return {}; + } + + // move to end of token + while (self->index < self->buffer.len && + !SplitIterator_isSplitByte(self, self->buffer.ptr[self->index])) + { + self->index += 1; + } + size_t end = self->index; + + return Optional<Slice<uint8_t>>::some(self->buffer.slice(start, end)); +} + // Ported from std/mem.zig Slice<uint8_t> SplitIterator_rest(SplitIterator *self) { // move to beginning of token |
