Skip to content

Commit

Permalink
fzf: add FzfParser::parse_not_extended
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Nov 26, 2023
1 parent 357b1df commit 29c990b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/algos/fzf/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ impl core::fmt::Debug for FzfParser {
}

impl FzfParser {
/// TODO: docs
#[inline]
pub fn new() -> Self {
Self::default()
}

/// TODO: docs
#[inline]
pub fn parse<'a>(&'a mut self, query: &str) -> FzfQuery<'a> {
Expand Down Expand Up @@ -85,13 +91,20 @@ impl FzfParser {
num_conditions += 1;
}

FzfQuery::new(&self.conditions[..num_conditions])
FzfQuery::new_extended(&self.conditions[..num_conditions])
}

/// TODO: docs
#[inline]
pub fn new() -> Self {
Self::default()
pub fn parse_not_extended<'a>(&'a mut self, query: &str) -> FzfQuery<'a> {
let mut char_len = 0;

for ch in query.chars() {
self.chars[char_len] = ch;
char_len += 1;
}

FzfQuery::new_not_extended(&self.chars[..char_len])
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/algos/fzf/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'a> FzfQuery<'a> {

/// TODO: docs
#[inline]
pub(super) fn new(conditions: &'a [Condition<'a>]) -> Self {
pub(super) fn new_extended(conditions: &'a [Condition<'a>]) -> Self {
// If there's only one condition with a single pattern, and that
// pattern is fuzzy, then we can use the non-extended search mode.
if conditions.len() == 1 {
Expand All @@ -68,6 +68,12 @@ impl<'a> FzfQuery<'a> {

Self { search_mode: SearchMode::Extended(conditions) }
}

/// TODO: docs
#[inline]
pub(super) fn new_not_extended(chars: &'a [char]) -> Self {
Self { search_mode: SearchMode::NotExtended(Pattern::parse(chars)) }
}
}

/// TODO: docs
Expand Down

0 comments on commit 29c990b

Please sign in to comment.