aboutsummaryrefslogtreecommitdiffstats
path: root/components/util/str.rs
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2015-07-08 05:18:07 +0900
committerCorey Farwell <coreyf@rwell.org>2015-07-08 05:18:07 +0900
commit7159fe749f59931d09cedcffcb3d2ff52432cbcc (patch)
tree5b151f9c95b17e9fcbd7d1066b7c7f467322f7d8 /components/util/str.rs
parentc77b5aa8e21a5b18b078c6a8c4eed194800e3901 (diff)
downloadservo-7159fe749f59931d09cedcffcb3d2ff52432cbcc.tar.gz
servo-7159fe749f59931d09cedcffcb3d2ff52432cbcc.zip
Create and utilize utility for joining strs
Diffstat (limited to 'components/util/str.rs')
-rw-r--r--components/util/str.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/components/util/str.rs b/components/util/str.rs
index b82f46598b7..fe6127e1106 100644
--- a/components/util/str.rs
+++ b/components/util/str.rs
@@ -327,3 +327,11 @@ impl Deref for LowercaseString {
pub unsafe fn c_str_to_string(s: *const c_char) -> String {
from_utf8(CStr::from_ptr(s).to_bytes()).unwrap().to_owned()
}
+
+pub fn str_join<T: AsRef<str>>(strs: &[T], join: &str) -> String {
+ strs.iter().fold(String::new(), |mut acc, s| {
+ if !acc.is_empty() { acc.push_str(join); }
+ acc.push_str(s.as_ref());
+ acc
+ })
+}