Function splitScalar [src]

Returns an iterator that iterates over the slices of buffer that are separated by delimiter. splitScalar(u8, "abc|def||ghi", '|') will return slices for "abc", "def", "", "ghi", null, in that order. If delimiter does not exist in buffer, the iterator will return buffer, null, in that order. See also: splitSequence, splitAny, splitBackwardsSequence, splitBackwardsAny,splitBackwardsScalar, tokenizeAny, tokenizeSequence, and tokenizeScalar.

Prototype

pub fn splitScalar(comptime T: type, buffer: []const T, delimiter: T) SplitIterator(T, .scalar)

Parameters

T: typebuffer: []const Tdelimiter: T

Example

test splitScalar { var it = splitScalar(u8, "abc|def||ghi", '|'); try testing.expectEqualSlices(u8, it.rest(), "abc|def||ghi"); try testing.expectEqualSlices(u8, it.first(), "abc"); try testing.expectEqualSlices(u8, it.rest(), "def||ghi"); try testing.expectEqualSlices(u8, it.peek().?, "def"); try testing.expectEqualSlices(u8, it.next().?, "def"); try testing.expectEqualSlices(u8, it.rest(), "|ghi"); try testing.expectEqualSlices(u8, it.next().?, ""); try testing.expectEqualSlices(u8, it.rest(), "ghi"); try testing.expectEqualSlices(u8, it.peek().?, "ghi"); try testing.expectEqualSlices(u8, it.next().?, "ghi"); try testing.expectEqualSlices(u8, it.rest(), ""); try testing.expect(it.peek() == null); try testing.expect(it.next() == null); it = splitScalar(u8, "", '|'); try testing.expectEqualSlices(u8, it.first(), ""); try testing.expect(it.next() == null); it = splitScalar(u8, "|", '|'); try testing.expectEqualSlices(u8, it.first(), ""); try testing.expectEqualSlices(u8, it.next().?, ""); try testing.expect(it.peek() == null); try testing.expect(it.next() == null); it = splitScalar(u8, "hello", ' '); try testing.expectEqualSlices(u8, it.first(), "hello"); try testing.expect(it.next() == null); var it16 = splitScalar( u16, std.unicode.utf8ToUtf16LeStringLiteral("hello"), ' ', ); try testing.expectEqualSlices(u16, it16.first(), std.unicode.utf8ToUtf16LeStringLiteral("hello")); try testing.expect(it16.next() == null); }

Source

pub fn splitScalar(comptime T: type, buffer: []const T, delimiter: T) SplitIterator(T, .scalar) { return .{ .index = 0, .buffer = buffer, .delimiter = delimiter, }; }