about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorblake2-ppc <blake2-ppc>2013-08-29 17:11:11 +0200
committerblake2-ppc <blake2-ppc>2013-08-29 17:11:11 +0200
commit479aefb6709eaa0ed83253aeab36a553e826c417 (patch)
tree19e836910c7f817529eafef7daab172c528cea8e /src/libstd
parentd8801ceabcf039708e448e07460f859d60771e18 (diff)
downloadrust-479aefb6709eaa0ed83253aeab36a553e826c417.tar.gz
rust-479aefb6709eaa0ed83253aeab36a553e826c417.zip
std::str: Fix bug in .slice_chars()
`s.slice_chars(a, b)` did not allow the case where `a == s.len()`, this
is a bug I introduced last time I touched the method; add a test for
this case.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/str.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index 750f5acaf2a..802fb0e4b99 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -1713,6 +1713,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) {
@@ -2700,8 +2701,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));
     }