summaryrefslogtreecommitdiff
path: root/plugins/yaml/node.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-11-17 19:10:25 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-11-17 19:10:25 (GMT)
commitcef46f9f06a7448db60116e8c0ccadee44d83692 (patch)
tree75201f66b26499ad1968d6e1cec88f18ad80b72b /plugins/yaml/node.c
parentc02661b7a8151a49a77c39241b040aa9bdb30223 (diff)
Extended the API to find an unique Yaml node.
Diffstat (limited to 'plugins/yaml/node.c')
-rw-r--r--plugins/yaml/node.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/plugins/yaml/node.c b/plugins/yaml/node.c
index 3dc6ec0..e2abeca 100644
--- a/plugins/yaml/node.c
+++ b/plugins/yaml/node.c
@@ -392,3 +392,44 @@ void g_yaml_node_find_by_path(GYamlNode *node, const char *path, GYamlNode ***no
_g_yaml_node_find_by_path(node, path, nodes, count);
}
+
+
+/******************************************************************************
+* *
+* Paramètres : node = noeud d'arborescence Yaml à consulter. *
+* path = chemin d'accès à parcourir. *
+* *
+* Description : Recherche l'unique noeud correspondant à un chemin. *
+* *
+* Retour : Noeud avec correspondance établie ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GYamlNode *g_yaml_node_find_one_by_path(GYamlNode *node, const char *path)
+{
+ GYamlNode *result; /* Trouvaille unique à renvoyer*/
+ GYamlNode **nodes; /* Liste de noeuds trouvés */
+ size_t count; /* Taille de cette liste */
+ size_t i; /* Boucle de parcours */
+
+ g_yaml_node_find_by_path(node, path, &nodes, &count);
+
+ if (count == 1)
+ {
+ result = nodes[0];
+ g_object_ref(G_OBJECT(result));
+ }
+ else
+ result = NULL;
+
+ for (i = 0; i < count; i++)
+ g_object_unref(G_OBJECT(nodes[i]));
+
+ if (nodes != NULL)
+ free(nodes);
+
+ return result;
+
+}