From 479aefb6709eaa0ed83253aeab36a553e826c417 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Thu, 29 Aug 2013 17:11:11 +0200 Subject: [PATCH] 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. --- src/libstd/str.rs | 4 ++++ 1 file changed, 4 insertions(+) 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)); }