vize_l0 0.577.0

L0 - the Davinci foundation level: ids, side tables, keys, dumps, diagnostics, passes and facts
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//! Total byte and slice helpers for the petite-vue document scanner.

/// The offset past the run of bytes from `pos` that satisfy `keep`.
pub(super) fn skip_while(bytes: &[u8], pos: usize, keep: impl Fn(&u8) -> bool) -> usize {
    pos + bytes
        .get(pos..)
        .map_or(0, |tail| tail.iter().take_while(|byte| keep(byte)).count())
}

/// `text[start..end]`, or empty when the range is not a char-boundary slice.
/// Every caller's bounds come from ASCII delimiters, so the fallback is
/// never observed.
pub(super) fn slice(text: &str, start: usize, end: usize) -> &str {
    text.get(start..end).unwrap_or_default()
}