| ... | @@ -1245,7 +1245,7 @@ test "bufPrintInt" { | ... | @@ -1245,7 +1245,7 @@ test "bufPrintInt" { |
| 1245 | std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 })); | 1245 | std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 })); |
| 1246 | } | 1246 | } |
| 1247 | | 1247 | |
| 1248 | fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) []u8 { | 1248 | pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) []u8 { |
| 1249 | return buf[0..formatIntBuf(buf, value, base, uppercase, options)]; | 1249 | return buf[0..formatIntBuf(buf, value, base, uppercase, options)]; |
| 1250 | } | 1250 | } |
| 1251 | | 1251 | |
| ... | @@ -1697,38 +1697,8 @@ fn testFmt(expected: []const u8, comptime template: []const u8, args: anytype) ! | ... | @@ -1697,38 +1697,8 @@ fn testFmt(expected: []const u8, comptime template: []const u8, args: anytype) ! |
| 1697 | return error.TestFailed; | 1697 | return error.TestFailed; |
| 1698 | } | 1698 | } |
| 1699 | | 1699 | |
| 1700 | pub fn trim(buf: []const u8) []const u8 { | 1700 | pub const trim = @compileError("deprecated; use std.mem.trim instead"); |
| 1701 | var start: usize = 0; | 1701 | pub const isWhiteSpace = @compileError("deprecated; use std.mem.isWhiteSpace instead"); |
| 1702 | while (start < buf.len and isWhiteSpace(buf[start])) : (start += 1) {} | | |
| 1703 | | | |
| 1704 | var end: usize = buf.len; | | |
| 1705 | while (true) { | | |
| 1706 | if (end > start) { | | |
| 1707 | const new_end = end - 1; | | |
| 1708 | if (isWhiteSpace(buf[new_end])) { | | |
| 1709 | end = new_end; | | |
| 1710 | continue; | | |
| 1711 | } | | |
| 1712 | } | | |
| 1713 | break; | | |
| 1714 | } | | |
| 1715 | return buf[start..end]; | | |
| 1716 | } | | |
| 1717 | | | |
| 1718 | test "trim" { | | |
| 1719 | std.testing.expect(mem.eql(u8, "abc", trim("\n abc \t"))); | | |
| 1720 | std.testing.expect(mem.eql(u8, "", trim(" "))); | | |
| 1721 | std.testing.expect(mem.eql(u8, "", trim(""))); | | |
| 1722 | std.testing.expect(mem.eql(u8, "abc", trim(" abc"))); | | |
| 1723 | std.testing.expect(mem.eql(u8, "abc", trim("abc "))); | | |
| 1724 | } | | |
| 1725 | | | |
| 1726 | pub fn isWhiteSpace(byte: u8) bool { | | |
| 1727 | return switch (byte) { | | |
| 1728 | ' ', '\t', '\n', '\r' => true, | | |
| 1729 | else => false, | | |
| 1730 | }; | | |
| 1731 | } | | |
| 1732 | | 1702 | |
| 1733 | pub fn hexToBytes(out: []u8, input: []const u8) !void { | 1703 | pub fn hexToBytes(out: []u8, input: []const u8) !void { |
| 1734 | if (out.len * 2 < input.len) | 1704 | if (out.len * 2 < input.len) |