File tree 1 file changed +20
-0
lines changed 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -624,6 +624,9 @@ impl GraphemeCursor {
624
624
if self . offset == 0 {
625
625
return Ok ( None ) ;
626
626
}
627
+ if self . offset == chunk_start {
628
+ return Err ( GraphemeIncomplete :: PrevChunk ) ;
629
+ }
627
630
let mut iter = chunk[ ..self . offset - chunk_start] . chars ( ) . rev ( ) ;
628
631
let mut ch = iter. next ( ) . unwrap ( ) ;
629
632
loop {
@@ -647,6 +650,7 @@ impl GraphemeCursor {
647
650
self . decide ( true ) ;
648
651
} else {
649
652
self . resuming = true ;
653
+ self . cat_after = Some ( gr:: grapheme_category ( ch) ) ;
650
654
return Err ( GraphemeIncomplete :: PrevChunk ) ;
651
655
}
652
656
}
@@ -659,3 +663,19 @@ impl GraphemeCursor {
659
663
}
660
664
}
661
665
}
666
+
667
+ #[ test]
668
+ fn test_grapheme_cursor_prev_boundary ( ) {
669
+ let s = "abcd" ;
670
+ let mut c = GraphemeCursor :: new ( 3 , s. len ( ) , true ) ;
671
+ assert_eq ! ( c. prev_boundary( & s[ 2 ..] , 2 ) , Err ( GraphemeIncomplete :: PrevChunk ) ) ;
672
+ assert_eq ! ( c. prev_boundary( & s[ ..2 ] , 0 ) , Ok ( Some ( 2 ) ) ) ;
673
+ }
674
+
675
+ #[ test]
676
+ fn test_grapheme_cursor_prev_boundary_chunk_start ( ) {
677
+ let s = "abcd" ;
678
+ let mut c = GraphemeCursor :: new ( 2 , s. len ( ) , true ) ;
679
+ assert_eq ! ( c. prev_boundary( & s[ 2 ..] , 2 ) , Err ( GraphemeIncomplete :: PrevChunk ) ) ;
680
+ assert_eq ! ( c. prev_boundary( & s[ ..2 ] , 0 ) , Ok ( Some ( 1 ) ) ) ;
681
+ }
You can’t perform that action at this time.
0 commit comments