summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-08-30 11:00:43 -0700
committerbors <bors@rust-lang.org>2013-08-30 11:00:43 -0700
commit0553618e0851eb3b492be79be980a997d22a214f (patch)
treefa2f01c9614f53c4c74beed7948b21d33d0ce5db /src/libstd
parent7077aefb10df0b85e482163047c68baecdae3c05 (diff)
parent15bb9b4e1abf06ada9985effc3ef034d017a4c18 (diff)
downloadrust-0553618e0851eb3b492be79be980a997d22a214f.tar.gz
rust-0553618e0851eb3b492be79be980a997d22a214f.zip
auto merge of #8858 : blake2-ppc/rust/small-bugs, r=alexcrichton
Fix a bug in `s.slice_chars(a, b)` that did not accept `a == s.len()`.

Fix a bug in `!=` defined for DList.

Also simplify NormalizationIterator to use the CharIterator directly instead of mimicing the iteration itself.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/str.rs37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index 3265c470e90..4b01d29a98b 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -621,8 +621,7 @@ enum NormalizationForm {
 #[deriving(Clone)]
 struct NormalizationIterator<'self> {
     priv kind: NormalizationForm,
-    priv index: uint,
-    priv string: &'self str,
+    priv iter: CharIterator<'self>,
     priv buffer: ~[(char, u8)],
     priv sorted: bool
 }
@@ -650,16 +649,17 @@ impl<'self> Iterator<char> for NormalizationIterator<'self> {
             NFKD => char::decompose_compatible
         };
 
-        while !self.sorted && self.index < self.string.len() {
-            let CharRange {ch, next} = self.string.char_range_at(self.index);
-            self.index = next;
-            do decomposer(ch) |d| {
-                let class = canonical_combining_class(d);
-                if class == 0 && !self.sorted {
-                    canonical_sort(self.buffer);
-                    self.sorted = true;
+        if !self.sorted {
+            for ch in self.iter {
+                do decomposer(ch) |d| {
+                    let class = canonical_combining_class(d);
+                    if class == 0 && !self.sorted {
+                        canonical_sort(self.buffer);
+                        self.sorted = true;
+                    }
+                    self.buffer.push((d, class));
                 }
-                self.buffer.push((d, class));
+                if self.sorted { break }
             }
         }
 
@@ -678,7 +678,10 @@ impl<'self> Iterator<char> for NormalizationIterator<'self> {
         }
     }
 
-    fn size_hint(&self) -> (uint, Option<uint>) { (self.string.len(), None) }
+    fn size_hint(&self) -> (uint, Option<uint>) {
+        let (lower, _) = self.iter.size_hint();
+        (lower, None)
+    }
 }
 
 /// Replace all occurrences of one string with another
@@ -1588,8 +1591,7 @@ impl<'self> StrSlice<'self> for &'self str {
     /// Returns the string in Unicode Normalization Form D (canonical decomposition)
     fn nfd_iter(&self) -> NormalizationIterator<'self> {
         NormalizationIterator {
-            index: 0,
-            string: *self,
+            iter: self.iter(),
             buffer: ~[],
             sorted: false,
             kind: NFD
@@ -1599,8 +1601,7 @@ impl<'self> StrSlice<'self> for &'self str {
     /// Returns the string in Unicode Normalization Form KD (compatibility decomposition)
     fn nfkd_iter(&self) -> NormalizationIterator<'self> {
         NormalizationIterator {
-            index: 0,
-            string: *self,
+            iter: self.iter(),
             buffer: ~[],
             sorted: false,
             kind: NFKD
@@ -1672,6 +1673,7 @@ impl<'self> StrSlice<'self> for &'self str {
             if count == end { end_byte = Some(idx); break; }
             count += 1;
         }
+        if begin_byte.is_none() && count == begin { begin_byte = Some(self.len()) }
         if end_byte.is_none() && count == end { end_byte = Some(self.len()) }
 
         match (begin_byte, end_byte) {
@@ -2659,8 +2661,11 @@ mod tests {
         fn t(a: &str, b: &str, start: uint) {
             assert_eq!(a.slice_chars(start, start + b.char_len()), b);
         }
+        t("", "", 0);
         t("hello", "llo", 2);
         t("hello", "el", 1);
+        t("αβλ", "β", 1);
+        t("αβλ", "", 3);
         assert_eq!("ะเทศไท", "ประเทศไทย中华Việt Nam".slice_chars(2, 8));
     }