summaryrefslogtreecommitdiffstats
path: root/crates/searcher/src/searcher/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/searcher/src/searcher/mod.rs')
-rw-r--r--crates/searcher/src/searcher/mod.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/crates/searcher/src/searcher/mod.rs b/crates/searcher/src/searcher/mod.rs
index 3bd939bb..9b6c9bd4 100644
--- a/crates/searcher/src/searcher/mod.rs
+++ b/crates/searcher/src/searcher/mod.rs
@@ -173,6 +173,9 @@ pub struct Config {
encoding: Option<Encoding>,
/// Whether to do automatic transcoding based on a BOM or not.
bom_sniffing: bool,
+ /// Whether to stop searching when a non-matching line is found after a
+ /// matching line.
+ stop_on_nonmatch: bool,
}
impl Default for Config {
@@ -190,6 +193,7 @@ impl Default for Config {
multi_line: false,
encoding: None,
bom_sniffing: true,
+ stop_on_nonmatch: false,
}
}
}
@@ -555,6 +559,19 @@ impl SearcherBuilder {
self.config.bom_sniffing = yes;
self
}
+
+ /// Stop searching a file when a non-matching line is found after a
+ /// matching line.
+ ///
+ /// This is useful for searching sorted files where it is expected that all
+ /// the matches will be on adjacent lines.
+ pub fn stop_on_nonmatch(
+ &mut self,
+ stop_on_nonmatch: bool,
+ ) -> &mut SearcherBuilder {
+ self.config.stop_on_nonmatch = stop_on_nonmatch;
+ self
+ }
}
/// A searcher executes searches over a haystack and writes results to a caller
@@ -838,6 +855,13 @@ impl Searcher {
self.config.multi_line
}
+ /// Returns true if and only if this searcher is configured to stop when in
+ /// finds a non-matching line after a matching one.
+ #[inline]
+ pub fn stop_on_nonmatch(&self) -> bool {
+ self.config.stop_on_nonmatch
+ }
+
/// Returns true if and only if this searcher will choose a multi-line
/// strategy given the provided matcher.
///