From 44e792d8da5ef93a88dac76b7b191e588203c42b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 28 Apr 2019 17:54:00 +0200 Subject: 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. --- src/reader.c | 9 ++------- src/serdi.c | 13 +++++++------ src/writer.c | 6 +++--- 3 files changed, 12 insertions(+), 16 deletions(-) (limited to 'src') 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 @@ -188,12 +189,6 @@ serd_reader_new(SerdWorld* world, return me; } -void -serd_reader_set_strict(SerdReader* reader, bool strict) -{ - reader->strict = strict; -} - void serd_reader_free(SerdReader* 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 -- cgit v1.2.1