authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-07-25 21:04:30+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-07-25 22:04:30+03:00
logcff5d9c805aa3433cc2562c3cb29bd3201817214
treeaa7bedeeb92523806f79887159d66b8b2934f375
parent2f34d06d01189ae6349e9c6341ba85ec50b92bb0
signature Signed by PGP key 4AEE18F83AFDEB23

std.mem: add `first` method to `SplitIterator` and `SplitBackwardsIterator`


14 files changed, 70 insertions(+), 49 deletions(-)

build.zig+4-4
...@@ -210,9 +210,9 @@ pub fn build(b: *Builder) !void {...@@ -210,9 +210,9 @@ pub fn build(b: *Builder) !void {
210 2 => {210 2 => {
211 // Untagged development build (e.g. 0.9.0-dev.2025+ecf0050a9).211 // Untagged development build (e.g. 0.9.0-dev.2025+ecf0050a9).
212 var it = mem.split(u8, git_describe, "-");212 var it = mem.split(u8, git_describe, "-");
213 const tagged_ancestor = it.next() orelse unreachable;213 const tagged_ancestor = it.first();
214 const commit_height = it.next() orelse unreachable;214 const commit_height = it.next().?;
215 const commit_id = it.next() orelse unreachable;215 const commit_id = it.next().?;
216216
217 const ancestor_ver = try std.builtin.Version.parse(tagged_ancestor);217 const ancestor_ver = try std.builtin.Version.parse(tagged_ancestor);
218 if (zig_version.order(ancestor_ver) != .gt) {218 if (zig_version.order(ancestor_ver) != .gt) {
...@@ -764,7 +764,7 @@ fn findAndParseConfigH(b: *Builder, config_h_path_option: ?[]const u8) ?CMakeCon...@@ -764,7 +764,7 @@ fn findAndParseConfigH(b: *Builder, config_h_path_option: ?[]const u8) ?CMakeCon
764 inline for (mappings) |mapping| {764 inline for (mappings) |mapping| {
765 if (mem.startsWith(u8, line, mapping.prefix)) {765 if (mem.startsWith(u8, line, mapping.prefix)) {
766 var it = mem.split(u8, line, "\"");766 var it = mem.split(u8, line, "\"");
767 _ = it.next().?; // skip the stuff before the quote767 _ = it.first(); // skip the stuff before the quote
768 const quoted = it.next().?; // the stuff inside the quote768 const quoted = it.next().?; // the stuff inside the quote
769 @field(ctx, mapping.field) = toNativePathSep(b, quoted);769 @field(ctx, mapping.field) = toNativePathSep(b, quoted);
770 }770 }
lib/std/SemanticVersion.zig+1-1
...@@ -88,7 +88,7 @@ pub fn parse(text: []const u8) !Version {...@@ -88,7 +88,7 @@ pub fn parse(text: []const u8) !Version {
88 const required = text[0..(extra_index orelse text.len)];88 const required = text[0..(extra_index orelse text.len)];
89 var it = std.mem.split(u8, required, ".");89 var it = std.mem.split(u8, required, ".");
90 var ver = Version{90 var ver = Version{
91 .major = try parseNum(it.next() orelse return error.InvalidVersion),91 .major = try parseNum(it.first()),
92 .minor = try parseNum(it.next() orelse return error.InvalidVersion),92 .minor = try parseNum(it.next() orelse return error.InvalidVersion),
93 .patch = try parseNum(it.next() orelse return error.InvalidVersion),93 .patch = try parseNum(it.next() orelse return error.InvalidVersion),
94 };94 };
lib/std/builtin.zig+1-1
...@@ -503,7 +503,7 @@ pub const Version = struct {...@@ -503,7 +503,7 @@ pub const Version = struct {
503503
504 var it = std.mem.split(u8, text[0..end], ".");504 var it = std.mem.split(u8, text[0..end], ".");
505 // substring is not empty, first call will succeed505 // substring is not empty, first call will succeed
506 const major = it.next().?;506 const major = it.first();
507 if (major.len == 0) return error.InvalidVersion;507 if (major.len == 0) return error.InvalidVersion;
508 const minor = it.next() orelse "0";508 const minor = it.next() orelse "0";
509 // ignore 'patch' if 'minor' is invalid509 // ignore 'patch' if 'minor' is invalid
lib/std/crypto/phc_encoding.zig+1-1
...@@ -253,7 +253,7 @@ fn serializeTo(params: anytype, out: anytype) !void {...@@ -253,7 +253,7 @@ fn serializeTo(params: anytype, out: anytype) !void {
253// Split a `key=value` string into `key` and `value`253// Split a `key=value` string into `key` and `value`
254fn kvSplit(str: []const u8) !struct { key: []const u8, value: []const u8 } {254fn kvSplit(str: []const u8) !struct { key: []const u8, value: []const u8 } {
255 var it = mem.split(u8, str, kv_delimiter);255 var it = mem.split(u8, str, kv_delimiter);
256 const key = it.next() orelse return Error.InvalidEncoding;256 const key = it.first();
257 const value = it.next() orelse return Error.InvalidEncoding;257 const value = it.next() orelse return Error.InvalidEncoding;
258 const ret = .{ .key = key, .value = value };258 const ret = .{ .key = key, .value = value };
259 return ret;259 return ret;
lib/std/crypto/scrypt.zig+1-1
...@@ -289,7 +289,7 @@ const crypt_format = struct {...@@ -289,7 +289,7 @@ const crypt_format = struct {
289289
290 var it = mem.split(u8, str[14..], "$");290 var it = mem.split(u8, str[14..], "$");
291291
292 const salt = it.next() orelse return EncodingError.InvalidEncoding;292 const salt = it.first();
293 if (@hasField(T, "salt")) out.salt = salt;293 if (@hasField(T, "salt")) out.salt = salt;
294294
295 const hash_str = it.next() orelse return EncodingError.InvalidEncoding;295 const hash_str = it.next() orelse return EncodingError.InvalidEncoding;
lib/std/mem.zig+46-22
...@@ -1597,12 +1597,15 @@ test "byteSwapAllFields" {...@@ -1597,12 +1597,15 @@ test "byteSwapAllFields" {
15971597
1598/// Returns an iterator that iterates over the slices of `buffer` that are not1598/// Returns an iterator that iterates over the slices of `buffer` that are not
1599/// any of the bytes in `delimiter_bytes`.1599/// any of the bytes in `delimiter_bytes`.
1600/// tokenize(u8, " abc def ghi ", " ")1600///
1601/// Will return slices for "abc", "def", "ghi", null, in that order.1601/// `tokenize(u8, " abc def ghi ", " ")` will return slices
1602/// for "abc", "def", "ghi", null, in that order.
1603///
1602/// If `buffer` is empty, the iterator will return null.1604/// If `buffer` is empty, the iterator will return null.
1603/// If `delimiter_bytes` does not exist in buffer,1605/// If `delimiter_bytes` does not exist in buffer,
1604/// the iterator will return `buffer`, null, in that order.1606/// the iterator will return `buffer`, null, in that order.
1605/// See also the related function `split`.1607///
1608/// See also: `split` and `splitBackwards`.
1606pub fn tokenize(comptime T: type, buffer: []const T, delimiter_bytes: []const T) TokenIterator(T) {1609pub fn tokenize(comptime T: type, buffer: []const T, delimiter_bytes: []const T) TokenIterator(T) {
1607 return .{1610 return .{
1608 .index = 0,1611 .index = 0,
...@@ -1696,12 +1699,15 @@ test "tokenize (reset)" {...@@ -1696,12 +1699,15 @@ test "tokenize (reset)" {
16961699
1697/// Returns an iterator that iterates over the slices of `buffer` that1700/// Returns an iterator that iterates over the slices of `buffer` that
1698/// are separated by bytes in `delimiter`.1701/// are separated by bytes in `delimiter`.
1699/// split(u8, "abc|def||ghi", "|")1702///
1700/// will return slices for "abc", "def", "", "ghi", null, in that order.1703/// `split(u8, "abc|def||ghi", "|")` will return slices
1704/// for "abc", "def", "", "ghi", null, in that order.
1705///
1701/// If `delimiter` does not exist in buffer,1706/// If `delimiter` does not exist in buffer,
1702/// the iterator will return `buffer`, null, in that order.1707/// the iterator will return `buffer`, null, in that order.
1703/// The delimiter length must not be zero.1708/// The delimiter length must not be zero.
1704/// See also the related function `tokenize`.1709///
1710/// See also: `tokenize` and `splitBackwards`.
1705pub fn split(comptime T: type, buffer: []const T, delimiter: []const T) SplitIterator(T) {1711pub fn split(comptime T: type, buffer: []const T, delimiter: []const T) SplitIterator(T) {
1706 assert(delimiter.len != 0);1712 assert(delimiter.len != 0);
1707 return .{1713 return .{
...@@ -1714,7 +1720,7 @@ pub fn split(comptime T: type, buffer: []const T, delimiter: []const T) SplitIte...@@ -1714,7 +1720,7 @@ pub fn split(comptime T: type, buffer: []const T, delimiter: []const T) SplitIte
1714test "split" {1720test "split" {
1715 var it = split(u8, "abc|def||ghi", "|");1721 var it = split(u8, "abc|def||ghi", "|");
1716 try testing.expectEqualSlices(u8, it.rest(), "abc|def||ghi");1722 try testing.expectEqualSlices(u8, it.rest(), "abc|def||ghi");
1717 try testing.expectEqualSlices(u8, it.next().?, "abc");1723 try testing.expectEqualSlices(u8, it.first(), "abc");
17181724
1719 try testing.expectEqualSlices(u8, it.rest(), "def||ghi");1725 try testing.expectEqualSlices(u8, it.rest(), "def||ghi");
1720 try testing.expectEqualSlices(u8, it.next().?, "def");1726 try testing.expectEqualSlices(u8, it.next().?, "def");
...@@ -1729,16 +1735,16 @@ test "split" {...@@ -1729,16 +1735,16 @@ test "split" {
1729 try testing.expect(it.next() == null);1735 try testing.expect(it.next() == null);
17301736
1731 it = split(u8, "", "|");1737 it = split(u8, "", "|");
1732 try testing.expectEqualSlices(u8, it.next().?, "");1738 try testing.expectEqualSlices(u8, it.first(), "");
1733 try testing.expect(it.next() == null);1739 try testing.expect(it.next() == null);
17341740
1735 it = split(u8, "|", "|");1741 it = split(u8, "|", "|");
1736 try testing.expectEqualSlices(u8, it.next().?, "");1742 try testing.expectEqualSlices(u8, it.first(), "");
1737 try testing.expectEqualSlices(u8, it.next().?, "");1743 try testing.expectEqualSlices(u8, it.next().?, "");
1738 try testing.expect(it.next() == null);1744 try testing.expect(it.next() == null);
17391745
1740 it = split(u8, "hello", " ");1746 it = split(u8, "hello", " ");
1741 try testing.expectEqualSlices(u8, it.next().?, "hello");1747 try testing.expectEqualSlices(u8, it.first(), "hello");
1742 try testing.expect(it.next() == null);1748 try testing.expect(it.next() == null);
17431749
1744 var it16 = split(1750 var it16 = split(
...@@ -1746,13 +1752,13 @@ test "split" {...@@ -1746,13 +1752,13 @@ test "split" {
1746 std.unicode.utf8ToUtf16LeStringLiteral("hello"),1752 std.unicode.utf8ToUtf16LeStringLiteral("hello"),
1747 std.unicode.utf8ToUtf16LeStringLiteral(" "),1753 std.unicode.utf8ToUtf16LeStringLiteral(" "),
1748 );1754 );
1749 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("hello"));1755 try testing.expectEqualSlices(u16, it16.first(), std.unicode.utf8ToUtf16LeStringLiteral("hello"));
1750 try testing.expect(it16.next() == null);1756 try testing.expect(it16.next() == null);
1751}1757}
17521758
1753test "split (multibyte)" {1759test "split (multibyte)" {
1754 var it = split(u8, "a, b ,, c, d, e", ", ");1760 var it = split(u8, "a, b ,, c, d, e", ", ");
1755 try testing.expectEqualSlices(u8, it.next().?, "a");1761 try testing.expectEqualSlices(u8, it.first(), "a");
1756 try testing.expectEqualSlices(u8, it.rest(), "b ,, c, d, e");1762 try testing.expectEqualSlices(u8, it.rest(), "b ,, c, d, e");
1757 try testing.expectEqualSlices(u8, it.next().?, "b ,");1763 try testing.expectEqualSlices(u8, it.next().?, "b ,");
1758 try testing.expectEqualSlices(u8, it.next().?, "c");1764 try testing.expectEqualSlices(u8, it.next().?, "c");
...@@ -1765,7 +1771,7 @@ test "split (multibyte)" {...@@ -1765,7 +1771,7 @@ test "split (multibyte)" {
1765 std.unicode.utf8ToUtf16LeStringLiteral("a, b ,, c, d, e"),1771 std.unicode.utf8ToUtf16LeStringLiteral("a, b ,, c, d, e"),
1766 std.unicode.utf8ToUtf16LeStringLiteral(", "),1772 std.unicode.utf8ToUtf16LeStringLiteral(", "),
1767 );1773 );
1768 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("a"));1774 try testing.expectEqualSlices(u16, it16.first(), std.unicode.utf8ToUtf16LeStringLiteral("a"));
1769 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("b ,"));1775 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("b ,"));
1770 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("c"));1776 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("c"));
1771 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("d"));1777 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("d"));
...@@ -1775,11 +1781,15 @@ test "split (multibyte)" {...@@ -1775,11 +1781,15 @@ test "split (multibyte)" {
17751781
1776/// Returns an iterator that iterates backwards over the slices of `buffer`1782/// Returns an iterator that iterates backwards over the slices of `buffer`
1777/// that are separated by bytes in `delimiter`.1783/// that are separated by bytes in `delimiter`.
1778/// splitBackwards(u8, "abc|def||ghi", "|")1784///
1779/// will return slices for "ghi", "", "def", "abc", null, in that order.1785/// `splitBackwards(u8, "abc|def||ghi", "|")` will return slices
1786/// for "ghi", "", "def", "abc", null, in that order.
1787///
1780/// If `delimiter` does not exist in buffer,1788/// If `delimiter` does not exist in buffer,
1781/// the iterator will return `buffer`, null, in that order.1789/// the iterator will return `buffer`, null, in that order.
1782/// The delimiter length must not be zero.1790/// The delimiter length must not be zero.
1791///
1792/// See also: `tokenize` and `split`.
1783pub fn splitBackwards(comptime T: type, buffer: []const T, delimiter: []const T) SplitBackwardsIterator(T) {1793pub fn splitBackwards(comptime T: type, buffer: []const T, delimiter: []const T) SplitBackwardsIterator(T) {
1784 assert(delimiter.len != 0);1794 assert(delimiter.len != 0);
1785 return SplitBackwardsIterator(T){1795 return SplitBackwardsIterator(T){
...@@ -1792,7 +1802,7 @@ pub fn splitBackwards(comptime T: type, buffer: []const T, delimiter: []const T)...@@ -1792,7 +1802,7 @@ pub fn splitBackwards(comptime T: type, buffer: []const T, delimiter: []const T)
1792test "splitBackwards" {1802test "splitBackwards" {
1793 var it = splitBackwards(u8, "abc|def||ghi", "|");1803 var it = splitBackwards(u8, "abc|def||ghi", "|");
1794 try testing.expectEqualSlices(u8, it.rest(), "abc|def||ghi");1804 try testing.expectEqualSlices(u8, it.rest(), "abc|def||ghi");
1795 try testing.expectEqualSlices(u8, it.next().?, "ghi");1805 try testing.expectEqualSlices(u8, it.first(), "ghi");
17961806
1797 try testing.expectEqualSlices(u8, it.rest(), "abc|def|");1807 try testing.expectEqualSlices(u8, it.rest(), "abc|def|");
1798 try testing.expectEqualSlices(u8, it.next().?, "");1808 try testing.expectEqualSlices(u8, it.next().?, "");
...@@ -1807,16 +1817,16 @@ test "splitBackwards" {...@@ -1807,16 +1817,16 @@ test "splitBackwards" {
1807 try testing.expect(it.next() == null);1817 try testing.expect(it.next() == null);
18081818
1809 it = splitBackwards(u8, "", "|");1819 it = splitBackwards(u8, "", "|");
1810 try testing.expectEqualSlices(u8, it.next().?, "");1820 try testing.expectEqualSlices(u8, it.first(), "");
1811 try testing.expect(it.next() == null);1821 try testing.expect(it.next() == null);
18121822
1813 it = splitBackwards(u8, "|", "|");1823 it = splitBackwards(u8, "|", "|");
1814 try testing.expectEqualSlices(u8, it.next().?, "");1824 try testing.expectEqualSlices(u8, it.first(), "");
1815 try testing.expectEqualSlices(u8, it.next().?, "");1825 try testing.expectEqualSlices(u8, it.next().?, "");
1816 try testing.expect(it.next() == null);1826 try testing.expect(it.next() == null);
18171827
1818 it = splitBackwards(u8, "hello", " ");1828 it = splitBackwards(u8, "hello", " ");
1819 try testing.expectEqualSlices(u8, it.next().?, "hello");1829 try testing.expectEqualSlices(u8, it.first(), "hello");
1820 try testing.expect(it.next() == null);1830 try testing.expect(it.next() == null);
18211831
1822 var it16 = splitBackwards(1832 var it16 = splitBackwards(
...@@ -1824,14 +1834,14 @@ test "splitBackwards" {...@@ -1824,14 +1834,14 @@ test "splitBackwards" {
1824 std.unicode.utf8ToUtf16LeStringLiteral("hello"),1834 std.unicode.utf8ToUtf16LeStringLiteral("hello"),
1825 std.unicode.utf8ToUtf16LeStringLiteral(" "),1835 std.unicode.utf8ToUtf16LeStringLiteral(" "),
1826 );1836 );
1827 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("hello"));1837 try testing.expectEqualSlices(u16, it16.first(), std.unicode.utf8ToUtf16LeStringLiteral("hello"));
1828 try testing.expect(it16.next() == null);1838 try testing.expect(it16.next() == null);
1829}1839}
18301840
1831test "splitBackwards (multibyte)" {1841test "splitBackwards (multibyte)" {
1832 var it = splitBackwards(u8, "a, b ,, c, d, e", ", ");1842 var it = splitBackwards(u8, "a, b ,, c, d, e", ", ");
1833 try testing.expectEqualSlices(u8, it.rest(), "a, b ,, c, d, e");1843 try testing.expectEqualSlices(u8, it.rest(), "a, b ,, c, d, e");
1834 try testing.expectEqualSlices(u8, it.next().?, "e");1844 try testing.expectEqualSlices(u8, it.first(), "e");
18351845
1836 try testing.expectEqualSlices(u8, it.rest(), "a, b ,, c, d");1846 try testing.expectEqualSlices(u8, it.rest(), "a, b ,, c, d");
1837 try testing.expectEqualSlices(u8, it.next().?, "d");1847 try testing.expectEqualSlices(u8, it.next().?, "d");
...@@ -1853,7 +1863,7 @@ test "splitBackwards (multibyte)" {...@@ -1853,7 +1863,7 @@ test "splitBackwards (multibyte)" {
1853 std.unicode.utf8ToUtf16LeStringLiteral("a, b ,, c, d, e"),1863 std.unicode.utf8ToUtf16LeStringLiteral("a, b ,, c, d, e"),
1854 std.unicode.utf8ToUtf16LeStringLiteral(", "),1864 std.unicode.utf8ToUtf16LeStringLiteral(", "),
1855 );1865 );
1856 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("e"));1866 try testing.expectEqualSlices(u16, it16.first(), std.unicode.utf8ToUtf16LeStringLiteral("e"));
1857 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("d"));1867 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("d"));
1858 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("c"));1868 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("c"));
1859 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("b ,"));1869 try testing.expectEqualSlices(u16, it16.next().?, std.unicode.utf8ToUtf16LeStringLiteral("b ,"));
...@@ -1944,6 +1954,13 @@ pub fn SplitIterator(comptime T: type) type {...@@ -1944,6 +1954,13 @@ pub fn SplitIterator(comptime T: type) type {
19441954
1945 const Self = @This();1955 const Self = @This();
19461956
1957 /// Returns a slice of the first field. This never fails.
1958 /// Call this only to get the first field and then use `next` to get all subsequent fields.
1959 pub fn first(self: *Self) []const T {
1960 assert(self.index.? == 0);
1961 return self.next().?;
1962 }
1963
1947 /// Returns a slice of the next field, or null if splitting is complete.1964 /// Returns a slice of the next field, or null if splitting is complete.
1948 pub fn next(self: *Self) ?[]const T {1965 pub fn next(self: *Self) ?[]const T {
1949 const start = self.index orelse return null;1966 const start = self.index orelse return null;
...@@ -1974,6 +1991,13 @@ pub fn SplitBackwardsIterator(comptime T: type) type {...@@ -1974,6 +1991,13 @@ pub fn SplitBackwardsIterator(comptime T: type) type {
19741991
1975 const Self = @This();1992 const Self = @This();
19761993
1994 /// Returns a slice of the first field. This never fails.
1995 /// Call this only to get the first field and then use `next` to get all subsequent fields.
1996 pub fn first(self: *Self) []const T {
1997 assert(self.index.? == self.buffer.len);
1998 return self.next().?;
1999 }
2000
1977 /// Returns a slice of the next field, or null if splitting is complete.2001 /// Returns a slice of the next field, or null if splitting is complete.
1978 pub fn next(self: *Self) ?[]const T {2002 pub fn next(self: *Self) ?[]const T {
1979 const end = self.index orelse return null;2003 const end = self.index orelse return null;
lib/std/net.zig+3-3
...@@ -1154,7 +1154,7 @@ fn linuxLookupNameFromHosts(...@@ -1154,7 +1154,7 @@ fn linuxLookupNameFromHosts(
1154 else => |e| return e,1154 else => |e| return e,
1155 }) |line| {1155 }) |line| {
1156 var split_it = mem.split(u8, line, "#");1156 var split_it = mem.split(u8, line, "#");
1157 const no_comment_line = split_it.next().?;1157 const no_comment_line = split_it.first();
11581158
1159 var line_it = mem.tokenize(u8, no_comment_line, " \t");1159 var line_it = mem.tokenize(u8, no_comment_line, " \t");
1160 const ip_text = line_it.next() orelse continue;1160 const ip_text = line_it.next() orelse continue;
...@@ -1356,7 +1356,7 @@ fn getResolvConf(allocator: mem.Allocator, rc: *ResolvConf) !void {...@@ -1356,7 +1356,7 @@ fn getResolvConf(allocator: mem.Allocator, rc: *ResolvConf) !void {
1356 }) |line| {1356 }) |line| {
1357 const no_comment_line = no_comment_line: {1357 const no_comment_line = no_comment_line: {
1358 var split = mem.split(u8, line, "#");1358 var split = mem.split(u8, line, "#");
1359 break :no_comment_line split.next().?;1359 break :no_comment_line split.first();
1360 };1360 };
1361 var line_it = mem.tokenize(u8, no_comment_line, " \t");1361 var line_it = mem.tokenize(u8, no_comment_line, " \t");
13621362
...@@ -1364,7 +1364,7 @@ fn getResolvConf(allocator: mem.Allocator, rc: *ResolvConf) !void {...@@ -1364,7 +1364,7 @@ fn getResolvConf(allocator: mem.Allocator, rc: *ResolvConf) !void {
1364 if (mem.eql(u8, token, "options")) {1364 if (mem.eql(u8, token, "options")) {
1365 while (line_it.next()) |sub_tok| {1365 while (line_it.next()) |sub_tok| {
1366 var colon_it = mem.split(u8, sub_tok, ":");1366 var colon_it = mem.split(u8, sub_tok, ":");
1367 const name = colon_it.next().?;1367 const name = colon_it.first();
1368 const value_txt = colon_it.next() orelse continue;1368 const value_txt = colon_it.next() orelse continue;
1369 const value = std.fmt.parseInt(u8, value_txt, 10) catch |err| switch (err) {1369 const value = std.fmt.parseInt(u8, value_txt, 10) catch |err| switch (err) {
1370 // TODO https://github.com/ziglang/zig/issues/118121370 // TODO https://github.com/ziglang/zig/issues/11812
lib/std/process.zig+1-1
...@@ -306,7 +306,7 @@ pub fn getEnvMap(allocator: Allocator) !EnvMap {...@@ -306,7 +306,7 @@ pub fn getEnvMap(allocator: Allocator) !EnvMap {
306 for (environ) |env| {306 for (environ) |env| {
307 const pair = mem.sliceTo(env, 0);307 const pair = mem.sliceTo(env, 0);
308 var parts = mem.split(u8, pair, "=");308 var parts = mem.split(u8, pair, "=");
309 const key = parts.next().?;309 const key = parts.first();
310 const value = parts.next().?;310 const value = parts.next().?;
311 try result.put(key, value);311 try result.put(key, value);
312 }312 }
lib/std/zig/CrossTarget.zig+5-5
...@@ -231,7 +231,7 @@ pub fn parse(args: ParseOptions) !CrossTarget {...@@ -231,7 +231,7 @@ pub fn parse(args: ParseOptions) !CrossTarget {
231 };231 };
232232
233 var it = mem.split(u8, args.arch_os_abi, "-");233 var it = mem.split(u8, args.arch_os_abi, "-");
234 const arch_name = it.next().?;234 const arch_name = it.first();
235 const arch_is_native = mem.eql(u8, arch_name, "native");235 const arch_is_native = mem.eql(u8, arch_name, "native");
236 if (!arch_is_native) {236 if (!arch_is_native) {
237 result.cpu_arch = std.meta.stringToEnum(Target.Cpu.Arch, arch_name) orelse237 result.cpu_arch = std.meta.stringToEnum(Target.Cpu.Arch, arch_name) orelse
...@@ -249,7 +249,7 @@ pub fn parse(args: ParseOptions) !CrossTarget {...@@ -249,7 +249,7 @@ pub fn parse(args: ParseOptions) !CrossTarget {
249 const opt_abi_text = it.next();249 const opt_abi_text = it.next();
250 if (opt_abi_text) |abi_text| {250 if (opt_abi_text) |abi_text| {
251 var abi_it = mem.split(u8, abi_text, ".");251 var abi_it = mem.split(u8, abi_text, ".");
252 const abi = std.meta.stringToEnum(Target.Abi, abi_it.next().?) orelse252 const abi = std.meta.stringToEnum(Target.Abi, abi_it.first()) orelse
253 return error.UnknownApplicationBinaryInterface;253 return error.UnknownApplicationBinaryInterface;
254 result.abi = abi;254 result.abi = abi;
255 diags.abi = abi;255 diags.abi = abi;
...@@ -330,7 +330,7 @@ pub fn parse(args: ParseOptions) !CrossTarget {...@@ -330,7 +330,7 @@ pub fn parse(args: ParseOptions) !CrossTarget {
330/// target CPU architecture in order to fully populate `ParseOptions`.330/// target CPU architecture in order to fully populate `ParseOptions`.
331pub fn parseCpuArch(args: ParseOptions) ?Target.Cpu.Arch {331pub fn parseCpuArch(args: ParseOptions) ?Target.Cpu.Arch {
332 var it = mem.split(u8, args.arch_os_abi, "-");332 var it = mem.split(u8, args.arch_os_abi, "-");
333 const arch_name = it.next().?;333 const arch_name = it.first();
334 const arch_is_native = mem.eql(u8, arch_name, "native");334 const arch_is_native = mem.eql(u8, arch_name, "native");
335 if (arch_is_native) {335 if (arch_is_native) {
336 return builtin.cpu.arch;336 return builtin.cpu.arch;
...@@ -632,7 +632,7 @@ pub fn updateCpuFeatures(self: CrossTarget, set: *Target.Cpu.Feature.Set) void {...@@ -632,7 +632,7 @@ pub fn updateCpuFeatures(self: CrossTarget, set: *Target.Cpu.Feature.Set) void {
632632
633fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const u8) !void {633fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const u8) !void {
634 var it = mem.split(u8, text, ".");634 var it = mem.split(u8, text, ".");
635 const os_name = it.next().?;635 const os_name = it.first();
636 diags.os_name = os_name;636 diags.os_name = os_name;
637 const os_is_native = mem.eql(u8, os_name, "native");637 const os_is_native = mem.eql(u8, os_name, "native");
638 if (!os_is_native) {638 if (!os_is_native) {
...@@ -711,7 +711,7 @@ fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const...@@ -711,7 +711,7 @@ fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const
711 .windows => {711 .windows => {
712 var range_it = mem.split(u8, version_text, "...");712 var range_it = mem.split(u8, version_text, "...");
713713
714 const min_text = range_it.next().?;714 const min_text = range_it.first();
715 const min_ver = std.meta.stringToEnum(Target.Os.WindowsVersion, min_text) orelse715 const min_ver = std.meta.stringToEnum(Target.Os.WindowsVersion, min_text) orelse
716 return error.InvalidOperatingSystemVersion;716 return error.InvalidOperatingSystemVersion;
717 result.os_version_min = .{ .windows = min_ver };717 result.os_version_min = .{ .windows = min_ver };
lib/std/zig/render.zig+1-1
...@@ -1820,7 +1820,7 @@ fn renderArrayInit(...@@ -1820,7 +1820,7 @@ fn renderArrayInit(
1820 } else {1820 } else {
1821 var by_line = std.mem.split(u8, expr_text, "\n");1821 var by_line = std.mem.split(u8, expr_text, "\n");
1822 var last_line_was_empty = false;1822 var last_line_was_empty = false;
1823 try ais.writer().writeAll(by_line.next().?);1823 try ais.writer().writeAll(by_line.first());
1824 while (by_line.next()) |line| {1824 while (by_line.next()) |line| {
1825 if (std.mem.startsWith(u8, line, "//") and last_line_was_empty) {1825 if (std.mem.startsWith(u8, line, "//") and last_line_was_empty) {
1826 try ais.insertNewline();1826 try ais.insertNewline();
src/Compilation.zig+1-1
...@@ -4392,7 +4392,7 @@ pub fn hasSharedLibraryExt(filename: []const u8) bool {...@@ -4392,7 +4392,7 @@ pub fn hasSharedLibraryExt(filename: []const u8) bool {
4392 }4392 }
4393 // Look for .so.X, .so.X.Y, .so.X.Y.Z4393 // Look for .so.X, .so.X.Y, .so.X.Y.Z
4394 var it = mem.split(u8, filename, ".");4394 var it = mem.split(u8, filename, ".");
4395 _ = it.next().?;4395 _ = it.first();
4396 var so_txt = it.next() orelse return false;4396 var so_txt = it.next() orelse return false;
4397 while (!mem.eql(u8, so_txt, "so")) {4397 while (!mem.eql(u8, so_txt, "so")) {
4398 so_txt = it.next() orelse return false;4398 so_txt = it.next() orelse return false;
src/libc_installation.zig+1-4
...@@ -64,10 +64,7 @@ pub const LibCInstallation = struct {...@@ -64,10 +64,7 @@ pub const LibCInstallation = struct {
64 while (it.next()) |line| {64 while (it.next()) |line| {
65 if (line.len == 0 or line[0] == '#') continue;65 if (line.len == 0 or line[0] == '#') continue;
66 var line_it = std.mem.split(u8, line, "=");66 var line_it = std.mem.split(u8, line, "=");
67 const name = line_it.next() orelse {67 const name = line_it.first();
68 log.err("missing equal sign after field name\n", .{});
69 return error.ParseError;
70 };
71 const value = line_it.rest();68 const value = line_it.rest();
72 inline for (fields) |field, i| {69 inline for (fields) |field, i| {
73 if (std.mem.eql(u8, name, field.name)) {70 if (std.mem.eql(u8, name, field.name)) {
src/test.zig+3-3
...@@ -303,7 +303,7 @@ const TestManifest = struct {...@@ -303,7 +303,7 @@ const TestManifest = struct {
303303
304 // Parse key=value(s)304 // Parse key=value(s)
305 var kv_it = std.mem.split(u8, trimmed, "=");305 var kv_it = std.mem.split(u8, trimmed, "=");
306 const key = kv_it.next() orelse return error.MissingKeyForConfig;306 const key = kv_it.first();
307 try manifest.config_map.putNoClobber(key, kv_it.next() orelse return error.MissingValuesForConfig);307 try manifest.config_map.putNoClobber(key, kv_it.next() orelse return error.MissingValuesForConfig);
308 }308 }
309309
...@@ -697,7 +697,7 @@ pub const TestContext = struct {...@@ -697,7 +697,7 @@ pub const TestContext = struct {
697 }697 }
698 // example: "file.zig:1:2: error: bad thing happened"698 // example: "file.zig:1:2: error: bad thing happened"
699 var it = std.mem.split(u8, err_msg_line, ":");699 var it = std.mem.split(u8, err_msg_line, ":");
700 const src_path = it.next() orelse @panic("missing colon");700 const src_path = it.first();
701 const line_text = it.next() orelse @panic("missing line");701 const line_text = it.next() orelse @panic("missing line");
702 const col_text = it.next() orelse @panic("missing column");702 const col_text = it.next() orelse @panic("missing column");
703 const kind_text = it.next() orelse @panic("missing 'error'/'note'");703 const kind_text = it.next() orelse @panic("missing 'error'/'note'");
...@@ -1698,7 +1698,7 @@ pub const TestContext = struct {...@@ -1698,7 +1698,7 @@ pub const TestContext = struct {
1698 var fib = std.io.fixedBufferStream(&buf);1698 var fib = std.io.fixedBufferStream(&buf);
1699 try msg.renderToWriter(.no_color, fib.writer(), "error", .Red, 0);1699 try msg.renderToWriter(.no_color, fib.writer(), "error", .Red, 0);
1700 var it = std.mem.split(u8, fib.getWritten(), "error: ");1700 var it = std.mem.split(u8, fib.getWritten(), "error: ");
1701 _ = it.next();1701 _ = it.first();
1702 const rendered = it.rest();1702 const rendered = it.rest();
1703 break :blk rendered[0 .. rendered.len - 1]; // trim final newline1703 break :blk rendered[0 .. rendered.len - 1]; // trim final newline
1704 };1704 };
tools/update_spirv_features.zig+1-1
...@@ -21,7 +21,7 @@ const Version = struct {...@@ -21,7 +21,7 @@ const Version = struct {
21 fn parse(str: []const u8) !Version {21 fn parse(str: []const u8) !Version {
22 var it = std.mem.split(u8, str, ".");22 var it = std.mem.split(u8, str, ".");
2323
24 const major = it.next() orelse return error.InvalidVersion;24 const major = it.first();
25 const minor = it.next() orelse return error.InvalidVersion;25 const minor = it.next() orelse return error.InvalidVersion;
2626
27 if (it.next() != null) return error.InvalidVersion;27 if (it.next() != null) return error.InvalidVersion;