Skip to content

Commit adf6984

Browse files
authored
Merge pull request #1007 from pbor/more-strv
More strv fixes
2 parents 2d4c666 + ff57484 commit adf6984

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

glib/src/collections/strv.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,14 +856,27 @@ impl StrV {
856856
/// Joins the strings into a longer string, with an optional separator
857857
#[inline]
858858
#[doc(alias = "g_strjoinv")]
859-
pub fn join(self, separator: Option<impl IntoGStr>) -> GString {
859+
pub fn join(&self, separator: Option<impl IntoGStr>) -> GString {
860860
separator.run_with_gstr(|separator| unsafe {
861861
from_glib_full(ffi::g_strjoinv(
862862
separator.to_glib_none().0,
863863
self.ptr.as_ptr(),
864864
))
865865
})
866866
}
867+
868+
// rustdoc-stripper-ignore-next
869+
/// Checks whether the `StrV` contains the specified string
870+
#[inline]
871+
#[doc(alias = "g_strv_contains")]
872+
pub fn contains(&self, s: impl IntoGStr) -> bool {
873+
s.run_with_gstr(|s| unsafe {
874+
from_glib(ffi::g_strv_contains(
875+
self.ptr.as_ptr() as *const _,
876+
s.to_glib_none().0,
877+
))
878+
})
879+
}
867880
}
868881

869882
impl FromGlibContainer<*mut c_char, *mut *mut c_char> for StrV {
@@ -1474,4 +1487,30 @@ mod test {
14741487
assert_eq!(s, items);
14751488
});
14761489
}
1490+
1491+
#[test]
1492+
fn test_join() {
1493+
let items = [
1494+
crate::gstr!("str1"),
1495+
crate::gstr!("str2"),
1496+
crate::gstr!("str3"),
1497+
];
1498+
1499+
let strv = StrV::from(&items[..]);
1500+
assert_eq!(strv.join(None::<&str>), "str1str2str3");
1501+
assert_eq!(strv.join(Some(",")), "str1,str2,str3");
1502+
}
1503+
1504+
#[test]
1505+
fn test_contains() {
1506+
let items = [
1507+
crate::gstr!("str1"),
1508+
crate::gstr!("str2"),
1509+
crate::gstr!("str3"),
1510+
];
1511+
1512+
let strv = StrV::from(&items[..]);
1513+
assert!(strv.contains("str2"));
1514+
assert!(!strv.contains("str4"));
1515+
}
14771516
}

0 commit comments

Comments
 (0)