8000 Fix a bug in Prepend handling · HughP/unicode-segmentation@4acb5e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4acb5e9

Browse files
committed
Fix a bug in Prepend handling
The state was not updated correctly for the char after the Prepend.
1 parent 83adfde commit 4acb5e9

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "unicode-segmentation"
4-
version = "1.0.0"
4+
version = "1.0.1"
55
authors = ["kwantam <kwantam@gmail.com>"]
66

77
homepage = "https://github.com/unicode-rs/unicode-segmentation"

src/grapheme.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ impl<'a> Iterator for Graphemes<'a> {
125125
}
126126
break; // rule GB4
127127
}
128-
Start => match cat {
129-
gr::GC_Control => break,
128+
Start | Prepend => match cat {
129+
gr::GC_Control => { // rule GB5
130+
take_curr = state == Start;
131+
break;
132+
}
130133
gr::GC_L => HangulL,
131134
gr::GC_LV | gr::GC_V => HangulLV,
132135
gr::GC_LVT | gr::GC_T => HangulLVT,
@@ -163,13 +166,6 @@ impl<'a> Iterator for Graphemes<'a> {
163166
break;
164167
}
165168
},
166-
Prepend => match cat { // rule GB9b
167-
gr::GC_Control => {
168-
take_curr = false;
169-
break;
170-
}
171-
_ => continue
172-
},
173169
Regional => match cat { // rule GB12/GB13
174170
gr::GC_Regional_Indicator => FindExtend,
175171
_ => {

src/test.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ fn test_graphemes() {
2323
("\u{20}\u{600}\u{600}\u{20}",
2424
&["\u{20}", "\u{600}\u{600}\u{20}"],
2525
&["\u{20}", "\u{600}", "\u{600}", "\u{20}"]),
26+
27+
// Test for Prepend followed by two Any chars
28+
("\u{600}\u{20}\u{20}",
29+
&["\u{600}\u{20}", "\u{20}"],
30+
&["\u{600}", "\u{20}", "\u{20}"]),
2631
];
2732

2833
for &(s, g) in TEST_SAME {

0 commit comments

Comments
 (0)
0