aboutsummaryrefslogtreecommitdiffstats
path: root/src/uri.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-12-24 21:51:27 +0000
committerDavid Robillard <d@drobilla.net>2011-12-24 21:51:27 +0000
commit834aede2613d3973170d9314e4a43695dfc14bf2 (patch)
tree0684cac5b64ecf3f421c9adde21995bf3783f184 /src/uri.c
parente2099741e85475b47be9edaa07d82de3689d6b32 (diff)
downloadserd-834aede2613d3973170d9314e4a43695dfc14bf2.tar.gz
serd-834aede2613d3973170d9314e4a43695dfc14bf2.tar.bz2
serd-834aede2613d3973170d9314e4a43695dfc14bf2.zip
Clean up path writing logic in serd_uri_serialise.
git-svn-id: http://svn.drobilla.net/serd/trunk@268 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/uri.c')
-rw-r--r--src/uri.c56
1 files changed, 26 insertions, 30 deletions
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) {