From c15d3215dea3dadf93c1be1291c4001c3bff8f4e Mon Sep 17 00:00:00 2001 From: Joursoir Date: Thu, 2 Mar 2023 23:57:15 +0400 Subject: add option to ignore search string case --- src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index c01823d..a716d13 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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) +} -- cgit v1.2.3-18-g5258