summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2023-03-03 00:00:55 +0400
committerJoursoir <chat@joursoir.net>2023-03-03 00:19:02 +0400
commit0fd76b8e90470b99f3e5c968b65562fde56d0c3e (patch)
tree1c2009dc3d857a12b02a3bbb5f0bb19f780b4dc9 /src/lib.rs
parentc15d3215dea3dadf93c1be1291c4001c3bff8f4e (diff)
downloadtrgrep-0fd76b8e90470b99f3e5c968b65562fde56d0c3e.tar.gz
trgrep-0fd76b8e90470b99f3e5c968b65562fde56d0c3e.tar.bz2
trgrep-0fd76b8e90470b99f3e5c968b65562fde56d0c3e.zip
add option to match only whole words
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index a716d13..eb43876 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -5,9 +5,13 @@ pub fn search<'a>(pattern: &str, contents: &'a str) -> Vec<&'a str> {
.collect()
}
-pub fn contains_pattern(src: &str, pat: &str, ignore_case: bool) -> bool {
+pub fn contains_pattern(src: &str, pat: &str, ignore_case: bool, word_regexp: 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)
+ if word_regexp {
+ src.split_whitespace().any(|p| p == pat)
+ } else {
+ src.contains(&pat)
+ }
}