use crate::dict::{Con, PREFIXES, ROOT_FIRST, SUBSCRIPTS, SUFFIXES, SUFFIXES2, SUPERSCRIPTS, Syntax};
pub(crate) fn is_standard_pair(top: Con, bottom: Con) -> bool {
SUPERSCRIPTS
.iter()
.any(|&(sup, lower, _)| sup == top && lower.contains(&bottom))
|| SUBSCRIPTS
.iter()
.any(|&(sub, upper, _)| sub == bottom && upper.contains(&top))
}
pub(crate) fn is_standard_triple(top: Con, middle: Con, bottom: Con) -> bool {
SUPERSCRIPTS
.iter()
.any(|&(sup, _, two)| sup == top && two.contains(&(middle, bottom)))
|| SUBSCRIPTS
.iter()
.any(|&(sub, _, two)| sub == bottom && two.contains(&(top, middle)))
}
pub(crate) fn is_standard_bottom(con: Con) -> bool {
SUBSCRIPTS.iter().any(|&(sub, _, _)| sub == con)
|| SUPERSCRIPTS
.iter()
.any(|&(_, lower, two)| lower.contains(&con) || two.iter().any(|&(_, l)| l == con))
}
#[inline]
pub(crate) fn is_suffix(letter: Con) -> bool {
SUFFIXES.contains(&letter)
}
#[inline]
pub(crate) fn can_suffix2(suffix2: Con, suffix: Con) -> bool {
SUFFIXES2
.iter()
.any(|&(s2, after)| s2 == suffix2 && after.contains(&suffix))
}
#[inline]
pub(crate) fn can_prefix(prefix: Con, root: &[Con]) -> bool {
let root = || {
(root.iter().enumerate())
.filter(|&(i, c)| i == 0 || *c != Con::W)
.map(|(_, c)| *c)
};
PREFIXES
.iter()
.any(|&(p, roots)| p == prefix && roots.iter().any(|r| r.iter().copied().eq(root())))
}
#[inline]
pub(crate) fn is_root_first(letters: &[Con]) -> bool {
ROOT_FIRST.iter().any(|word| word[..] == *letters)
}
pub(crate) fn unicode_escape(rest: &[u8]) -> Option<(char, usize)> {
let digits = Syntax::unicode_escape_digits(*rest.first()?)?;
let mut code = 0;
for &b in rest.get(1..=digits)? {
code = code * 16 + char::from(b).to_digit(16)?;
}
Some((char::from_u32(code)?, 1 + digits))
}