From 582bfbe1cb0a6aa833f56c5bd8cf42abe5c5d13a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 12 May 2018 13:28:47 +0200 Subject: WIP: Add model --- src/node.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/node.c') diff --git a/src/node.c b/src/node.c index 523893df..32852dc1 100644 --- a/src/node.c +++ b/src/node.c @@ -247,6 +247,30 @@ serd_node_equals(const SerdNode* a, const SerdNode* b) return false; } +/** Compare nodes, considering NULL a match iff `wildcards` is true. */ +int +serd_node_compare(const SerdNode* a, const SerdNode* b, bool wildcards) +{ + if (a == b) { + return 0; + } else if (!a || !b) { + return wildcards ? 0 : (a < b) ? -1 : (a > b) ? 1 : 0; + } else if (a->type != b->type) { + return a->type - b->type; + } + + int cmp = strcmp(serd_node_get_string(a), serd_node_get_string(b)); + if (cmp) { + return cmp; + } + + cmp = serd_node_compare(serd_node_maybe_get_meta_c(a), + serd_node_maybe_get_meta_c(b), + false); + + return cmp; +} + static size_t serd_uri_string_length(const SerdURI* uri) { -- cgit v1.2.1