~irimi1/learning-rust

d736e3c7beb69912e8f52f96338ae72498d26a7a — Manuel Groß 2 years ago 030b72b
minigrep: Implement case insensitive search
1 files changed, 10 insertions(+), 1 deletions(-)

M projects/minigrep/src/lib.rs
M projects/minigrep/src/lib.rs => projects/minigrep/src/lib.rs +10 -1
@@ 24,7 24,16 @@ 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
}

pub struct Config {