From 4acb5e9bb66dd033823871c012913dc686a71535 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 27 Dec 2016 10:03:26 -0800 Subject: [PATCH] Fix a bug in Prepend handling The state was not updated correctly for the char after the Prepend. --- Cargo.toml | 2 +- src/grapheme.rs | 14 +++++--------- src/test.rs | 5 +++++ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8cdfc64..aee86b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "unicode-segmentation" -version = "1.0.0" +version = "1.0.1" authors = ["kwantam "] homepage = "https://github.com/unicode-rs/unicode-segmentation" diff --git a/src/grapheme.rs b/src/grapheme.rs index f922c3c..fed1777 100644 --- a/src/grapheme.rs +++ b/src/grapheme.rs @@ -125,8 +125,11 @@ impl<'a> Iterator for Graphemes<'a> { } break; // rule GB4 } - Start => match cat { - gr::GC_Control => break, + Start | Prepend => match cat { + gr::GC_Control => { // rule GB5 + take_curr = state == Start; + break; + } gr::GC_L => HangulL, gr::GC_LV | gr::GC_V => HangulLV, gr::GC_LVT | gr::GC_T => HangulLVT, @@ -163,13 +166,6 @@ impl<'a> Iterator for Graphemes<'a> { break; } }, - Prepend => match cat { // rule GB9b - gr::GC_Control => { - take_curr = false; - break; - } - _ => continue - }, Regional => match cat { // rule GB12/GB13 gr::GC_Regional_Indicator => FindExtend, _ => { diff --git a/src/test.rs b/src/test.rs index 70e0aa9..42cb205 100644 --- a/src/test.rs +++ b/src/test.rs @@ -23,6 +23,11 @@ fn test_graphemes() { ("\u{20}\u{600}\u{600}\u{20}", &["\u{20}", "\u{600}\u{600}\u{20}"], &["\u{20}", "\u{600}", "\u{600}", "\u{20}"]), + + // Test for Prepend followed by two Any chars + ("\u{600}\u{20}\u{20}", + &["\u{600}\u{20}", "\u{20}"], + &["\u{600}", "\u{20}", "\u{20}"]), ]; for &(s, g) in TEST_SAME {