aboutsummaryrefslogtreecommitdiffstats
path: root/src/uri.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-09-29 00:53:39 +0000
committerDavid Robillard <d@drobilla.net>2011-09-29 00:53:39 +0000
commitc8e9bd0923f624945dd69e2af8b8a05c5a09d29c (patch)
tree6204b6f93a83c1e4b57886d47bf58f322776af6c /src/uri.c
parentde5aa9e275107f59cdf12f76fe55895605ee7dc6 (diff)
downloadserd-c8e9bd0923f624945dd69e2af8b8a05c5a09d29c.tar.gz
serd-c8e9bd0923f624945dd69e2af8b8a05c5a09d29c.tar.bz2
serd-c8e9bd0923f624945dd69e2af8b8a05c5a09d29c.zip
Tidy.
git-svn-id: http://svn.drobilla.net/serd/trunk@218 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/uri.c')
-rw-r--r--src/uri.c85
1 files changed, 42 insertions, 43 deletions
diff --git a/src/uri.c b/src/uri.c
index 04ca8c84..61fb35ce 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -292,68 +292,67 @@ serd_uri_serialise(const SerdURI* uri, SerdSink sink, void* stream)
if (uri->path_base.len) {
if (!uri->path.buf && (uri->fragment.buf || uri->query.buf)) {
WRITE_COMPONENT("", uri->path_base, "");
- } else {
+ } else if (uri->path.buf) {
/* Merge paths, removing dot components.
See http://tools.ietf.org/html/rfc3986#section-5.2.3
*/
const uint8_t* begin = uri->path.buf;
size_t up = 1;
- if (begin) {
- // Count and skip leading dot components
- const uint8_t* end = uri->path.buf + uri->path.len;
- for (bool done = false; !done && (begin < end);) {
- switch (begin[0]) {
+ // Count and skip leading dot components
+ const uint8_t* end = uri->path.buf + uri->path.len;
+ for (bool done = false; !done && (begin < end);) {
+ switch (begin[0]) {
+ case '.':
+ switch (begin[1]) {
+ case '/':
+ begin += 2; // Chop leading "./"
+ break;
case '.':
- switch (begin[1]) {
+ ++up;
+ switch (begin[2]) {
case '/':
- begin += 2; // Chop leading "./"
- break;
- case '.':
- ++up;
- switch (begin[2]) {
- case '/':
- begin += 3; // Chop lading "../"
- break;
- default:
- begin += 2; // Chop leading ".."
- }
+ begin += 3; // Chop lading "../"
break;
default:
- ++begin; // Chop leading "."
+ begin += 2; // Chop leading ".."
}
break;
- case '/':
- if (begin[1] == '/') {
- ++begin; // Replace leading "//" with "/"
- break;
- } // else fall through
default:
- done = true; // Finished chopping dot components
+ ++begin; // Chop leading "."
}
+ break;
+ case '/':
+ if (begin[1] == '/') {
+ ++begin; // Replace leading "//" with "/"
+ break;
+ } // else fall through
+ default:
+ done = true; // Finished chopping dot components
}
+ }
- if (uri->path.buf && 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));
-
- // Write base URI prefix
- const size_t base_len = base_last - uri->path_base.buf + 1;
- WRITE(uri->path_base.buf, base_len);
+ if (uri->path.buf && 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));
- } else {
- // Relative path is just query or fragment, append it to full base URI
- WRITE_COMPONENT("", uri->path_base, "");
- }
+ // Write base URI prefix
+ const size_t base_len = base_last - uri->path_base.buf + 1;
+ WRITE(uri->path_base.buf, base_len);
- // Write URI suffix
- WRITE(begin, end - begin);
+ } 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 {
WRITE_COMPONENT("", uri->path, "");