diff options
author | David Robillard <d@drobilla.net> | 2017-06-29 12:53:23 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2017-06-30 10:29:33 -0400 |
commit | 902d171c5e79561a534c3cbb9cc547cd1fadeab7 (patch) | |
tree | 20b2e3bdadb7e390ab33d5e1163ebdfe8b6280cf /src | |
parent | 195e4bcff3c4dfd3fe8bbf0df57d53ce89ca99e8 (diff) | |
download | serd-902d171c5e79561a534c3cbb9cc547cd1fadeab7.tar.gz serd-902d171c5e79561a534c3cbb9cc547cd1fadeab7.tar.bz2 serd-902d171c5e79561a534c3cbb9cc547cd1fadeab7.zip |
Fix various clang-tidy issues
Diffstat (limited to 'src')
-rw-r--r-- | src/env.c | 32 | ||||
-rw-r--r-- | src/node.c | 8 | ||||
-rw-r--r-- | src/reader.c | 83 | ||||
-rw-r--r-- | src/serd_internal.h | 2 | ||||
-rw-r--r-- | src/string.c | 4 | ||||
-rw-r--r-- | src/uri.c | 28 | ||||
-rw-r--r-- | src/writer.c | 2 |
7 files changed, 78 insertions, 81 deletions
@@ -69,16 +69,16 @@ serd_env_get_base_uri(const SerdEnv* env, SERD_API SerdStatus serd_env_set_base_uri(SerdEnv* env, - const SerdNode* uri_node) + const SerdNode* uri) { - if (!env || !uri_node) { + if (!env || !uri) { return SERD_ERR_BAD_ARG; } // Resolve base URI and create a new node and URI for it SerdURI base_uri; SerdNode base_uri_node = serd_node_new_uri_from_node( - uri_node, &env->base_uri, &base_uri); + uri, &env->base_uri, &base_uri); if (base_uri_node.buf) { // Replace the current base URI @@ -128,18 +128,18 @@ SERD_API SerdStatus serd_env_set_prefix(SerdEnv* env, const SerdNode* name, - const SerdNode* uri_node) + const SerdNode* uri) { - if (!name->buf || uri_node->type != SERD_URI) { + if (!name->buf || uri->type != SERD_URI) { return SERD_ERR_BAD_ARG; - } else if (serd_uri_string_has_scheme(uri_node->buf)) { + } else if (serd_uri_string_has_scheme(uri->buf)) { // Set prefix to absolute URI - serd_env_add(env, name, uri_node); + serd_env_add(env, name, uri); } else { // Resolve relative URI and create a new node and URI for it SerdURI abs_uri; SerdNode abs_uri_node = serd_node_new_uri_from_node( - uri_node, &env->base_uri, &abs_uri); + uri, &env->base_uri, &abs_uri); // Set prefix to resolved (absolute) URI serd_env_add(env, name, &abs_uri_node); @@ -185,7 +185,7 @@ SERD_API bool serd_env_qualify(const SerdEnv* env, const SerdNode* uri, - SerdNode* prefix_name, + SerdNode* prefix, SerdChunk* suffix) { for (size_t i = 0; i < env->n_prefixes; ++i) { @@ -194,7 +194,7 @@ serd_env_qualify(const SerdEnv* env, if (!strncmp((const char*)uri->buf, (const char*)prefix_uri->buf, prefix_uri->n_bytes)) { - *prefix_name = env->prefixes[i].name; + *prefix = env->prefixes[i].name; suffix->buf = uri->buf + prefix_uri->n_bytes; suffix->len = uri->n_bytes - prefix_uri->n_bytes; if (is_name(suffix->buf, suffix->len)) { @@ -209,23 +209,23 @@ serd_env_qualify(const SerdEnv* env, SERD_API SerdStatus serd_env_expand(const SerdEnv* env, - const SerdNode* qname, + const SerdNode* curie, SerdChunk* uri_prefix, SerdChunk* uri_suffix) { const uint8_t* const colon = (const uint8_t*)memchr( - qname->buf, ':', qname->n_bytes + 1); + curie->buf, ':', curie->n_bytes + 1); if (!colon) { - return SERD_ERR_BAD_ARG; // Invalid qname + return SERD_ERR_BAD_ARG; // Invalid CURIE } - const size_t name_len = colon - qname->buf; - const SerdPrefix* const prefix = serd_env_find(env, qname->buf, name_len); + const size_t name_len = colon - curie->buf; + const SerdPrefix* const prefix = serd_env_find(env, curie->buf, name_len); if (prefix) { uri_prefix->buf = prefix->uri.buf; uri_prefix->len = prefix->uri.n_bytes; uri_suffix->buf = colon + 1; - uri_suffix->len = qname->n_bytes - (colon - qname->buf) - 1; + uri_suffix->len = curie->n_bytes - (colon - curie->buf) - 1; return SERD_SUCCESS; } return SERD_ERR_NOT_FOUND; @@ -33,16 +33,16 @@ SERD_API SerdNode -serd_node_from_string(SerdType type, const uint8_t* buf) +serd_node_from_string(SerdType type, const uint8_t* str) { - if (!buf) { + if (!str) { return SERD_NODE_NULL; } uint32_t flags = 0; size_t buf_n_bytes = 0; - const size_t buf_n_chars = serd_strlen(buf, &buf_n_bytes, &flags); - SerdNode ret = { buf, buf_n_bytes, buf_n_chars, flags, type }; + const size_t buf_n_chars = serd_strlen(str, &buf_n_bytes, &flags); + SerdNode ret = { str, buf_n_bytes, buf_n_chars, flags, type }; return ret; } diff --git a/src/reader.c b/src/reader.c index 54e2724a..0ea95fcc 100644 --- a/src/reader.c +++ b/src/reader.c @@ -189,7 +189,7 @@ push_node_padded(SerdReader* reader, size_t maxlen, #ifdef SERD_STACK_CHECK reader->allocs = realloc( - reader->allocs, sizeof(uint8_t*) * (++reader->n_allocs)); + reader->allocs, sizeof(reader->allocs) * (++reader->n_allocs)); reader->allocs[reader->n_allocs - 1] = ((uint8_t*)mem - reader->stack.buf); #endif return (uint8_t*)node - reader->stack.buf; @@ -278,10 +278,9 @@ read_HEX(SerdReader* reader) const uint8_t c = peek_byte(reader); if (is_digit(c) || in_range(c, 'A', 'F') || in_range(c, 'a', 'f')) { return eat_byte_safe(reader, c); - } else { - return r_err(reader, SERD_ERR_BAD_SYNTAX, - "invalid hexadecimal digit `%c'\n", c); } + return r_err(reader, SERD_ERR_BAD_SYNTAX, + "invalid hexadecimal digit `%c'\n", c); } // Read UCHAR escape, initial \ is already eaten by caller @@ -456,9 +455,8 @@ read_character(SerdReader* reader, Ref dest, SerdNodeFlags* flags, uint8_t c) } push_byte(reader, dest, c); return SERD_SUCCESS; - } else { - return read_utf8_character(reader, dest, c); } + return read_utf8_character(reader, dest, c); } // [10] comment ::= '#' ( [^#xA #xD] )* @@ -540,11 +538,10 @@ read_STRING_LITERAL_LONG(SerdReader* reader, SerdNodeFlags* flags, uint8_t q) if (q2 == q && q3 == q) { // End of string eat_byte_safe(reader, q3); return ref; - } else { - *flags |= SERD_HAS_QUOTE; - push_byte(reader, ref, c); - read_character(reader, ref, flags, q2); } + *flags |= SERD_HAS_QUOTE; + push_byte(reader, ref, c); + read_character(reader, ref, flags, q2); } else { read_character(reader, ref, flags, eat_byte_safe(reader, c)); } @@ -672,11 +669,10 @@ read_PLX(SerdReader* reader, Ref dest) if (is_alpha(c = peek_byte(reader))) { // Escapes like \u \n etc. are not supported return SERD_ERR_BAD_SYNTAX; - } else { - // Allow escaping of pretty much any other character - push_byte(reader, dest, eat_byte_safe(reader, c)); - return SERD_SUCCESS; } + // Allow escaping of pretty much any other character + push_byte(reader, dest, eat_byte_safe(reader, c)); + return SERD_SUCCESS; default: return SERD_FAILURE; } @@ -1001,27 +997,26 @@ read_verb(SerdReader* reader, Ref* dest) { if (peek_byte(reader) == '<') { return (*dest = read_IRIREF(reader)); - } else { - /* Either a qname, or "a". Read the prefix first, and if it is in fact - "a", produce that instead. - */ - *dest = push_node(reader, SERD_CURIE, "", 0); - SerdNode* node = deref(reader, *dest); - const SerdStatus st = read_PN_PREFIX(reader, *dest); - bool ate_dot = false; - if (!st && node->n_bytes == 1 && node->buf[0] == 'a' && - is_token_end(peek_byte(reader))) { - pop_node(reader, *dest); - return (*dest = push_node(reader, SERD_URI, NS_RDF "type", 47)); - } else if (st > SERD_FAILURE || - !read_PrefixedName(reader, *dest, false, &ate_dot) || - ate_dot) { - return (*dest = pop_node(reader, *dest)); - } else { - return true; - } } - return false; + + /* Either a qname, or "a". Read the prefix first, and if it is in fact + "a", produce that instead. + */ + *dest = push_node(reader, SERD_CURIE, "", 0); + SerdNode* node = deref(reader, *dest); + const SerdStatus st = read_PN_PREFIX(reader, *dest); + bool ate_dot = false; + if (!st && node->n_bytes == 1 && node->buf[0] == 'a' && + is_token_end(peek_byte(reader))) { + pop_node(reader, *dest); + return (*dest = push_node(reader, SERD_URI, NS_RDF "type", 47)); + } else if (st > SERD_FAILURE || + !read_PrefixedName(reader, *dest, false, &ate_dot) || + ate_dot) { + return (*dest = pop_node(reader, *dest)); + } + + return true; } static Ref @@ -1901,16 +1896,18 @@ serd_reader_end_stream(SerdReader* me) SERD_API SerdStatus -serd_reader_read_file_handle(SerdReader* me, FILE* file, const uint8_t* name) +serd_reader_read_file_handle(SerdReader* reader, + FILE* file, + const uint8_t* name) { return serd_reader_read_source( - me, (SerdSource)fread, (SerdStreamErrorFunc)ferror, + reader, (SerdSource)fread, (SerdStreamErrorFunc)ferror, file, name, SERD_PAGE_SIZE); } SERD_API SerdStatus -serd_reader_read_source(SerdReader* me, +serd_reader_read_source(SerdReader* reader, SerdSource source, SerdStreamErrorFunc error, void* stream, @@ -1918,17 +1915,17 @@ serd_reader_read_source(SerdReader* me, size_t page_size) { SerdStatus st = serd_reader_start_source_stream( - me, source, error, stream, name, page_size); + reader, source, error, stream, name, page_size); - if ((st = serd_reader_prepare(me))) { - serd_reader_end_stream(me); + if (st || (st = serd_reader_prepare(reader))) { + serd_reader_end_stream(reader); return st; - } else if (!read_doc(me)) { - serd_reader_end_stream(me); + } else if (!read_doc(reader)) { + serd_reader_end_stream(reader); return SERD_ERR_UNKNOWN; } - return serd_reader_end_stream(me); + return serd_reader_end_stream(reader); } SERD_API diff --git a/src/serd_internal.h b/src/serd_internal.h index 297b4507..aa5b3c53 100644 --- a/src/serd_internal.h +++ b/src/serd_internal.h @@ -43,7 +43,7 @@ static inline FILE* serd_fopen(const char* path, const char* mode) { - FILE* fd = fopen((const char*)path, mode); + FILE* fd = fopen(path, mode); if (!fd) { fprintf(stderr, "Error opening file %s (%s)\n", path, strerror(errno)); return NULL; diff --git a/src/string.c b/src/string.c index 1e653795..9381015d 100644 --- a/src/string.c +++ b/src/string.c @@ -20,9 +20,9 @@ SERD_API const uint8_t* -serd_strerror(SerdStatus st) +serd_strerror(SerdStatus status) { - switch (st) { + switch (status) { case SERD_SUCCESS: return (const uint8_t*)"Success"; case SERD_FAILURE: return (const uint8_t*)"Non-fatal failure"; case SERD_ERR_UNKNOWN: return (const uint8_t*)"Unknown error"; @@ -137,9 +137,9 @@ serd_uri_dump(const SerdURI* uri, FILE* file) SERD_API SerdStatus -serd_uri_parse(const uint8_t* utf8, SerdURI* uri) +serd_uri_parse(const uint8_t* utf8, SerdURI* out) { - *uri = SERD_URI_NULL; + *out = SERD_URI_NULL; const uint8_t* ptr = utf8; @@ -155,8 +155,8 @@ serd_uri_parse(const uint8_t* utf8, SerdURI* uri) ptr = utf8; goto path; // Relative URI (starts with path by definition) case ':': - uri->scheme.buf = utf8; - uri->scheme.len = (ptr++) - utf8; + out->scheme.buf = utf8; + out->scheme.len = (ptr++) - utf8; goto maybe_authority; // URI with scheme case '+': case '-': case '.': continue; @@ -175,14 +175,14 @@ serd_uri_parse(const uint8_t* utf8, SerdURI* uri) maybe_authority: if (*ptr == '/' && *(ptr + 1) == '/') { ptr += 2; - uri->authority.buf = ptr; + out->authority.buf = ptr; for (uint8_t c; (c = *ptr) != '\0'; ++ptr) { switch (c) { case '/': goto path; case '?': goto query; case '#': goto fragment; default: - ++uri->authority.len; + ++out->authority.len; } } } @@ -197,14 +197,14 @@ path: case '\0': goto end; default: break; } - uri->path.buf = ptr; - uri->path.len = 0; + out->path.buf = ptr; + out->path.len = 0; for (uint8_t c; (c = *ptr) != '\0'; ++ptr) { switch (c) { case '?': goto query; case '#': goto fragment; default: - ++uri->path.len; + ++out->path.len; } } @@ -214,13 +214,13 @@ path: */ query: if (*ptr == '?') { - uri->query.buf = ++ptr; + out->query.buf = ++ptr; for (uint8_t c; (c = *ptr) != '\0'; ++ptr) { switch (c) { case '#': goto fragment; default: - ++uri->query.len; + ++out->query.len; } } } @@ -231,16 +231,16 @@ query: */ fragment: if (*ptr == '#') { - uri->fragment.buf = ptr; + out->fragment.buf = ptr; while (*ptr++ != '\0') { - ++uri->fragment.len; + ++out->fragment.len; } } end: #ifdef URI_DEBUG fprintf(stderr, "PARSE URI <%s>\n", utf8); - serd_uri_dump(uri, stderr); + serd_uri_dump(out, stderr); fprintf(stderr, "\n"); #endif diff --git a/src/writer.c b/src/writer.c index 3c3bbb48..75d61bc8 100644 --- a/src/writer.c +++ b/src/writer.c @@ -669,7 +669,7 @@ serd_writer_write_statement(SerdWriter* writer, } #define TRY(write_result) \ - if (!write_result) { \ + if (!(write_result)) { \ return SERD_ERR_UNKNOWN; \ } |