aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-07-09 21:36:52 -0400
committerDavid Robillard <d@drobilla.net>2022-01-13 23:04:12 -0500
commit2638ded01498b41a67574a2eae4181106226a933 (patch)
tree1f57ba340780ccf3c729c7b7cf94650ab6d5a55a
parente0e5b83f30b784699a5ae039e8ae7e1dd69410d4 (diff)
downloadserd-2638ded01498b41a67574a2eae4181106226a933.tar.gz
serd-2638ded01498b41a67574a2eae4181106226a933.tar.bz2
serd-2638ded01498b41a67574a2eae4181106226a933.zip
Replace SERD_WRITE_STRICT flag with SERD_WRITE_LAX
The unset value for flags should represent the best default, which in this case is strict parsing. Lax parsing is the riskier opt-in option.
-rw-r--r--include/serd/serd.h2
-rw-r--r--src/serdi.c4
-rw-r--r--src/writer.c8
-rw-r--r--test/test_reader_writer.c4
-rw-r--r--test/test_writer.c6
5 files changed, 12 insertions, 12 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 3263027b..e2e610db 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -1598,7 +1598,7 @@ typedef enum {
SERD_WRITE_UNQUALIFIED = 1u << 1u, ///< Do not shorten URIs into CURIEs
SERD_WRITE_UNRESOLVED = 1u << 2u, ///< Do not make URIs relative
SERD_WRITE_TERSE = 1u << 3u, ///< Write terser output without newlines
- SERD_WRITE_STRICT = 1u << 4u ///< Abort with error on lossy output
+ SERD_WRITE_LAX = 1u << 4u ///< Tolerate lossy output
} SerdWriterFlag;
/// Bitwise OR of SerdWriterFlag values
diff --git a/src/serdi.c b/src/serdi.c
index 2aea8657..155e570a 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -98,7 +98,7 @@ main(int argc, char** argv)
SerdSyntax input_syntax = (SerdSyntax)0;
SerdSyntax output_syntax = (SerdSyntax)0;
- SerdWriterFlags writer_flags = SERD_WRITE_STRICT;
+ SerdWriterFlags writer_flags = 0;
bool from_string = false;
bool from_stdin = false;
bool bulk_read = true;
@@ -130,7 +130,7 @@ main(int argc, char** argv)
} else if (opt == 'h') {
return print_usage(prog, false);
} else if (opt == 'l') {
- writer_flags &= ~(unsigned)SERD_WRITE_STRICT;
+ writer_flags |= SERD_WRITE_LAX;
lax = true;
} else if (opt == 'q') {
quiet = true;
diff --git a/src/writer.c b/src/writer.c
index 74d858c7..2b1bc39d 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -338,7 +338,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;
}
@@ -361,7 +361,7 @@ ewrite_uri(SerdWriter* writer, const char* utf8, size_t n_bytes)
SerdStatus st = SERD_SUCCESS;
write_uri(writer, utf8, n_bytes, &st);
- return (st == SERD_ERR_BAD_WRITE || (writer->flags & SERD_WRITE_STRICT))
+ return (st == SERD_ERR_BAD_WRITE || !(writer->flags & SERD_WRITE_LAX))
? st
: SERD_SUCCESS;
}
@@ -527,7 +527,7 @@ write_text(SerdWriter* writer,
// Write UTF-8 character
size_t size = 0;
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;
}
@@ -541,7 +541,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 {
diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c
index ec9f194b..3f538ada 100644
--- a/test/test_reader_writer.c
+++ b/test/test_reader_writer.c
@@ -178,8 +178,8 @@ test_writer(const char* const path)
SerdWorld* world = serd_world_new();
SerdNodes* nodes = serd_world_nodes(world);
- SerdWriter* writer =
- serd_writer_new(world, SERD_TURTLE, 0, env, (SerdWriteFunc)fwrite, fd);
+ SerdWriter* writer = serd_writer_new(
+ world, SERD_TURTLE, SERD_WRITE_LAX, env, (SerdWriteFunc)fwrite, fd);
assert(writer);
serd_writer_chop_blank_prefix(writer, "tmp");
diff --git a/test/test_writer.c b/test/test_writer.c
index 169c460a..aa5694cd 100644
--- a/test/test_writer.c
+++ b/test/test_writer.c
@@ -181,9 +181,9 @@ test_strict_write(void)
FILE* fd = fopen(path, "wb");
assert(fd);
- SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
- SerdWriter* writer = serd_writer_new(
- world, SERD_TURTLE, SERD_WRITE_STRICT, env, (SerdWriteFunc)fwrite, fd);
+ SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
+ SerdWriter* writer =
+ serd_writer_new(world, SERD_TURTLE, 0u, env, (SerdWriteFunc)fwrite, fd);
assert(writer);