Repository: alacritty/alacritty
File: alacritty_terminal/src/term/search.rs (Rust)

Code before:
        start: Point,
        end: Point,
    ) -> Option<Match> {
        // Find start and end of match.
        let match_end = self.regex_search(start, end, Direction::Right, false, &mut regex.fdfa)?;
        let match_start =
            self.regex_search(match_end, start, Direction::Left, true, &mut regex.rdfa)?;

        Some(match_start..=match_end)
    }

    /// 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,
        end: Point,
        direction: Direction,
        anchored: bool,
        regex: &mut LazyDfa,
    ) -> Option<Point> {
        match self.regex_search_internal(start, end, direction, anchored, regex) {
            Ok(regex_match) => regex_match,
            Err(err) => {
                log::warn!("Regex exceeded complexity limit");
                log::debug!("    {err}");
                None
            },
        }
    }

    /// Find the next regex match.
    ///
    /// To automatically log regex complexity errors, use [`Self::regex_search`] instead.
    fn regex_search_internal(
        &self,
        start: Point,
        end: Point,
        direction: Direction,
        anchored: bool,
        regex: &mut LazyDfa,
    ) -> Result<Option<Point>, Box<dyn Error>> {
        let topmost_line = self.topmost_line();
        let screen_lines = self.screen_lines() as i32;
        let last_column = self.last_column();

        // Advance the iterator.
        let next = match direction {
            Direction::Right => GridIterator::next,
            Direction::Left => GridIterator::prev,

Review comment (bug):
Maybe we should say which regex somehow? Also, import `warn!` and `debug!`.

Code after:
        regex: &mut RegexSearch,
        start: Point,
        end: Point,
    ) -> Option<Match> {
        // Find start and end of match.
        let match_end = self.regex_search(start, end, Direction::Right, false, &mut regex.fdfa)?;
        let match_start =
            self.regex_search(match_end, start, Direction::Left, true, &mut regex.rdfa)?;

        Some(match_start..=match_end)
    }

    /// 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,
        end: Point,
        direction: Direction,
        anchored: bool,
        regex: &mut LazyDfa,
    ) -> Option<Point> {
        match self.regex_search_internal(start, end, direction, anchored, regex) {
            Ok(regex_match) => regex_match,
            Err(err) => {
                warn!("Regex exceeded complexity limit");
                debug!("    {err}");
                None
            },
        }
    }

    /// Find the next regex match.
    ///
    /// To automatically log regex complexity errors, use [`Self::regex_search`] instead.
    fn regex_search_internal(
        &self,
        start: Point,
        end: Point,
        direction: Direction,
        anchored: bool,
        regex: &mut LazyDfa,
    ) -> Result<Option<Point>, Box<dyn Error>> {
        let topmost_line = self.topmost_line();
        let screen_lines = self.screen_lines() as i32;
        let last_column = self.last_column();

        // Advance the iterator.
        let next = match direction {
            Direction::Right => GridIterator::next,