aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--serd/serd.h22
-rw-r--r--src/reader.c9
-rw-r--r--src/serdi.c13
-rw-r--r--src/writer.c6
-rw-r--r--tests/overflow_test.c4
-rw-r--r--tests/read_chunk_test.c2
-rw-r--r--tests/serd_test.c8
7 files changed, 30 insertions, 34 deletions
diff --git a/serd/serd.h b/serd/serd.h
index ce0213a7..30564943 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -254,6 +254,14 @@ typedef struct {
SerdStringView fragment; ///< Fragment
} SerdURI;
+/// Reader options
+typedef enum {
+ SERD_READ_LAX = 1 << 0 ///< Tolerate invalid input where possible
+} SerdReaderFlag;
+
+/// Bitwise OR of SerdReaderFlag values
+typedef uint32_t SerdReaderFlags;
+
/**
Writer style options
@@ -265,7 +273,7 @@ typedef struct {
typedef enum {
SERD_WRITE_ASCII = 1 << 0, ///< Escape all non-ASCII characters
SERD_WRITE_TERSE = 1 << 1, ///< Write terser output without newlines
- SERD_WRITE_STRICT = 1 << 2, ///< Abort with error on lossy output
+ SERD_WRITE_LAX = 1 << 2 ///< Tolerate lossy output
} SerdWriterFlag;
/// Bitwise OR of SerdWriterFlag values
@@ -1144,21 +1152,11 @@ SERD_API
SerdReader*
serd_reader_new(SerdWorld* world,
SerdSyntax syntax,
+ SerdReaderFlags flags,
const SerdSink* 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* 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
diff --git a/src/reader.c b/src/reader.c
index 1f8c2678..a11ba2ce 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -164,6 +164,7 @@ serd_reader_read_document(SerdReader* reader)
SerdReader*
serd_reader_new(SerdWorld* world,
SerdSyntax syntax,
+ SerdReaderFlags flags,
const SerdSink* sink,
size_t stack_size)
{
@@ -174,7 +175,7 @@ serd_reader_new(SerdWorld* world,
me->stack = serd_stack_new(stack_size);
me->syntax = syntax;
me->next_id = 1;
- me->strict = true;
+ me->strict = !(flags & SERD_READ_LAX);
me->rdf_first = push_node(me, SERD_URI, NS_RDF "first", 48);
me->rdf_rest = push_node(me, SERD_URI, NS_RDF "rest", 47);
@@ -184,12 +185,6 @@ serd_reader_new(SerdWorld* world,
}
void
-serd_reader_set_strict(SerdReader* reader, bool strict)
-{
- reader->strict = strict;
-}
-
-void
serd_reader_free(SerdReader* reader)
{
serd_reader_finish(reader);
diff --git a/src/serdi.c b/src/serdi.c
index 908cd037..d408fa7b 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -87,13 +87,13 @@ main(int argc, char** argv)
SerdSyntax input_syntax = (SerdSyntax)0;
SerdSyntax output_syntax = (SerdSyntax)0;
- SerdWriterFlags writer_flags = SERD_WRITE_STRICT;
+ 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 no_inline = false;
- bool lax = false;
bool use_model = false;
bool quiet = false;
size_t stack_size = 4194304;
@@ -116,8 +116,8 @@ main(int argc, char** argv)
} else if (argv[a][1] == 'h') {
return print_usage(argv[0], false);
} else if (argv[a][1] == 'l') {
- writer_flags &= ~SERD_WRITE_STRICT;
- lax = true;
+ reader_flags |= SERD_READ_LAX;
+ writer_flags |= SERD_WRITE_LAX;
} else if (argv[a][1] == 'm') {
use_model = true;
} else if (argv[a][1] == 'q') {
@@ -234,8 +234,9 @@ main(int argc, char** argv)
sink = serd_writer_get_sink(writer);
}
- reader = serd_reader_new(world, input_syntax, sink, stack_size);
- serd_reader_set_strict(reader, !lax);
+ reader = serd_reader_new(
+ world, input_syntax, reader_flags, sink, stack_size);
+
if (quiet) {
serd_world_set_log_func(world, serd_quiet_error_func, NULL);
}
diff --git a/src/writer.c b/src/writer.c
index 2f2a3914..0fb12dc3 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -325,7 +325,7 @@ write_uri(SerdWriter* writer, const char* utf8, size_t n_bytes, SerdStatus* st)
size_t size = 0;
len += write_character(writer, (const uint8_t*)utf8 + i, &size, st);
i += size;
- if (*st && (writer->flags & SERD_WRITE_STRICT)) {
+ if (*st && !(writer->flags & SERD_WRITE_LAX)) {
break;
} else if (size == 0) {
// Corrupt input, scan to start of next character
@@ -341,7 +341,7 @@ ewrite_uri(SerdWriter* writer, const char* utf8, size_t n_bytes)
SerdStatus st = SERD_SUCCESS;
write_uri(writer, utf8, n_bytes, &st);
- return (writer->flags & SERD_WRITE_STRICT) ? st : SERD_SUCCESS;
+ return (writer->flags & SERD_WRITE_LAX) ? SERD_SUCCESS : st;
}
SERD_WARN_UNUSED_RESULT static SerdStatus
@@ -470,7 +470,7 @@ write_text(SerdWriter* writer,
}
}
- return (writer->flags & SERD_WRITE_STRICT) ? st : SERD_SUCCESS;
+ return (writer->flags & SERD_WRITE_LAX) ? SERD_SUCCESS : st;
}
SERD_WARN_UNUSED_RESULT static size_t
diff --git a/tests/overflow_test.c b/tests/overflow_test.c
index 7e545793..e3031b7e 100644
--- a/tests/overflow_test.c
+++ b/tests/overflow_test.c
@@ -24,7 +24,9 @@
static SerdStatus
test(SerdWorld* world, SerdSink* sink, const char* str, size_t stack_size)
{
- SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, stack_size);
+ SerdReader* reader =
+ serd_reader_new(world, SERD_TURTLE, 0, sink, stack_size);
+
serd_reader_start_string(reader, str, NULL);
const SerdStatus st = serd_reader_read_document(reader);
serd_reader_free(reader);
diff --git a/tests/read_chunk_test.c b/tests/read_chunk_test.c
index 54513f06..f38f4cb8 100644
--- a/tests/read_chunk_test.c
+++ b/tests/read_chunk_test.c
@@ -80,7 +80,7 @@ main(void)
serd_sink_set_statement_func(sink, on_statement);
serd_sink_set_end_func(sink, on_end);
- 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/tests/serd_test.c b/tests/serd_test.c
index ac4b712c..b502c31f 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -134,7 +134,7 @@ test_read_chunks(void)
assert(sink);
serd_sink_set_statement_func(sink, count_statements);
- SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0, sink, 4096);
assert(reader);
assert(f);
@@ -216,7 +216,7 @@ test_strict_write(void)
SerdEnv* env = serd_env_new(NULL);
SerdWriter* writer = serd_writer_new(world,
SERD_TURTLE,
- SERD_WRITE_STRICT,
+ 0,
env,
(SerdWriteFunc)fwrite,
fd);
@@ -742,7 +742,7 @@ test_writer(const char* const path)
SerdWriter* writer = serd_writer_new(world,
SERD_TURTLE,
- 0,
+ SERD_WRITE_LAX,
env,
(SerdWriteFunc)fwrite,
fd);
@@ -858,7 +858,7 @@ test_reader(const char* path)
SerdSink* sink = serd_sink_new(&n_statements, NULL);
serd_sink_set_statement_func(sink, count_statements);
- SerdReader* reader = serd_reader_new(world, SERD_TURTLE, sink, 4096);
+ SerdReader* reader = serd_reader_new(world, SERD_TURTLE, 0, sink, 4096);
assert(reader);
serd_reader_add_blank_prefix(reader, "tmp");