Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfb5d7b6

Browse files
committed
fix crashes on prev_boundary
Fixes#38,#39
1 parent611eaa7 commitfb5d7b6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎src/grapheme.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,9 @@ impl GraphemeCursor {
624624
ifself.offset ==0{
625625
returnOk(None);
626626
}
627+
ifself.offset == chunk_start{
628+
returnErr(GraphemeIncomplete::PrevChunk);
629+
}
627630
letmut iter = chunk[..self.offset - chunk_start].chars().rev();
628631
letmut ch = iter.next().unwrap();
629632
loop{
@@ -647,6 +650,7 @@ impl GraphemeCursor {
647650
self.decide(true);
648651
}else{
649652
self.resuming =true;
653+
self.cat_after =Some(gr::grapheme_category(ch));
650654
returnErr(GraphemeIncomplete::PrevChunk);
651655
}
652656
}
@@ -659,3 +663,19 @@ impl GraphemeCursor {
659663
}
660664
}
661665
}
666+
667+
#[test]
668+
fntest_grapheme_cursor_prev_boundary(){
669+
let s ="abcd";
670+
letmut 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+
fntest_grapheme_cursor_prev_boundary_chunk_start(){
677+
let s ="abcd";
678+
letmut 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+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp