[gexiv2] Purge duplicates from gexiv2_metadata_get_iptc_tags() return value



commit c12fb8745e39ef665d88587e9a131f124d469953
Author: postscript-dev <43813-postscript-dev users noreply gitlab gnome org>
Date:   Sat Nov 14 18:16:43 2020 +0000

    Purge duplicates from gexiv2_metadata_get_iptc_tags() return value
    
    - Added comment to documentation explaining that:
    ```c
    gexiv2_metadata_get_exif_tags ()
    gexiv2_metadata_get_xmp_tags ()
    gexiv2_metadata_get_iptc_tags ()
    ```
    only return unique list of tags.
    
    - Fixed spelling mistake.

 gexiv2/gexiv2-metadata-iptc.cpp | 35 +++++++++++++++++++----------------
 gexiv2/gexiv2-metadata.h        |  8 ++++----
 2 files changed, 23 insertions(+), 20 deletions(-)
---
diff --git a/gexiv2/gexiv2-metadata-iptc.cpp b/gexiv2/gexiv2-metadata-iptc.cpp
index 24de73b..aae654f 100644
--- a/gexiv2/gexiv2-metadata-iptc.cpp
+++ b/gexiv2/gexiv2-metadata-iptc.cpp
@@ -67,33 +67,36 @@ void gexiv2_metadata_clear_iptc (GExiv2Metadata *self) {
     self->priv->image->iptcData().clear ();
 }
 
-gchar** gexiv2_metadata_get_iptc_tags (GExiv2Metadata *self) {
-    g_return_val_if_fail(GEXIV2_IS_METADATA (self), NULL);
+gchar** gexiv2_metadata_get_iptc_tags(GExiv2Metadata* self) {
+    g_return_val_if_fail(GEXIV2_IS_METADATA(self), NULL);
+    g_return_val_if_fail(self->priv != NULL, NULL);
     g_return_val_if_fail(self->priv->image.get() != NULL, NULL);
-    
+
     // get a copy of the IptcData and sort it by key, preserving the original
     Exiv2::IptcData iptc_data = Exiv2::IptcData(self->priv->image->iptcData());
     iptc_data.sortByKey();
-    
-    GSList *list = NULL;
-    GSList *list_iter;
-    gchar** data;
+
+    GSList* list = NULL;
+    GSList* list_iter = NULL;
+    gchar** data = NULL;
     gint count = 0;
-    
+    gchar* previous_tag = NULL; // From previous iteration
+
     for (Exiv2::IptcData::iterator it = iptc_data.begin(); it != iptc_data.end(); ++it) {
-        if (it->count() > 0) {
-            list = g_slist_prepend (list, g_strdup (it->key ().c_str ()));
+        if (it->count() > 0 && g_strcmp0(it->key().c_str(), previous_tag) != 0) {
+            list = g_slist_prepend(list, g_strdup(it->key().c_str()));
             count++;
+            previous_tag = static_cast<gchar*>(list->data);
         }
     }
-    
-    data = g_new (gchar*, count + 1);
-    data[count --] = NULL;
+
+    data = g_new(gchar*, count + 1);
+    data[count--] = NULL;
     for (list_iter = list; list_iter != NULL; list_iter = list_iter->next)
         data[count--] = static_cast<gchar*>(list_iter->data);
-    
-    g_slist_free (list);
-    
+
+    g_slist_free(list);
+
     return data;
 }
 
diff --git a/gexiv2/gexiv2-metadata.h b/gexiv2/gexiv2-metadata.h
index f65db7e..8eb18ed 100644
--- a/gexiv2/gexiv2-metadata.h
+++ b/gexiv2/gexiv2-metadata.h
@@ -623,7 +623,7 @@ void                        gexiv2_metadata_clear_exif                      
(GExiv2Metadata *self);
  *
  * Query @self for a list of available EXIF tags
  *
- * Returns: (transfer full) (array zero-terminated=1): A list of the available EXIF tags in the
+ * Returns: (transfer full) (array zero-terminated=1): A unique list of the available EXIF tags in the
  * loaded image
  */
 gchar**                        gexiv2_metadata_get_exif_tags           (GExiv2Metadata *self);
@@ -751,7 +751,7 @@ gchar*                      gexiv2_metadata_get_xmp_packet          (GExiv2Metadata 
*self);
  * gexiv2_metadata_get_xmp_tags:
  * @self: An instance of #GExiv2Metadata
  *
- * Returns: (transfer full) (array zero-terminated=1): A list of the available XMP tags
+ * Returns: (transfer full) (array zero-terminated=1): A unique list of the available XMP tags
  */
 gchar**                        gexiv2_metadata_get_xmp_tags            (GExiv2Metadata *self);
 
@@ -801,7 +801,7 @@ void                        gexiv2_metadata_clear_iptc                      
(GExiv2Metadata *self);
  *
  * Query @self for a list of available IPTC tags
  *
- * Returns: (transfer full) (array zero-terminated=1): A list of the available IPTC tags
+ * Returns: (transfer full) (array zero-terminated=1): A unique list of the available IPTC tags
  */
 gchar**                        gexiv2_metadata_get_iptc_tags           (GExiv2Metadata *self);
 
@@ -1038,7 +1038,7 @@ gboolean          gexiv2_metadata_set_gps_info                            
(GExiv2Metadata *self, gdouble longitu
  * @latitude: Latitude value to set or replace current value
  * @altitude: Altitude value to set or replace current value
  *
- * Convenience function to update longitute, latitude and altitude at once.
+ * Convenience function to update longitude, latitude and altitude at once.
  *
  * Returns: (skip): Boolean success value.
  * Since: 0.12.1


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