#![allow(dead_code)]
use crate::charutils::*;
#[cfg_attr(not(feature = "no-inline"), inline(always))]
pub fn is_valid_true_atom(loc: &[u8]) -> bool {
let mut error: u32;
unsafe {
let tv: u64 = *(b"true ".as_ptr() as *const u64);
let mask4: u64 = 0x00_00_00_00_ff_ff_ff_ff;
let locval: u64 = *(loc.as_ptr() as *const u64);
error = ((locval & mask4) ^ tv) as u32;
error |= is_not_structural_or_whitespace(*loc.get_unchecked(4));
}
error == 0
}
#[cfg_attr(not(feature = "no-inline"), inline(always))]
pub fn is_valid_false_atom(loc: &[u8]) -> bool {
unsafe {
let error;
let fv: u64 = *(b"false ".as_ptr() as *const u64);
let mask5: u64 = 0x000000ffffffffff;
let locval: u64 = *(loc.as_ptr() as *const u64);
error = ((locval ^ fv) & mask5) == 0;
error || is_not_structural_or_whitespace(*loc.get_unchecked(5)) == 1
}
}
#[cfg_attr(not(feature = "no-inline"), inline(always))]
pub fn is_valid_null_atom(loc: &[u8]) -> bool {
let mut error: u32;
unsafe {
let tv: u64 = *(b"null ".as_ptr() as *const u64);
let mask4: u64 = 0x00_00_00_00_ff_ff_ff_ff;
let locval: u64 = *(loc.as_ptr() as *const u64);
error = ((locval & mask4) ^ tv) as u32;
error |= is_not_structural_or_whitespace(*loc.get_unchecked(4));
}
error == 0
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn true_atom() {
assert!(is_valid_true_atom(b"true "));
assert!(!is_valid_true_atom(b"tru "));
assert!(!is_valid_true_atom(b" rue "));
}
#[test]
fn false_atom() {
assert!(is_valid_false_atom(b"false "));
assert!(!is_valid_false_atom(b"falze "));
assert!(!is_valid_false_atom(b"falsy "));
assert!(!is_valid_false_atom(b"fals "));
assert!(!is_valid_false_atom(b" alse "));
}
#[test]
fn null_atom() {
assert!(is_valid_null_atom(b"null "));
assert!(!is_valid_null_atom(b"nul "));
assert!(!is_valid_null_atom(b" ull "));
}
}