pub fn seek_sequence(
haystack: &[String],
needle: &[String],
start_pos: usize,
is_end_of_file: bool,
) -> Option<usize> {
if needle.is_empty() {
return None;
}
if is_end_of_file && haystack.ends_with(needle) {
return Some(haystack.len() - needle.len());
}
if let Some(pos) = haystack[start_pos..]
.windows(needle.len())
.position(|window| window == needle)
{
return Some(start_pos + pos);
}
let needle_norm: Vec<String> = needle.iter().map(|s| normalize_for_match(s)).collect();
if let Some(pos) = haystack[start_pos..]
.windows(needle.len())
.position(|window| {
let window_norm: Vec<String> = window.iter().map(|s| normalize_for_match(s)).collect();
window_norm == needle_norm
})
{
return Some(start_pos + pos);
}
None
}
fn normalize_for_match(s: &str) -> String {
s.trim()
.replace(['\u{2013}', '\u{2014}', '\u{2015}'], "-") .replace('\u{2011}', "-") }