| ... | ... | @@ -137,6 +137,16 @@ pub fn isPrint(c: u8) bool { |
| 137 | 137 | return isAscii(c) and !isControl(c); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | /// Returns whether the character has some graphical representation, |
| 141 | pub fn isGraphical(c: u8) bool { |
| 142 | return isPrint(c) and c != ' '; |
| 143 | } |
| 144 | |
| 145 | /// Returns whether the character is a punctuation character. |
| 146 | pub fn isPunctuation(c: u8) bool { |
| 147 | return isGraphical(c) and !isAlphanumeric(c); |
| 148 | } |
| 149 | |
| 140 | 150 | /// Returns whether this character is included in `whitespace`. |
| 141 | 151 | pub fn isWhitespace(c: u8) bool { |
| 142 | 152 | return switch (c) { |
| ... | ... | @@ -264,6 +274,17 @@ test "ASCII character classes" { |
| 264 | 274 | try testing.expect(!isPrint(control_code.esc)); |
| 265 | 275 | try testing.expect(!isPrint(0x80)); |
| 266 | 276 | 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')); |
| 267 | 288 | } |
| 268 | 289 | |
| 269 | 290 | /// Writes a lower case copy of `ascii_string` to `output`. |