From 8a315ba8778378c1d9e5f03173a1c0715698a601 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 4 Feb 2018 20:49:28 +0100 Subject: Remove serd_uri_to_path() --- NEWS | 1 + serd/serd.h | 11 ----------- src/serdi.c | 9 +++++++-- src/uri.c | 23 ----------------------- tests/serd_test.c | 36 ------------------------------------ 5 files changed, 8 insertions(+), 72 deletions(-) diff --git a/NEWS b/NEWS index 3ab7a4cd..a21f95c0 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ serd (1.0.0) unstable; + * Remove serd_uri_to_path() * Use SerdBuffer for mutable buffers instead of abusing SerdChunk * Add serd_node_new_relative_uri() * Fix construction and comparison of URIs with UTF-8 characters diff --git a/serd/serd.h b/serd/serd.h index eeb5a0c0..1ad0c87d 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -383,17 +383,6 @@ static const SerdURI SERD_URI_NULL = { {NULL, 0}, {NULL, 0}, {NULL, 0}, {NULL, 0}, {NULL, 0}, {NULL, 0} }; -/** - 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. diff --git a/src/serdi.c b/src/serdi.c index 571e2208..ec66cfd3 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -199,11 +199,15 @@ main(int argc, char** argv) return 1; } - 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; } @@ -294,6 +298,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); diff --git a/src/uri.c b/src/uri.c index d47580ae..15c6c0df 100644 --- a/src/uri.c +++ b/src/uri.c @@ -21,29 +21,6 @@ // #define URI_DEBUG 1 -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 1e563006..c6fb975a 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -254,42 +254,6 @@ main(void) } msg = serd_strerror((SerdStatus)-1); - // Test serd_uri_to_path - - const char* uri = "file:///home/user/foo.ttl"; - if (strcmp(serd_uri_to_path(uri), "/home/user/foo.ttl")) { - FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri); - } - uri = "file://localhost/home/user/foo.ttl"; - if (strcmp(serd_uri_to_path(uri), "/home/user/foo.ttl")) { - FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri); - } - uri = "file:illegal/file/uri"; - if (serd_uri_to_path(uri)) { - FAILF("Converted invalid URI `%s' to path `%s'\n", - uri, serd_uri_to_path(uri)); - } - uri = "file:///c:/awful/system"; - if (strcmp((const char*)serd_uri_to_path(uri), "c:/awful/system")) { - FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri); - } - uri = "file:///c:awful/system"; - if (strcmp((const char*)serd_uri_to_path(uri), "/c:awful/system")) { - FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri); - } - uri = "file:///0/1"; - if (strcmp((const char*)serd_uri_to_path(uri), "/0/1")) { - FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri); - } - uri = "C:\\Windows\\Sucks"; - if (strcmp((const char*)serd_uri_to_path(uri), "C:\\Windows\\Sucks")) { - FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri); - } - uri = "C|/Windows/Sucks"; - if (strcmp((const char*)serd_uri_to_path(uri), "C|/Windows/Sucks")) { - FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri); - } - // Test file URI escaping and parsing if (check_file_uri(NULL, "C:/My 100%", true, -- cgit v1.2.1