diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-07-08 13:51:48 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-08 13:51:48 -0400 |
| commit | 4953e84902df3467b6d7491532e48bf33b5e56b9 (patch) | |
| tree | aa7d7fcb91a0e6ca8725d3fbdd586e168f62a27f /src/util.cpp | |
| parent | d39dcd6d9db2faf18287b2ff734ffda0d4080e5a (diff) | |
| parent | 201033d83b80d65380aaade37b76eafa17258f16 (diff) | |
| download | zig-4953e84902df3467b6d7491532e48bf33b5e56b9.tar.gz zig-4953e84902df3467b6d7491532e48bf33b5e56b9.zip | |
Merge pull request #2847 from ziglang/glibc-abi-versioning
support glibc version as part of the target
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 |
