Auto merge of #7806 - frewsxcv:consistent-str-join, r=mbrubeck

Make util::str::str_join consistent with SliceConcatExt::join

Prior to this commit, `str_join` would skip empty items at the start of
the `Iterator` until it found a non-empty item. This contradicts
`SliceConcatExt::join` which doesn't skip anything.

Brought up in:

https://github.com/servo/servo/pull/7776#issuecomment-144317281

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7806)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-09-30 19:34:44 -06:00
commit 520c907742
2 changed files with 27 additions and 3 deletions

View file

@ -329,8 +329,8 @@ pub unsafe fn c_str_to_string(s: *const c_char) -> String {
pub fn str_join<I, T>(strs: I, join: &str) -> String
where I: IntoIterator<Item=T>, T: AsRef<str>,
{
strs.into_iter().fold(String::new(), |mut acc, s| {
if !acc.is_empty() { acc.push_str(join); }
strs.into_iter().enumerate().fold(String::new(), |mut acc, (i, s)| {
if i > 0 { acc.push_str(join); }
acc.push_str(s.as_ref());
acc
})