authorgravatar for me@gasinfinity.devGasInfinity <me@gasinfinity.dev> 2026-01-09 02:27:31+01:00
committergravatar for me@gasinfinity.devGasInfinity <me@gasinfinity.dev> 2026-01-09 02:27:31+01:00
loge558e64ca0fc779ac4de0d25e8662f3bd1c910da
tree6f47e494eea90901774c8b298c920ddbffe15cb2
parent7f6eab270493592d4c3e5788dfcb34fdbca80539
signaturebadge-check Signed by SSH key SHA256:p3IHbr0lyK2ekfDC1Zi7dOEV/9T6lGghNawhl5sBnM4

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


1 files changed, 21 insertions(+), 0 deletions(-)

lib/std/ascii.zig+21
......@@ -137,6 +137,16 @@ pub fn isPrint(c: u8) bool {
137137 return isAscii(c) and !isControl(c);
138138}
139139
140/// Returns whether the character has some graphical representation,
141pub fn isGraphical(c: u8) bool {
142 return isPrint(c) and c != ' ';
143}
144
145/// Returns whether the character is a punctuation character.
146pub fn isPunctuation(c: u8) bool {
147 return isGraphical(c) and !isAlphanumeric(c);
148}
149
140150/// Returns whether this character is included in `whitespace`.
141151pub fn isWhitespace(c: u8) bool {
142152 return switch (c) {
......@@ -264,6 +274,17 @@ test "ASCII character classes" {
264274 try testing.expect(!isPrint(control_code.esc));
265275 try testing.expect(!isPrint(0x80));
266276 try testing.expect(!isPrint(0xff));
277
278 try testing.expect(isGraphical('@'));
279 try testing.expect(isGraphical('!'));
280 try testing.expect(!isGraphical(' '));
281
282 try testing.expect(isPunctuation('@'));
283 try testing.expect(isPunctuation('!'));
284 try testing.expect(isPunctuation(';'));
285 try testing.expect(isPunctuation(','));
286 try testing.expect(!isPunctuation('A'));
287 try testing.expect(!isPunctuation('8'));
267288}
268289
269290/// Writes a lower case copy of `ascii_string` to `output`.