[template-glib] scope: add dup_string() helper
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [template-glib] scope: add dup_string() helper
- Date: Sat, 28 May 2022 00:49:04 +0000 (UTC)
commit d5493a5611c3823903e78ac706fafb5d876d5ae6
Author: Christian Hergert <chergert redhat com>
Date: Fri May 27 17:48:55 2022 -0700
scope: add dup_string() helper
src/tmpl-scope.c | 31 +++++++++++++++++++++++++++++++
src/tmpl-scope.h | 3 +++
2 files changed, 34 insertions(+)
---
diff --git a/src/tmpl-scope.c b/src/tmpl-scope.c
index b61a088..81d1cf6 100644
--- a/src/tmpl-scope.c
+++ b/src/tmpl-scope.c
@@ -493,3 +493,34 @@ tmpl_scope_set_null (TmplScope *self,
tmpl_scope_set_value (self, name, &value);
}
+
+/**
+ * tmpl_scope_dup_string:
+ * @self: a #TmplScope
+ *
+ * Gets a string if the symbol @name is a string.
+ *
+ * Otherwise, %NULL is returned.
+ *
+ * Returns: (transfer full) (nullable): a string or %NULL
+ *
+ * Since: 3.36
+ */
+char *
+tmpl_scope_dup_string (TmplScope *self,
+ const char *name)
+{
+ GValue value = G_VALUE_INIT;
+ TmplSymbol *symbol;
+ char *ret = NULL;
+
+ if (!(symbol = tmpl_scope_peek (self, name)))
+ return NULL;
+
+ tmpl_symbol_get_value (symbol, &value);
+ if (G_VALUE_HOLDS_STRING (&value))
+ ret = g_value_dup_string (&value);
+ g_value_unset (&value);
+
+ return ret;
+}
diff --git a/src/tmpl-scope.h b/src/tmpl-scope.h
index 8e09c9c..8965a9a 100644
--- a/src/tmpl-scope.h
+++ b/src/tmpl-scope.h
@@ -102,6 +102,9 @@ char **tmpl_scope_list_symbols (TmplScope *self,
TMPL_AVAILABLE_IN_3_36
void tmpl_scope_set_null (TmplScope *self,
const char *name);
+TMPL_AVAILABLE_IN_3_36
+char *tmpl_scope_dup_string (TmplScope *self,
+ const char *name);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (TmplScope, tmpl_scope_unref)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]