plugins types FEATURE sort callback in empty
... implemented via new lyplg_type_sort_simple().
diff --git a/src/plugins_types.c b/src/plugins_types.c
index 9ebcf48..8305691 100644
--- a/src/plugins_types.c
+++ b/src/plugins_types.c
@@ -29,6 +29,7 @@
#include "dict.h"
#include "ly_common.h"
#include "path.h"
+#include "plugins_internal.h"
#include "schema_compile.h"
#include "set.h"
#include "tree.h"
@@ -314,6 +315,27 @@
return LY_ENOT;
}
+LIBYANG_API_DEF int
+lyplg_type_sort_simple(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
+{
+ int cmp;
+ const char *can1, *can2;
+
+ can1 = lyd_value_get_canonical(ctx, val1);
+ can2 = lyd_value_get_canonical(ctx, val2);
+ if (can1 && can2) {
+ cmp = strcmp(can1, can2);
+ return cmp;
+ } else if (!can1 && can2) {
+ return -1;
+ } else if (can1 && !can2) {
+ return 1;
+ } else {
+ /* !can1 && !can2 */
+ return 0;
+ }
+}
+
LIBYANG_API_DEF const void *
lyplg_type_print_simple(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *value, LY_VALUE_FORMAT UNUSED(format),
void *UNUSED(prefix_data), ly_bool *dynamic, size_t *value_len)
diff --git a/src/plugins_types.h b/src/plugins_types.h
index f056643..a6851e8 100644
--- a/src/plugins_types.h
+++ b/src/plugins_types.h
@@ -658,6 +658,12 @@
const struct lyd_value *val2);
/**
+ * @brief Implementation of ::lyplg_type_sort_clb for a generic simple type.
+ */
+LIBYANG_API_DEF int lyplg_type_sort_simple(const struct ly_ctx *ctx, const struct lyd_value *val1,
+ const struct lyd_value *val2);
+
+/**
* @brief Implementation of ::lyplg_type_print_clb for a generic simple type.
*/
LIBYANG_API_DECL const void *lyplg_type_print_simple(const struct ly_ctx *ctx, const struct lyd_value *value,
diff --git a/src/plugins_types/empty.c b/src/plugins_types/empty.c
index 45062d8..b7b82dc 100644
--- a/src/plugins_types/empty.c
+++ b/src/plugins_types/empty.c
@@ -93,7 +93,7 @@
.plugin.store = lyplg_type_store_empty,
.plugin.validate = NULL,
.plugin.compare = lyplg_type_compare_simple,
- .plugin.sort = NULL,
+ .plugin.sort = lyplg_type_sort_simple,
.plugin.print = lyplg_type_print_simple,
.plugin.duplicate = lyplg_type_dup_simple,
.plugin.free = lyplg_type_free_simple,