aboutsummaryrefslogtreecommitdiffstats
path: root/src/uri.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/uri.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/uri.c')
-rw-r--r--src/uri.c35
1 files changed, 12 insertions, 23 deletions
diff --git a/src/uri.c b/src/uri.c
index a0078920..6aa7ec62 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -98,9 +98,6 @@ SerdStatus
serd_uri_parse(const uint8_t* utf8, SerdURI* uri)
{
*uri = SERD_URI_NULL;
- assert(uri->path_base.buf == NULL);
- assert(uri->path_base.len == 0);
- assert(uri->authority.len == 0);
const uint8_t* ptr = utf8;
@@ -137,7 +134,6 @@ maybe_authority:
if (*ptr == '/' && *(ptr + 1) == '/') {
ptr += 2;
uri->authority.buf = ptr;
- assert(uri->authority.len == 0);
for (uint8_t c; (c = *ptr) != '\0'; ++ptr) {
switch (c) {
case '/': goto path;
@@ -331,28 +327,18 @@ serd_uri_serialise(const SerdURI* uri, SerdSink sink, void* stream)
size_t write_size = 0;
#define WRITE(buf, len) \
write_size += len; \
- if (len) { \
- sink((const uint8_t*)buf, len, stream); \
- }
-#define WRITE_CHAR(c) WRITE(&(c), 1)
-#define WRITE_COMPONENT(prefix, field, suffix) \
- if ((field).len) { \
- for (const uint8_t* c = (const uint8_t*)prefix; *c != '\0'; ++c) { \
- WRITE(c, 1); \
- } \
- WRITE((field).buf, (field).len); \
- for (const uint8_t* c = (const uint8_t*)suffix; *c != '\0'; ++c) { \
- WRITE(c, 1); \
- } \
- }
+ sink((const uint8_t*)buf, len, stream);
- WRITE_COMPONENT("", uri->scheme, ":");
+ if (uri->scheme.buf) {
+ WRITE(uri->scheme.buf, uri->scheme.len);
+ WRITE(":", 1);
+ }
if (uri->authority.buf) {
WRITE("//", 2);
WRITE(uri->authority.buf, uri->authority.len);
}
if (!uri->path.buf) {
- WRITE_COMPONENT("", uri->path_base, "");
+ WRITE(uri->path_base.buf, uri->path_base.len);
} else {
const uint8_t* begin = uri->path.buf;
const uint8_t* const end = uri->path.buf + uri->path.len;
@@ -377,16 +363,19 @@ serd_uri_serialise(const SerdURI* uri, SerdSink sink, void* stream)
} else {
// Relative path is just query or fragment, append to base URI
- WRITE_COMPONENT("", uri->path_base, "");
+ WRITE(uri->path_base.buf, uri->path_base.len);
}
// Write URI suffix
WRITE(begin, end - begin);
}
- WRITE_COMPONENT("?", uri->query, "");
+ if (uri->query.buf) {
+ WRITE("?", 1);
+ WRITE(uri->query.buf, uri->query.len);
+ }
if (uri->fragment.buf) {
// Note uri->fragment.buf includes the leading `#'
- WRITE_COMPONENT("", uri->fragment, "");
+ WRITE(uri->fragment.buf, uri->fragment.len);
}
return write_size;
}