struct cYAML *cYAML_get_object_item(struct cYAML *parent, const char *name)
{
- struct cYAML *node;
+ struct cYAML *node = parent, *found = NULL;
- if (parent == NULL || parent->cy_child == NULL || name == NULL)
+ if (!node || !name)
return NULL;
- node = parent->cy_child;
-
- while (node != NULL &&
- strcmp(node->cy_string, name) != 0) {
- node = node->cy_next;
+ if (node->cy_string) {
+ if (strcmp(node->cy_string, name) == 0)
+ return node;
}
- return node;
+ if (node->cy_child)
+ found = cYAML_get_object_item(node->cy_child, name);
+
+ if (!found && node->cy_next)
+ found = cYAML_get_object_item(node->cy_next, name);
+
+ return found;
}
struct cYAML *cYAML_get_next_seq_item(struct cYAML *seq, struct cYAML **itm)