From deb6f1a68d051242c2333b9e13bcd8b6752b4f04 Mon Sep 17 00:00:00 2001 From: Riccardo Mazzarini Date: Tue, 7 Nov 2023 22:00:48 +0100 Subject: [PATCH] fzf: add `is_case_sensitive` to functions --- src/algos/fzf/query.rs | 3 +++ src/algos/fzf/v2.rs | 15 +++++++++++++++ src/utils.rs | 4 ++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/algos/fzf/query.rs b/src/algos/fzf/query.rs index 93df986..67ceef5 100644 --- a/src/algos/fzf/query.rs +++ b/src/algos/fzf/query.rs @@ -10,6 +10,7 @@ type FuzzyAlgo = fn( &Scheme, CharEq, bool, + bool, T, ) -> Option<(Score, MatchedRanges)>; @@ -287,6 +288,7 @@ impl<'a> Pattern<'a> { candidate: &str, scheme: &Scheme, char_eq: CharEq, + is_case_sensitive: bool, with_matched_ranges: bool, extras: Extras, fuzzy_algo: FuzzyAlgo, @@ -297,6 +299,7 @@ impl<'a> Pattern<'a> { candidate, scheme, char_eq, + is_case_sensitive, with_matched_ranges, extras, ), diff --git a/src/algos/fzf/v2.rs b/src/algos/fzf/v2.rs index 962d5d2..5462c7d 100644 --- a/src/algos/fzf/v2.rs +++ b/src/algos/fzf/v2.rs @@ -111,6 +111,7 @@ impl Metric for FzfV2 { candidate, &self.scheme, char_eq, + is_case_sensitive, self.with_matched_ranges, (&mut self.slab, is_candidate_ascii), )?; @@ -143,6 +144,7 @@ impl Metric for FzfV2 { candidate, &self.scheme, char_eq, + is_case_sensitive, self.with_matched_ranges, (&mut self.slab, is_candidate_ascii), fzf_v2, @@ -169,6 +171,7 @@ pub(super) fn fzf_v2( candidate: &str, scheme: &Scheme, char_eq: CharEq, + is_case_sensitive: bool, with_matched_ranges: bool, (slab, is_candidate_ascii): (&mut V2Slab, bool), ) -> Option<(Score, MatchedRanges)> { @@ -176,6 +179,7 @@ pub(super) fn fzf_v2( &mut slab.matched_indices, pattern, candidate, + is_case_sensitive, is_candidate_ascii, char_eq, )?; @@ -207,6 +211,7 @@ pub(super) fn fzf_v2( &mut slab.consecutive_matrix, pattern, candidate, + is_case_sensitive, is_candidate_ascii, char_eq, matches, @@ -238,6 +243,7 @@ fn matches<'idx>( indices_slab: &'idx mut MatchedIndicesSlab, pattern: Pattern, mut candidate: &str, + is_case_sensitive: bool, is_candidate_ascii: bool, char_eq: CharEq, ) -> Option<(&'idx mut [MatchedIdx], usize)> { @@ -254,6 +260,7 @@ fn matches<'idx>( query_char, candidate, is_candidate_ascii, + is_case_sensitive, char_eq, )?; @@ -292,6 +299,7 @@ fn matches<'idx>( last_query_char, candidate, is_candidate_ascii, + is_case_sensitive, char_eq, ) .unwrap_or((0, last_query_char)); @@ -330,6 +338,7 @@ fn score<'scoring, 'consecutive>( consecutive_slab: &'consecutive mut MatrixSlab, pattern: Pattern, candidate: &str, + is_case_sensitive: bool, is_candidate_ascii: bool, char_eq: CharEq, matches: &[MatchedIdx], @@ -353,6 +362,7 @@ fn score<'scoring, 'consecutive>( bonus_vector, pattern.char(0), candidate, + is_case_sensitive, is_candidate_ascii, char_eq, ); @@ -364,6 +374,7 @@ fn score<'scoring, 'consecutive>( matches, candidate, bonus_vector, + is_case_sensitive, is_candidate_ascii, char_eq, max_score, @@ -381,6 +392,7 @@ fn score_first_row( bonus_vector: &[Score], query_first_char: char, mut candidate: &str, + is_case_sensitive: bool, is_candidate_ascii: bool, char_eq: CharEq, ) -> (Score, MatrixCell) { @@ -402,6 +414,7 @@ fn score_first_row( let Some((byte_idx, matched_ch)) = utils::find_first( query_first_char, candidate, + is_case_sensitive, is_candidate_ascii, char_eq, ) else { @@ -464,6 +477,7 @@ fn score_remaining_rows( matches: &[MatchedIdx], candidate: &str, bonus_vector: &[Score], + is_case_sensitive: bool, is_candidate_ascii: bool, char_eq: CharEq, mut max_score: Score, @@ -493,6 +507,7 @@ fn score_remaining_rows( let Some((byte_offset, matched_ch)) = utils::find_first( query_char, candidate, + is_case_sensitive, is_candidate_ascii, char_eq, ) else { diff --git a/src/utils.rs b/src/utils.rs index 2a202c4..aa2a6e7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -57,11 +57,11 @@ pub fn find_first( needle: char, haystack: &str, is_candidate_ascii: bool, + is_case_sensitive: bool, char_eq: CharEq, ) -> Option<(usize, char)> { if is_candidate_ascii { if needle.is_ascii() { - let is_case_sensitive = char_eq('a', 'A'); find_first_ascii(needle as u8, haystack, is_case_sensitive) } else { None @@ -110,11 +110,11 @@ pub fn find_last( needle: char, haystack: &str, is_candidate_ascii: bool, + is_case_sensitive: bool, char_eq: CharEq, ) -> Option<(usize, char)> { if is_candidate_ascii { if needle.is_ascii() { - let is_case_sensitive = char_eq('a', 'A'); find_last_ascii(needle as u8, haystack, is_case_sensitive) } else { None