mirror of
https://github.com/openharmony/third_party_rust_unicode-normalization.git
synced 2026-07-19 23:13:33 -04:00
restore done field to Decompositions
This commit is contained in:
+13
-5
@@ -33,25 +33,31 @@ pub struct Decompositions<I> {
|
||||
// to sort in canonical order and is not safe to emit.
|
||||
buffer: SmallVec<[(u8, char); 4]>,
|
||||
ready: Range<usize>,
|
||||
|
||||
// The only purpose of this field is to prevent us calling `next` on an
|
||||
// exhausted iterator; otherwise it would be redundant.
|
||||
done: bool,
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new_canonical<I: Iterator<Item=char>>(iter: I) -> Decompositions<I> {
|
||||
pub fn new_canonical<I: Iterator<Item = char>>(iter: I) -> Decompositions<I> {
|
||||
Decompositions {
|
||||
kind: self::DecompositionType::Canonical,
|
||||
iter: iter,
|
||||
buffer: SmallVec::new(),
|
||||
ready: 0..0,
|
||||
done: false,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new_compatible<I: Iterator<Item=char>>(iter: I) -> Decompositions<I> {
|
||||
pub fn new_compatible<I: Iterator<Item = char>>(iter: I) -> Decompositions<I> {
|
||||
Decompositions {
|
||||
kind: self::DecompositionType::Compatible,
|
||||
iter: iter,
|
||||
buffer: SmallVec::new(),
|
||||
ready: 0..0,
|
||||
done: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,13 +104,14 @@ impl<I> Decompositions<I> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Iterator<Item=char>> Iterator for Decompositions<I> {
|
||||
impl<I: Iterator<Item = char>> Iterator for Decompositions<I> {
|
||||
type Item = char;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<char> {
|
||||
while self.ready.end == 0 {
|
||||
match (self.iter.next(), &self.kind) {
|
||||
let next = if self.done { None } else { self.iter.next() };
|
||||
match (next, &self.kind) {
|
||||
(Some(ch), &DecompositionType::Canonical) => {
|
||||
super::char::decompose_canonical(ch, |d| self.push_back(d));
|
||||
}
|
||||
@@ -116,6 +123,7 @@ impl<I: Iterator<Item=char>> Iterator for Decompositions<I> {
|
||||
return None;
|
||||
} else {
|
||||
self.sort_pending();
|
||||
self.done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -133,7 +141,7 @@ impl<I: Iterator<Item=char>> Iterator for Decompositions<I> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Iterator<Item=char> + Clone> fmt::Display for Decompositions<I> {
|
||||
impl<I: Iterator<Item = char> + Clone> fmt::Display for Decompositions<I> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
for c in self.clone() {
|
||||
f.write_char(c)?;
|
||||
|
||||
Reference in New Issue
Block a user