aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2019-04-28 17:54:00 +0200
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:58 +0100
commit44e792d8da5ef93a88dac76b7b191e588203c42b (patch)
tree654d6767998c0a444f8eff8fd3de2461295e1fa3 /src
parent02f77d71211825b590e43f571b1d65bcf56cde4d (diff)
downloadserd-44e792d8da5ef93a88dac76b7b191e588203c42b.tar.gz
serd-44e792d8da5ef93a88dac76b7b191e588203c42b.tar.bz2
serd-44e792d8da5ef93a88dac76b7b191e588203c42b.zip
Replace serd_reader_set_strict() with SerdReaderFlags
This makes reader options extensible and should hopefully prevent the need for grafting on more similar functions in the future.
Diffstat (limited to 'src')
-rw-r--r--src/reader.c9
-rw-r--r--src/serdi.c13
-rw-r--r--src/writer.c6
3 files changed, 12 insertions, 16 deletions
diff --git a/src/reader.c b/src/reader.c
index f4a874cb..6a4b0dc2 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -158,6 +158,7 @@ serd_reader_read_document(SerdReader* reader)
SerdReader*
serd_reader_new(SerdWorld* world,
SerdSyntax syntax,
+ SerdReaderFlags flags,
const SerdSink* sink,
size_t stack_size)
{
@@ -172,7 +173,7 @@ serd_reader_new(SerdWorld* world,
me->stack = serd_stack_new(stack_size, serd_node_align);
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. This
particular kind of overflow could be detected (in emit_statement), but
@@ -189,12 +190,6 @@ serd_reader_new(SerdWorld* world,
}
void
-serd_reader_set_strict(SerdReader* reader, bool strict)
-{
- reader->strict = strict;
-}
-
-void
serd_reader_free(SerdReader* reader)
{
if (!reader) {
diff --git a/src/serdi.c b/src/serdi.c
index ec4b0384..14b3e6e5 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 &= ~(unsigned)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') {
@@ -236,8 +236,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 aa882a31..a6c5f8c7 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -326,7 +326,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
@@ -342,7 +342,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
@@ -471,7 +471,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