[gnome-builder] flatpak: add util to split flatpak ids



commit f8153becb107a9487b50bc3c3242428252a8b849
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jan 15 20:24:38 2018 -0800

    flatpak: add util to split flatpak ids

 src/plugins/flatpak/gbp-flatpak-util.c | 49 ++++++++++++++++++++++++++++++++++
 src/plugins/flatpak/gbp-flatpak-util.h |  4 +++
 2 files changed, 53 insertions(+)
---
diff --git a/src/plugins/flatpak/gbp-flatpak-util.c b/src/plugins/flatpak/gbp-flatpak-util.c
index 15ee93948..685b3aa28 100644
--- a/src/plugins/flatpak/gbp-flatpak-util.c
+++ b/src/plugins/flatpak/gbp-flatpak-util.c
@@ -97,3 +97,52 @@ gbp_flatpak_is_ignored (const gchar *name)
          strstr (name, ".PlatformTheme") != NULL;
 }
 
+gboolean
+gbp_flatpak_split_id (const gchar  *str,
+                      gchar       **id,
+                      gchar       **arch,
+                      gchar       **branch)
+{
+  g_auto(GStrv) parts = g_strsplit (str, "/", 0);
+  guint i = 0;
+
+  if (id)
+    *id = NULL;
+
+  if (arch)
+    *arch = NULL;
+
+  if (branch)
+    *branch = NULL;
+
+  if (parts[i] != NULL)
+    {
+      if (id != NULL)
+        *id = g_strdup (parts[i]);
+    }
+  else
+    {
+      /* we require at least a runtime/app ID */
+      return FALSE;
+    }
+
+  i++;
+
+  if (parts[i] != NULL)
+    {
+      if (arch != NULL)
+        *arch = g_strdup (parts[i]);
+    }
+  else
+    return TRUE;
+
+  i++;
+
+  if (parts[i] != NULL)
+    {
+      if (branch != NULL)
+        *branch = g_strdup (parts[i]);
+    }
+
+  return TRUE;
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-util.h b/src/plugins/flatpak/gbp-flatpak-util.h
index c17c86494..c71a639ec 100644
--- a/src/plugins/flatpak/gbp-flatpak-util.h
+++ b/src/plugins/flatpak/gbp-flatpak-util.h
@@ -25,5 +25,9 @@ G_BEGIN_DECLS
 gboolean  gbp_flatpak_is_ignored      (const gchar      *name);
 gchar    *gbp_flatpak_get_repo_dir    (IdeConfiguration *configuration);
 gchar    *gbp_flatpak_get_staging_dir (IdeConfiguration *configuration);
+gboolean  gbp_flatpak_split_id        (const gchar       *str,
+                                       gchar            **id,
+                                       gchar            **arch,
+                                       gchar            **branch);
 
 G_END_DECLS


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