aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-12-31 12:37:57 +0100
committerDavid Robillard <d@drobilla.net>2020-12-31 12:37:57 +0100
commit8a93d0b3be5b6d80a1bef85bc73b2661f5ab4376 (patch)
treec65c3327fde67505a8f989e57cb245ee0f286cb9 /src
parent19d8a055ff1e58a699e3679b701a1a60a2927243 (diff)
downloadserd-8a93d0b3be5b6d80a1bef85bc73b2661f5ab4376.tar.gz
serd-8a93d0b3be5b6d80a1bef85bc73b2661f5ab4376.tar.bz2
serd-8a93d0b3be5b6d80a1bef85bc73b2661f5ab4376.zip
Avoid "else" after "break" and "return"
Diffstat (limited to 'src')
-rw-r--r--src/.clang-tidy1
-rw-r--r--src/byte_sink.h4
-rw-r--r--src/byte_source.c15
-rw-r--r--src/env.c9
-rw-r--r--src/n3.c46
-rw-r--r--src/reader.c4
-rw-r--r--src/serdi.c15
-rw-r--r--src/string_utils.h13
-rw-r--r--src/uri.c9
-rw-r--r--src/uri_utils.h7
-rw-r--r--src/writer.c47
11 files changed, 117 insertions, 53 deletions
diff --git a/src/.clang-tidy b/src/.clang-tidy
index 251c57b0..5be37470 100644
--- a/src/.clang-tidy
+++ b/src/.clang-tidy
@@ -1,6 +1,5 @@
Checks: >
*,
- -*-else-after-return,
-*-magic-numbers,
-*-uppercase-literal-suffix,
-bugprone-branch-clone,
diff --git a/src/byte_sink.h b/src/byte_sink.h
index c3d5045a..71d525ce 100644
--- a/src/byte_sink.h
+++ b/src/byte_sink.h
@@ -70,7 +70,9 @@ serd_byte_sink_write(const void* buf, size_t len, SerdByteSink* bsink)
{
if (len == 0) {
return 0;
- } else if (bsink->block_size == 1) {
+ }
+
+ if (bsink->block_size == 1) {
return bsink->sink(buf, len, bsink->stream);
}
diff --git a/src/byte_source.c b/src/byte_source.c
index 5c0404a7..a62f7a47 100644
--- a/src/byte_source.c
+++ b/src/byte_source.c
@@ -30,15 +30,19 @@ serd_byte_source_page(SerdByteSource* source)
source->read_head = 0;
const size_t n_read = source->read_func(
source->file_buf, 1, source->page_size, source->stream);
+
if (n_read == 0) {
source->file_buf[0] = '\0';
source->eof = true;
return (source->error_func(source->stream)
? SERD_ERR_UNKNOWN : SERD_FAILURE);
- } else if (n_read < source->page_size) {
+ }
+
+ if (n_read < source->page_size) {
source->file_buf[n_read] = '\0';
source->buf_size = n_read;
}
+
return SERD_SUCCESS;
}
@@ -76,13 +80,12 @@ SerdStatus
serd_byte_source_prepare(SerdByteSource* source)
{
source->prepared = true;
+
if (source->from_stream) {
- if (source->page_size > 1) {
- return serd_byte_source_page(source);
- } else if (source->from_stream) {
- return serd_byte_source_advance(source);
- }
+ return (source->page_size > 1 ? serd_byte_source_page(source)
+ : serd_byte_source_advance(source));
}
+
return SERD_SUCCESS;
}
diff --git a/src/env.c b/src/env.c
index 843db088..d11553b4 100644
--- a/src/env.c
+++ b/src/env.c
@@ -76,7 +76,9 @@ serd_env_set_base_uri(SerdEnv* env,
{
if (!env || (uri && uri->type != SERD_URI)) {
return SERD_ERR_BAD_ARG;
- } else if (!uri || !uri->buf) {
+ }
+
+ if (!uri || !uri->buf) {
serd_node_free(&env->base_uri_node);
env->base_uri_node = SERD_NODE_NULL;
env->base_uri = SERD_URI_NULL;
@@ -139,7 +141,9 @@ serd_env_set_prefix(SerdEnv* env,
{
if (!name->buf || uri->type != SERD_URI) {
return SERD_ERR_BAD_ARG;
- } else if (serd_uri_string_has_scheme(uri->buf)) {
+ }
+
+ if (serd_uri_string_has_scheme(uri->buf)) {
// Set prefix to absolute URI
serd_env_add(env, name, uri);
} else {
@@ -152,6 +156,7 @@ serd_env_set_prefix(SerdEnv* env,
serd_env_add(env, name, &abs_uri_node);
serd_node_free(&abs_uri_node);
}
+
return SERD_SUCCESS;
}
diff --git a/src/n3.c b/src/n3.c
index 81ec5d56..c12b1ff0 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -403,7 +403,9 @@ read_String(SerdReader* reader, Ref node, SerdNodeFlags* flags)
const int q2 = peek_byte(reader);
if (q2 == EOF) {
return r_err(reader, SERD_ERR_BAD_SYNTAX, "unexpected end of file\n");
- } else if (q2 != q1) { // Short string (not triple quoted)
+ }
+
+ if (q2 != q1) { // Short string (not triple quoted)
return read_STRING_LITERAL(reader, node, flags, (uint8_t)q1);
}
@@ -411,7 +413,9 @@ read_String(SerdReader* reader, Ref node, SerdNodeFlags* flags)
const int q3 = peek_byte(reader);
if (q3 == EOF) {
return r_err(reader, SERD_ERR_BAD_SYNTAX, "unexpected end of file\n");
- } else if (q3 != q1) { // Empty short string ("" or '')
+ }
+
+ if (q3 != q1) { // Empty short string ("" or '')
return SERD_SUCCESS;
}
@@ -655,7 +659,9 @@ read_IRIREF_scheme(SerdReader* reader, Ref dest)
while ((c = peek_byte(reader)) != EOF) {
if (c == '>') {
return r_err(reader, SERD_ERR_BAD_SYNTAX, "missing IRI scheme\n");
- } else if (!is_uri_scheme_char(c)) {
+ }
+
+ if (!is_uri_scheme_char(c)) {
return r_err(reader, SERD_ERR_BAD_SYNTAX,
"bad IRI scheme char U+%04X (%c)\n",
(unsigned)c,
@@ -752,7 +758,9 @@ read_PrefixedName(SerdReader* reader, Ref dest, bool read_prefix, bool* ate_dot)
SerdStatus st = SERD_SUCCESS;
if (read_prefix && ((st = read_PN_PREFIX(reader, dest)) > SERD_FAILURE)) {
return st;
- } else if (peek_byte(reader) != ':') {
+ }
+
+ if (peek_byte(reader) != ':') {
return SERD_FAILURE;
}
@@ -907,9 +915,11 @@ read_verb(SerdReader* reader, Ref* dest)
pop_node(reader, *dest);
*dest = push_node(reader, SERD_URI, NS_RDF "type", 47);
return SERD_SUCCESS;
- } else if (st > SERD_FAILURE ||
- read_PrefixedName(reader, *dest, false, &ate_dot) ||
- ate_dot) {
+ }
+
+ if (st > SERD_FAILURE ||
+ read_PrefixedName(reader, *dest, false, &ate_dot) ||
+ ate_dot) {
*dest = pop_node(reader, *dest);
return r_err(reader, SERD_ERR_BAD_SYNTAX, "bad verb\n");
}
@@ -1352,10 +1362,13 @@ read_base(SerdReader* reader, bool sparql, bool token)
read_ws_star(reader);
if (!sparql) {
return eat_byte_check(reader, '.') ? SERD_SUCCESS : SERD_ERR_BAD_SYNTAX;
- } else if (peek_byte(reader) == '.') {
+ }
+
+ if (peek_byte(reader) == '.') {
return r_err(reader, SERD_ERR_BAD_SYNTAX,
"full stop after SPARQL BASE\n");
}
+
return SERD_SUCCESS;
}
@@ -1432,10 +1445,13 @@ read_wrappedGraph(SerdReader* reader, ReadContext* ctx)
SerdStatus st = read_subject(reader, *ctx, &ctx->subject, &s_type);
if (st) {
return r_err(reader, SERD_ERR_BAD_SYNTAX, "bad subject\n");
- } else if (read_triples(reader, *ctx, &ate_dot) && s_type != '[') {
+ }
+
+ if (read_triples(reader, *ctx, &ate_dot) && s_type != '[') {
return r_err(reader, SERD_ERR_BAD_SYNTAX,
"missing predicate object list\n");
}
+
pop_node(reader, ctx->subject);
read_ws_star(reader);
if (peek_byte(reader) == '.') {
@@ -1527,12 +1543,14 @@ read_n3_statement(SerdReader* reader)
} else if ((st = read_triples(reader, ctx, &ate_dot))) {
if (st == SERD_FAILURE && s_type == '[') {
return SERD_SUCCESS;
- } else if (ate_dot) {
+ }
+
+ if (ate_dot) {
return r_err(reader, SERD_ERR_BAD_SYNTAX,
"unexpected end of statement\n");
- } else {
- return st > SERD_FAILURE ? st : SERD_ERR_BAD_SYNTAX;
}
+
+ return st > SERD_FAILURE ? st : SERD_ERR_BAD_SYNTAX;
} else if (!ate_dot) {
read_ws_star(reader);
st = (eat_byte_check(reader, '.') == '.') ? SERD_SUCCESS
@@ -1578,7 +1596,9 @@ read_nquadsDoc(SerdReader* reader)
read_ws_star(reader);
if (peek_byte(reader) == EOF) {
break;
- } else if (peek_byte(reader) == '@') {
+ }
+
+ if (peek_byte(reader) == '@') {
return r_err(reader, SERD_ERR_BAD_SYNTAX,
"syntax does not support directives\n");
}
diff --git a/src/reader.c b/src/reader.c
index fd859bf8..2b802b5f 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -394,7 +394,9 @@ serd_reader_read_source(SerdReader* reader,
if (st || (st = serd_reader_prepare(reader))) {
serd_reader_end_stream(reader);
return st;
- } else if ((st = read_doc(reader))) {
+ }
+
+ if ((st = read_doc(reader))) {
serd_reader_end_stream(reader);
return st;
}
diff --git a/src/serdi.c b/src/serdi.c
index 189692dd..69304cad 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -205,7 +205,9 @@ main(int argc, char** argv)
in_name = (const uint8_t*)"(stdin)";
in_fd = stdin;
break;
- } else if (argv[a][1] == 'a') {
+ }
+
+ if (argv[a][1] == 'a') {
ascii = true;
} else if (argv[a][1] == 'b') {
bulk_write = true;
@@ -229,29 +231,36 @@ main(int argc, char** argv)
} else if (argv[a][1] == 'i') {
if (++a == argc) {
return missing_arg(argv[0], 'i');
- } else if (!(input_syntax = get_syntax(argv[a]))) {
+ }
+
+ if (!(input_syntax = get_syntax(argv[a]))) {
return print_usage(argv[0], true);
}
} else if (argv[a][1] == 'o') {
if (++a == argc) {
return missing_arg(argv[0], 'o');
- } else if (!(output_syntax = get_syntax(argv[a]))) {
+ }
+
+ if (!(output_syntax = get_syntax(argv[a]))) {
return print_usage(argv[0], true);
}
} else if (argv[a][1] == 'p') {
if (++a == argc) {
return missing_arg(argv[0], 'p');
}
+
add_prefix = (const uint8_t*)argv[a];
} else if (argv[a][1] == 'c') {
if (++a == argc) {
return missing_arg(argv[0], 'c');
}
+
chop_prefix = (const uint8_t*)argv[a];
} else if (argv[a][1] == 'r') {
if (++a == argc) {
return missing_arg(argv[0], 'r');
}
+
root_uri = (const uint8_t*)argv[a];
} else {
SERDI_ERRORF("invalid option -- '%s'\n", argv[a] + 1);
diff --git a/src/string_utils.h b/src/string_utils.h
index 744ba4ca..a80c3a27 100644
--- a/src/string_utils.h
+++ b/src/string_utils.h
@@ -119,13 +119,20 @@ utf8_num_bytes(const uint8_t c)
{
if ((c & 0x80) == 0) { // Starts with `0'
return 1;
- } else if ((c & 0xE0) == 0xC0) { // Starts with `110'
+ }
+
+ if ((c & 0xE0) == 0xC0) { // Starts with `110'
return 2;
- } else if ((c & 0xF0) == 0xE0) { // Starts with `1110'
+ }
+
+ if ((c & 0xF0) == 0xE0) { // Starts with `1110'
return 3;
- } else if ((c & 0xF8) == 0xF0) { // Starts with `11110'
+ }
+
+ if ((c & 0xF8) == 0xF0) { // Starts with `11110'
return 4;
}
+
return 0;
}
diff --git a/src/uri.c b/src/uri.c
index 54ff1bba..718f24ee 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -33,7 +33,9 @@ serd_uri_to_path(const uint8_t* uri)
if (strncmp((const char*)uri, "file:", 5)) {
fprintf(stderr, "Non-file URI `%s'\n", uri);
return NULL;
- } else if (!strncmp((const char*)uri, "file://localhost/", 17)) {
+ }
+
+ if (!strncmp((const char*)uri, "file://localhost/", 17)) {
path = uri + 16;
} else if (!strncmp((const char*)uri, "file://", 7)) {
path = uri + 7;
@@ -41,6 +43,7 @@ serd_uri_to_path(const uint8_t* uri)
fprintf(stderr, "Invalid file URI `%s'\n", uri);
return NULL;
}
+
if (is_windows_path(path + 1)) {
++path; // Special case for terrible Windows file URIs
}
@@ -106,7 +109,9 @@ serd_uri_string_has_scheme(const uint8_t* utf8)
for (uint8_t c = 0; (c = *++utf8) != '\0';) {
if (!is_uri_scheme_char(c)) {
return false;
- } else if (c == ':') {
+ }
+
+ if (c == ':') {
return true; // End of scheme
}
}
diff --git a/src/uri_utils.h b/src/uri_utils.h
index 7fa87463..d7c90b12 100644
--- a/src/uri_utils.h
+++ b/src/uri_utils.h
@@ -41,11 +41,8 @@ uri_path_len(const SerdURI* uri)
static inline uint8_t
uri_path_at(const SerdURI* uri, size_t i)
{
- if (i < uri->path_base.len) {
- return uri->path_base.buf[i];
- } else {
- return uri->path.buf[i - uri->path_base.len];
- }
+ return (i < uri->path_base.len) ? uri->path_base.buf[i]
+ : uri->path.buf[i - uri->path_base.len];
}
/**
diff --git a/src/writer.c b/src/writer.c
index 987d2b98..8c0d4b3f 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -212,10 +212,10 @@ write_character(SerdWriter* writer, const uint8_t* utf8, size_t* size)
if (c <= 0xFFFF) {
snprintf(escape, sizeof(escape), "\\u%04X", c);
return sink(escape, 6, writer);
- } else {
- snprintf(escape, sizeof(escape), "\\U%08X", c);
- return sink(escape, 10, writer);
}
+
+ snprintf(escape, sizeof(escape), "\\U%08X", c);
+ return sink(escape, 10, writer);
}
static inline bool
@@ -454,10 +454,12 @@ write_literal(SerdWriter* writer,
!strcmp(type_uri + sizeof(NS_XSD) - 1, "integer"))) {
sink(node->buf, node->n_bytes, writer);
return true;
- } else if (!strncmp(type_uri, NS_XSD, sizeof(NS_XSD) - 1) &&
- !strcmp(type_uri + sizeof(NS_XSD) - 1, "decimal") &&
- strchr((const char*)node->buf, '.') &&
- node->buf[node->n_bytes - 1] != '.') {
+ }
+
+ if (!strncmp(type_uri, NS_XSD, sizeof(NS_XSD) - 1) &&
+ !strcmp(type_uri + sizeof(NS_XSD) - 1, "decimal") &&
+ strchr((const char*)node->buf, '.') &&
+ node->buf[node->n_bytes - 1] != '.') {
/* xsd:decimal literals without trailing digits, e.g. "5.", can
not be written bare in Turtle. We could add a 0 which is
prettier, but changes the text and breaks round tripping.
@@ -520,11 +522,15 @@ write_uri_node(SerdWriter* const writer,
if (field == FIELD_PREDICATE &&
!strcmp((const char*)node->buf, NS_RDF "type")) {
return sink("a", 1, writer) == 1;
- } else if (!strcmp((const char*)node->buf, NS_RDF "nil")) {
+ }
+
+ if (!strcmp((const char*)node->buf, NS_RDF "nil")) {
return sink("()", 2, writer) == 2;
- } else if (has_scheme && (writer->style & SERD_STYLE_CURIED) &&
- serd_env_qualify(writer->env, node, &prefix, &suffix) &&
- is_name(suffix.buf, suffix.len)) {
+ }
+
+ if (has_scheme && (writer->style & SERD_STYLE_CURIED) &&
+ serd_env_qualify(writer->env, node, &prefix, &suffix) &&
+ is_name(suffix.buf, suffix.len)) {
write_uri(writer, prefix.buf, prefix.n_bytes);
sink(":", 1, writer);
write_uri(writer, suffix.buf, suffix.len);
@@ -618,18 +624,24 @@ write_blank(SerdWriter* const writer,
if (is_inline_start(writer, field, flags)) {
++writer->indent;
return write_sep(writer, SEP_ANON_BEGIN);
- } else if (field == FIELD_SUBJECT && (flags & SERD_LIST_S_BEGIN)) {
+ }
+
+ if (field == FIELD_SUBJECT && (flags & SERD_LIST_S_BEGIN)) {
assert(writer->list_depth == 0);
copy_node(&writer->list_subj, node);
++writer->list_depth;
++writer->indent;
return write_sep(writer, SEP_LIST_BEGIN);
- } else if (field == FIELD_OBJECT && (flags & SERD_LIST_O_BEGIN)) {
+ }
+
+ if (field == FIELD_OBJECT && (flags & SERD_LIST_O_BEGIN)) {
++writer->indent;
++writer->list_depth;
return write_sep(writer, SEP_LIST_BEGIN);
- } else if ((field == FIELD_SUBJECT && (flags & SERD_EMPTY_S)) ||
- (field == FIELD_OBJECT && (flags & SERD_EMPTY_O))) {
+ }
+
+ if ((field == FIELD_SUBJECT && (flags & SERD_EMPTY_S)) ||
+ (field == FIELD_OBJECT && (flags & SERD_EMPTY_O))) {
return sink("[]", 2, writer) == 2;
}
}
@@ -703,10 +715,13 @@ write_list_obj(SerdWriter* writer,
--writer->indent;
write_sep(writer, SEP_LIST_END);
return true;
- } else if (!strcmp((const char*)predicate->buf, NS_RDF "first")) {
+ }
+
+ if (!strcmp((const char*)predicate->buf, NS_RDF "first")) {
write_sep(writer, SEP_LIST_SEP);
write_node(writer, object, datatype, lang, FIELD_OBJECT, flags);
}
+
return false;
}