authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2020-11-02 19:06:31+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-02 13:20:58-05:00
log50ba0182235be67f79a1d088f279d69efd06b5d2
tree6a200b2c4850c5964d3a3e8c27c1a9b8f85673b1
parent909aae8153e7ac71197bc9f864e4ceb2793317f2

std/ascii: add spaces array

This may be combined with std.mem.trim to form a proper replacement for the now deprecated std.fmt.trimWhitespace().

2 files changed, 16 insertions(+), 3 deletions(-)

lib/std/ascii.zig+14
......@@ -230,6 +230,20 @@ pub fn isSpace(c: u8) bool {
230230 return inTable(c, tIndex.Space);
231231}
232232
233/// All the values for which isSpace() returns true. This may be used with
234/// e.g. std.mem.trim() to trim whiteSpace.
235pub const spaces = [_]u8{ ' ', '\t', '\n', '\r', control_code.VT, control_code.FF };
236
237test "spaces" {
238 const testing = std.testing;
239 for (spaces) |space| testing.expect(isSpace(space));
240
241 var i: u8 = 0;
242 while (isASCII(i)) : (i += 1) {
243 if (isSpace(i)) testing.expect(std.mem.indexOfScalar(u8, &spaces, i) != null);
244 }
245}
246
233247pub fn isUpper(c: u8) bool {
234248 return inTable(c, tIndex.Upper);
235249}
lib/std/fmt.zig+2-3
......@@ -1703,8 +1703,8 @@ fn testFmt(expected: []const u8, comptime template: []const u8, args: anytype) !
17031703 return error.TestFailed;
17041704}
17051705
1706pub const trim = @compileError("deprecated; use std.mem.trim instead");
1707pub const isWhiteSpace = @compileError("deprecated; use std.mem.isWhiteSpace instead");
1706pub const trim = @compileError("deprecated; use std.mem.trim with std.ascii.spaces instead");
1707pub const isWhiteSpace = @compileError("deprecated; use std.ascii.isSpace instead");
17081708
17091709pub fn hexToBytes(out: []u8, input: []const u8) !void {
17101710 if (out.len * 2 < input.len)
......@@ -1890,4 +1890,3 @@ test "null" {
18901890 const inst = null;
18911891 try testFmt("null", "{}", .{inst});
18921892}
1893