aboutsummaryrefslogtreecommitdiff
path: root/helix-stdx
diff options
context:
space:
mode:
Diffstat (limited to 'helix-stdx')
-rw-r--r--helix-stdx/src/rope.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/helix-stdx/src/rope.rs b/helix-stdx/src/rope.rs
index 7b4edda4..7e2549f5 100644
--- a/helix-stdx/src/rope.rs
+++ b/helix-stdx/src/rope.rs
@@ -14,6 +14,8 @@ pub trait RopeSliceExt<'a>: Sized {
byte_range: R,
) -> RegexInput<RopeyCursor<'a>>;
fn regex_input_at<R: RangeBounds<usize>>(self, char_range: R) -> RegexInput<RopeyCursor<'a>>;
+ fn first_non_whitespace_char(self) -> Option<usize>;
+ fn last_non_whitespace_char(self) -> Option<usize>;
}
impl<'a> RopeSliceExt<'a> for RopeSlice<'a> {
@@ -64,4 +66,13 @@ impl<'a> RopeSliceExt<'a> for RopeSlice<'a> {
};
input.range(byte_range)
}
+ fn first_non_whitespace_char(self) -> Option<usize> {
+ self.chars().position(|ch| !ch.is_whitespace())
+ }
+ fn last_non_whitespace_char(self) -> Option<usize> {
+ self.chars_at(self.len_chars())
+ .reversed()
+ .position(|ch| !ch.is_whitespace())
+ .map(|pos| self.len_chars() - pos - 1)
+ }
}