aboutsummaryrefslogtreecommitdiffstats
path: root/src/node.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/node.c')
-rw-r--r--src/node.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/node.c b/src/node.c
index 1f22bf4f..1af22aa9 100644
--- a/src/node.c
+++ b/src/node.c
@@ -65,6 +65,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);
@@ -301,6 +309,33 @@ 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));
+}
+
+/** Compare nodes, considering NULL a wildcard match. */
+int
+serd_node_wildcard_compare(const SerdNode* a, const SerdNode* b)
+{
+ return (!a || !b) ? 0 : serd_node_compare(a, b);
+}
+
static size_t
serd_uri_string_length(const SerdURI* uri)
{