diff options
author | David Robillard <d@drobilla.net> | 2024-06-24 15:03:42 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-06-25 15:54:43 -0400 |
commit | 72ab488af39cd487a5cefc862e3e2d3466facff3 (patch) | |
tree | abc7cffe63594828e64d40de25219af8ea8b5e92 | |
parent | 47f30703ee6935de393303b7a4d6bab8ce7780f4 (diff) | |
download | serd-72ab488af39cd487a5cefc862e3e2d3466facff3.tar.gz serd-72ab488af39cd487a5cefc862e3e2d3466facff3.tar.bz2 serd-72ab488af39cd487a5cefc862e3e2d3466facff3.zip |
Clean up redundant and/or inconsistent conditionals
-rw-r--r-- | src/n3.c | 16 | ||||
-rw-r--r-- | src/stack.h | 4 | ||||
-rw-r--r-- | src/string.c | 12 | ||||
-rw-r--r-- | src/writer.c | 14 |
4 files changed, 19 insertions, 27 deletions
@@ -179,7 +179,7 @@ read_utf8_bytes(SerdReader* const reader, const uint8_t c) { *size = utf8_num_bytes(c); - if (*size <= 1 || *size > 4) { + if (*size <= 1) { return bad_char(reader, "invalid UTF-8 start 0x%X\n", c); } @@ -264,7 +264,7 @@ read_comment(SerdReader* const reader) skip_byte(reader, '#'); int c = 0; - while (((c = peek_byte(reader)) != 0xA) && c != 0xD && c != EOF && c) { + while (((c = peek_byte(reader)) > 0) && c != 0xA && c != 0xD) { skip_byte(reader, c); } } @@ -608,7 +608,7 @@ read_PN_LOCAL(SerdReader* const reader, const Ref dest, bool* const ate_dot) } } - while ((c = peek_byte(reader))) { // Middle: (PN_CHARS | '.' | ':')* + while ((c = peek_byte(reader)) > 0) { // Middle: (PN_CHARS | '.' | ':')* if (c == '.' || c == ':') { push_byte(reader, dest, eat_byte_safe(reader, c)); } else if ((st = read_PLX(reader, dest)) > SERD_FAILURE) { @@ -635,7 +635,7 @@ static SerdStatus read_PN_PREFIX_tail(SerdReader* const reader, const Ref dest) { int c = 0; - while ((c = peek_byte(reader))) { // Middle: (PN_CHARS | '.')* + while ((c = peek_byte(reader)) > 0) { // Middle: (PN_CHARS | '.')* if (c == '.') { push_byte(reader, dest, eat_byte_safe(reader, c)); } else if (read_PN_CHARS(reader, dest)) { @@ -671,13 +671,13 @@ read_LANGTAG(SerdReader* const reader, Ref* const dest) SerdStatus st = SERD_SUCCESS; TRY(st, push_byte(reader, *dest, eat_byte_safe(reader, c))); - while ((c = peek_byte(reader)) && is_alpha(c)) { + while (((c = peek_byte(reader)) > 0) && is_alpha(c)) { TRY(st, push_byte(reader, *dest, eat_byte_safe(reader, c))); } while (peek_byte(reader) == '-') { TRY(st, push_byte(reader, *dest, eat_byte_safe(reader, '-'))); - while ((c = peek_byte(reader)) && (is_alpha(c) || is_digit(c))) { + while (((c = peek_byte(reader)) > 0) && (is_alpha(c) || is_digit(c))) { TRY(st, push_byte(reader, *dest, eat_byte_safe(reader, c))); } } @@ -693,7 +693,7 @@ read_IRIREF_scheme(SerdReader* const reader, const Ref dest) return r_err(reader, SERD_ERR_BAD_SYNTAX, "bad IRI scheme start '%c'\n", c); } - while ((c = peek_byte(reader)) != EOF) { + while ((c = peek_byte(reader)) > 0) { if (c == '>') { return r_err(reader, SERD_ERR_BAD_SYNTAX, "missing IRI scheme\n"); } @@ -1003,7 +1003,7 @@ read_BLANK_NODE_LABEL(SerdReader* const reader, return r_err(reader, SERD_ERR_BAD_SYNTAX, "invalid name start\n"); } - while ((c = peek_byte(reader))) { // Middle: (PN_CHARS | '.')* + while ((c = peek_byte(reader)) > 0) { // Middle: (PN_CHARS | '.')* if (c == '.') { push_byte(reader, ref, eat_byte_safe(reader, c)); } else if (read_PN_CHARS(reader, ref)) { diff --git a/src/stack.h b/src/stack.h index d118430a..388dd054 100644 --- a/src/stack.h +++ b/src/stack.h @@ -78,9 +78,7 @@ serd_stack_push_aligned(SerdStack* stack, size_t n_bytes, size_t align) // Push padding if necessary const size_t pad = align - stack->size % align; - if (pad > 0) { - serd_stack_push(stack, pad); - } + serd_stack_push(stack, pad); // Set top of stack to pad count so we can properly pop later assert(pad < UINT8_MAX); diff --git a/src/string.c b/src/string.c index 11c12bee..936989c2 100644 --- a/src/string.c +++ b/src/string.c @@ -62,6 +62,9 @@ serd_substrlen(const uint8_t* const str, size_t* const n_bytes, SerdNodeFlags* const flags) { + assert(n_bytes); + assert(flags); + size_t n_chars = 0; size_t i = 0; SerdNodeFlags f = 0; @@ -71,12 +74,9 @@ serd_substrlen(const uint8_t* const str, serd_update_flags(str[i], &f); } } - if (n_bytes) { - *n_bytes = i; - } - if (flags) { - *flags = f; - } + + *n_bytes = i; + *flags = f; return n_chars; } diff --git a/src/writer.c b/src/writer.c index 1d3eed4d..bea1efcd 100644 --- a/src/writer.c +++ b/src/writer.c @@ -148,12 +148,6 @@ supports_abbrev(const SerdWriter* writer) return writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG; } -SERD_NODISCARD static bool -supports_uriref(const SerdWriter* writer) -{ - return writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG; -} - static SerdStatus free_context(WriteContext* const ctx) { @@ -746,7 +740,8 @@ write_uri_node(SerdWriter* const writer, } } - if (!has_scheme && !supports_uriref(writer) && + if (!has_scheme && + (writer->syntax == SERD_NTRIPLES || writer->syntax == SERD_NQUADS) && !serd_env_get_base_uri(writer->env, NULL)->buf) { return w_err(writer, SERD_ERR_BAD_ARG, @@ -870,7 +865,7 @@ write_node(SerdWriter* writer, static bool is_resource(const SerdNode* node) { - return node && node->buf && node->type > SERD_LITERAL; + return node->buf && node->type > SERD_LITERAL; } SERD_NODISCARD static SerdStatus @@ -944,8 +939,7 @@ serd_writer_write_statement(SerdWriter* writer, SerdStatus st = SERD_SUCCESS; - if (!is_resource(subject) || !is_resource(predicate) || !object || - !object->buf) { + if (!is_resource(subject) || !is_resource(predicate) || !object->buf) { return SERD_ERR_BAD_ARG; } |