[gexiv2/wip/63] Implement XMP namespace lookup




commit 6399a5dcfe53deac40bc0ddd3a84b47a04cf3dee
Author: Jens Georg <mail jensge org>
Date:   Tue Dec 15 13:44:31 2020 +0100

    Implement XMP namespace lookup
    
    Fixes #63

 gexiv2/gexiv2-metadata-xmp.cpp | 31 +++++++++++++++++++++++++++++++
 gexiv2/gexiv2-metadata.h       |  9 +++++++++
 2 files changed, 40 insertions(+)
---
diff --git a/gexiv2/gexiv2-metadata-xmp.cpp b/gexiv2/gexiv2-metadata-xmp.cpp
index a1c9236..69bc6a5 100644
--- a/gexiv2/gexiv2-metadata-xmp.cpp
+++ b/gexiv2/gexiv2-metadata-xmp.cpp
@@ -530,4 +530,35 @@ void gexiv2_metadata_unregister_all_xmp_namespaces (void) {
     Exiv2::XmpProperties::unregisterNs();
 }
 
+char* gexiv2_metadata_get_xmp_namespace_for_tag(const char* tag) {
+    g_return_val_if_fail(tag != nullptr, nullptr);
+    g_return_val_if_fail(strlen(tag) != 0, nullptr);
+
+    char** list = nullptr;
+    char* result = nullptr;
+
+    try {
+        list = g_strsplit(tag, ".", 3);
+        const char* name = nullptr;
+        if (g_strv_length(list) == 0) {
+            g_assert_not_reached();
+        }
+        if (g_strv_length(list) == 1) {
+            name = list[0];
+        } else  {
+            name = list[1];
+        }
+
+        auto info = Exiv2::XmpProperties::ns(name);
+
+        result = g_strdup(info.c_str());
+    } catch (Exiv2::Error&) {
+        // No such namespace
+    }
+
+    g_clear_pointer(&list, g_strfreev);
+
+    return result;
+}
+
 G_END_DECLS
diff --git a/gexiv2/gexiv2-metadata.h b/gexiv2/gexiv2-metadata.h
index dceeb7e..0e103b4 100644
--- a/gexiv2/gexiv2-metadata.h
+++ b/gexiv2/gexiv2-metadata.h
@@ -871,6 +871,15 @@ gboolean        gexiv2_metadata_unregister_xmp_namespace (const gchar* name);
  */
 void            gexiv2_metadata_unregister_all_xmp_namespaces (void);
 
+/**
+ * gexiv2_metadata_get_xmp_namespace_for_tag:
+ * @tag: (in): Full tag name or XMP namespace identifier
+ * Returns: (transfer full): %NULL if there was no namespace registered for the tag, the URI of the 
namespace otherwise.
+ *
+ * Since: 0.12.2
+ */
+char* gexiv2_metadata_get_xmp_namespace_for_tag(const char* tag);
+
 /* IPTC functions */
 
 /**


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