Adding utilities to count childs

This commit is contained in:
AnonymusRaccoon
2020-01-09 17:19:03 +01:00
parent f7750c3d72
commit 05fec3bfff
3 changed files with 18 additions and 1 deletions
+1
View File
@@ -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);
+16
View File
@@ -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)
{
+1 -1
View File
@@ -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);
}