/// Find the next regex match.
///
/// This will always return the side of the first match which is farthest from the start point.
Find the next regex match.
This will always return the side of the first match which is farthest from the start point.
Find the next regex match . This will always return the side of the first match which is farthest from the start point .
fn regex_search(
        &self,
        start: Point<usize>,
        end: Point<usize>,
        direction: Direction,
        dfa: &impl DFA,
    ) -> Option<Point<usize>> {
        let last_line = self.total_lines() - 1;
        let last_col = self.cols() - 1;
        // Advance the iterator.
        let next = match direction {
            Direction::Right => GridIterator::next,
            Direction::Left => GridIterator::prev,
        };
        let mut iter = self.grid.iter_from(start);
        let mut state = dfa.start_state();
        let mut last_wrapped = false;
        let mut regex_match = None;
        let mut cell = iter.cell();
        self.skip_fullwidth(&mut iter, &mut cell, direction);
        let mut c = cell.c;
        let mut point = iter.point();
        loop {
            // Convert char to array of bytes.
            let mut buf = [0; 4];
            let utf8_len = c.encode_utf8(&mut buf).len();
            // Pass char to DFA as individual bytes.
            for i in 0..utf8_len {
                // Inverse byte order when going left.
                let byte = match direction {
                    Direction::Right => buf[i],
                    Direction::Left => buf[utf8_len - i - 1],
                };
                // Since we get the state from the DFA, it doesn't need to be checked.
                state = unsafe { dfa.next_state_unchecked(state, byte) };
            }
            // Handle regex state changes.
            if dfa.is_match_or_dead_state(state) {
                if dfa.is_dead_state(state) {
                    break;
                } else {
                    regex_match = Some(point);
                }
            }
            // Stop once we've reached the target point.
            if point == end {
                break;
            }
            // Advance grid cell iterator.
            let mut cell = match next(&mut iter) {
                Some(cell) => cell,
                None => {
                    // Wrap around to other end of the scrollback buffer.
                    let start = Point::new(last_line - point.line, last_col - point.col);
                    iter = self.grid.iter_from(start);
                    iter.cell()
                },
            };
            self.skip_fullwidth(&mut iter, &mut cell, direction);
            let wrapped = cell.flags.contains(Flags::WRAPLINE);
            c = cell.c;
            let last_point = mem::replace(&mut point, iter.point());
            // Handle linebreaks.
            if (last_point.col == last_col && point.col == Column(0) && !last_wrapped)
                || (last_point.col == Column(0) && point.col == last_col && !wrapped)
            {
                match regex_match {
                    Some(_) => break,
                    None => state = dfa.start_state(),
                }
            }
            last_wrapped = wrapped;
        }
        regex_match
    }
fn regex_search ( & self , start : Point < usize > , end : Point < usize > , direction : Direction , dfa : & impl DFA , ) -> Option < Point < usize > > { let last_line = self . total_lines ( ) - 1 ; let last_col = self . cols ( ) - 1 ; // Advance the iterator. let next = match direction { Direction :: Right => GridIterator :: next , Direction :: Left => GridIterator :: prev , } ; let mut iter = self . grid . iter_from ( start ) ; let mut state = dfa . start_state ( ) ; let mut last_wrapped = false ; let mut regex_match = None ; let mut cell = iter . cell ( ) ; self . skip_fullwidth ( & mut iter , & mut cell , direction ) ; let mut c = cell . c ; let mut point = iter . point ( ) ; loop { // Convert char to array of bytes. let mut buf = [ 0 ; 4 ] ; let utf8_len = c . encode_utf8 ( & mut buf ) . len ( ) ; // Pass char to DFA as individual bytes. for i in 0 .. utf8_len { // Inverse byte order when going left. let byte = match direction { Direction :: Right => buf [ i ] , Direction :: Left => buf [ utf8_len - i - 1 ] , } ; // Since we get the state from the DFA, it doesn't need to be checked. state = unsafe { dfa . next_state_unchecked ( state , byte ) } ; } // Handle regex state changes. if dfa . is_match_or_dead_state ( state ) { if dfa . is_dead_state ( state ) { break ; } else { regex_match = Some ( point ) ; } } // Stop once we've reached the target point. if point == end { break ; } // Advance grid cell iterator. let mut cell = match next ( & mut iter ) { Some ( cell ) => cell , None => { // Wrap around to other end of the scrollback buffer. let start = Point :: new ( last_line - point . line , last_col - point . col ) ; iter = self . grid . iter_from ( start ) ; iter . cell ( ) } , } ; self . skip_fullwidth ( & mut iter , & mut cell , direction ) ; let wrapped = cell . flags . contains ( Flags :: WRAPLINE ) ; c = cell . c ; let last_point = mem :: replace ( & mut point , iter . point ( ) ) ; // Handle linebreaks. if ( last_point . col == last_col && point . col == Column ( 0 ) && ! last_wrapped ) || ( last_point . col == Column ( 0 ) && point . col == last_col && ! wrapped ) { match regex_match { Some ( _ ) => break , None => state = dfa . start_state ( ) , } } last_wrapped = wrapped ; } regex_match }
Find the next regex match.
Find the next regex match .
&self
start
Point<usize>
end
Point<usize>
direction
Direction
dfa
&impl DFA