Skip to content

Commit

Permalink
strv: add join() method
Browse files Browse the repository at this point in the history
  • Loading branch information
pbor committed Feb 13, 2023
1 parent 9839ec6 commit 877d0bc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion glib/src/collections/strv.rs
Expand Up @@ -2,7 +2,7 @@

use std::{ffi::c_char, fmt, marker::PhantomData, mem, ptr};

use crate::{translate::*, GStr, GString, GStringPtr};
use crate::{translate::*, GStr, GString, GStringPtr, IntoGStr, IntoOptionalGStr};

// rustdoc-stripper-ignore-next
/// Minimum size of the `StrV` allocation.
Expand Down Expand Up @@ -851,6 +851,18 @@ impl StrV {
}
}
}

// rustdoc-stripper-ignore-next
/// Joins the strings into a longer string, with an optional separator
#[inline]
pub fn join(self, separator: Option<impl IntoGStr>) -> GString {
separator.run_with_gstr(|separator| unsafe {
from_glib_full(ffi::g_strjoinv(
separator.to_glib_none().0,
self.ptr.as_ptr(),
))
})
}
}

impl FromGlibContainer<*mut c_char, *mut *mut c_char> for StrV {
Expand Down

0 comments on commit 877d0bc

Please sign in to comment.