diff options
author | David Robillard <d@drobilla.net> | 2018-02-04 20:49:28 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-04-13 19:15:32 +0200 |
commit | a0b173de316be27bea4cd00cd88c9bf65016df45 (patch) | |
tree | a8c9d4a0cb3e6c677660f8335c8dcae25871be4c | |
parent | 2cdb106b83c9e471a9a8ee9ba623d9943323e58e (diff) | |
download | serd-a0b173de316be27bea4cd00cd88c9bf65016df45.tar.gz serd-a0b173de316be27bea4cd00cd88c9bf65016df45.tar.bz2 serd-a0b173de316be27bea4cd00cd88c9bf65016df45.zip |
Remove serd_uri_to_path()
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | serd/serd.h | 11 | ||||
-rw-r--r-- | src/serdi.c | 9 | ||||
-rw-r--r-- | src/uri.c | 23 | ||||
-rw-r--r-- | tests/serd_test.c | 26 |
5 files changed, 8 insertions, 62 deletions
@@ -6,6 +6,7 @@ serd (1.0.0) unstable; * Rename SerdChunk to SerdStringView * Make serd_strtod API const-correct * Make nodes opaque + * Remove half-baked serd_uri_to_path() -- David Robillard <d@drobilla.net> Sat, 19 Jan 2019 13:31:12 +0100 diff --git a/serd/serd.h b/serd/serd.h index 91903c7e..abc2cc10 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -383,17 +383,6 @@ static const SerdURI SERD_URI_NULL = { }; /** - Return the local path for `uri`, or NULL if `uri` is not a file URI. - Note this (inappropriately named) function only removes the file scheme if - necessary, and returns `uri` unmodified if it is an absolute path. Percent - encoding and other issues are not handled, to properly convert a file URI to - a path, use serd_file_uri_parse(). -*/ -SERD_API -const char* -serd_uri_to_path(const char* uri); - -/** Get the unescaped path and hostname from a file URI. @param uri A file URI. @param hostname If non-NULL, set to the hostname, if present. diff --git a/src/serdi.c b/src/serdi.c index f6b7c529..a631aebf 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -211,11 +211,15 @@ main(int argc, char** argv) _setmode(fileno(stdout), _O_BINARY); #endif - const char* input = (const char*)argv[a++]; + char* input_path = NULL; + const char* input = (const char*)argv[a++]; if (from_file) { in_name = in_name ? in_name : input; if (!in_fd) { - input = serd_uri_to_path(in_name); + if (!strncmp(input, "file:", 5)) { + input_path = serd_file_uri_parse(input, NULL); + input = input_path; + } if (!input || !(in_fd = serd_fopen(input, "rb"))) { return 1; } @@ -306,6 +310,7 @@ main(int argc, char** argv) serd_writer_free(writer); serd_env_free(env); serd_node_free(base); + free(input_path); if (from_file) { fclose(in_fd); @@ -19,29 +19,6 @@ #include <stdlib.h> #include <string.h> -const char* -serd_uri_to_path(const char* uri) -{ - const char* path = uri; - if (!is_windows_path(uri) && serd_uri_string_has_scheme(uri)) { - if (strncmp(uri, "file:", 5)) { - fprintf(stderr, "Non-file URI `%s'\n", uri); - return NULL; - } else if (!strncmp(uri, "file://localhost/", 17)) { - path = uri + 16; - } else if (!strncmp(uri, "file://", 7)) { - path = uri + 7; - } else { - fprintf(stderr, "Invalid file URI `%s'\n", uri); - return NULL; - } - if (is_windows_path(path + 1)) { - ++path; // Special case for terrible Windows file URIs - } - } - return path; -} - char* serd_file_uri_parse(const char* uri, char** hostname) { diff --git a/tests/serd_test.c b/tests/serd_test.c index 3f50ca83..81e5a813 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -224,32 +224,6 @@ main(void) } msg = serd_strerror((SerdStatus)-1); - // Test serd_uri_to_path - - const char* uri = "file:///home/user/foo.ttl"; - assert(!strcmp(serd_uri_to_path(uri), "/home/user/foo.ttl")); - - uri = "file://localhost/home/user/foo.ttl"; - assert(!strcmp(serd_uri_to_path(uri), "/home/user/foo.ttl")); - - uri = "file:illegal/file/uri"; - assert(!serd_uri_to_path(uri)); - - uri = "file:///c:/awful/system"; - assert(!strcmp(serd_uri_to_path(uri), "c:/awful/system")); - - uri = "file:///c:awful/system"; - assert(!strcmp(serd_uri_to_path(uri), "/c:awful/system")); - - uri = "file:///0/1"; - assert(!strcmp(serd_uri_to_path(uri), "/0/1")); - - uri = "C:\\Windows\\Sucks"; - assert(!strcmp(serd_uri_to_path(uri), "C:\\Windows\\Sucks")); - - uri = "C|/Windows/Sucks"; - assert(!strcmp(serd_uri_to_path(uri), "C|/Windows/Sucks")); - // Test file URI escaping and parsing if (check_file_uri(NULL, "C:/My 100%", true, |