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>2023-12-02 18:49:07 -0500
commitd1ba721d37af61f2b529faaa16bd20ba1e161b06 (patch)
tree2930f07857d5416eb193fe8afbcc4adecdc2e7ea /src/node.c
parent08a3b8a18093d1623309f5f406865f51e7bff39a (diff)
downloadserd-d1ba721d37af61f2b529faaa16bd20ba1e161b06.tar.gz
serd-d1ba721d37af61f2b529faaa16bd20ba1e161b06.tar.bz2
serd-d1ba721d37af61f2b529faaa16bd20ba1e161b06.zip
Add serd_node_compare()
Diffstat (limited to 'src/node.c')
-rw-r--r--src/node.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/node.c b/src/node.c
index c2f6ebab..a4b3dfbb 100644
--- a/src/node.c
+++ b/src/node.c
@@ -458,6 +458,33 @@ serd_node_equals(const SerdNode* const a, const SerdNode* const b)
return true;
}
+int
+serd_node_compare(const SerdNode* const a, const SerdNode* const b)
+{
+ assert(a);
+ assert(b);
+
+ int cmp = 0;
+
+ if ((cmp = ((int)a->type - (int)b->type)) ||
+ (cmp = strcmp(serd_node_string_i(a), serd_node_string_i(b))) ||
+ (cmp = ((int)a->flags - (int)b->flags)) ||
+ !(a->flags & (SERD_HAS_LANGUAGE | SERD_HAS_DATATYPE))) {
+ return cmp;
+ }
+
+ assert(a->flags == b->flags);
+ assert(a->flags & (SERD_HAS_LANGUAGE | SERD_HAS_DATATYPE));
+ assert(b->flags & (SERD_HAS_LANGUAGE | SERD_HAS_DATATYPE));
+ const SerdNode* const ma = serd_node_meta_c(a);
+ const SerdNode* const mb = serd_node_meta_c(b);
+
+ assert(ma->type == mb->type);
+ assert(ma->flags == mb->flags);
+
+ return strcmp(serd_node_string_i(ma), serd_node_string_i(mb));
+}
+
SerdNode*
serd_new_uri(const SerdStringView string)
{