return matched;
}
+
+/**
+ * g_strv_contains:
+ * @strv: a %NULL-terminated array of strings
+ * @str: a string
+ *
+ * Checks if @strv contains @str. @strv must not be %NULL.
+ *
+ * Returns: %TRUE if @str is an element of @strv, according to g_str_equal().
+ *
+ * Since: 2.44
+ */
+gboolean
+g_strv_contains (const gchar * const *strv,
+ const gchar *str)
+{
+ g_return_val_if_fail (strv != NULL, FALSE);
+ g_return_val_if_fail (str != NULL, FALSE);
+
+ for (; *strv != NULL; strv++)
+ {
+ if (g_str_equal (str, *strv))
+ return TRUE;
+ }
+
+ return FALSE;
+}
const gchar *potential_hit,
gboolean accept_alternates);
+GLIB_AVAILABLE_IN_2_44
+gboolean g_strv_contains (const gchar * const *strv,
+ const gchar *str);
+
G_END_DECLS
#endif /* __G_STRFUNCS_H__ */
g_free (out);
}
+static void
+test_strv_contains (void)
+{
+ static const gchar *strv_simple[] = { "hello", "there", NULL };
+ static const gchar *strv_dupe[] = { "dupe", "dupe", NULL };
+ static const gchar *strv_empty[] = { NULL };
+
+ g_assert_true (g_strv_contains (strv_simple, "hello"));
+ g_assert_true (g_strv_contains (strv_simple, "there"));
+ g_assert_false (g_strv_contains (strv_simple, "non-existent"));
+ g_assert_false (g_strv_contains (strv_simple, ""));
+
+ g_assert_true (g_strv_contains (strv_dupe, "dupe"));
+
+ g_assert_false (g_strv_contains (strv_empty, "empty!"));
+ g_assert_false (g_strv_contains (strv_empty, ""));
+}
+
int
main (int argc,
char *argv[])
g_test_add_func ("/strfuncs/strsignal", test_strsignal);
g_test_add_func ("/strfuncs/strup", test_strup);
g_test_add_func ("/strfuncs/transliteration", test_transliteration);
+ g_test_add_func ("/strfuncs/strv-contains", test_strv_contains);
return g_test_run();
}