const ALPHABIT: u32 = 0;
const DIGITBIT: u32 = 1;
const PRINTBIT: u32 = 2;
const SPACEBIT: u32 = 3;
const XDIGITBIT: u32 = 4;
pub(crate) static CTYPE_TABLE: [u8; 257] = [
0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16,
0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05,
0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
#[inline]
fn test_prop(c: i32, mask: u8) -> bool {
debug_assert!(
c >= -1 && c <= 255,
"test_prop: c out of range: {}",
c
);
CTYPE_TABLE[(c + 1) as usize] & mask != 0
}
#[inline]
pub(crate) fn lislalpha(c: i32) -> bool {
test_prop(c, 1u8 << ALPHABIT)
}
#[inline]
pub(crate) fn lislalnum(c: i32) -> bool {
test_prop(c, (1u8 << ALPHABIT) | (1u8 << DIGITBIT))
}
#[inline]
pub(crate) fn lisdigit(c: i32) -> bool {
test_prop(c, 1u8 << DIGITBIT)
}
#[inline]
pub(crate) fn lisspace(c: i32) -> bool {
test_prop(c, 1u8 << SPACEBIT)
}
#[inline]
pub(crate) fn lisprint(c: i32) -> bool {
test_prop(c, 1u8 << PRINTBIT)
}
#[inline]
pub(crate) fn lisxdigit(c: i32) -> bool {
test_prop(c, 1u8 << XDIGITBIT)
}
#[inline]
pub(crate) fn ltolower(c: i32) -> i32 {
debug_assert!(
('A' as i32 <= c && c <= 'Z' as i32) || c == (c | ('A' as i32 ^ 'a' as i32)),
"ltolower: argument must be an uppercase letter or already lowercase/'.'"
);
c | ('A' as i32 ^ 'a' as i32)
}