[gnome-builder/gnome-builder-3-28] util: add helper to parse environment variable



commit 6f60b740b8724f94e8faeab4f61857fc73f68c56
Author: Christian Hergert <chergert redhat com>
Date:   Sun Apr 15 22:47:57 2018 -0700

    util: add helper to parse environment variable

 src/libide/util/ide-glib.c | 29 +++++++++++++++++++++++++++++
 src/libide/util/ide-glib.h |  4 ++++
 2 files changed, 33 insertions(+)
---
diff --git a/src/libide/util/ide-glib.c b/src/libide/util/ide-glib.c
index b735a6b0e..92fb6638c 100644
--- a/src/libide/util/ide-glib.c
+++ b/src/libide/util/ide-glib.c
@@ -630,3 +630,32 @@ ide_g_host_file_get_contents (const gchar  *path,
 
   return TRUE;
 }
+
+gboolean
+ide_environ_parse (const gchar  *pair,
+                   gchar       **key,
+                   gchar       **value)
+{
+  const gchar *eq;
+
+  g_return_val_if_fail (pair != NULL, FALSE);
+
+  if (key != NULL)
+    *key = NULL;
+
+  if (value != NULL)
+    *value = NULL;
+
+  if ((eq = strchr (pair, '=')))
+    {
+      if (key != NULL)
+        *key = g_strndup (pair, eq - pair);
+
+      if (value != NULL)
+        *value = g_strdup (eq + 1);
+
+      return TRUE;
+    }
+
+  return FALSE;
+}
diff --git a/src/libide/util/ide-glib.h b/src/libide/util/ide-glib.h
index 0e4752fb9..345cd7c06 100644
--- a/src/libide/util/ide-glib.h
+++ b/src/libide/util/ide-glib.h
@@ -35,6 +35,10 @@ G_BEGIN_DECLS
   ({ IDE_PTR_ARRAY_CLEAR_FREE_FUNC (*(arptr)); \
      g_steal_pointer ((arptr)); })
 
+IDE_AVAILABLE_IN_3_30
+gboolean     ide_environ_parse                        (const gchar          *pair,
+                                                       gchar               **key,
+                                                       gchar               **value);
 IDE_AVAILABLE_IN_ALL
 const gchar *ide_gettext                              (const gchar          *message);
 IDE_AVAILABLE_IN_ALL


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