[evolution-data-server] Provide EClient's GSList utility functions within e-data-server-util.h
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Provide EClient's GSList utility functions within e-data-server-util.h
- Date: Mon, 3 Oct 2011 12:17:22 +0000 (UTC)
commit 0f174bd6e37fa03c3c9894215b78d520e1ec1e0d
Author: Milan Crha <mcrha redhat com>
Date: Mon Oct 3 14:15:57 2011 +0200
Provide EClient's GSList utility functions within e-data-server-util.h
libedataserver/e-client.c | 61 ++------------
libedataserver/e-data-server-util.c | 154 +++++++++++++++++++++++++++++++++++
libedataserver/e-data-server-util.h | 7 ++
3 files changed, 169 insertions(+), 53 deletions(-)
---
diff --git a/libedataserver/e-client.c b/libedataserver/e-client.c
index 1d7879c..a0e4a6d 100644
--- a/libedataserver/e-client.c
+++ b/libedataserver/e-client.c
@@ -26,6 +26,8 @@
#include <glib/gi18n-lib.h>
#include <gio/gio.h>
+#include <libedataserver/e-data-server-util.h>
+
#include "e-gdbus-marshallers.h"
#include "e-client.h"
@@ -1657,22 +1659,7 @@ e_client_refresh_sync (EClient *client,
gchar **
e_client_util_slist_to_strv (const GSList *strings)
{
- const GSList *iter;
- GPtrArray *array;
-
- array = g_ptr_array_sized_new (g_slist_length ((GSList *) strings) + 1);
-
- for (iter = strings; iter; iter = iter->next) {
- const gchar *str = iter->data;
-
- if (str)
- g_ptr_array_add (array, g_strdup (str));
- }
-
- /* NULL-terminated */
- g_ptr_array_add (array, NULL);
-
- return (gchar **) g_ptr_array_free (array, FALSE);
+ return e_util_slist_to_strv (strings);
}
/**
@@ -1691,17 +1678,7 @@ e_client_util_slist_to_strv (const GSList *strings)
GSList *
e_client_util_strv_to_slist (const gchar * const *strv)
{
- GSList *slist = NULL;
- gint ii;
-
- if (!strv)
- return NULL;
-
- for (ii = 0; strv[ii]; ii++) {
- slist = g_slist_prepend (slist, g_strdup (strv[ii]));
- }
-
- return g_slist_reverse (slist);
+ return e_util_strv_to_slist (strv);
}
/**
@@ -1720,14 +1697,7 @@ GSList *
e_client_util_copy_string_slist (GSList *copy_to,
const GSList *strings)
{
- GSList *res = copy_to;
- const GSList *iter;
-
- for (iter = strings; iter; iter = iter->next) {
- res = g_slist_append (res, g_strdup (iter->data));
- }
-
- return res;
+ return e_util_copy_string_slist (copy_to, strings);
}
/**
@@ -1746,14 +1716,7 @@ GSList *
e_client_util_copy_object_slist (GSList *copy_to,
const GSList *objects)
{
- GSList *res = copy_to;
- const GSList *iter;
-
- for (iter = objects; iter; iter = iter->next) {
- res = g_slist_append (res, g_object_ref (iter->data));
- }
-
- return res;
+ return e_util_copy_object_slist (copy_to, objects);
}
/**
@@ -1767,11 +1730,7 @@ e_client_util_copy_object_slist (GSList *copy_to,
void
e_client_util_free_string_slist (GSList *strings)
{
- if (!strings)
- return;
-
- g_slist_foreach (strings, (GFunc) g_free, NULL);
- g_slist_free (strings);
+ e_util_free_string_slist (strings);
}
/**
@@ -1786,11 +1745,7 @@ e_client_util_free_string_slist (GSList *strings)
void
e_client_util_free_object_slist (GSList *objects)
{
- if (!objects)
- return;
-
- g_slist_foreach (objects, (GFunc) g_object_unref, NULL);
- g_slist_free (objects);
+ e_util_free_object_slist (objects);
}
/**
diff --git a/libedataserver/e-data-server-util.c b/libedataserver/e-data-server-util.c
index e5269b3..764fa09 100644
--- a/libedataserver/e-data-server-util.c
+++ b/libedataserver/e-data-server-util.c
@@ -38,6 +38,8 @@
#include <mbstring.h>
#endif
+#include <glib-object.h>
+
#include "e-data-server-util.h"
/**
@@ -789,6 +791,158 @@ e_filename_mkdir_encoded (const gchar *basepath, const gchar *fileprefix, const
return res;
}
+/**
+ * e_util_slist_to_strv:
+ * @strings: a #GSList of strings (const gchar *)
+ *
+ * Convert list of strings into NULL-terminates array of strings.
+ *
+ * Returns: (transfer full): Newly allocated NULL-terminated array of strings.
+ * Returned pointer should be freed with g_strfreev().
+ *
+ * Note: Pair function for this is e_util_strv_to_slist().
+ *
+ * Since: 3.4
+ **/
+gchar **
+e_util_slist_to_strv (const GSList *strings)
+{
+ const GSList *iter;
+ GPtrArray *array;
+
+ array = g_ptr_array_sized_new (g_slist_length ((GSList *) strings) + 1);
+
+ for (iter = strings; iter; iter = iter->next) {
+ const gchar *str = iter->data;
+
+ if (str)
+ g_ptr_array_add (array, g_strdup (str));
+ }
+
+ /* NULL-terminated */
+ g_ptr_array_add (array, NULL);
+
+ return (gchar **) g_ptr_array_free (array, FALSE);
+}
+
+/**
+ * e_util_strv_to_slist:
+ * @strv: a NULL-terminated array of strings (const gchar *)
+ *
+ * Convert NULL-terminated array of strings to a list of strings.
+ *
+ * Returns: (transfer full): Newly allocated #GSList of newly allocated strings.
+ * Returned pointer should be freed with e_util_free_string_slist().
+ *
+ * Note: Pair function for this is e_util_slist_to_strv().
+ *
+ * Since: 3.4
+ **/
+GSList *
+e_util_strv_to_slist (const gchar * const *strv)
+{
+ GSList *slist = NULL;
+ gint ii;
+
+ if (!strv)
+ return NULL;
+
+ for (ii = 0; strv[ii]; ii++) {
+ slist = g_slist_prepend (slist, g_strdup (strv[ii]));
+ }
+
+ return g_slist_reverse (slist);
+}
+
+/**
+ * e_util_copy_string_slist:
+ * @copy_to: Where to copy; can be NULL
+ * @strings: GSList of strings to be copied
+ *
+ * Copies GSList of strings at the end of @copy_to.
+ *
+ * Returns: (transfer full): New head of @copy_to.
+ * Returned pointer can be freed with e_util_free_string_slist().
+ *
+ * Since: 3.4
+ **/
+GSList *
+e_util_copy_string_slist (GSList *copy_to,
+ const GSList *strings)
+{
+ GSList *res = copy_to;
+ const GSList *iter;
+
+ for (iter = strings; iter; iter = iter->next) {
+ res = g_slist_append (res, g_strdup (iter->data));
+ }
+
+ return res;
+}
+
+/**
+ * e_util_copy_object_slist:
+ * @copy_to: Where to copy; can be NULL
+ * @objects: GSList of GObject-s to be copied
+ *
+ * Copies GSList of GObject-s at the end of @copy_to.
+ *
+ * Returns: (transfer full): New head of @copy_to.
+ * Returned pointer can be freed with e_util_free_object_slist().
+ *
+ * Since: 3.4
+ **/
+GSList *
+e_util_copy_object_slist (GSList *copy_to,
+ const GSList *objects)
+{
+ GSList *res = copy_to;
+ const GSList *iter;
+
+ for (iter = objects; iter; iter = iter->next) {
+ res = g_slist_append (res, g_object_ref (iter->data));
+ }
+
+ return res;
+}
+
+/**
+ * e_util_free_string_slist:
+ * @strings: a #GSList of strings (gchar *)
+ *
+ * Frees memory previously allocated by e_util_strv_to_slist().
+ *
+ * Since: 3.4
+ **/
+void
+e_util_free_string_slist (GSList *strings)
+{
+ if (!strings)
+ return;
+
+ g_slist_foreach (strings, (GFunc) g_free, NULL);
+ g_slist_free (strings);
+}
+
+/**
+ * e_util_free_object_slist:
+ * @objects: a #GSList of #GObject-s
+ *
+ * Calls g_object_unref() on each member of @objects and then frees
+ * also @objects itself.
+ *
+ * Since: 3.4
+ **/
+void
+e_util_free_object_slist (GSList *objects)
+{
+ if (!objects)
+ return;
+
+ g_slist_foreach (objects, (GFunc) g_object_unref, NULL);
+ g_slist_free (objects);
+}
+
#ifdef G_OS_WIN32
#include <windows.h>
diff --git a/libedataserver/e-data-server-util.h b/libedataserver/e-data-server-util.h
index 9feeedc..8162b0c 100644
--- a/libedataserver/e-data-server-util.h
+++ b/libedataserver/e-data-server-util.h
@@ -63,6 +63,13 @@ gsize e_strftime (gchar *string,
const gchar *fmt,
const struct tm *tm);
+gchar ** e_util_slist_to_strv (const GSList *strings);
+GSList * e_util_strv_to_slist (const gchar * const *strv);
+GSList * e_util_copy_string_slist (GSList *copy_to, const GSList *strings);
+GSList * e_util_copy_object_slist (GSList *copy_to, const GSList *objects);
+void e_util_free_string_slist (GSList *strings);
+void e_util_free_object_slist (GSList *objects);
+
#ifdef G_OS_WIN32
const gchar * e_util_get_prefix (void) G_GNUC_CONST;
const gchar * e_util_get_cp_prefix (void) G_GNUC_CONST;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]