mirror of
https://github.com/ziglang/zig.git
synced 2025-12-15 02:33:07 +00:00
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().
This commit is contained in:
parent
909aae8153
commit
50ba018223
@ -230,6 +230,20 @@ pub fn isSpace(c: u8) bool {
|
|||||||
return inTable(c, tIndex.Space);
|
return inTable(c, tIndex.Space);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// All the values for which isSpace() returns true. This may be used with
|
||||||
|
/// e.g. std.mem.trim() to trim whiteSpace.
|
||||||
|
pub const spaces = [_]u8{ ' ', '\t', '\n', '\r', control_code.VT, control_code.FF };
|
||||||
|
|
||||||
|
test "spaces" {
|
||||||
|
const testing = std.testing;
|
||||||
|
for (spaces) |space| testing.expect(isSpace(space));
|
||||||
|
|
||||||
|
var i: u8 = 0;
|
||||||
|
while (isASCII(i)) : (i += 1) {
|
||||||
|
if (isSpace(i)) testing.expect(std.mem.indexOfScalar(u8, &spaces, i) != null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn isUpper(c: u8) bool {
|
pub fn isUpper(c: u8) bool {
|
||||||
return inTable(c, tIndex.Upper);
|
return inTable(c, tIndex.Upper);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1703,8 +1703,8 @@ fn testFmt(expected: []const u8, comptime template: []const u8, args: anytype) !
|
|||||||
return error.TestFailed;
|
return error.TestFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const trim = @compileError("deprecated; use std.mem.trim instead");
|
pub const trim = @compileError("deprecated; use std.mem.trim with std.ascii.spaces instead");
|
||||||
pub const isWhiteSpace = @compileError("deprecated; use std.mem.isWhiteSpace instead");
|
pub const isWhiteSpace = @compileError("deprecated; use std.ascii.isSpace instead");
|
||||||
|
|
||||||
pub fn hexToBytes(out: []u8, input: []const u8) !void {
|
pub fn hexToBytes(out: []u8, input: []const u8) !void {
|
||||||
if (out.len * 2 < input.len)
|
if (out.len * 2 < input.len)
|
||||||
@ -1890,4 +1890,3 @@ test "null" {
|
|||||||
const inst = null;
|
const inst = null;
|
||||||
try testFmt("null", "{}", .{inst});
|
try testFmt("null", "{}", .{inst});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user