aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/node.c27
-rw-r--r--src/node.h6
2 files changed, 33 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)
{
diff --git a/src/node.h b/src/node.h
index 359da4b9..fc03bf72 100644
--- a/src/node.h
+++ b/src/node.h
@@ -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);