Skip to content

Commit 479aefb

Browse files
author
blake2-ppc
committed
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.
1 parent d8801ce commit 479aefb

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/libstd/str.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,7 @@ impl<'self> StrSlice<'self> for &'self str {
17131713
if count == end { end_byte = Some(idx); break; }
17141714
count += 1;
17151715
}
1716+
if begin_byte.is_none() && count == begin { begin_byte = Some(self.len()) }
17161717
if end_byte.is_none() && count == end { end_byte = Some(self.len()) }
17171718
17181719
match (begin_byte, end_byte) {
@@ -2700,8 +2701,11 @@ mod tests {
27002701
fn t(a: &str, b: &str, start: uint) {
27012702
assert_eq!(a.slice_chars(start, start + b.char_len()), b);
27022703
}
2704+
t("", "", 0);
27032705
t("hello", "llo", 2);
27042706
t("hello", "el", 1);
2707+
t("αβλ", "β", 1);
2708+
t("αβλ", "", 3);
27052709
assert_eq!("ะเทศไท", "ประเทศไทย中华Việt Nam".slice_chars(2, 8));
27062710
}
27072711

0 commit comments

Comments
 (0)