aboutsummaryrefslogtreecommitdiffstats
path: root/include/serd
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-05-05 12:35:46 -0400
committerDavid Robillard <d@drobilla.net>2023-12-02 18:49:08 -0500
commit439d6ec3d6dfbea74334beace790f500e61c9b7d (patch)
treee385755a7d557dd5eb6f33b841072375cfaca29d /include/serd
parentc9afaab2a84f592e4567b37b3551511381e734e4 (diff)
downloadserd-439d6ec3d6dfbea74334beace790f500e61c9b7d.tar.gz
serd-439d6ec3d6dfbea74334beace790f500e61c9b7d.tar.bz2
serd-439d6ec3d6dfbea74334beace790f500e61c9b7d.zip
Add statement filter sink and serd-filter tool
Diffstat (limited to 'include/serd')
-rw-r--r--include/serd/filter.h60
-rw-r--r--include/serd/serd.h1
-rw-r--r--include/serd/status.h1
3 files changed, 62 insertions, 0 deletions
diff --git a/include/serd/filter.h b/include/serd/filter.h
new file mode 100644
index 00000000..856df530
--- /dev/null
+++ b/include/serd/filter.h
@@ -0,0 +1,60 @@
+// Copyright 2011-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef SERD_FILTER_H
+#define SERD_FILTER_H
+
+#include "serd/attributes.h"
+#include "serd/node.h"
+#include "serd/sink.h"
+#include "serd/world.h"
+#include "zix/attributes.h"
+
+#include <stdbool.h>
+
+SERD_BEGIN_DECLS
+
+/**
+ @defgroup serd_filter Filter
+ @ingroup serd_streaming
+ @{
+*/
+
+/**
+ Return a new sink that filters out statements that do not match a pattern.
+
+ The returned sink acts like `target` in all respects, except that some
+ statements may be dropped.
+
+ @param world The world to create the sink in.
+
+ @param target The target sink to pass the filtered data to.
+
+ @param subject The optional subject of the filter pattern.
+
+ @param predicate The optional predicate of the filter pattern.
+
+ @param object The optional object of the filter pattern.
+
+ @param graph The optional graph of the filter pattern.
+
+ @param inclusive If true, then only statements that match the pattern are
+ passed through. Otherwise, only statements that do *not* match the pattern
+ are passed through.
+*/
+SERD_API SerdSink* ZIX_ALLOCATED
+serd_filter_new(const SerdWorld* ZIX_NONNULL world,
+ const SerdSink* ZIX_NONNULL target,
+ const SerdNode* ZIX_NULLABLE subject,
+ const SerdNode* ZIX_NULLABLE predicate,
+ const SerdNode* ZIX_NULLABLE object,
+ const SerdNode* ZIX_NULLABLE graph,
+ bool inclusive);
+
+/**
+ @}
+*/
+
+SERD_END_DECLS
+
+#endif // SERD_FILTER_H
diff --git a/include/serd/serd.h b/include/serd/serd.h
index f874a0cc..77d1abf8 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -72,6 +72,7 @@
#include "serd/canon.h"
#include "serd/env.h"
#include "serd/event.h"
+#include "serd/filter.h"
#include "serd/sink.h"
/**
diff --git a/include/serd/status.h b/include/serd/status.h
index c6047aff..5aedd5a6 100644
--- a/include/serd/status.h
+++ b/include/serd/status.h
@@ -39,6 +39,7 @@ typedef enum {
SERD_BAD_URI, ///< Invalid or unresolved URI
SERD_BAD_DATA, ///< Invalid data
SERD_BAD_LITERAL, ///< Invalid literal
+ SERD_BAD_PATTERN, ///< Invalid statement pattern
} SerdStatus;
/// Return a string describing a status code