diff options
author | David Robillard <d@drobilla.net> | 2018-12-20 13:02:24 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-12-31 11:37:49 -0500 |
commit | 88d62648449a3f7d8e31a70d3d81dec6c895dd31 (patch) | |
tree | c63472ef33552484b8590ed168424685e4b306d2 /src/node.c | |
parent | 66412dc1084040263f8ec75fde51129176a053de (diff) | |
download | serd-88d62648449a3f7d8e31a70d3d81dec6c895dd31.tar.gz serd-88d62648449a3f7d8e31a70d3d81dec6c895dd31.tar.bz2 serd-88d62648449a3f7d8e31a70d3d81dec6c895dd31.zip |
Add serd_node_compare()
Diffstat (limited to 'src/node.c')
-rw-r--r-- | src/node.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -66,6 +66,14 @@ serd_node_pad_size(const size_t n_bytes) } static const SerdNode* +serd_node_maybe_get_meta_c(const SerdNode* node) +{ + return (node->flags & (SERD_HAS_LANGUAGE | SERD_HAS_DATATYPE)) + ? (node + 1 + (serd_node_pad_size(node->n_bytes) / serd_node_align)) + : NULL; +} + +static const SerdNode* serd_node_get_meta_c(const SerdNode* node) { return node + 1 + (serd_node_pad_size(node->n_bytes) / serd_node_align); @@ -303,6 +311,26 @@ serd_node_equals(const SerdNode* a, const SerdNode* b) return false; } +int +serd_node_compare(const SerdNode* a, const SerdNode* b) +{ + if (a == b) { + return 0; + } else if (!a || !b) { + return (a < b) ? -1 : (a > b) ? 1 : 0; + } else if (a->type != b->type) { + return a->type - b->type; + } + + const int cmp = strcmp(serd_node_get_string(a), serd_node_get_string(b)); + if (cmp) { + return cmp; + } + + return 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) { |