mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 04:24:33 +01:00
feat(std.ascii): add isGraphical and isPunctuation
This commit is contained in:
parent
7f6eab2704
commit
e558e64ca0
1 changed files with 21 additions and 0 deletions
|
|
@ -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`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue