diff options
author | David Robillard <d@drobilla.net> | 2018-12-20 13:02:24 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-14 19:37:51 -0500 |
commit | 94eeeadeb5be3d9c9266bed5d3c32c6ff29695b4 (patch) | |
tree | d1c6de5dc7985f2f602ddd7daf9b24a2a5cd0945 /src | |
parent | 4ac6d94d9a8826e09b81c6505408bed44d11e567 (diff) | |
download | serd-94eeeadeb5be3d9c9266bed5d3c32c6ff29695b4.tar.gz serd-94eeeadeb5be3d9c9266bed5d3c32c6ff29695b4.tar.bz2 serd-94eeeadeb5be3d9c9266bed5d3c32c6ff29695b4.zip |
Add serd_node_compare()
Diffstat (limited to 'src')
-rw-r--r-- | src/node.c | 27 | ||||
-rw-r--r-- | src/node.h | 6 |
2 files changed, 33 insertions, 0 deletions
@@ -428,6 +428,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 str) { @@ -43,6 +43,12 @@ serd_node_buffer_c(const SerdNode* SERD_NONNULL node) return (const char*)(node + 1); } +static inline const char* SERD_NONNULL +serd_node_string_i(const SerdNode* const SERD_NONNULL node) +{ + return (const char*)(node + 1); +} + SerdNode* SERD_ALLOCATED serd_node_malloc(size_t length, SerdNodeFlags flags, SerdNodeType type); |