use crate::syntax::CodePoint;
#[cfg(test)]
mod tests;
const DOT: CodePoint = '.' as u32;
pub fn split_segments<F>(cps: &[CodePoint], is_sep: F) -> Vec<&[CodePoint]>
where
F: Fn(CodePoint) -> bool,
{
let mut out = Vec::new();
let mut start: Option<usize> = None;
for (i, &cp) in cps.iter().enumerate() {
if is_sep(cp) {
if let Some(s) = start.take() {
out.push(&cps[s..i]);
}
} else if start.is_none() {
start = Some(i);
}
}
if let Some(s) = start {
out.push(&cps[s..]);
}
out
}
pub fn is_dot(seg: &[CodePoint]) -> bool {
seg == [DOT]
}
pub fn is_dotdot(seg: &[CodePoint]) -> bool {
seg == [DOT, DOT]
}