@@ -59,6 +59,7 @@ enum GraphemeState {
59
59
HangulLV ,
60
60
HangulLVT ,
61
61
Regional ,
62
+ Zwj ,
62
63
}
63
64
64
65
impl < ' a > Iterator for Graphemes < ' a > {
@@ -93,13 +94,14 @@ impl<'a> Iterator for Graphemes<'a> {
93
94
_ => self . cat . take ( ) . unwrap ( )
94
95
} ;
95
96
96
- if match cat {
97
- gr:: GC_Extend => true ,
98
- gr:: GC_SpacingMark if self . extended => true ,
99
- _ => false
97
+ if let Some ( new_state) = match cat {
98
+ gr:: GC_Extend => Some ( FindExtend ) , // rule GB9
99
+ gr:: GC_SpacingMark if self . extended => Some ( FindExtend ) , // rule GB9a
100
+ gr:: GC_ZWJ => Some ( Zwj ) , // rule GB9/GB11
101
+ _ => None
100
102
} {
101
- state = FindExtend ; // rule GB9/GB9a
102
- continue ;
103
+ state = new_state ;
104
+ continue ;
103
105
}
104
106
105
107
state = match state {
@@ -153,7 +155,14 @@ impl<'a> Iterator for Graphemes<'a> {
153
155
take_curr = false ;
154
156
break ;
155
157
}
156
- }
158
+ } ,
159
+ Zwj => match cat { // rule GB11: ZWJ x (GAZ|EBG)
160
+ gr:: GC_Glue_After_Zwj | gr:: GC_E_Base_GAZ => continue ,
161
+ _ => {
162
+ take_curr = false ;
163
+ break ;
164
+ }
165
+ } ,
157
166
}
158
167
}
159
168
@@ -215,6 +224,8 @@ impl<'a> DoubleEndedIterator for Graphemes<'a> {
215
224
Start | FindExtend => match cat {
216
225
gr:: GC_Extend => FindExtend ,
217
226
gr:: GC_SpacingMark if self . extended => FindExtend ,
227
+ gr:: GC_ZWJ => FindExtend ,
228
+ gr:: GC_Glue_After_Zwj | gr:: GC_E_Base_GAZ => Zwj ,
218
229
gr:: GC_L | gr:: GC_LV | gr:: GC_LVT => HangulL ,
219
230
gr:: GC_V => HangulLV ,
220
231
gr:: GC_T => HangulLVT ,
@@ -255,6 +266,13 @@ impl<'a> DoubleEndedIterator for Graphemes<'a> {
255
266
take_curr = false ;
256
267
break ;
257
268
}
269
+ } ,
270
+ Zwj => match cat { // char to right is (GAZ|EBG)
271
+ gr:: GC_ZWJ => continue , // rule GB11: ZWJ x (GAZ|EBG)
272
+ _ => {
273
+ take_curr = false ;
274
+ break ;
275
+ }
258
276
}
259
277
}
260
278
}
0 commit comments