@@ -621,8 +621,7 @@ enum NormalizationForm {
621
621
#[ deriving( Clone ) ]
622
622
struct NormalizationIterator < ' self > {
623
623
priv kind : NormalizationForm ,
624
- priv index : uint ,
625
- priv string : & ' self str ,
624
+ priv iter : CharIterator < ' self > ,
626
625
priv buffer : ~[ ( char , u8 ) ] ,
627
626
priv sorted : bool
628
627
}
@@ -650,16 +649,17 @@ impl<'self> Iterator<char> for NormalizationIterator<'self> {
650
649
NFKD => char:: decompose_compatible
651
650
} ;
652
651
653
- while !self . sorted && self . index < self . string . len ( ) {
654
- let CharRange { ch, next} = self . string . char_range_at ( self . index ) ;
655
- self . index = next;
656
- do decomposer( ch) |d| {
657
- let class = canonical_combining_class ( d) ;
658
- if class == 0 && !self . sorted {
659
- canonical_sort ( self . buffer ) ;
660
- self . sorted = true ;
652
+ if !self . sorted {
653
+ for ch in self . iter {
654
+ do decomposer ( ch) |d| {
655
+ let class = canonical_combining_class ( d) ;
656
+ if class == 0 && !self . sorted {
657
+ canonical_sort ( self . buffer ) ;
658
+ self . sorted = true ;
659
+ }
660
+ self . buffer . push ( ( d, class) ) ;
661
661
}
662
- self . buffer . push ( ( d , class ) ) ;
662
+ if self . sorted { break }
663
663
}
664
664
}
665
665
@@ -678,7 +678,10 @@ impl<'self> Iterator<char> for NormalizationIterator<'self> {
678
678
}
679
679
}
680
680
681
- fn size_hint ( & self ) -> ( uint , Option < uint > ) { ( self . string . len ( ) , None ) }
681
+ fn size_hint ( & self ) -> ( uint , Option < uint > ) {
682
+ let ( lower, _) = self . iter . size_hint ( ) ;
683
+ ( lower, None )
684
+ }
682
685
}
683
686
684
687
/// Replace all occurrences of one string with another
@@ -1628,8 +1631,7 @@ impl<'self> StrSlice<'self> for &'self str {
1628
1631
/// Returns the string in Unicode Normalization Form D (canonical decomposition)
1629
1632
fn nfd_iter(&self) -> NormalizationIterator<'self> {
1630
1633
NormalizationIterator {
1631
- index: 0,
1632
- string: *self,
1634
+ iter: self.iter(),
1633
1635
buffer: ~[],
1634
1636
sorted: false,
1635
1637
kind: NFD
@@ -1639,8 +1641,7 @@ impl<'self> StrSlice<'self> for &'self str {
1639
1641
/// Returns the string in Unicode Normalization Form KD (compatibility decomposition)
1640
1642
fn nfkd_iter(&self) -> NormalizationIterator<'self> {
1641
1643
NormalizationIterator {
1642
- index: 0,
1643
- string: *self,
1644
+ iter: self.iter(),
1644
1645
buffer: ~[],
1645
1646
sorted: false,
1646
1647
kind: NFKD
0 commit comments