zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit e558e64ca0fc779ac4de0d25e8662f3bd1c910da (tree)
parent 7f6eab270493592d4c3e5788dfcb34fdbca80539
Author: GasInfinity <me@gasinfinity.dev>
Date:   Fri,  9 Jan 2026 02:27:31 +0100

feat(std.ascii): add `isGraphical` and `isPunctuation`

Diffstat:
Mlib/std/ascii.zig | 21+++++++++++++++++++++
1 file changed, 21 insertions(+), 0 deletions(-)

diff --git a/lib/std/ascii.zig b/lib/std/ascii.zig @@ -137,6 +137,16 @@ pub fn isPrint(c: u8) bool { return isAscii(c) and !isControl(c); } +/// Returns whether the character has some graphical representation, +pub fn isGraphical(c: u8) bool { + return isPrint(c) and c != ' '; +} + +/// Returns whether the character is a punctuation character. +pub fn isPunctuation(c: u8) bool { + return isGraphical(c) and !isAlphanumeric(c); +} + /// Returns whether this character is included in `whitespace`. pub fn isWhitespace(c: u8) bool { return switch (c) { @@ -264,6 +274,17 @@ test "ASCII character classes" { try testing.expect(!isPrint(control_code.esc)); try testing.expect(!isPrint(0x80)); try testing.expect(!isPrint(0xff)); + + try testing.expect(isGraphical('@')); + try testing.expect(isGraphical('!')); + try testing.expect(!isGraphical(' ')); + + try testing.expect(isPunctuation('@')); + try testing.expect(isPunctuation('!')); + try testing.expect(isPunctuation(';')); + try testing.expect(isPunctuation(',')); + try testing.expect(!isPunctuation('A')); + try testing.expect(!isPunctuation('8')); } /// Writes a lower case copy of `ascii_string` to `output`.