aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/serd/serd.h20
-rw-r--r--src/reader.c9
-rw-r--r--src/serdi.c9
-rw-r--r--test/test_overflow.c6
-rw-r--r--test/test_read_chunk.c2
-rw-r--r--test/test_reader.c9
-rw-r--r--test/test_reader_writer.c4
7 files changed, 27 insertions, 32 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 8d00f4e5..47eca580 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -1453,26 +1453,24 @@ serd_env_write_prefixes(const SerdEnv* SERD_NONNULL env,
/// Streaming parser that reads a text stream and writes to a statement sink
typedef struct SerdReaderImpl SerdReader;
+/// Reader options
+typedef enum {
+ SERD_READ_LAX = 1u << 0u ///< Tolerate invalid input where possible
+} SerdReaderFlag;
+
+/// Bitwise OR of SerdReaderFlag values
+typedef uint32_t SerdReaderFlags;
+
/// Create a new RDF reader
SERD_API
SerdReader* SERD_ALLOCATED
serd_reader_new(SerdWorld* SERD_NONNULL world,
SerdSyntax syntax,
+ SerdReaderFlags flags,
const SerdSink* SERD_NONNULL sink,
size_t stack_size);
/**
- Enable or disable strict parsing.
-
- The reader is non-strict (lax) by default, which will tolerate URIs with
- invalid characters. Setting strict will fail when parsing such files. An
- error is printed for invalid input in either case.
-*/
-SERD_API
-void
-serd_reader_set_strict(SerdReader* SERD_NONNULL reader, bool strict);
-
-/**
Set a prefix to be added to all blank node identifiers.
This is useful when multiple files are to be parsed into the same output (a
diff --git a/src/reader.c b/src/reader.c
index 661d48ae..73e92d40 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -176,6 +176,7 @@ serd_reader_read_document(SerdReader* const reader)
SerdReader*
serd_reader_new(SerdWorld* const world,
const SerdSyntax syntax,
+ const SerdReaderFlags flags,
const SerdSink* const sink,
const size_t stack_size)
{
@@ -190,7 +191,7 @@ serd_reader_new(SerdWorld* const world,
me->stack = serd_stack_new(stack_size);
me->syntax = syntax;
me->next_id = 1;
- me->strict = true;
+ me->strict = !(flags & SERD_READ_LAX);
// Reserve a bit of space at the end of the stack to zero pad nodes
me->stack.buf_size -= serd_node_align;
@@ -208,12 +209,6 @@ serd_reader_new(SerdWorld* const world,
}
void
-serd_reader_set_strict(SerdReader* const reader, const bool strict)
-{
- reader->strict = strict;
-}
-
-void
serd_reader_free(SerdReader* const reader)
{
if (!reader) {
diff --git a/src/serdi.c b/src/serdi.c
index ea6bb22b..3f3bce06 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -100,12 +100,12 @@ main(int argc, char** argv)
SerdSyntax input_syntax = SERD_SYNTAX_EMPTY;
SerdSyntax output_syntax = SERD_SYNTAX_EMPTY;
+ SerdReaderFlags reader_flags = 0;
SerdWriterFlags writer_flags = 0;
bool from_string = false;
bool from_stdin = false;
bool bulk_read = true;
bool bulk_write = false;
- bool lax = false;
bool osyntax_set = false;
bool quiet = false;
size_t stack_size = 4194304;
@@ -134,8 +134,8 @@ main(int argc, char** argv)
} else if (opt == 'h') {
return print_usage(prog, false);
} else if (opt == 'l') {
+ reader_flags |= SERD_READ_LAX;
writer_flags |= SERD_WRITE_LAX;
- lax = true;
} else if (opt == 'q') {
quiet = true;
} else if (opt == 't') {
@@ -262,10 +262,9 @@ main(int argc, char** argv)
SerdWriter* const writer =
serd_writer_new(world, output_syntax, writer_flags, env, byte_sink);
- SerdReader* const reader =
- serd_reader_new(world, input_syntax, serd_writer_sink(writer), stack_size);
+ SerdReader* const reader = serd_reader_new(
+ world, input_syntax, reader_flags, serd_writer_sink(writer), stack_size);
- serd_reader_set_strict(reader, !lax);
if (quiet) {
serd_world_set_error_func(world, quiet_error_func, NULL);
}
diff --git a/test/test_overflow.c b/test/test_overflow.c
index f29c8652..8395a13b 100644
--- a/test/test_overflow.c
+++ b/test/test_overflow.c
@@ -30,8 +30,10 @@ test_size(SerdWorld* const world,
const SerdSyntax syntax,
const size_t stack_size)
{
- SerdSink* sink = serd_sink_new(NULL, NULL, NULL);
- SerdReader* const reader = serd_reader_new(world, syntax, sink, stack_size);
+ SerdSink* sink = serd_sink_new(NULL, NULL, NULL);
+ SerdReader* const reader =
+ serd_reader_new(world, syntax, 0u, sink, stack_size);
+
assert(reader);
serd_reader_start_string(reader, str, NULL);
diff --git a/test/test_read_chunk.c b/test/test_read_chunk.c
index 0055ef3a..78cd402e 100644
--- a/test/test_read_chunk.c
+++ b/test/test_read_chunk.c
@@ -94,7 +94,7 @@ main(void)
SerdWorld* world = serd_world_new();
SerdSink* sink = serd_sink_new(NULL, on_event, NULL);
- SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0, sink, 4096);
assert(reader);
assert(!serd_reader_start_string(reader,
diff --git a/test/test_reader.c b/test/test_reader.c
index a641a26a..532411c6 100644
--- a/test/test_reader.c
+++ b/test/test_reader.c
@@ -41,7 +41,7 @@ test_read_string(void)
SerdSink* sink = serd_sink_new(&n_statements, count_statements, NULL);
assert(sink);
- SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0u, sink, 4096);
assert(reader);
// Test reading a string that ends exactly at the end of input (no newline)
@@ -118,7 +118,7 @@ test_read_eof_by_page(void)
SerdWorld* world = serd_world_new();
size_t ignored = 0u;
SerdSink* sink = serd_sink_new(&ignored, count_statements, NULL);
- SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0u, sink, 4096);
serd_reader_start_stream(
reader, (SerdReadFunc)fread, (SerdStreamErrorFunc)ferror, temp, NULL, 4096);
@@ -140,7 +140,7 @@ test_read_eof_by_byte(void)
SerdWorld* world = serd_world_new();
size_t ignored = 0u;
SerdSink* sink = serd_sink_new(&ignored, count_statements, NULL);
- SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0u, sink, 4096);
size_t n_reads = 0u;
serd_reader_start_stream(reader,
@@ -171,7 +171,8 @@ test_read_chunks(void)
SerdSink* const sink = serd_sink_new(&n_statements, count_statements, NULL);
assert(sink);
- SerdReader* const reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
+ SerdReader* const reader =
+ serd_reader_new(world, SERD_TURTLE, 0u, sink, 4096);
assert(reader);
SerdStatus st = serd_reader_start_stream(
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index fa45786c..41f6aee0 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -144,9 +144,9 @@ test_reader(const char* path)
assert(sink);
// Test that too little stack space fails gracefully
- assert(!serd_reader_new(world, SERD_TURTLE, sink, 32));
+ assert(!serd_reader_new(world, SERD_TURTLE, 0u, sink, 32));
- SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0u, sink, 4096);
assert(reader);
serd_reader_add_blank_prefix(reader, "tmp");