Fix some char boundary violation bugs.
This commit is contained in:
parent
ffd3a83cbd
commit
aba3970d62
|
|
@ -512,9 +512,9 @@ pub fn find_good_break(slice: &RopeSlice, lower_limit: usize, byte_idx: usize) -
|
||||||
let mut prev = if i == slice_len {
|
let mut prev = if i == slice_len {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(slice.char(byte_idx))
|
Some(slice.char(i))
|
||||||
};
|
};
|
||||||
let mut char_itr = slice.chars_at(byte_idx);
|
let mut char_itr = slice.chars_at(i);
|
||||||
while i > lower_limit {
|
while i > lower_limit {
|
||||||
let c = char_itr.prev();
|
let c = char_itr.prev();
|
||||||
if WS_CHARS.contains(&c.unwrap()) && prev.map(|pc| !WS_CHARS.contains(&pc)).unwrap_or(true)
|
if WS_CHARS.contains(&c.unwrap()) && prev.map(|pc| !WS_CHARS.contains(&pc)).unwrap_or(true)
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,8 @@ pub fn prev_grapheme_boundary(slice: &RopeSlice, byte_idx: usize) -> usize {
|
||||||
// Bounds check
|
// Bounds check
|
||||||
debug_assert!(byte_idx <= slice.len());
|
debug_assert!(byte_idx <= slice.len());
|
||||||
|
|
||||||
|
let byte_idx = slice.ceil_char_boundary(byte_idx);
|
||||||
|
|
||||||
// Get the chunk with our byte index in it.
|
// Get the chunk with our byte index in it.
|
||||||
let (mut chunk, mut chunk_byte_idx) = slice.chunk(byte_idx);
|
let (mut chunk, mut chunk_byte_idx) = slice.chunk(byte_idx);
|
||||||
|
|
||||||
|
|
@ -82,6 +84,8 @@ pub fn next_grapheme_boundary(slice: &RopeSlice, byte_idx: usize) -> usize {
|
||||||
// Bounds check
|
// Bounds check
|
||||||
debug_assert!(byte_idx <= slice.len());
|
debug_assert!(byte_idx <= slice.len());
|
||||||
|
|
||||||
|
let byte_idx = slice.floor_char_boundary(byte_idx);
|
||||||
|
|
||||||
// Get the chunk with our byte index in it.
|
// Get the chunk with our byte index in it.
|
||||||
let (mut chunk, mut chunk_byte_idx) = slice.chunk(byte_idx);
|
let (mut chunk, mut chunk_byte_idx) = slice.chunk(byte_idx);
|
||||||
|
|
||||||
|
|
@ -115,6 +119,11 @@ pub fn is_grapheme_boundary(slice: &RopeSlice, byte_idx: usize) -> bool {
|
||||||
// Get the chunk with our byte index in it.
|
// Get the chunk with our byte index in it.
|
||||||
let (chunk, chunk_byte_idx) = slice.chunk(byte_idx);
|
let (chunk, chunk_byte_idx) = slice.chunk(byte_idx);
|
||||||
|
|
||||||
|
// Can't be a grapheme boundary if it's not a char boundary.
|
||||||
|
if !chunk.is_char_boundary(chunk_byte_idx) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Set up the grapheme cursor.
|
// Set up the grapheme cursor.
|
||||||
let mut gc = GraphemeCursor::new(byte_idx, slice.len(), true);
|
let mut gc = GraphemeCursor::new(byte_idx, slice.len(), true);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user