Function
match_substring_in
(
query: &str,
commands: &'static [CommandSpec],
)
Source from the content-addressed store, hash-verified
| 135 | ]; |
| 136 | |
| 137 | pub fn match_substring_in( |
| 138 | query: &str, |
| 139 | commands: &'static [CommandSpec], |
| 140 | ) -> Vec<&'static CommandSpec> { |
| 141 | if query.is_empty() { |
| 142 | return Vec::new(); |
| 143 | } |
| 144 | let q = query.strip_prefix('/').unwrap_or(query).to_lowercase(); |
| 145 | if q.is_empty() { |
| 146 | return Vec::new(); |
| 147 | } |
| 148 | commands |
| 149 | .iter() |
| 150 | .filter(|spec| { |
| 151 | spec.name |
| 152 | .strip_prefix('/') |
| 153 | .unwrap_or(spec.name) |
| 154 | .to_lowercase() |
| 155 | .contains(&q) |
| 156 | }) |
| 157 | .collect() |
| 158 | } |
| 159 | |
| 160 | #[cfg(test)] |
| 161 | mod tests { |