@@ -50,11 +50,11 @@ where
50
50
let ( last_char_index, last_byte_index) =
51
51
self . last_char_index_to_byte_index . get ( ) ;
52
52
let byte_index = last_byte_index as usize ;
53
- let mut char_index = last_char_index as usize ;
54
53
55
54
if start_char_index >= last_char_index as usize
56
55
|| end_char_index >= last_char_index as usize
57
56
{
57
+ let mut char_index = last_char_index as usize ;
58
58
#[ allow( unsafe_code) ]
59
59
let slice = unsafe {
60
60
// SAFETY: Since `indices` iterates over the `CharIndices` of `self`, we can guarantee
77
77
}
78
78
char_index += 1 ;
79
79
}
80
- } else {
80
+ }
81
+
82
+ if start_char_index < last_char_index as usize
83
+ || end_char_index < last_char_index as usize
84
+ {
85
+ let mut char_index = last_char_index as usize ;
81
86
#[ allow( unsafe_code) ]
82
87
let slice = unsafe {
83
88
// SAFETY: Since `indices` iterates over the `CharIndices` of `self`, we can guarantee
@@ -162,5 +167,11 @@ mod tests {
162
167
assert_eq ! ( rope_with_indices. substring( 10 , 13 ) , "d 你" ) ;
163
168
assert_eq ! ( rope_with_indices. substring( 13 , 15 ) , "好世" ) ;
164
169
assert_eq ! ( rope_with_indices. substring( 10 , 13 ) , "d 你" ) ;
170
+
171
+ let rope_with_indices =
172
+ WithIndices :: new ( Rope :: from ( "export const answer = 42;\n " ) ) ;
173
+ assert_eq ! ( rope_with_indices. substring( 7 , 13 ) , "const " ) ;
174
+ assert_eq ! ( rope_with_indices. substring( 13 , 19 ) , "answer" ) ;
175
+ assert_eq ! ( rope_with_indices. substring( 7 , 22 ) , "const answer = " ) ;
165
176
}
166
177
}
0 commit comments