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>2021-03-08 23:23:06 -0500
commit229443778ffc6b26a13322983b81f4f1912427af (patch)
tree028e9c7cdf7ca9b994603986c979fba183078345 /src/node.c
parentc7a5af0235706bc0624a236fae03fc728144234f (diff)
downloadserd-229443778ffc6b26a13322983b81f4f1912427af.tar.gz
serd-229443778ffc6b26a13322983b81f4f1912427af.tar.bz2
serd-229443778ffc6b26a13322983b81f4f1912427af.zip
Add serd_node_compare()
Diffstat (limited to 'src/node.c')
-rw-r--r--src/node.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/node.c b/src/node.c
index 4c76ed9b..268b53af 100644
--- a/src/node.c
+++ b/src/node.c
@@ -436,6 +436,31 @@ 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;
+ }
+
+ if (!a) {
+ return -1;
+ }
+
+ if (!b) {
+ return 1;
+ }
+
+ if (a->type != b->type) {
+ return (a->type < b->type) ? -1 : 1;
+ }
+
+ const int cmp = strcmp(serd_node_string(a), serd_node_string(b));
+ return cmp ? cmp
+ : serd_node_compare(serd_node_maybe_get_meta_c(a),
+ serd_node_maybe_get_meta_c(b));
+}
+
SerdNode*
serd_new_uri(const SerdStringView str)
{