sqruff_lib/core/
string_helpers.rs1pub fn find_all(substr: &str, in_str: &str) -> Vec<usize> {
4 if substr.is_empty() || in_str.is_empty() {
6 return Vec::new();
7 }
8 in_str.match_indices(substr).map(|(i, _)| i).collect()
9}
10
11#[cfg(test)]
12mod tests {
13 use super::*;
14
15 #[test]
16 fn test_find_all() {
17 vec![
18 ("", "", vec![]),
19 ("a", "a", vec![0]),
20 ("foobar", "o", vec![1, 2]),
21 ("bar bar bar bar", "bar", vec![0, 4, 8, 12]),
22 ]
23 .into_iter()
24 .for_each(|(in_str, substr, expected)| assert_eq!(expected, find_all(substr, in_str)));
25 }
26}