Skip to main content

clean_prefix_len

Function clean_prefix_len 

Source
pub fn clean_prefix_len(haystack: &[u8], needles: &[u8]) -> usize
Expand description

Length of the leading run of bytes in haystack that are NOT in needles. Equivalent to find_any_of(haystack, needles).unwrap_or(haystack.len()) but expresses the “skip-clean-prefix” intent more directly at call sites. Useful in scanner inner loops where the next event is “consume the run, then handle the boundary byte”.

Polarity sibling: see match_prefix_len for the inverse — “skip the leading run that is in the needle set.” Mixing them up is a bug class (cf. commit 1e7dace which broke the YAML parser by passing the wrong polarity to skip_blank); the two names are deliberately verb-symmetric to make call sites self-documenting.

§Examples

use noyalib::simd::clean_prefix_len;

// The 7-byte run "abc def" precedes the colon at index 7.
assert_eq!(clean_prefix_len(b"abc def: value", &[b':', b'\n']), 7);

// No needle byte at all — the whole input is "clean".
assert_eq!(clean_prefix_len(b"all clean", &[b':', b'\n']), 9);

// Needle at index 0 — empty prefix.
assert_eq!(clean_prefix_len(b":foo", &[b':']), 0);