aboutsummaryrefslogtreecommitdiffstats
path: root/src/node.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-12-25 07:09:29 +0000
committerDavid Robillard <d@drobilla.net>2011-12-25 07:09:29 +0000
commitf3c95977f6c71b936e98f41c321265835c4fd623 (patch)
treeab275f04a3dd592c5572687230ba25f422359a36 /src/node.c
parentb2effabfc5d02bab56bae00e7aa138a42bd7d3b6 (diff)
downloadserd-f3c95977f6c71b936e98f41c321265835c4fd623.tar.gz
serd-f3c95977f6c71b936e98f41c321265835c4fd623.tar.bz2
serd-f3c95977f6c71b936e98f41c321265835c4fd623.zip
Near 100% branch coverage.
git-svn-id: http://svn.drobilla.net/serd/trunk@277 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/node.c')
-rw-r--r--src/node.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/node.c b/src/node.c
index 59839e34..4628be99 100644
--- a/src/node.c
+++ b/src/node.c
@@ -37,7 +37,7 @@ SERD_API
SerdNode
serd_node_copy(const SerdNode* node)
{
- if (!node || !node->buf) {
+ if (!node) {
return SERD_NODE_NULL;
}
@@ -93,7 +93,9 @@ serd_node_new_uri_from_node(const SerdNode* uri_node,
const SerdURI* base,
SerdURI* out)
{
- return serd_node_new_uri_from_string(uri_node->buf, base, out);
+ return (uri_node->type == SERD_URI)
+ ? serd_node_new_uri_from_string(uri_node->buf, base, out)
+ : SERD_NODE_NULL;
}
SERD_API
@@ -104,13 +106,10 @@ serd_node_new_uri_from_string(const uint8_t* str,
{
if (!str || str[0] == '\0') {
return serd_node_new_uri(base, NULL, out); // Empty URI => Base URI
- } else {
- SerdURI uri;
- if (!serd_uri_parse(str, &uri)) {
- return serd_node_new_uri(&uri, base, out); // Resolve/Serialise
- }
}
- return SERD_NODE_NULL;
+ SerdURI uri;
+ serd_uri_parse(str, &uri);
+ return serd_node_new_uri(&uri, base, out); // Resolve/Serialise
}
SERD_API
@@ -134,7 +133,9 @@ serd_node_new_uri(const SerdURI* uri, const SerdURI* base, SerdURI* out)
node.n_bytes = actual_len;
node.n_chars = actual_len;
- serd_uri_parse(buf, out); // TODO: cleverly avoid double parse
+ if (out) {
+ serd_uri_parse(buf, out); // TODO: cleverly avoid double parse
+ }
return node;
}
@@ -177,7 +178,7 @@ serd_node_new_decimal(double d, unsigned frac_digits)
unsigned i = 0;
// Skip trailing zeros
- for (; i < frac_digits && (frac % 10 == 0); ++i, --s, frac /= 10) {}
+ for (; i < frac_digits - 1 && !(frac % 10); ++i, --s, frac /= 10) {}
node.n_bytes = node.n_chars = (s - buf) + 1;