From 05fec3bfffe8820943b8609c3aa0b0b72de9c12f Mon Sep 17 00:00:00 2001
From: AnonymusRaccoon
Date: Thu, 9 Jan 2020 17:19:03 +0100
Subject: [PATCH] Adding utilities to count childs
---
include/xml.h | 1 +
src/child.c | 16 ++++++++++++++++
src/xmlget.c | 2 +-
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/include/xml.h b/include/xml.h
index 32c5bf5..c0f3a39 100644
--- a/include/xml.h
+++ b/include/xml.h
@@ -35,4 +35,5 @@ int xml_getbinaprop(node *n, const char *key);
int xml_gethexaprop(node *n, const char *key);
float xml_getfloatprop(node *n, const char *key);
int xml_getchildcount(node *n);
+int xml_getchildcount_filtered(node *n, char *name);
void xml_destroy(node *n);
\ No newline at end of file
diff --git a/src/child.c b/src/child.c
index 48283fa..cc16c64 100644
--- a/src/child.c
+++ b/src/child.c
@@ -6,6 +6,22 @@
*/
#include "xml.h"
+#include "my.h"
+
+int xml_getchildcount_filtered(node *n, char *name)
+{
+ int i = 1;
+
+ if (!n || !n->child)
+ return (0);
+ n = n->child;
+ while (n->next) {
+ n = n->next;
+ if (!my_strcmp(n->name, name))
+ i++;
+ }
+ return (i);
+}
int xml_getchildcount(node *n)
{
diff --git a/src/xmlget.c b/src/xmlget.c
index e2c75d9..381ef59 100644
--- a/src/xmlget.c
+++ b/src/xmlget.c
@@ -15,7 +15,7 @@ char *xml_getproperty(node *n, const char *key)
{
for (dictionary *prop = n->properties; prop; prop = prop->next) {
if (!my_strcmp(key, prop->key))
- return (prop->value);
+ return (my_strdup(prop->value));
}
return (NULL);
}