//! ASCII character classification helpers shared across the standard library.

@test mod tests;

/// Return `true` when `ch` is an ASCII digit.
export fn isDigit(ch: u8) -> bool {
    return ch >= '0' and ch <= '9';
}

/// Return `true` when `ch` is an ASCII hexadecimal digit.
export fn isHexDigit(ch: u8) -> bool {
    return (ch >= '0' and ch <= '9')
        or (ch >= 'a' and ch <= 'f')
        or (ch >= 'A' and ch <= 'F');
}

/// Return `true` when `ch` is a binary digit.
export fn isBinDigit(ch: u8) -> bool {
    return ch == '0' or ch == '1';
}

/// Return `true` when `ch` is an ASCII alphabetic character.
export fn isAlpha(ch: u8) -> bool {
    return (ch >= 'a' and ch <= 'z')
        or (ch >= 'A' and ch <= 'Z');
}

/// Return `true` when `ch` is printable ASCII.
export fn isPrint(ch: u8) -> bool {
    return ch >= ' ' and ch <= '~';
}
