diff options
author | David Robillard <d@drobilla.net> | 2019-04-28 17:54:00 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-08 23:23:05 -0500 |
commit | 2ab2b5f2c7bd4d26aa99eee959f0e5192b3813dc (patch) | |
tree | 9fccf392d6eb69fb11b9bc2bbe24cf35eaa63ab2 /src | |
parent | 01daa5914169d57a6a6c4925d3f8d76db80a2bd8 (diff) | |
download | serd-2ab2b5f2c7bd4d26aa99eee959f0e5192b3813dc.tar.gz serd-2ab2b5f2c7bd4d26aa99eee959f0e5192b3813dc.tar.bz2 serd-2ab2b5f2c7bd4d26aa99eee959f0e5192b3813dc.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.c | 9 | ||||
-rw-r--r-- | src/serdi.c | 13 | ||||
-rw-r--r-- | src/writer.c | 10 |
3 files changed, 13 insertions, 19 deletions
diff --git a/src/reader.c b/src/reader.c index ceef5fb4..8a0b1a1f 100644 --- a/src/reader.c +++ b/src/reader.c @@ -156,6 +156,7 @@ serd_reader_read_document(SerdReader* reader) SerdReader* serd_reader_new(SerdWorld* const world, const SerdSyntax syntax, + SerdReaderFlags flags, const SerdSink* const sink, const size_t stack_size) { @@ -170,7 +171,7 @@ serd_reader_new(SerdWorld* const world, me->stack = serd_stack_new(stack_size, sizeof(SerdNode)); 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 @@ -187,12 +188,6 @@ serd_reader_new(SerdWorld* const 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 64206d7f..72b7afe1 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -97,12 +97,12 @@ 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 lax = false; bool quiet = false; size_t stack_size = 4194304; const char* add_prefix = NULL; @@ -126,8 +126,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] == 'q') { quiet = true; } else if (argv[a][1] == 'v') { @@ -232,10 +232,9 @@ main(int argc, char** argv) (SerdWriteFunc)serd_byte_sink_write, 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/src/writer.c b/src/writer.c index 3ac8f4d9..71766d9d 100644 --- a/src/writer.c +++ b/src/writer.c @@ -343,7 +343,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; } @@ -366,7 +366,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 @@ -531,7 +531,7 @@ write_text(SerdWriter* writer, // Write UTF-8 character size_t size = 0; len += write_character(writer, (const uint8_t*)utf8 + i - 1, &size, &st); - if (st && (writer->flags & SERD_WRITE_STRICT)) { + if (st && !(writer->flags & SERD_WRITE_LAX)) { return st; } @@ -545,7 +545,7 @@ write_text(SerdWriter* writer, } } - return (writer->flags & SERD_WRITE_STRICT) ? st : SERD_SUCCESS; + return (writer->flags & SERD_WRITE_LAX) ? SERD_SUCCESS : st; } typedef struct { @@ -796,7 +796,7 @@ write_uri_node(SerdWriter* const writer, : serd_write_uri(serd_relative_uri(uri, base_uri), uri_sink, &ctx); st = ctx.status; - if (st && (writer->flags & SERD_WRITE_STRICT)) { + if (st && !(writer->flags & SERD_WRITE_LAX)) { return st; } } else { |