Skip to content

Commit

Permalink
fzf: add is_case_sensitive to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Nov 7, 2023
1 parent f586f5e commit deb6f1a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/algos/fzf/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type FuzzyAlgo<T> = fn(
&Scheme,
CharEq,
bool,
bool,
T,
) -> Option<(Score, MatchedRanges)>;

Expand Down Expand Up @@ -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<Extras>,
Expand All @@ -297,6 +299,7 @@ impl<'a> Pattern<'a> {
candidate,
scheme,
char_eq,
is_case_sensitive,
with_matched_ranges,
extras,
),
Expand Down
15 changes: 15 additions & 0 deletions src/algos/fzf/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)?;
Expand Down Expand Up @@ -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,
Expand All @@ -169,13 +171,15 @@ 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)> {
let (matches, last_match_offset) = matches(
&mut slab.matched_indices,
pattern,
candidate,
is_case_sensitive,
is_candidate_ascii,
char_eq,
)?;
Expand Down Expand Up @@ -207,6 +211,7 @@ pub(super) fn fzf_v2(
&mut slab.consecutive_matrix,
pattern,
candidate,
is_case_sensitive,
is_candidate_ascii,
char_eq,
matches,
Expand Down Expand Up @@ -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)> {
Expand All @@ -254,6 +260,7 @@ fn matches<'idx>(
query_char,
candidate,
is_candidate_ascii,
is_case_sensitive,
char_eq,
)?;

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -330,6 +338,7 @@ fn score<'scoring, 'consecutive>(
consecutive_slab: &'consecutive mut MatrixSlab<usize>,
pattern: Pattern,
candidate: &str,
is_case_sensitive: bool,
is_candidate_ascii: bool,
char_eq: CharEq,
matches: &[MatchedIdx],
Expand All @@ -353,6 +362,7 @@ fn score<'scoring, 'consecutive>(
bonus_vector,
pattern.char(0),
candidate,
is_case_sensitive,
is_candidate_ascii,
char_eq,
);
Expand All @@ -364,6 +374,7 @@ fn score<'scoring, 'consecutive>(
matches,
candidate,
bonus_vector,
is_case_sensitive,
is_candidate_ascii,
char_eq,
max_score,
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit deb6f1a

Please sign in to comment.