From f3c95977f6c71b936e98f41c321265835c4fd623 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 25 Dec 2011 07:09:29 +0000 Subject: Near 100% branch coverage. git-svn-id: http://svn.drobilla.net/serd/trunk@277 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/env.c | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) (limited to 'src/env.c') diff --git a/src/env.c b/src/env.c index 2a63cf1d..89eaae6c 100644 --- a/src/env.c +++ b/src/env.c @@ -111,8 +111,6 @@ serd_env_add(SerdEnv* env, const SerdNode* name, const SerdNode* uri) { - assert(name && uri); - assert(name->n_bytes == strlen((const char*)name->buf)); SerdPrefix* const prefix = serd_env_find(env, name->buf, name->n_bytes); if (prefix) { SerdNode old_prefix_uri = prefix->uri; @@ -132,7 +130,7 @@ serd_env_set_prefix(SerdEnv* env, const SerdNode* name, const SerdNode* uri_node) { - if (!name->buf || !uri_node->buf || uri_node->type != SERD_URI) { + if (!name->buf || uri_node->type != SERD_URI) { return SERD_ERR_BAD_ARG; } else if (serd_uri_string_has_scheme(uri_node->buf)) { // Set prefix to absolute URI @@ -164,16 +162,10 @@ serd_env_set_prefix_from_strings(SerdEnv* env, return ret; } -static inline bool -is_nameStartChar(const uint8_t c) -{ - return is_alpha(c) || is_digit(c) || c == '_'; -} - static inline bool is_nameChar(const uint8_t c) { - return is_nameStartChar(c) || c == '.' || c == 0xB7; + return is_alpha(c) || is_digit(c) || c == '_'; } /** @@ -183,15 +175,12 @@ is_nameChar(const uint8_t c) static inline bool is_name(const uint8_t* buf, size_t len) { - if (is_nameStartChar(buf[0])) { - for (size_t i = 1; i < len; ++i) { - if (!is_nameChar(buf[i])) { - return false; - } + for (size_t i = 0; i < len; ++i) { + if (!is_nameChar(buf[i])) { + return false; } - return true; } - return false; + return true; } SERD_API @@ -248,23 +237,25 @@ SerdNode serd_env_expand_node(const SerdEnv* env, const SerdNode* node) { - if (node->type == SERD_CURIE) { + switch (node->type) { + case SERD_CURIE: { SerdChunk prefix; SerdChunk suffix; - serd_env_expand(env, node, &prefix, &suffix); - SerdNode ret = { NULL, - prefix.len + suffix.len + 1, - prefix.len + suffix.len, // FIXME: UTF-8 - 0, - SERD_URI }; + if (serd_env_expand(env, node, &prefix, &suffix)) { + return SERD_NODE_NULL; + } + const size_t len = prefix.len + suffix.len; // FIXME: UTF-8? + SerdNode ret = { NULL, len, len, 0, SERD_URI }; ret.buf = malloc(ret.n_bytes + 1); snprintf((char*)ret.buf, ret.n_bytes + 1, "%s%s", prefix.buf, suffix.buf); return ret; - } else if (node->type == SERD_URI) { + } + case SERD_URI: { SerdURI ignored; return serd_node_new_uri_from_node(node, &env->base_uri, &ignored); - } else { + } + default: return SERD_NODE_NULL; } } -- cgit v1.2.1