diff options
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
@@ -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) { @@ -33,6 +33,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); |