From 834aede2613d3973170d9314e4a43695dfc14bf2 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 24 Dec 2011 21:51:27 +0000 Subject: Clean up path writing logic in serd_uri_serialise. git-svn-id: http://svn.drobilla.net/serd/trunk@268 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/uri.c | 56 ++++++++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 30 deletions(-) (limited to 'src/uri.c') diff --git a/src/uri.c b/src/uri.c index 1366ef43..4388571c 100644 --- a/src/uri.c +++ b/src/uri.c @@ -353,41 +353,37 @@ serd_uri_serialise(const SerdURI* uri, SerdSink sink, void* stream) WRITE("//", 2); WRITE(uri->authority.buf, uri->authority.len); } - if (uri->path_base.len || uri->path.len) { - if (!uri->path.buf && (uri->fragment.buf || uri->query.buf)) { - WRITE_COMPONENT("", uri->path_base, ""); - } else if (uri->path.buf) { - const uint8_t* begin = uri->path.buf; - const uint8_t* const end = uri->path.buf + uri->path.len; + if (!uri->path.buf) { + WRITE_COMPONENT("", uri->path_base, ""); + } else { + const uint8_t* begin = uri->path.buf; + const uint8_t* const end = uri->path.buf + uri->path.len; - size_t up; - begin = remove_dot_segments(uri->path.buf, uri->path.len, &up); - ++up; + size_t up; + begin = remove_dot_segments(uri->path.buf, uri->path.len, &up); - if (uri->path_base.buf) { - // Find the up'th last slash - const uint8_t* base_last = (uri->path_base.buf - + uri->path_base.len - 1); - do { - if (*base_last == '/') { - --up; - } - } while (up > 0 && (--base_last > uri->path_base.buf)); + if (uri->path_base.buf) { + // Find the up'th last slash + const uint8_t* base_last = (uri->path_base.buf + + uri->path_base.len - 1); + ++up; + do { + if (*base_last == '/') { + --up; + } + } while (up > 0 && (--base_last > uri->path_base.buf)); - // Write base URI prefix - const size_t base_len = base_last - uri->path_base.buf + 1; - WRITE(uri->path_base.buf, base_len); + // Write base URI prefix + const size_t base_len = base_last - uri->path_base.buf + 1; + WRITE(uri->path_base.buf, base_len); - } else { - // Relative path is just query or fragment, append to base URI - WRITE_COMPONENT("", uri->path_base, ""); - } - - // Write URI suffix - WRITE(begin, end - begin); + } else { + // Relative path is just query or fragment, append to base URI + WRITE_COMPONENT("", uri->path_base, ""); } - } else { - WRITE_COMPONENT("", uri->path, ""); + + // Write URI suffix + WRITE(begin, end - begin); } WRITE_COMPONENT("?", uri->query, ""); if (uri->fragment.buf) { -- cgit v1.2.1