aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-07-10 22:01:30 -0400
committerDavid Robillard <d@drobilla.net>2022-01-14 19:37:51 -0500
commit07b716c38625dd954be279e3476164b5bb1d6293 (patch)
tree3b2d75ab74dad40c7d54d2dbee2fcad3d54f6935 /src
parent94eeeadeb5be3d9c9266bed5d3c32c6ff29695b4 (diff)
downloadserd-07b716c38625dd954be279e3476164b5bb1d6293.tar.gz
serd-07b716c38625dd954be279e3476164b5bb1d6293.tar.bz2
serd-07b716c38625dd954be279e3476164b5bb1d6293.zip
Add serd_statement_matches()
Diffstat (limited to 'src')
-rw-r--r--src/node.h8
-rw-r--r--src/statement.c14
2 files changed, 22 insertions, 0 deletions
diff --git a/src/node.h b/src/node.h
index 29164dc2..e064e96b 100644
--- a/src/node.h
+++ b/src/node.h
@@ -20,6 +20,7 @@
#include "exess/exess.h"
#include "serd/serd.h"
+#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@@ -49,6 +50,13 @@ serd_node_string_i(const SerdNode* const SERD_NONNULL node)
return (const char*)(node + 1);
}
+static inline bool
+serd_node_pattern_match(const SerdNode* SERD_NULLABLE a,
+ const SerdNode* SERD_NULLABLE b)
+{
+ return !a || !b || serd_node_equals(a, b);
+}
+
SerdNode* SERD_ALLOCATED
serd_node_malloc(size_t length, SerdNodeFlags flags, SerdNodeType type);
diff --git a/src/statement.c b/src/statement.c
index f3034566..d6571c6c 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -17,6 +17,7 @@
#include "statement.h"
#include "caret.h"
+#include "node.h"
#include <assert.h>
#include <stdbool.h>
@@ -132,3 +133,16 @@ serd_statement_equals(const SerdStatement* const a,
serd_node_equals(a->nodes[2], b->nodes[2]) &&
serd_node_equals(a->nodes[3], b->nodes[3])));
}
+
+bool
+serd_statement_matches(const SerdStatement* const statement,
+ const SerdNode* const subject,
+ const SerdNode* const predicate,
+ const SerdNode* const object,
+ const SerdNode* const graph)
+{
+ return (serd_node_pattern_match(statement->nodes[0], subject) &&
+ serd_node_pattern_match(statement->nodes[1], predicate) &&
+ serd_node_pattern_match(statement->nodes[2], object) &&
+ serd_node_pattern_match(statement->nodes[3], graph));
+}