summaryrefslogtreecommitdiffstats
path: root/src/pattern
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2021-05-07 17:18:59 +0200
committerCanop <cano.petrole@gmail.com>2021-05-07 17:18:59 +0200
commitccf6da2d2ed5e30355e2c9e3fd445f6297c9493b (patch)
tree6ca4c5145224a8d6c0be6fe95adaa5b205c2dc62 /src/pattern
parent8593028c16d899b5b69dec45ac860d252d18af66 (diff)
apply a different style to the subpath before the filename
This style is visible when searching on subpath
Diffstat (limited to 'src/pattern')
-rw-r--r--src/pattern/name_match.rs17
-rw-r--r--src/pattern/pos.rs1
2 files changed, 18 insertions, 0 deletions
diff --git a/src/pattern/name_match.rs b/src/pattern/name_match.rs
index a4bffcf..cdbeed3 100644
--- a/src/pattern/name_match.rs
+++ b/src/pattern/name_match.rs
@@ -1,5 +1,6 @@
use {
super::Pos,
+ smallvec::SmallVec,
};
/// A NameMatch is a positive result of pattern matching inside
@@ -11,6 +12,7 @@ pub struct NameMatch {
}
impl NameMatch {
+ /// wraps any group of matching characters with match_start and match_end
pub fn wrap(&self, name: &str, match_start: &str, match_end: &str) -> String {
let mut result = String::new();
let mut index_in_pos = 0;
@@ -33,5 +35,20 @@ impl NameMatch {
}
result
}
+ // cut the name match in two parts by recomputing the pos
+ // arrays
+ pub fn cut_after(&mut self, chars_count: usize) -> Self {
+ let mut tail = Self {
+ score: self.score,
+ pos: SmallVec::new(),
+ };
+ let idx = self.pos.iter().position(|&p| p >= chars_count);
+ if let Some(idx) = idx {
+ for p in self.pos.drain(idx..) {
+ tail.pos.push(p - chars_count);
+ }
+ }
+ tail
+ }
}
diff --git a/src/pattern/pos.rs b/src/pattern/pos.rs
index cee14a5..11bdb3d 100644
--- a/src/pattern/pos.rs
+++ b/src/pattern/pos.rs
@@ -5,3 +5,4 @@ use {
/// a vector of indexes of the matching characters (not bytes)
pub type Pos = SmallVec<[usize; 8]>;
+