changeset 6478:3fc2b4750c18

core: Remove unused byte index grapheme functions
author Michael Davis <mcarsondavis@gmail.com>
date Sun, 26 Jan 2025 19:16:02 -0500
parents 57e73759dae6
children e03c4f2f58e0
files helix-core/src/graphemes.rs
diffstat 1 files changed, 3 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/helix-core/src/graphemes.rs	Sun Jan 26 16:52:29 2025 -0500
+++ b/helix-core/src/graphemes.rs	Sun Jan 26 19:16:02 2025 -0500
@@ -119,6 +119,9 @@
     }
 }
 
+// NOTE: for byte indexing versions of these functions see `RopeSliceExt`'s
+// `floor_grapheme_boundary` and `ceil_grapheme_boundary` and the rope grapheme iterators.
+
 #[must_use]
 pub fn nth_prev_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize {
     // Bounds check
@@ -208,43 +211,6 @@
     chunk_char_idx + tmp
 }
 
-#[must_use]
-pub fn nth_next_grapheme_boundary_byte(slice: RopeSlice, mut byte_idx: usize, n: usize) -> usize {
-    // Bounds check
-    debug_assert!(byte_idx <= slice.len_bytes());
-
-    // Get the chunk with our byte index in it.
-    let (mut chunk, mut chunk_byte_idx, mut _chunk_char_idx, _) = slice.chunk_at_byte(byte_idx);
-
-    // Set up the grapheme cursor.
-    let mut gc = GraphemeCursor::new(byte_idx, slice.len_bytes(), true);
-
-    // Find the nth next grapheme cluster boundary.
-    for _ in 0..n {
-        loop {
-            match gc.next_boundary(chunk, chunk_byte_idx) {
-                Ok(None) => return slice.len_bytes(),
-                Ok(Some(n)) => {
-                    byte_idx = n;
-                    break;
-                }
-                Err(GraphemeIncomplete::NextChunk) => {
-                    chunk_byte_idx += chunk.len();
-                    let (a, _, _c, _) = slice.chunk_at_byte(chunk_byte_idx);
-                    chunk = a;
-                    // chunk_char_idx = c;
-                }
-                Err(GraphemeIncomplete::PreContext(n)) => {
-                    let ctx_chunk = slice.chunk_at_byte(n - 1).0;
-                    gc.provide_context(ctx_chunk, n - ctx_chunk.len());
-                }
-                _ => unreachable!(),
-            }
-        }
-    }
-    byte_idx
-}
-
 /// Finds the next grapheme boundary after the given char position.
 #[must_use]
 #[inline(always)]
@@ -252,13 +218,6 @@
     nth_next_grapheme_boundary(slice, char_idx, 1)
 }
 
-/// Finds the next grapheme boundary after the given byte position.
-#[must_use]
-#[inline(always)]
-pub fn next_grapheme_boundary_byte(slice: RopeSlice, byte_idx: usize) -> usize {
-    nth_next_grapheme_boundary_byte(slice, byte_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]
@@ -311,31 +270,6 @@
     }
 }
 
-/// Returns whether the given byte position is a grapheme boundary.
-#[must_use]
-pub fn is_grapheme_boundary_byte(slice: RopeSlice, byte_idx: usize) -> bool {
-    // Bounds check
-    debug_assert!(byte_idx <= slice.len_bytes());
-
-    // Get the chunk with our byte index in it.
-    let (chunk, chunk_byte_idx, _, _) = slice.chunk_at_byte(byte_idx);
-
-    // Set up the grapheme cursor.
-    let mut gc = GraphemeCursor::new(byte_idx, slice.len_bytes(), true);
-
-    // Determine if the given position is a grapheme cluster boundary.
-    loop {
-        match gc.is_boundary(chunk, chunk_byte_idx) {
-            Ok(n) => return n,
-            Err(GraphemeIncomplete::PreContext(n)) => {
-                let (ctx_chunk, ctx_byte_start, _, _) = slice.chunk_at_byte(n - 1);
-                gc.provide_context(ctx_chunk, ctx_byte_start);
-            }
-            Err(_) => unreachable!(),
-        }
-    }
-}
-
 /// An iterator over the graphemes of a `RopeSlice`.
 #[derive(Clone)]
 pub struct RopeGraphemes<'a> {