8000 Merge pull request #62 from unicode-rs/streamsafe-reset · unicode-rs/unicode-normalization@c243fee · GitHub
[go: up one dir, main page]

Skip to content

Commit c243fee

Browse files
authored
Merge pull request #62 from unicode-rs/streamsafe-reset
Correctly reset streamsafe iterator
2 parents e9580ff + a558091 commit c243fee

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/stream_safe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<I: Iterator<Item = char>> Iterator for StreamSafe<I> {
4242
let d = classify_nonstarters(next_ch);
4343
if self.nonstarter_count + d.leading_nonstarters > MAX_NONSTARTERS {
4444
self.buffer = Some(next_ch);
45-
self.nonstarter_count = 0;
45+
self.nonstarter_count += d.decomposition_len;
4646
return Some(COMBINING_GRAPHEME_JOINER);
4747
}
4848

tests/test_streamsafe_regression.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use unicode_normalization::{
2+
char::canonical_combining_class, is_nfc, is_nfc_stream_safe, UnicodeNormalization,
3+
};
4+
5+
#[test]
6+
fn test_streamsafe_regression(){
7+
let input = "\u{342}".repeat(55) + &"\u{344}".repeat(3);
8+
let nfc_ss = input.chars().nfc().stream_safe().collect::<String>();
9+
10+
// The result should be NFC:
11+
assert!(is_nfc(&nfc_ss));
12+
// and should be stream-safe:
13+
assert!(is_nfc_stream_safe(&nfc_ss))
14+
}

0 commit comments

Comments
 (0)
0