pub fn simple_match(
        &self,
        choice: &str,
        pattern: &str,
        case_sensitive: bool,
        with_pos: bool,
    ) -> Option<(i64, Vec<usize>)> {
        let mut choice_iter = choice.char_indices().peekable();
        let mut pattern_iter = pattern.chars().peekable();
        let mut o_start_byte = None;

        // scan forward to find the first match of whole pattern
        let mut start_chars = 0;
        while choice_iter.peek().is_some() && pattern_iter.peek().is_some() {
            let (byte_idx, c) = choice_iter.next().unwrap();
            match pattern_iter.peek() {
                Some(&p) => {
                    if char_equal(c, p, case_sensitive) {
                        let _ = pattern_iter.next();
                        o_start_byte = o_start_byte.or(Some(byte_idx));
                    }
                }
                None => break,
            }

            if o_start_byte.is_none() {
                start_chars += 1;
            }
        }

        if pattern_iter.peek().is_some() {
            return None;
        }

        let start_byte = o_start_byte.unwrap_or(0);
        let end_byte = choice_iter
            .next()
            .map(|(idx, _)| idx)
            .unwrap_or(choice.len());

        // scan backward to find the first match of whole pattern
        let mut o_nearest_start_byte = None;
        let mut pattern_iter = pattern.chars().rev().peekable();
        for (idx, c) in choice[start_byte..end_byte].char_indices().rev() {
            match pattern_iter.peek() {
                Some(&p) => {
                    if char_equal(c, p, case_sensitive) {
                        let _ = pattern_iter.next();
                        o_nearest_start_byte = Some(idx);
                    }
                }
                None => break,
            }
        }

        let start_byte = start_byte + o_nearest_start_byte.unwrap_or(0);
        Some(self.calculate_score_with_pos(
            choice,
            pattern,
            start_byte,
            end_byte,
            start_chars,
            case_sensitive,
            with_pos,
        ))
    }
/// Borrowed from fzf v1, if the memory limit exceeded, fallback to simple linear search
Borrowed from fzf v1, if the memory limit exceeded, fallback to simple linear search
Borrowed from fzf v1 if the memory limit exceeded fallback to simple linear search
pub fn simple_match(
        &self,
        choice: &str,
        pattern: &str,
        case_sensitive: bool,
        with_pos: bool,
    ) -> Option<(i64, Vec<usize>)> {
        let mut choice_iter = choice.char_indices().peekable();
        let mut pattern_iter = pattern.chars().peekable();
        let mut o_start_byte = None;
        // scan forward to find the first match of whole pattern
        let mut start_chars = 0;
        while choice_iter.peek().is_some() && pattern_iter.peek().is_some() {
            let (byte_idx, c) = choice_iter.next().unwrap();
            match pattern_iter.peek() {
                Some(&p) => {
                    if char_equal(c, p, case_sensitive) {
                        let _ = pattern_iter.next();
                        o_start_byte = o_start_byte.or(Some(byte_idx));
                    }
                }
                None => break,
            }
            if o_start_byte.is_none() {
                start_chars += 1;
            }
        }
        if pattern_iter.peek().is_some() {
            return None;
        }
        let start_byte = o_start_byte.unwrap_or(0);
        let end_byte = choice_iter
            .next()
            .map(|(idx, _)| idx)
            .unwrap_or(choice.len());
        // scan backward to find the first match of whole pattern
        let mut o_nearest_start_byte = None;
        let mut pattern_iter = pattern.chars().rev().peekable();
        for (idx, c) in choice[start_byte..end_byte].char_indices().rev() {
            match pattern_iter.peek() {
                Some(&p) => {
                    if char_equal(c, p, case_sensitive) {
                        let _ = pattern_iter.next();
                        o_nearest_start_byte = Some(idx);
                    }
                }
                None => break,
            }
        }
        let start_byte = start_byte + o_nearest_start_byte.unwrap_or(0);
        Some(self.calculate_score_with_pos(
            choice,
            pattern,
            start_byte,
            end_byte,
            start_chars,
            case_sensitive,
            with_pos,
        ))
    }
pub fn simple_match ( & self , choice : & str , pattern : & str , case_sensitive : bool , with_pos : bool , ) -> Option < ( i64 , Vec < usize > ) > { let mut choice_iter = choice . char_indices ( ) . peekable ( ) ; let mut pattern_iter = pattern . chars ( ) . peekable ( ) ; let mut o_start_byte = None ; // scan forward to find the first match of whole pattern let mut start_chars = 0 ; while choice_iter . peek ( ) . is_some ( ) && pattern_iter . peek ( ) . is_some ( ) { let ( byte_idx , c ) = choice_iter . next ( ) . unwrap ( ) ; match pattern_iter . peek ( ) { Some ( & p ) => { if char_equal ( c , p , case_sensitive ) { let _ = pattern_iter . next ( ) ; o_start_byte = o_start_byte . or ( Some ( byte_idx ) ) ; } } None => break , } if o_start_byte . is_none ( ) { start_chars += 1 ; } } if pattern_iter . peek ( ) . is_some ( ) { return None ; } let start_byte = o_start_byte . unwrap_or ( 0 ) ; let end_byte = choice_iter . next ( ) . map ( | ( idx , _ ) | idx ) . unwrap_or ( choice . len ( ) ) ; // scan backward to find the first match of whole pattern let mut o_nearest_start_byte = None ; let mut pattern_iter = pattern . chars ( ) . rev ( ) . peekable ( ) ; for ( idx , c ) in choice [ start_byte .. end_byte ] . char_indices ( ) . rev ( ) { match pattern_iter . peek ( ) { Some ( & p ) => { if char_equal ( c , p , case_sensitive ) { let _ = pattern_iter . next ( ) ; o_nearest_start_byte = Some ( idx ) ; } } None => break , } } let start_byte = start_byte + o_nearest_start_byte . unwrap_or ( 0 ) ; Some ( self . calculate_score_with_pos ( choice , pattern , start_byte , end_byte , start_chars , case_sensitive , with_pos , ) ) }
Borrowed from fzf v1, if the memory limit exceeded, fallback to simple linear search
Borrowed from fzf v1 if the memory limit exceeded fallback to simple linear search
&self
choice
&str
pattern
&str
case_sensitive
bool
with_pos
bool