From e558e64ca0fc779ac4de0d25e8662f3bd1c910da Mon Sep 17 00:00:00 2001 From: GasInfinity Date: Fri, 9 Jan 2026 02:27:31 +0100 Subject: [PATCH] feat(std.ascii): add `isGraphical` and `isPunctuation` --- lib/std/ascii.zig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/std/ascii.zig b/lib/std/ascii.zig index b85ff592d8468811f77909d2d10483c351ea80ee..bd33f2cadd74cc8226994e6d1f374cf25cc3ad0d 100644 --- 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`. -- 2.54.0