Add an implementation for the case insensitive search
This commit is contained in:
parent
ba37e08a5d
commit
8bbd8391a0
1 changed files with 11 additions and 1 deletions
|
@ -41,9 +41,19 @@ pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
|
|||
}
|
||||
|
||||
pub fn search_case_insensitive<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
|
||||
vec![]
|
||||
let query = query.to_lowercase();
|
||||
let mut results = Vec::new();
|
||||
|
||||
for line in contents.lines() {
|
||||
if line.to_lowercase().contains(&query) {
|
||||
results.push(line);
|
||||
}
|
||||
}
|
||||
|
||||
results
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in a new issue