aboutsummaryrefslogtreecommitdiffstats
path: root/src/node.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-12-20 13:02:24 -0500
committerDavid Robillard <d@drobilla.net>2020-06-21 18:12:04 +0200
commite10776b1aa80d5b5da2749a6e13f00eb5b690871 (patch)
tree81af5a5bbb5fab8923b29ec189905ef18419c43d /src/node.c
parent8a83be33760f3304647cbab6d9e5fbda2c9c766c (diff)
downloadserd-e10776b1aa80d5b5da2749a6e13f00eb5b690871.tar.gz
serd-e10776b1aa80d5b5da2749a6e13f00eb5b690871.tar.bz2
serd-e10776b1aa80d5b5da2749a6e13f00eb5b690871.zip
Add serd_node_compare()
Diffstat (limited to 'src/node.c')
-rw-r--r--src/node.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/node.c b/src/node.c
index 55ee1d70..4f0010d2 100644
--- a/src/node.c
+++ b/src/node.c
@@ -367,6 +367,25 @@ serd_node_equals(const SerdNode* a, const SerdNode* b)
return serd_node_total_size(b) == a_size && !memcmp(a, b, a_size);
}
+int
+serd_node_compare(const SerdNode* a, const SerdNode* b)
+{
+ if (a == b) {
+ return 0;
+ } else if (!a) {
+ return -1;
+ } else if (!b) {
+ return 1;
+ } else if (a->type != b->type) {
+ return (a->type < b->type) ? -1 : 1;
+ }
+
+ const int cmp = strcmp(serd_node_get_string(a), serd_node_get_string(b));
+ return cmp ? cmp
+ : serd_node_compare(serd_node_maybe_get_meta_c(a),
+ serd_node_maybe_get_meta_c(b));
+}
+
static size_t
serd_uri_string_length(const SerdURI* uri)
{