diff options
author | Nathan Vegdahl | 2021-06-28 14:51:47 +0000 |
---|---|---|
committer | Nathan Vegdahl | 2021-07-01 21:22:28 +0000 |
commit | 77a266e818bf9d2eded39816b6a77de140234e4f (patch) | |
tree | 03771e6c323161f00cec3b76532dcc0fdba30b56 /helix-core/src/graphemes.rs | |
parent | d07074740bc44b71de83cf23dd692fa90c2854a9 (diff) |
Better validation method APIs for `Range`.
This way they do less work, are more specific to what we actually
need, and they compose.
Diffstat (limited to 'helix-core/src/graphemes.rs')
-rw-r--r-- | helix-core/src/graphemes.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/helix-core/src/graphemes.rs b/helix-core/src/graphemes.rs index f7bf66c0..0465fe51 100644 --- a/helix-core/src/graphemes.rs +++ b/helix-core/src/graphemes.rs @@ -71,6 +71,8 @@ pub fn nth_prev_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) - } /// Finds the previous grapheme boundary before the given char position. +#[must_use] +#[inline(always)] pub fn prev_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> usize { nth_prev_grapheme_boundary(slice, char_idx, 1) } @@ -117,12 +119,16 @@ pub fn nth_next_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) - } /// Finds the next grapheme boundary after the given char position. +#[must_use] +#[inline(always)] pub fn next_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> usize { nth_next_grapheme_boundary(slice, char_idx, 1) } /// Returns the passed char index if it's already a grapheme boundary, /// or the next grapheme boundary char index if not. +#[must_use] +#[inline] pub fn ensure_grapheme_boundary_next(slice: RopeSlice, char_idx: usize) -> usize { if char_idx == 0 { char_idx @@ -133,6 +139,8 @@ pub fn ensure_grapheme_boundary_next(slice: RopeSlice, char_idx: usize) -> usize /// Returns the passed char index if it's already a grapheme boundary, /// or the prev grapheme boundary char index if not. +#[must_use] +#[inline] pub fn ensure_grapheme_boundary_prev(slice: RopeSlice, char_idx: usize) -> usize { if char_idx == slice.len_chars() { char_idx @@ -142,6 +150,7 @@ pub fn ensure_grapheme_boundary_prev(slice: RopeSlice, char_idx: usize) -> usize } /// Returns whether the given char position is a grapheme boundary. +#[must_use] pub fn is_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> bool { // Bounds check debug_assert!(char_idx <= slice.len_chars()); |