diff options
author | Joursoir <chat@joursoir.net> | 2023-03-02 23:57:15 +0400 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2023-03-03 00:06:53 +0400 |
commit | c15d3215dea3dadf93c1be1291c4001c3bff8f4e (patch) | |
tree | 3ae322dff3c1d27a742a954566573dacb47a16b6 /src/lib.rs | |
parent | 74361b83133822fef6d8a4baf1b0d70e22f9e04e (diff) | |
download | trgrep-c15d3215dea3dadf93c1be1291c4001c3bff8f4e.tar.gz trgrep-c15d3215dea3dadf93c1be1291c4001c3bff8f4e.tar.bz2 trgrep-c15d3215dea3dadf93c1be1291c4001c3bff8f4e.zip |
add option to ignore search string case
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -4,3 +4,10 @@ pub fn search<'a>(pattern: &str, contents: &'a str) -> Vec<&'a str> { .filter(|line| line.contains(pattern)) .collect() } + +pub fn contains_pattern(src: &str, pat: &str, ignore_case: bool) -> bool { + let src = if ignore_case { src.to_lowercase() } else { src.to_owned() }; + let pat = if ignore_case { pat.to_lowercase() } else { pat.to_owned() }; + + src.contains(&pat) +} |