lib/std/char.rad 855 B raw
1
//! ASCII character classification helpers shared across the standard library.
2
3
@test mod tests;
4
5
/// Return `true` when `ch` is an ASCII digit.
6
export fn isDigit(ch: u8) -> bool {
7
    return ch >= '0' and ch <= '9';
8
}
9
10
/// Return `true` when `ch` is an ASCII hexadecimal digit.
11
export fn isHexDigit(ch: u8) -> bool {
12
    return (ch >= '0' and ch <= '9')
13
        or (ch >= 'a' and ch <= 'f')
14
        or (ch >= 'A' and ch <= 'F');
15
}
16
17
/// Return `true` when `ch` is a binary digit.
18
export fn isBinDigit(ch: u8) -> bool {
19
    return ch == '0' or ch == '1';
20
}
21
22
/// Return `true` when `ch` is an ASCII alphabetic character.
23
export fn isAlpha(ch: u8) -> bool {
24
    return (ch >= 'a' and ch <= 'z')
25
        or (ch >= 'A' and ch <= 'Z');
26
}
27
28
/// Return `true` when `ch` is printable ASCII.
29
export fn isPrint(ch: u8) -> bool {
30
    return ch >= ' ' and ch <= '~';
31
}