use crate::ops::string_matching::search_contract::{to_u32_offset, validate_search_inputs, MatchError};
pub fn substring_find_all(haystack: &[u8], needle: &[u8]) -> Result<Vec<u32>, MatchError> {
validate_search_inputs(haystack, needle)?;
if needle.is_empty() {
let mut offsets = Vec::with_capacity(haystack.len() + 1);
for index in 0..=haystack.len() {
offsets.push(to_u32_offset(index)?);
}
return Ok(offsets);
}
let mut offsets = Vec::new();
for (index, window) in haystack.windows(needle.len()).enumerate() {
if window == needle {
offsets.push(to_u32_offset(index)?);
}
}
Ok(offsets)
}