diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-09-30 19:34:44 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-09-30 19:34:44 -0600 |
commit | 520c907742afbb94085c6b5e62156a5457530010 (patch) | |
tree | b2d58d3e53995a3d9f25d74df015a16f7d132eff /components/util/str.rs | |
parent | 94e85a5226fe5b18bde40a2d5f6727b717bd148f (diff) | |
parent | ea5e4e3ad000c1552ec7c2739f84af61a33b1acc (diff) | |
download | servo-520c907742afbb94085c6b5e62156a5457530010.tar.gz servo-520c907742afbb94085c6b5e62156a5457530010.zip |
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 -->
Diffstat (limited to 'components/util/str.rs')
-rw-r--r-- | components/util/str.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/components/util/str.rs b/components/util/str.rs index 78a444be094..e2759e936d6 100644 --- a/components/util/str.rs +++ b/components/util/str.rs @@ -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 }) |