From 47fe7397574208ecdcccc63770ce1b0374de1126 Mon Sep 17 00:00:00 2001 From: antoyo Date: Fri, 1 Apr 2022 09:14:37 -0400 Subject: Jump to the next number on the line before incrementing (#1778) * Jump to the next number on the line before incrementing Partially fix #1645 * Refactor to avoid duplicating find_nth_next--- helix-core/src/search.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'helix-core/src') diff --git a/helix-core/src/search.rs b/helix-core/src/search.rs index 243ac227..81cb4129 100644 --- a/helix-core/src/search.rs +++ b/helix-core/src/search.rs @@ -1,6 +1,28 @@ use crate::RopeSlice; -pub fn find_nth_next(text: RopeSlice, ch: char, mut pos: usize, n: usize) -> Option { +// TODO: switch to std::str::Pattern when it is stable. +pub trait CharMatcher { + fn char_match(&self, ch: char) -> bool; +} + +impl CharMatcher for char { + fn char_match(&self, ch: char) -> bool { + *self == ch + } +} + +impl bool> CharMatcher for F { + fn char_match(&self, ch: char) -> bool { + (*self)(&ch) + } +} + +pub fn find_nth_next( + text: RopeSlice, + char_matcher: M, + mut pos: usize, + n: usize, +) -> Option { if pos >= text.len_chars() || n == 0 { return None; } @@ -13,7 +35,7 @@ pub fn find_nth_next(text: RopeSlice, ch: char, mut pos: usize, n: usize) -> Opt pos += 1; - if c == ch { + if char_matcher.char_match(c) { break; } } -- cgit v1.2.3-70-g09d2