[Telepathy-commits] [telepathy-glib/master] Add tp_strv_contains() utility function.
Will Thompson
will.thompson at collabora.co.uk
Wed Sep 3 07:37:31 PDT 2008
---
docs/reference/telepathy-glib-sections.txt | 1 +
telepathy-glib/util.c | 28 ++++++++++++++++++++++++++++
telepathy-glib/util.h | 2 ++
tests/test-util.c | 17 +++++++++++++++++
4 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 7419eda..8b60806 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -849,6 +849,7 @@ tp_g_value_slice_dup
tp_strdiff
tp_mixin_offset_cast
tp_escape_as_identifier
+tp_strv_contains
</SECTION>
<SECTION>
diff --git a/telepathy-glib/util.c b/telepathy-glib/util.c
index adc66ae..d7dd07c 100644
--- a/telepathy-glib/util.c
+++ b/telepathy-glib/util.c
@@ -297,3 +297,31 @@ tp_escape_as_identifier (const gchar *name)
}
return g_string_free (op, FALSE);
}
+
+
+/**
+ * tp_strv_contains:
+ * @strv: a NULL-terminated array of strings
+ * @str: a non-NULL string
+ *
+ * <!-- -->
+ * Returns: TRUE if @str is an element of @strv, according to strcmp().
+ *
+ * Since: 0.7.UNRELEASED
+ */
+gboolean
+tp_strv_contains (const gchar * const *strv,
+ const gchar *str)
+{
+ g_return_val_if_fail (str != NULL, FALSE);
+ g_return_val_if_fail (strv != NULL, FALSE);
+
+ while (*strv != NULL)
+ {
+ if (!strcmp (str, *strv))
+ return TRUE;
+ strv++;
+ }
+
+ return FALSE;
+}
diff --git a/telepathy-glib/util.h b/telepathy-glib/util.h
index 1927f83..bb65978 100644
--- a/telepathy-glib/util.h
+++ b/telepathy-glib/util.h
@@ -44,6 +44,8 @@ gpointer tp_mixin_offset_cast (gpointer instance, guint offset);
gchar *tp_escape_as_identifier (const gchar *name);
+gboolean tp_strv_contains (const gchar * const *strv, const gchar *str);
+
G_END_DECLS
#endif /* __TP_UTIL_H__ */
diff --git a/tests/test-util.c b/tests/test-util.c
index 7236e0f..e350718 100644
--- a/tests/test-util.c
+++ b/tests/test-util.c
@@ -4,6 +4,23 @@
#include <telepathy-glib/util.h>
+void test_strv_contains (void);
+
+void
+test_strv_contains (void)
+{
+ const gchar * const strv[] = {
+ "Pah",
+ "Pah",
+ "Pah-pah-pah",
+ "Patrick!",
+ NULL
+ };
+
+ g_assert (tp_strv_contains (strv, "Patrick!"));
+ g_assert (!tp_strv_contains (strv, "Snakes!"));
+}
+
int main (int argc, char **argv)
{
GPtrArray *ptrarray;
--
1.5.6.3
More information about the Telepathy-commits
mailing list