Skip to content

Commit

Permalink
Implement new rule WB14 (Emoji modifier sequences)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrubeck committed Dec 13, 2016
1 parent d9b17e5 commit 624aba4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ enum UWordBoundsState {
Regional,
FormatExtend(FormatExtendType),
Zwj,
Emoji,
}

// subtypes for FormatExtend state in UWordBoundsState
Expand Down Expand Up @@ -163,6 +164,7 @@ impl<'a> Iterator for UWordBounds<'a> {
wd::WC_Regional_Indicator => Regional, // rule WB13c
wd::WC_LF | wd::WC_Newline => break, // rule WB3a
wd::WC_ZWJ => Zwj, // rule WB3c
wd::WC_E_Base | wd::WC_E_Base_GAZ => Emoji, // rule WB14
_ => {
if let Some(ncat) = self.get_next_cat(idx) { // rule WB4
if ncat == wd::WC_Format || ncat == wd::WC_Extend || ncat == wd::WC_ZWJ {
Expand Down Expand Up @@ -245,6 +247,13 @@ impl<'a> Iterator for UWordBounds<'a> {
break;
}
},
Emoji => match cat { // rule WB14
wd::WC_E_Modifier => continue,
_ => {
take_curr = false;
break;
}
},
FormatExtend(t) => match t { // handle FormatExtends depending on what type
RequireNumeric if cat == wd::WC_Numeric => Numeric, // rule WB11
RequireLetter | AcceptQLetter if cat == wd::WC_ALetter => Letter, // rule WB7
Expand Down Expand Up @@ -355,6 +364,7 @@ impl<'a> DoubleEndedIterator for UWordBounds<'a> {
saveidx = idx;
FormatExtend(AcceptQLetter) // rule WB7a
},
wd::WC_E_Modifier => Emoji, // rule WB14
wd::WC_CR | wd::WC_LF | wd::WC_Newline => {
if state == Start {
if cat == wd::WC_LF {
Expand Down Expand Up @@ -435,6 +445,13 @@ impl<'a> DoubleEndedIterator for UWordBounds<'a> {
break;
}
},
Emoji => match cat { // rule WB14
wd::WC_E_Base | wd::WC_E_Base_GAZ => continue,
_ => {
take_curr = false;
break;
}
},
FormatExtend(t) => match t {
RequireNumeric if cat == wd::WC_Numeric => Numeric, // rule WB12
RequireLetter if cat == wd::WC_ALetter => Letter, // rule WB6
Expand Down

0 comments on commit 624aba4

Please sign in to comment.