diff options
author | David Robillard <d@drobilla.net> | 2011-12-24 22:14:46 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-12-24 22:14:46 +0000 |
commit | 544486680095d1024ae991ce95cde52080cbf43c (patch) | |
tree | 8c1cd74c86bef156eaf4402641a2aa5f1df12d12 /src/uri.c | |
parent | 834aede2613d3973170d9314e4a43695dfc14bf2 (diff) | |
download | serd-544486680095d1024ae991ce95cde52080cbf43c.tar.gz serd-544486680095d1024ae991ce95cde52080cbf43c.tar.bz2 serd-544486680095d1024ae991ce95cde52080cbf43c.zip |
Support file://localhost/foo URIs in serd_uri_to_path().
Support Windows file://c:/foo URIs in serd_uri_to_path() on all platforms.
100% test coverage (by line) for uri.c.
git-svn-id: http://svn.drobilla.net/serd/trunk@269 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/uri.c')
-rw-r--r-- | src/uri.c | 26 |
1 files changed, 12 insertions, 14 deletions
@@ -26,29 +26,27 @@ SERD_API const uint8_t* serd_uri_to_path(const uint8_t* uri) { - const uint8_t* filename = NULL; + const uint8_t* path = NULL; if (serd_uri_string_has_scheme(uri)) { - // Absolute URI, ensure it a file and chop scheme if (strncmp((const char*)uri, "file:", 5)) { fprintf(stderr, "Non-file URI `%s'\n", uri); return NULL; - } else if (strncmp((const char*)uri + 5, "//", 2)) { - fprintf(stderr, "Illegal file URI `%s'\n", uri); - return NULL; -#ifdef __WIN32__ - } else if (!strncmp((const char*)uri, "file:///", 8)) { - filename = uri + 8; -#else + } else if (!strncmp((const char*)uri, "file://localhost/", 17)) { + path = uri + 16; } else if (!strncmp((const char*)uri, "file://", 7)) { - filename = uri + 7; -#endif + path = uri + 7; } else { - filename = uri + 5; + fprintf(stderr, "Invalid file URI `%s'\n", uri); + return NULL; + } + // Special case for awful Windows file URIs + if (is_alpha(path[1]) && path[2] == ':' && path[3] == '/') { + ++path; // Special case for terrible Windows file URIs } } else { - filename = uri; + path = uri; } - return filename; + return path; } SERD_API |