authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-10-31 22:58:08+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-01 15:48:50-05:00
logd530e7f9c7e19b2c9d9117c3120cd75855f4023b
tree9c3b3cf94025ce4d01dda00d319ddc23233e5b6e
parent6418284680920a19fd34ec1a10d79113a5bec75d

Make std.fmt.bufPrintIntToSlice public

Deprecate `std.fmt.trim` and `std.fmt.isWhiteSpace` in favour of `std.mem` alternatives. Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>

1 files changed, 3 insertions(+), 33 deletions(-)

lib/std/fmt.zig+3-33
...@@ -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}
12471247
1248fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) []u8 {1248pub 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}
12511251
...@@ -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}
16991699
1700pub fn trim(buf: []const u8) []const u8 {1700pub const trim = @compileError("deprecated; use std.mem.trim instead");
1701 var start: usize = 0;1701pub 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
1718test "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
1726pub fn isWhiteSpace(byte: u8) bool {
1727 return switch (byte) {
1728 ' ', '\t', '\n', '\r' => true,
1729 else => false,
1730 };
1731}
17321702
1733pub fn hexToBytes(out: []u8, input: []const u8) !void {1703pub fn hexToBytes(out: []u8, input: []const u8) !void {
1734 if (out.len * 2 < input.len)1704 if (out.len * 2 < input.len)