| author | |
| committer | |
| log | bc3c50c21ea3dd902731c1da6bf9b7135eb5b1c1 |
| tree | d0a27940f7b29825d2d7c94bb09a9af51e847ab4 |
| parent | 8285de62d51dbdba0f47ef2848b0e53a93ace6ad |
| parent | 195471a98d8a1a775c56f030aee4524ce0746510 |
| signature |
chore(std.mem): Rename `trimLeft` and `trimRight` to `trimStart` and `trimEnd`22 files changed, 59 insertions(+), 47 deletions(-)
lib/compiler/resinator/compile.zig+1-1| ... | @@ -3274,7 +3274,7 @@ pub const StringTable = struct { | ... | @@ -3274,7 +3274,7 @@ pub const StringTable = struct { |
| 3274 | // Note: This is only the case for STRINGTABLE strings | 3274 | // Note: This is only the case for STRINGTABLE strings |
| 3275 | const trimmed = trimToDoubleNUL(u16, utf16_string); | 3275 | const trimmed = trimToDoubleNUL(u16, utf16_string); |
| 3276 | // We also want to trim any trailing NUL characters | 3276 | // We also want to trim any trailing NUL characters |
| 3277 | break :trim std.mem.trimRight(u16, trimmed, &[_]u16{0}); | 3277 | break :trim std.mem.trimEnd(u16, trimmed, &[_]u16{0}); |
| 3278 | }; | 3278 | }; |
| 3279 | 3279 | ||
| 3280 | // String literals are limited to maxInt(u15) codepoints, so these UTF-16 encoded | 3280 | // String literals are limited to maxInt(u15) codepoints, so these UTF-16 encoded |
lib/docs/wasm/markdown/Parser.zig+5-5| ... | @@ -140,7 +140,7 @@ const Block = struct { | ... | @@ -140,7 +140,7 @@ const Block = struct { |
| 140 | /// (e.g. for a blockquote, this would be everything except the leading | 140 | /// (e.g. for a blockquote, this would be everything except the leading |
| 141 | /// `>`). If unsuccessful, returns null. | 141 | /// `>`). If unsuccessful, returns null. |
| 142 | fn match(b: Block, line: []const u8) ?[]const u8 { | 142 | fn match(b: Block, line: []const u8) ?[]const u8 { |
| 143 | const unindented = mem.trimLeft(u8, line, " \t"); | 143 | const unindented = mem.trimStart(u8, line, " \t"); |
| 144 | const indent = line.len - unindented.len; | 144 | const indent = line.len - unindented.len; |
| 145 | return switch (b.tag) { | 145 | return switch (b.tag) { |
| 146 | .list => line, | 146 | .list => line, |
| ... | @@ -156,7 +156,7 @@ const Block = struct { | ... | @@ -156,7 +156,7 @@ const Block = struct { |
| 156 | .table_row => null, | 156 | .table_row => null, |
| 157 | .heading => null, | 157 | .heading => null, |
| 158 | .code_block => code_block: { | 158 | .code_block => code_block: { |
| 159 | const trimmed = mem.trimRight(u8, unindented, " \t"); | 159 | const trimmed = mem.trimEnd(u8, unindented, " \t"); |
| 160 | if (mem.indexOfNone(u8, trimmed, "`") != null or trimmed.len != b.data.code_block.fence_len) { | 160 | if (mem.indexOfNone(u8, trimmed, "`") != null or trimmed.len != b.data.code_block.fence_len) { |
| 161 | const effective_indent = @min(indent, b.data.code_block.indent); | 161 | const effective_indent = @min(indent, b.data.code_block.indent); |
| 162 | break :code_block line[effective_indent..]; | 162 | break :code_block line[effective_indent..]; |
| ... | @@ -225,7 +225,7 @@ pub fn feedLine(p: *Parser, line: []const u8) Allocator.Error!void { | ... | @@ -225,7 +225,7 @@ pub fn feedLine(p: *Parser, line: []const u8) Allocator.Error!void { |
| 225 | p.pending_blocks.items.len > 0 and | 225 | p.pending_blocks.items.len > 0 and |
| 226 | p.pending_blocks.getLast().tag == .paragraph) | 226 | p.pending_blocks.getLast().tag == .paragraph) |
| 227 | { | 227 | { |
| 228 | try p.addScratchStringLine(mem.trimLeft(u8, rest_line, " \t")); | 228 | try p.addScratchStringLine(mem.trimStart(u8, rest_line, " \t")); |
| 229 | return; | 229 | return; |
| 230 | } | 230 | } |
| 231 | 231 | ||
| ... | @@ -261,7 +261,7 @@ pub fn feedLine(p: *Parser, line: []const u8) Allocator.Error!void { | ... | @@ -261,7 +261,7 @@ pub fn feedLine(p: *Parser, line: []const u8) Allocator.Error!void { |
| 261 | last_pending_block.canAccept() | 261 | last_pending_block.canAccept() |
| 262 | else | 262 | else |
| 263 | .blocks; | 263 | .blocks; |
| 264 | const rest_line_trimmed = mem.trimLeft(u8, rest_line, " \t"); | 264 | const rest_line_trimmed = mem.trimStart(u8, rest_line, " \t"); |
| 265 | switch (can_accept) { | 265 | switch (can_accept) { |
| 266 | .blocks => { | 266 | .blocks => { |
| 267 | // If we're inside a list item and the rest of the line is blank, it | 267 | // If we're inside a list item and the rest of the line is blank, it |
| ... | @@ -500,7 +500,7 @@ fn appendBlockStart(p: *Parser, block_start: BlockStart) !void { | ... | @@ -500,7 +500,7 @@ fn appendBlockStart(p: *Parser, block_start: BlockStart) !void { |
| 500 | } | 500 | } |
| 501 | 501 | ||
| 502 | fn startBlock(p: *Parser, line: []const u8) !?BlockStart { | 502 | fn startBlock(p: *Parser, line: []const u8) !?BlockStart { |
| 503 | const unindented = mem.trimLeft(u8, line, " \t"); | 503 | const unindented = mem.trimStart(u8, line, " \t"); |
| 504 | const indent = line.len - unindented.len; | 504 | const indent = line.len - unindented.len; |
| 505 | if (isThematicBreak(line)) { | 505 | if (isThematicBreak(line)) { |
| 506 | // Thematic breaks take precedence over list items. | 506 | // Thematic breaks take precedence over list items. |
lib/std/crypto/tls/Client.zig+2-2| ... | @@ -364,7 +364,7 @@ pub fn init(stream: anytype, options: Options) InitError(@TypeOf(stream))!Client | ... | @@ -364,7 +364,7 @@ pub fn init(stream: anytype, options: Options) InitError(@TypeOf(stream))!Client |
| 364 | }; | 364 | }; |
| 365 | P.AEAD.decrypt(cleartext, ciphertext, auth_tag, record_header, nonce, pv.server_handshake_key) catch | 365 | P.AEAD.decrypt(cleartext, ciphertext, auth_tag, record_header, nonce, pv.server_handshake_key) catch |
| 366 | return error.TlsBadRecordMac; | 366 | return error.TlsBadRecordMac; |
| 367 | cleartext_fragment_end += std.mem.trimRight(u8, cleartext, "\x00").len; | 367 | cleartext_fragment_end += std.mem.trimEnd(u8, cleartext, "\x00").len; |
| 368 | }, | 368 | }, |
| 369 | } | 369 | } |
| 370 | read_seq += 1; | 370 | read_seq += 1; |
| ... | @@ -1353,7 +1353,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.posix.iove | ... | @@ -1353,7 +1353,7 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.posix.iove |
| 1353 | const cleartext = cleartext_buf[0..ciphertext.len]; | 1353 | const cleartext = cleartext_buf[0..ciphertext.len]; |
| 1354 | P.AEAD.decrypt(cleartext, ciphertext, auth_tag, ad, nonce, pv.server_key) catch | 1354 | P.AEAD.decrypt(cleartext, ciphertext, auth_tag, ad, nonce, pv.server_key) catch |
| 1355 | return error.TlsBadRecordMac; | 1355 | return error.TlsBadRecordMac; |
| 1356 | const msg = mem.trimRight(u8, cleartext, "\x00"); | 1356 | const msg = mem.trimEnd(u8, cleartext, "\x00"); |
| 1357 | break :cleartext .{ msg[0 .. msg.len - 1], @enumFromInt(msg[msg.len - 1]) }; | 1357 | break :cleartext .{ msg[0 .. msg.len - 1], @enumFromInt(msg[msg.len - 1]) }; |
| 1358 | }, | 1358 | }, |
| 1359 | .tls_1_2 => { | 1359 | .tls_1_2 => { |
lib/std/elf.zig+3-3| ... | @@ -2330,12 +2330,12 @@ pub const ar_hdr = extern struct { | ... | @@ -2330,12 +2330,12 @@ pub const ar_hdr = extern struct { |
| 2330 | ar_fmag: [2]u8, | 2330 | ar_fmag: [2]u8, |
| 2331 | 2331 | ||
| 2332 | pub fn date(self: ar_hdr) std.fmt.ParseIntError!u64 { | 2332 | pub fn date(self: ar_hdr) std.fmt.ParseIntError!u64 { |
| 2333 | const value = mem.trimRight(u8, &self.ar_date, &[_]u8{0x20}); | 2333 | const value = mem.trimEnd(u8, &self.ar_date, &[_]u8{0x20}); |
| 2334 | return std.fmt.parseInt(u64, value, 10); | 2334 | return std.fmt.parseInt(u64, value, 10); |
| 2335 | } | 2335 | } |
| 2336 | 2336 | ||
| 2337 | pub fn size(self: ar_hdr) std.fmt.ParseIntError!u32 { | 2337 | pub fn size(self: ar_hdr) std.fmt.ParseIntError!u32 { |
| 2338 | const value = mem.trimRight(u8, &self.ar_size, &[_]u8{0x20}); | 2338 | const value = mem.trimEnd(u8, &self.ar_size, &[_]u8{0x20}); |
| 2339 | return std.fmt.parseInt(u32, value, 10); | 2339 | return std.fmt.parseInt(u32, value, 10); |
| 2340 | } | 2340 | } |
| 2341 | 2341 | ||
| ... | @@ -2369,7 +2369,7 @@ pub const ar_hdr = extern struct { | ... | @@ -2369,7 +2369,7 @@ pub const ar_hdr = extern struct { |
| 2369 | pub fn nameOffset(self: ar_hdr) std.fmt.ParseIntError!?u32 { | 2369 | pub fn nameOffset(self: ar_hdr) std.fmt.ParseIntError!?u32 { |
| 2370 | const value = &self.ar_name; | 2370 | const value = &self.ar_name; |
| 2371 | if (value[0] != '/') return null; | 2371 | if (value[0] != '/') return null; |
| 2372 | const trimmed = mem.trimRight(u8, value, &[_]u8{0x20}); | 2372 | const trimmed = mem.trimEnd(u8, value, &[_]u8{0x20}); |
| 2373 | return try std.fmt.parseInt(u32, trimmed[1..], 10); | 2373 | return try std.fmt.parseInt(u32, trimmed[1..], 10); |
| 2374 | } | 2374 | } |
| 2375 | }; | 2375 | }; |
lib/std/fmt.zig+1-1| ... | @@ -1162,7 +1162,7 @@ pub fn formatFloatHexadecimal( | ... | @@ -1162,7 +1162,7 @@ pub fn formatFloatHexadecimal( |
| 1162 | 1162 | ||
| 1163 | try writer.writeAll("0x"); | 1163 | try writer.writeAll("0x"); |
| 1164 | try writer.writeByte(buf[0]); | 1164 | try writer.writeByte(buf[0]); |
| 1165 | const trimmed = mem.trimRight(u8, buf[1..], "0"); | 1165 | const trimmed = mem.trimEnd(u8, buf[1..], "0"); |
| 1166 | if (options.precision) |precision| { | 1166 | if (options.precision) |precision| { |
| 1167 | if (precision > 0) try writer.writeAll("."); | 1167 | if (precision > 0) try writer.writeAll("."); |
| 1168 | } else if (trimmed.len > 0) { | 1168 | } else if (trimmed.len > 0) { |
lib/std/http/Client.zig+1-1| ... | @@ -473,7 +473,7 @@ pub const Response = struct { | ... | @@ -473,7 +473,7 @@ pub const Response = struct { |
| 473 | }; | 473 | }; |
| 474 | if (first_line[8] != ' ') return error.HttpHeadersInvalid; | 474 | if (first_line[8] != ' ') return error.HttpHeadersInvalid; |
| 475 | const status: http.Status = @enumFromInt(parseInt3(first_line[9..12])); | 475 | const status: http.Status = @enumFromInt(parseInt3(first_line[9..12])); |
| 476 | const reason = mem.trimLeft(u8, first_line[12..], " "); | 476 | const reason = mem.trimStart(u8, first_line[12..], " "); |
| 477 | 477 | ||
| 478 | res.version = version; | 478 | res.version = version; |
| 479 | res.status = status; | 479 | res.status = status; |
lib/std/mem.zig+16-4| ... | @@ -1200,19 +1200,33 @@ pub fn allEqual(comptime T: type, slice: []const T, scalar: T) bool { | ... | @@ -1200,19 +1200,33 @@ pub fn allEqual(comptime T: type, slice: []const T, scalar: T) bool { |
| 1200 | } | 1200 | } |
| 1201 | 1201 | ||
| 1202 | /// Remove a set of values from the beginning of a slice. | 1202 | /// Remove a set of values from the beginning of a slice. |
| 1203 | pub fn trimLeft(comptime T: type, slice: []const T, values_to_strip: []const T) []const T { | 1203 | pub fn trimStart(comptime T: type, slice: []const T, values_to_strip: []const T) []const T { |
| 1204 | var begin: usize = 0; | 1204 | var begin: usize = 0; |
| 1205 | while (begin < slice.len and indexOfScalar(T, values_to_strip, slice[begin]) != null) : (begin += 1) {} | 1205 | while (begin < slice.len and indexOfScalar(T, values_to_strip, slice[begin]) != null) : (begin += 1) {} |
| 1206 | return slice[begin..]; | 1206 | return slice[begin..]; |
| 1207 | } | 1207 | } |
| 1208 | 1208 | ||
| 1209 | test trimStart { | ||
| 1210 | try testing.expectEqualSlices(u8, "foo\n ", trimStart(u8, " foo\n ", " \n")); | ||
| 1211 | } | ||
| 1212 | |||
| 1213 | /// Deprecated: use `trimStart` instead. | ||
| 1214 | pub const trimLeft = trimStart; | ||
| 1215 | |||
| 1209 | /// Remove a set of values from the end of a slice. | 1216 | /// Remove a set of values from the end of a slice. |
| 1210 | pub fn trimRight(comptime T: type, slice: []const T, values_to_strip: []const T) []const T { | 1217 | pub fn trimEnd(comptime T: type, slice: []const T, values_to_strip: []const T) []const T { |
| 1211 | var end: usize = slice.len; | 1218 | var end: usize = slice.len; |
| 1212 | while (end > 0 and indexOfScalar(T, values_to_strip, slice[end - 1]) != null) : (end -= 1) {} | 1219 | while (end > 0 and indexOfScalar(T, values_to_strip, slice[end - 1]) != null) : (end -= 1) {} |
| 1213 | return slice[0..end]; | 1220 | return slice[0..end]; |
| 1214 | } | 1221 | } |
| 1215 | 1222 | ||
| 1223 | test trimEnd { | ||
| 1224 | try testing.expectEqualSlices(u8, " foo", trimEnd(u8, " foo\n ", " \n")); | ||
| 1225 | } | ||
| 1226 | |||
| 1227 | /// Deprecated: use `trimEnd` instead. | ||
| 1228 | pub const trimRight = trimEnd; | ||
| 1229 | |||
| 1216 | /// Remove a set of values from the beginning and end of a slice. | 1230 | /// Remove a set of values from the beginning and end of a slice. |
| 1217 | pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []const T { | 1231 | pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []const T { |
| 1218 | var begin: usize = 0; | 1232 | var begin: usize = 0; |
| ... | @@ -1223,8 +1237,6 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co | ... | @@ -1223,8 +1237,6 @@ pub fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []co |
| 1223 | } | 1237 | } |
| 1224 | 1238 | ||
| 1225 | test trim { | 1239 | test trim { |
| 1226 | try testing.expectEqualSlices(u8, "foo\n ", trimLeft(u8, " foo\n ", " \n")); | ||
| 1227 | try testing.expectEqualSlices(u8, " foo", trimRight(u8, " foo\n ", " \n")); | ||
| 1228 | try testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n")); | 1240 | try testing.expectEqualSlices(u8, "foo", trim(u8, " foo\n ", " \n")); |
| 1229 | try testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n")); | 1241 | try testing.expectEqualSlices(u8, "foo", trim(u8, "foo", " \n")); |
| 1230 | } | 1242 | } |
lib/std/tar.zig+2-2| ... | @@ -250,8 +250,8 @@ const Header = struct { | ... | @@ -250,8 +250,8 @@ const Header = struct { |
| 250 | const raw = header.bytes[start..][0..len]; | 250 | const raw = header.bytes[start..][0..len]; |
| 251 | // Zero-filled octal number in ASCII. Each numeric field of width w | 251 | // Zero-filled octal number in ASCII. Each numeric field of width w |
| 252 | // contains w minus 1 digits, and a null | 252 | // contains w minus 1 digits, and a null |
| 253 | const ltrimmed = std.mem.trimLeft(u8, raw, "0 "); | 253 | const ltrimmed = std.mem.trimStart(u8, raw, "0 "); |
| 254 | const rtrimmed = std.mem.trimRight(u8, ltrimmed, " \x00"); | 254 | const rtrimmed = std.mem.trimEnd(u8, ltrimmed, " \x00"); |
| 255 | if (rtrimmed.len == 0) return 0; | 255 | if (rtrimmed.len == 0) return 0; |
| 256 | return std.fmt.parseInt(u64, rtrimmed, 8) catch return error.TarHeader; | 256 | return std.fmt.parseInt(u64, rtrimmed, 8) catch return error.TarHeader; |
| 257 | } | 257 | } |
lib/std/zig/LibCInstallation.zig+1-1| ... | @@ -317,7 +317,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, args: FindNativeOptions) F | ... | @@ -317,7 +317,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, args: FindNativeOptions) F |
| 317 | while (path_i < search_paths.items.len) : (path_i += 1) { | 317 | while (path_i < search_paths.items.len) : (path_i += 1) { |
| 318 | // search in reverse order | 318 | // search in reverse order |
| 319 | const search_path_untrimmed = search_paths.items[search_paths.items.len - path_i - 1]; | 319 | const search_path_untrimmed = search_paths.items[search_paths.items.len - path_i - 1]; |
| 320 | const search_path = std.mem.trimLeft(u8, search_path_untrimmed, " "); | 320 | const search_path = std.mem.trimStart(u8, search_path_untrimmed, " "); |
| 321 | var search_dir = fs.cwd().openDir(search_path, .{}) catch |err| switch (err) { | 321 | var search_dir = fs.cwd().openDir(search_path, .{}) catch |err| switch (err) { |
| 322 | error.FileNotFound, | 322 | error.FileNotFound, |
| 323 | error.NotDir, | 323 | error.NotDir, |
lib/std/zig/Parse.zig+1-1| ... | @@ -1849,7 +1849,7 @@ fn parseTypeExpr(p: *Parse) Error!?Node.Index { | ... | @@ -1849,7 +1849,7 @@ fn parseTypeExpr(p: *Parse) Error!?Node.Index { |
| 1849 | var sentinel: ?Node.Index = null; | 1849 | var sentinel: ?Node.Index = null; |
| 1850 | if (p.eatToken(.identifier)) |ident| { | 1850 | if (p.eatToken(.identifier)) |ident| { |
| 1851 | const ident_slice = p.source[p.tokenStart(ident)..p.tokenStart(ident + 1)]; | 1851 | const ident_slice = p.source[p.tokenStart(ident)..p.tokenStart(ident + 1)]; |
| 1852 | if (!std.mem.eql(u8, std.mem.trimRight(u8, ident_slice, &std.ascii.whitespace), "c")) { | 1852 | if (!std.mem.eql(u8, std.mem.trimEnd(u8, ident_slice, &std.ascii.whitespace), "c")) { |
| 1853 | p.tok_i -= 1; | 1853 | p.tok_i -= 1; |
| 1854 | } | 1854 | } |
| 1855 | } else if (p.eatToken(.colon)) |_| { | 1855 | } else if (p.eatToken(.colon)) |_| { |
lib/std/zig/render.zig+3-3| ... | @@ -2955,7 +2955,7 @@ fn renderComments(r: *Render, start: usize, end: usize) Error!bool { | ... | @@ -2955,7 +2955,7 @@ fn renderComments(r: *Render, start: usize, end: usize) Error!bool { |
| 2955 | const newline = if (newline_index) |i| comment_start + i else null; | 2955 | const newline = if (newline_index) |i| comment_start + i else null; |
| 2956 | 2956 | ||
| 2957 | const untrimmed_comment = tree.source[comment_start .. newline orelse tree.source.len]; | 2957 | const untrimmed_comment = tree.source[comment_start .. newline orelse tree.source.len]; |
| 2958 | const trimmed_comment = mem.trimRight(u8, untrimmed_comment, &std.ascii.whitespace); | 2958 | const trimmed_comment = mem.trimEnd(u8, untrimmed_comment, &std.ascii.whitespace); |
| 2959 | 2959 | ||
| 2960 | // Don't leave any whitespace at the start of the file | 2960 | // Don't leave any whitespace at the start of the file |
| 2961 | if (index != 0) { | 2961 | if (index != 0) { |
| ... | @@ -2976,7 +2976,7 @@ fn renderComments(r: *Render, start: usize, end: usize) Error!bool { | ... | @@ -2976,7 +2976,7 @@ fn renderComments(r: *Render, start: usize, end: usize) Error!bool { |
| 2976 | 2976 | ||
| 2977 | index = 1 + (newline orelse end - 1); | 2977 | index = 1 + (newline orelse end - 1); |
| 2978 | 2978 | ||
| 2979 | const comment_content = mem.trimLeft(u8, trimmed_comment["//".len..], &std.ascii.whitespace); | 2979 | const comment_content = mem.trimStart(u8, trimmed_comment["//".len..], &std.ascii.whitespace); |
| 2980 | if (ais.disabled_offset != null and mem.eql(u8, comment_content, "zig fmt: on")) { | 2980 | if (ais.disabled_offset != null and mem.eql(u8, comment_content, "zig fmt: on")) { |
| 2981 | // Write the source for which formatting was disabled directly | 2981 | // Write the source for which formatting was disabled directly |
| 2982 | // to the underlying writer, fixing up invalid whitespace. | 2982 | // to the underlying writer, fixing up invalid whitespace. |
| ... | @@ -3103,7 +3103,7 @@ fn tokenSliceForRender(tree: Ast, token_index: Ast.TokenIndex) []const u8 { | ... | @@ -3103,7 +3103,7 @@ fn tokenSliceForRender(tree: Ast, token_index: Ast.TokenIndex) []const u8 { |
| 3103 | var ret = tree.tokenSlice(token_index); | 3103 | var ret = tree.tokenSlice(token_index); |
| 3104 | switch (tree.tokenTag(token_index)) { | 3104 | switch (tree.tokenTag(token_index)) { |
| 3105 | .container_doc_comment, .doc_comment => { | 3105 | .container_doc_comment, .doc_comment => { |
| 3106 | ret = mem.trimRight(u8, ret, &std.ascii.whitespace); | 3106 | ret = mem.trimEnd(u8, ret, &std.ascii.whitespace); |
| 3107 | }, | 3107 | }, |
| 3108 | else => {}, | 3108 | else => {}, |
| 3109 | } | 3109 | } |
lib/std/zig/system.zig+2-2| ... | @@ -1182,13 +1182,13 @@ fn detectAbiAndDynamicLinker( | ... | @@ -1182,13 +1182,13 @@ fn detectAbiAndDynamicLinker( |
| 1182 | // We detected shebang, now parse entire line. | 1182 | // We detected shebang, now parse entire line. |
| 1183 | 1183 | ||
| 1184 | // Trim leading "#!", spaces and tabs. | 1184 | // Trim leading "#!", spaces and tabs. |
| 1185 | const trimmed_line = mem.trimLeft(u8, content[2..], &.{ ' ', '\t' }); | 1185 | const trimmed_line = mem.trimStart(u8, content[2..], &.{ ' ', '\t' }); |
| 1186 | 1186 | ||
| 1187 | // This line can have: | 1187 | // This line can have: |
| 1188 | // * Interpreter path only, | 1188 | // * Interpreter path only, |
| 1189 | // * Interpreter path and arguments, all separated by space, tab or NUL character. | 1189 | // * Interpreter path and arguments, all separated by space, tab or NUL character. |
| 1190 | // And optionally newline at the end. | 1190 | // And optionally newline at the end. |
| 1191 | const path_maybe_args = mem.trimRight(u8, trimmed_line, "\n"); | 1191 | const path_maybe_args = mem.trimEnd(u8, trimmed_line, "\n"); |
| 1192 | 1192 | ||
| 1193 | // Separate path and args. | 1193 | // Separate path and args. |
| 1194 | const path_end = mem.indexOfAny(u8, path_maybe_args, &.{ ' ', '\t', 0 }) orelse path_maybe_args.len; | 1194 | const path_end = mem.indexOfAny(u8, path_maybe_args, &.{ ' ', '\t', 0 }) orelse path_maybe_args.len; |
lib/std/zig/system/darwin.zig+1-1| ... | @@ -59,7 +59,7 @@ pub fn getSdk(allocator: Allocator, target: Target) ?[]const u8 { | ... | @@ -59,7 +59,7 @@ pub fn getSdk(allocator: Allocator, target: Target) ?[]const u8 { |
| 59 | .Exited => |code| if (code != 0) return null, | 59 | .Exited => |code| if (code != 0) return null, |
| 60 | else => return null, | 60 | else => return null, |
| 61 | } | 61 | } |
| 62 | return allocator.dupe(u8, mem.trimRight(u8, result.stdout, "\r\n")) catch null; | 62 | return allocator.dupe(u8, mem.trimEnd(u8, result.stdout, "\r\n")) catch null; |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | test { | 65 | test { |
lib/std/zig/system/linux.zig+2-2| ... | @@ -362,8 +362,8 @@ fn CpuinfoParser(comptime impl: anytype) type { | ... | @@ -362,8 +362,8 @@ fn CpuinfoParser(comptime impl: anytype) type { |
| 362 | while (true) { | 362 | while (true) { |
| 363 | const line = (try reader.readUntilDelimiterOrEof(&line_buf, '\n')) orelse break; | 363 | const line = (try reader.readUntilDelimiterOrEof(&line_buf, '\n')) orelse break; |
| 364 | const colon_pos = mem.indexOfScalar(u8, line, ':') orelse continue; | 364 | const colon_pos = mem.indexOfScalar(u8, line, ':') orelse continue; |
| 365 | const key = mem.trimRight(u8, line[0..colon_pos], " \t"); | 365 | const key = mem.trimEnd(u8, line[0..colon_pos], " \t"); |
| 366 | const value = mem.trimLeft(u8, line[colon_pos + 1 ..], " \t"); | 366 | const value = mem.trimStart(u8, line[colon_pos + 1 ..], " \t"); |
| 367 | 367 | ||
| 368 | if (!try obj.line_hook(key, value)) | 368 | if (!try obj.line_hook(key, value)) |
| 369 | break; | 369 | break; |
src/link.zig+1-1| ... | @@ -192,7 +192,7 @@ pub const Diags = struct { | ... | @@ -192,7 +192,7 @@ pub const Diags = struct { |
| 192 | current_err.?.* = .{ .msg = duped_msg }; | 192 | current_err.?.* = .{ .msg = duped_msg }; |
| 193 | } else if (current_err != null) { | 193 | } else if (current_err != null) { |
| 194 | const context_prefix = ">>> "; | 194 | const context_prefix = ">>> "; |
| 195 | var trimmed = mem.trimRight(u8, line, &std.ascii.whitespace); | 195 | var trimmed = mem.trimEnd(u8, line, &std.ascii.whitespace); |
| 196 | if (mem.startsWith(u8, trimmed, context_prefix)) { | 196 | if (mem.startsWith(u8, trimmed, context_prefix)) { |
| 197 | trimmed = trimmed[context_prefix.len..]; | 197 | trimmed = trimmed[context_prefix.len..]; |
| 198 | } | 198 | } |
src/link/MachO/Archive.zig+3-3| ... | @@ -159,12 +159,12 @@ pub const ar_hdr = extern struct { | ... | @@ -159,12 +159,12 @@ pub const ar_hdr = extern struct { |
| 159 | ar_fmag: [2]u8, | 159 | ar_fmag: [2]u8, |
| 160 | 160 | ||
| 161 | fn date(self: ar_hdr) !u64 { | 161 | fn date(self: ar_hdr) !u64 { |
| 162 | const value = mem.trimRight(u8, &self.ar_date, &[_]u8{@as(u8, 0x20)}); | 162 | const value = mem.trimEnd(u8, &self.ar_date, &[_]u8{@as(u8, 0x20)}); |
| 163 | return std.fmt.parseInt(u64, value, 10); | 163 | return std.fmt.parseInt(u64, value, 10); |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | fn size(self: ar_hdr) !u32 { | 166 | fn size(self: ar_hdr) !u32 { |
| 167 | const value = mem.trimRight(u8, &self.ar_size, &[_]u8{@as(u8, 0x20)}); | 167 | const value = mem.trimEnd(u8, &self.ar_size, &[_]u8{@as(u8, 0x20)}); |
| 168 | return std.fmt.parseInt(u32, value, 10); | 168 | return std.fmt.parseInt(u32, value, 10); |
| 169 | } | 169 | } |
| 170 | 170 | ||
| ... | @@ -178,7 +178,7 @@ pub const ar_hdr = extern struct { | ... | @@ -178,7 +178,7 @@ pub const ar_hdr = extern struct { |
| 178 | fn nameLength(self: ar_hdr) !?u32 { | 178 | fn nameLength(self: ar_hdr) !?u32 { |
| 179 | const value = &self.ar_name; | 179 | const value = &self.ar_name; |
| 180 | if (!mem.startsWith(u8, value, "#1/")) return null; | 180 | if (!mem.startsWith(u8, value, "#1/")) return null; |
| 181 | const trimmed = mem.trimRight(u8, self.ar_name["#1/".len..], &[_]u8{0x20}); | 181 | const trimmed = mem.trimEnd(u8, self.ar_name["#1/".len..], &[_]u8{0x20}); |
| 182 | return try std.fmt.parseInt(u32, trimmed, 10); | 182 | return try std.fmt.parseInt(u32, trimmed, 10); |
| 183 | } | 183 | } |
| 184 | }; | 184 | }; |
src/link/Wasm/Archive.zig+2-2| ... | @@ -64,7 +64,7 @@ const Header = extern struct { | ... | @@ -64,7 +64,7 @@ const Header = extern struct { |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | fn getValue(raw: []const u8) []const u8 { | 66 | fn getValue(raw: []const u8) []const u8 { |
| 67 | return mem.trimRight(u8, raw, &[_]u8{@as(u8, 0x20)}); | 67 | return mem.trimEnd(u8, raw, &[_]u8{@as(u8, 0x20)}); |
| 68 | } | 68 | } |
| 69 | }; | 69 | }; |
| 70 | 70 | ||
| ... | @@ -162,7 +162,7 @@ pub fn parseObject( | ... | @@ -162,7 +162,7 @@ pub fn parseObject( |
| 162 | .index => |index| n: { | 162 | .index => |index| n: { |
| 163 | const long_file_names = file_contents[archive.long_file_names.off..][0..archive.long_file_names.len]; | 163 | const long_file_names = file_contents[archive.long_file_names.off..][0..archive.long_file_names.len]; |
| 164 | const name = mem.sliceTo(long_file_names[index..], 0x0a); | 164 | const name = mem.sliceTo(long_file_names[index..], 0x0a); |
| 165 | break :n mem.trimRight(u8, name, "/"); | 165 | break :n mem.trimEnd(u8, name, "/"); |
| 166 | }, | 166 | }, |
| 167 | }; | 167 | }; |
| 168 | 168 |
test/src/Cases.zig+1-1| ... | @@ -856,7 +856,7 @@ const TestManifest = struct { | ... | @@ -856,7 +856,7 @@ const TestManifest = struct { |
| 856 | 856 | ||
| 857 | fn next(self: *TrailingIterator) ?[]const u8 { | 857 | fn next(self: *TrailingIterator) ?[]const u8 { |
| 858 | const next_inner = self.inner.next() orelse return null; | 858 | const next_inner = self.inner.next() orelse return null; |
| 859 | return if (next_inner.len == 2) "" else std.mem.trimRight(u8, next_inner[3..], " \t"); | 859 | return if (next_inner.len == 2) "" else std.mem.trimEnd(u8, next_inner[3..], " \t"); |
| 860 | } | 860 | } |
| 861 | }; | 861 | }; |
| 862 | 862 |
test/standalone/simple/guess_number/main.zig+1-1| ... | @@ -20,7 +20,7 @@ pub fn main() !void { | ... | @@ -20,7 +20,7 @@ pub fn main() !void { |
| 20 | try stdout.print("Input too long.\n", .{}); | 20 | try stdout.print("Input too long.\n", .{}); |
| 21 | continue; | 21 | continue; |
| 22 | } | 22 | } |
| 23 | const line = std.mem.trimRight(u8, line_buf[0..amt], "\r\n"); | 23 | const line = std.mem.trimEnd(u8, line_buf[0..amt], "\r\n"); |
| 24 | 24 | ||
| 25 | const guess = fmt.parseUnsigned(u8, line, 10) catch { | 25 | const guess = fmt.parseUnsigned(u8, line, 10) catch { |
| 26 | try stdout.print("Invalid number.\n", .{}); | 26 | try stdout.print("Invalid number.\n", .{}); |
tools/docgen.zig+3-3| ... | @@ -943,10 +943,10 @@ fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void { | ... | @@ -943,10 +943,10 @@ fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void { |
| 943 | var cmd_cont: bool = false; | 943 | var cmd_cont: bool = false; |
| 944 | var iter = std.mem.splitScalar(u8, trimmed_shell_content, '\n'); | 944 | var iter = std.mem.splitScalar(u8, trimmed_shell_content, '\n'); |
| 945 | while (iter.next()) |orig_line| { | 945 | while (iter.next()) |orig_line| { |
| 946 | const line = mem.trimRight(u8, orig_line, " \r"); | 946 | const line = mem.trimEnd(u8, orig_line, " \r"); |
| 947 | if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] != '\\') { | 947 | if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] != '\\') { |
| 948 | try out.writeAll("$ <kbd>"); | 948 | try out.writeAll("$ <kbd>"); |
| 949 | const s = std.mem.trimLeft(u8, line[1..], " "); | 949 | const s = std.mem.trimStart(u8, line[1..], " "); |
| 950 | if (escape) { | 950 | if (escape) { |
| 951 | try writeEscaped(out, s); | 951 | try writeEscaped(out, s); |
| 952 | } else { | 952 | } else { |
| ... | @@ -955,7 +955,7 @@ fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void { | ... | @@ -955,7 +955,7 @@ fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void { |
| 955 | try out.writeAll("</kbd>" ++ "\n"); | 955 | try out.writeAll("</kbd>" ++ "\n"); |
| 956 | } else if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] == '\\') { | 956 | } else if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] == '\\') { |
| 957 | try out.writeAll("$ <kbd>"); | 957 | try out.writeAll("$ <kbd>"); |
| 958 | const s = std.mem.trimLeft(u8, line[1..], " "); | 958 | const s = std.mem.trimStart(u8, line[1..], " "); |
| 959 | if (escape) { | 959 | if (escape) { |
| 960 | try writeEscaped(out, s); | 960 | try writeEscaped(out, s); |
| 961 | } else { | 961 | } else { |
tools/doctest.zig+3-3| ... | @@ -1109,10 +1109,10 @@ fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void { | ... | @@ -1109,10 +1109,10 @@ fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void { |
| 1109 | var cmd_cont: bool = false; | 1109 | var cmd_cont: bool = false; |
| 1110 | var iter = std.mem.splitScalar(u8, trimmed_shell_content, '\n'); | 1110 | var iter = std.mem.splitScalar(u8, trimmed_shell_content, '\n'); |
| 1111 | while (iter.next()) |orig_line| { | 1111 | while (iter.next()) |orig_line| { |
| 1112 | const line = mem.trimRight(u8, orig_line, " \r"); | 1112 | const line = mem.trimEnd(u8, orig_line, " \r"); |
| 1113 | if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] != '\\') { | 1113 | if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] != '\\') { |
| 1114 | try out.writeAll("$ <kbd>"); | 1114 | try out.writeAll("$ <kbd>"); |
| 1115 | const s = std.mem.trimLeft(u8, line[1..], " "); | 1115 | const s = std.mem.trimStart(u8, line[1..], " "); |
| 1116 | if (escape) { | 1116 | if (escape) { |
| 1117 | try writeEscaped(out, s); | 1117 | try writeEscaped(out, s); |
| 1118 | } else { | 1118 | } else { |
| ... | @@ -1121,7 +1121,7 @@ fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void { | ... | @@ -1121,7 +1121,7 @@ fn printShell(out: anytype, shell_content: []const u8, escape: bool) !void { |
| 1121 | try out.writeAll("</kbd>" ++ "\n"); | 1121 | try out.writeAll("</kbd>" ++ "\n"); |
| 1122 | } else if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] == '\\') { | 1122 | } else if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] == '\\') { |
| 1123 | try out.writeAll("$ <kbd>"); | 1123 | try out.writeAll("$ <kbd>"); |
| 1124 | const s = std.mem.trimLeft(u8, line[1..], " "); | 1124 | const s = std.mem.trimStart(u8, line[1..], " "); |
| 1125 | if (escape) { | 1125 | if (escape) { |
| 1126 | try writeEscaped(out, s); | 1126 | try writeEscaped(out, s); |
| 1127 | } else { | 1127 | } else { |
tools/incr-check.zig+4-4| ... | @@ -670,7 +670,7 @@ const Case = struct { | ... | @@ -670,7 +670,7 @@ const Case = struct { |
| 670 | if (std.mem.startsWith(u8, line, "#")) { | 670 | if (std.mem.startsWith(u8, line, "#")) { |
| 671 | var line_it = std.mem.splitScalar(u8, line, '='); | 671 | var line_it = std.mem.splitScalar(u8, line, '='); |
| 672 | const key = line_it.first()[1..]; | 672 | const key = line_it.first()[1..]; |
| 673 | const val = std.mem.trimRight(u8, line_it.rest(), "\r"); // windows moment | 673 | const val = std.mem.trimEnd(u8, line_it.rest(), "\r"); // windows moment |
| 674 | if (val.len == 0) { | 674 | if (val.len == 0) { |
| 675 | fatal("line {d}: missing value", .{line_n}); | 675 | fatal("line {d}: missing value", .{line_n}); |
| 676 | } else if (std.mem.eql(u8, key, "target")) { | 676 | } else if (std.mem.eql(u8, key, "target")) { |
| ... | @@ -720,7 +720,7 @@ const Case = struct { | ... | @@ -720,7 +720,7 @@ const Case = struct { |
| 720 | 720 | ||
| 721 | while (true) { | 721 | while (true) { |
| 722 | const next_line_raw = it.peek() orelse fatal("line {d}: unexpected EOF", .{line_n}); | 722 | const next_line_raw = it.peek() orelse fatal("line {d}: unexpected EOF", .{line_n}); |
| 723 | const next_line = std.mem.trimRight(u8, next_line_raw, "\r"); | 723 | const next_line = std.mem.trimEnd(u8, next_line_raw, "\r"); |
| 724 | if (std.mem.startsWith(u8, next_line, "#")) break; | 724 | if (std.mem.startsWith(u8, next_line, "#")) break; |
| 725 | 725 | ||
| 726 | _ = it.next(); | 726 | _ = it.next(); |
| ... | @@ -759,7 +759,7 @@ const Case = struct { | ... | @@ -759,7 +759,7 @@ const Case = struct { |
| 759 | if (!std.mem.startsWith(u8, next_line, "#")) break; | 759 | if (!std.mem.startsWith(u8, next_line, "#")) break; |
| 760 | var new_line_it = std.mem.splitScalar(u8, next_line, '='); | 760 | var new_line_it = std.mem.splitScalar(u8, next_line, '='); |
| 761 | const new_key = new_line_it.first()[1..]; | 761 | const new_key = new_line_it.first()[1..]; |
| 762 | const new_val = std.mem.trimRight(u8, new_line_it.rest(), "\r"); | 762 | const new_val = std.mem.trimEnd(u8, new_line_it.rest(), "\r"); |
| 763 | if (new_val.len == 0) break; | 763 | if (new_val.len == 0) break; |
| 764 | if (!std.mem.eql(u8, new_key, "expect_error")) break; | 764 | if (!std.mem.eql(u8, new_key, "expect_error")) break; |
| 765 | 765 | ||
| ... | @@ -774,7 +774,7 @@ const Case = struct { | ... | @@ -774,7 +774,7 @@ const Case = struct { |
| 774 | if (!std.mem.startsWith(u8, next_line, "#")) break; | 774 | if (!std.mem.startsWith(u8, next_line, "#")) break; |
| 775 | var new_line_it = std.mem.splitScalar(u8, next_line, '='); | 775 | var new_line_it = std.mem.splitScalar(u8, next_line, '='); |
| 776 | const new_key = new_line_it.first()[1..]; | 776 | const new_key = new_line_it.first()[1..]; |
| 777 | const new_val = std.mem.trimRight(u8, new_line_it.rest(), "\r"); | 777 | const new_val = std.mem.trimEnd(u8, new_line_it.rest(), "\r"); |
| 778 | if (new_val.len == 0) break; | 778 | if (new_val.len == 0) break; |
| 779 | if (!std.mem.eql(u8, new_key, "expect_compile_log")) break; | 779 | if (!std.mem.eql(u8, new_key, "expect_compile_log")) break; |
| 780 | 780 |