mirror of
https://github.com/servo/servo.git
synced 2025-08-01 11:40:30 +01:00
Create and utilize utility for joining strs
This commit is contained in:
parent
c77b5aa8e2
commit
7159fe749f
3 changed files with 12 additions and 12 deletions
|
@ -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
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue