[gnome-photos] Add photos_utils_set_string



commit bcee906aebbab6fea7ca58d6e2d31bf46261b8c0
Author: Debarshi Ray <debarshir gnome org>
Date:   Sat Jul 9 14:33:00 2016 +0200

    Add photos_utils_set_string
    
    This is similar to g_set_object, but for C strings.
    
    Based on an implementation by Emmanuele Bassi.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768548

 src/photos-utils.c |   23 +++++++++++++++++++++++
 src/photos-utils.h |    2 ++
 2 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 0e5951a..1fc46d9 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -1450,3 +1450,26 @@ photos_utils_set_favorite (const gchar *urn, gboolean is_favorite)
   g_free (sparql);
   g_clear_object (&queue);
 }
+
+
+gboolean
+photos_utils_set_string (gchar **string_ptr, const gchar *new_string)
+{
+  gboolean ret_val = FALSE;
+
+  g_return_val_if_fail (string_ptr != NULL, FALSE);
+
+  if (*string_ptr == new_string)
+    goto out;
+
+  if (g_strcmp0 (*string_ptr, new_string) == 0)
+    goto out;
+
+  g_free (*string_ptr);
+  *string_ptr = g_strdup (new_string);
+
+  ret_val = TRUE;
+
+ out:
+  return ret_val;
+}
diff --git a/src/photos-utils.h b/src/photos-utils.h
index b788e4d..184ecff 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -176,6 +176,8 @@ void             photos_utils_set_edited_name             (const gchar *urn, con
 
 void             photos_utils_set_favorite                (const gchar *urn, gboolean is_favorite);
 
+gboolean         photos_utils_set_string                  (gchar **string_ptr, const gchar *new_string);
+
 G_END_DECLS
 
 #endif /* PHOTOS_UTILS_H */


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