cyaml · Section 3
cyaml_remove
NAME
cyaml_remove - remove and free the DOM node at a dot-separated path
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cyaml.h> ccol_retval cyaml_remove(cyaml root, const char *path);
DESCRIPTION
Walks to the parent of the node that the path addresses, removes that child and frees its whole subtree. The path has the same dot-separated syntax as in cyaml_get and cyaml_set. When the parent is a dictionary, the leaf component is the key to remove. When it is a list, the leaf component must be a '#N' token, so "#0" removes the first element. The path is split at its LAST unescaped dot, so "a.b.c" targets the key "c" inside the node at "a.b". A path with no dot has root as its parent. The escapes '\.' and '\\' give a literal dot and a literal backslash in a key name, as they do in cyaml_get and cyaml_set.
RETURN VALUE
ccol_retval, which is ccol_success on success. ccol_invalid_args for a NULL root, a NULL path, an empty path, a malformed component and a path whose shape cannot apply to the tree. A component is malformed when it is empty (nothing between two dots, a leading dot, or a trailing dot), when it has bad '#N' index syntax on a list, or when it is not well-formed UTF-8. A shape cannot apply when a component on a list is not '#N', or when the macro finds any component under a scalar. This code can come from any position in the path, not only the leaf, and it wins over an absent component earlier in the path. ccol_key_not_found only when a well-formed component (a dictionary key or a '#N' index) is absent, at any position, and when a list index with correct syntax is out of range, however many digits it has. ccol_not_enough_memory when an internal allocation fails.
EXAMPLES
cyaml_remove(doc, "server.debug"); cyaml_remove(doc, "hosts.#0"); cyaml_remove(doc, "users.alice.address");
SEE ALSO
cyaml_get(3), cyaml_set(3), cyaml_dictionary_remove(3), cyaml_list_remove(3)