data tree CHANGE provide lyd_is_default()
Rename internal ly_is_default() to lyd_is_default() and make it public
as a replacement for lyd_wd_default() from libyang 1.x.
diff --git a/src/tree_data.c b/src/tree_data.c
index 4da6eb2..6514520 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -273,6 +273,44 @@
return ret;
}
+API ly_bool
+lyd_is_default(const struct lyd_node *node)
+{
+ const struct lysc_node_leaf *leaf;
+ const struct lysc_node_leaflist *llist;
+ const struct lyd_node_term *term;
+ LY_ARRAY_COUNT_TYPE u;
+
+ assert(node->schema->nodetype & LYD_NODE_TERM);
+ term = (const struct lyd_node_term *)node;
+
+ if (node->schema->nodetype == LYS_LEAF) {
+ leaf = (const struct lysc_node_leaf *)node->schema;
+ if (!leaf->dflt) {
+ return 0;
+ }
+
+ /* compare with the default value */
+ if (leaf->type->plugin->compare(&term->value, leaf->dflt)) {
+ return 0;
+ }
+ } else {
+ llist = (const struct lysc_node_leaflist *)node->schema;
+ if (!llist->dflts) {
+ return 0;
+ }
+
+ LY_ARRAY_FOR(llist->dflts, u) {
+ /* compare with each possible default value */
+ if (llist->type->plugin->compare(&term->value, llist->dflts[u])) {
+ return 0;
+ }
+ }
+ }
+
+ return 1;
+}
+
static LYD_FORMAT
lyd_parse_get_format(const struct ly_in *in, LYD_FORMAT format)
{