[gnome-color-manager] Add a utility function to convert a GPtrArray to a GStrv



commit ee1572a29b50c9a8b7bbe17136dd2781cd533dc0
Author: Richard Hughes <richard hughsie com>
Date:   Sun Nov 1 12:33:09 2009 +0000

    Add a utility function to convert a GPtrArray to a GStrv

 src/gcm-utils.c |   28 ++++++++++++++++++++++++++++
 src/gcm-utils.h |    1 +
 2 files changed, 29 insertions(+), 0 deletions(-)
---
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 6f1d71e..0864e61 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -367,3 +367,31 @@ gcm_utils_get_profile_destination (const gchar *filename)
 	return destination;
 }
 
+/**
+ * gcm_utils_ptr_array_to_strv:
+ * @array: the GPtrArray of strings
+ *
+ * Form a composite string array of strings.
+ * The data in the GPtrArray is copied.
+ *
+ * Return value: the string array, or %NULL if invalid
+ **/
+gchar **
+gcm_utils_ptr_array_to_strv (GPtrArray *array)
+{
+	gchar **value;
+	const gchar *value_temp;
+	guint i;
+
+	g_return_val_if_fail (array != NULL, NULL);
+
+	/* copy the array to a strv */
+	value = g_new0 (gchar *, array->len + 1);
+	for (i=0; i<array->len; i++) {
+		value_temp = (const gchar *) g_ptr_array_index (array, i);
+		value[i] = g_strdup (value_temp);
+	}
+
+	return value;
+}
+
diff --git a/src/gcm-utils.h b/src/gcm-utils.h
index 59d488b..86151fa 100644
--- a/src/gcm-utils.h
+++ b/src/gcm-utils.h
@@ -49,6 +49,7 @@ gboolean	 gcm_utils_mkdir_and_copy		(const gchar		*source,
 							 const gchar		*destination,
 							 GError			**error);
 gchar		*gcm_utils_get_profile_destination	(const gchar		*filename);
+gchar		**gcm_utils_ptr_array_to_strv		(GPtrArray		*array);
 
 #endif /* __GCM_UTILS_H */
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]