From d530e7f9c7e19b2c9d9117c3120cd75855f4023b Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Sat, 31 Oct 2020 22:58:08 +0100 Subject: [PATCH] Make std.fmt.bufPrintIntToSlice public Deprecate `std.fmt.trim` and `std.fmt.isWhiteSpace` in favour of `std.mem` alternatives. Signed-off-by: Jakub Konka --- lib/std/fmt.zig | 36 +++--------------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index c3f0209e16..4ce15905f1 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -1245,7 +1245,7 @@ test "bufPrintInt" { std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 })); } -fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) []u8 { +pub fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) []u8 { return buf[0..formatIntBuf(buf, value, base, uppercase, options)]; } @@ -1697,38 +1697,8 @@ fn testFmt(expected: []const u8, comptime template: []const u8, args: anytype) ! return error.TestFailed; } -pub fn trim(buf: []const u8) []const u8 { - var start: usize = 0; - while (start < buf.len and isWhiteSpace(buf[start])) : (start += 1) {} - - var end: usize = buf.len; - while (true) { - if (end > start) { - const new_end = end - 1; - if (isWhiteSpace(buf[new_end])) { - end = new_end; - continue; - } - } - break; - } - return buf[start..end]; -} - -test "trim" { - std.testing.expect(mem.eql(u8, "abc", trim("\n abc \t"))); - std.testing.expect(mem.eql(u8, "", trim(" "))); - std.testing.expect(mem.eql(u8, "", trim(""))); - std.testing.expect(mem.eql(u8, "abc", trim(" abc"))); - std.testing.expect(mem.eql(u8, "abc", trim("abc "))); -} - -pub fn isWhiteSpace(byte: u8) bool { - return switch (byte) { - ' ', '\t', '\n', '\r' => true, - else => false, - }; -} +pub const trim = @compileError("deprecated; use std.mem.trim instead"); +pub const isWhiteSpace = @compileError("deprecated; use std.mem.isWhiteSpace instead"); pub fn hexToBytes(out: []u8, input: []const u8) !void { if (out.len * 2 < input.len)