summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs7
-rw-r--r--src/main.rs9
2 files changed, 15 insertions, 1 deletions
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)
+}
diff --git a/src/main.rs b/src/main.rs
index af3b56a..3111766 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,6 +14,10 @@ struct Config {
///
/// If no FILE is given, read standard input.
files: Vec<String>,
+
+ /// Ignores the case of the search string
+ #[arg(short, long)]
+ ignore_case: bool,
}
fn main() {
@@ -43,7 +47,10 @@ fn run(config: Config) -> Result<(), Box<dyn Error>> {
&mut file_read
};
- for line in reader.lines().map(|l| l.unwrap().contains(&config.pattern)) {
+ for line in reader.lines().map(|l| l.unwrap()) {
+ if !trgrep::contains_pattern(&line, &config.pattern, config.ignore_case) {
+ continue;
+ }
println!("{line}");
}
}