| author | |
| committer | |
| log | 50ba0182235be67f79a1d088f279d69efd06b5d2 |
| tree | 6a200b2c4850c5964d3a3e8c27c1a9b8f85673b1 |
| parent | 909aae8153e7ac71197bc9f864e4ceb2793317f2 |
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 { |
| 230 | 230 | return inTable(c, tIndex.Space); |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | /// All the values for which isSpace() returns true. This may be used with | |
| 234 | /// e.g. std.mem.trim() to trim whiteSpace. | |
| 235 | pub const spaces = [_]u8{ ' ', '\t', '\n', '\r', control_code.VT, control_code.FF }; | |
| 236 | ||
| 237 | test "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 | ||
| 233 | 247 | pub fn isUpper(c: u8) bool { |
| 234 | 248 | return inTable(c, tIndex.Upper); |
| 235 | 249 | } |
lib/std/fmt.zig+2-3| ... | ... | @@ -1703,8 +1703,8 @@ fn testFmt(expected: []const u8, comptime template: []const u8, args: anytype) ! |
| 1703 | 1703 | return error.TestFailed; |
| 1704 | 1704 | } |
| 1705 | 1705 | |
| 1706 | pub const trim = @compileError("deprecated; use std.mem.trim instead"); | |
| 1707 | pub const isWhiteSpace = @compileError("deprecated; use std.mem.isWhiteSpace instead"); | |
| 1706 | pub const trim = @compileError("deprecated; use std.mem.trim with std.ascii.spaces instead"); | |
| 1707 | pub const isWhiteSpace = @compileError("deprecated; use std.ascii.isSpace instead"); | |
| 1708 | 1708 | |
| 1709 | 1709 | pub fn hexToBytes(out: []u8, input: []const u8) !void { |
| 1710 | 1710 | if (out.len * 2 < input.len) |
| ... | ... | @@ -1890,4 +1890,3 @@ test "null" { |
| 1890 | 1890 | const inst = null; |
| 1891 | 1891 | try testFmt("null", "{}", .{inst}); |
| 1892 | 1892 | } |
| 1893 |