aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-02-04 20:49:28 +0100
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:58 +0100
commit45358052fb4fa254f06d0d704a27c5ed9608cc58 (patch)
treeb1a63145d5da80651cb8a7c3d0eb1130897cc8b7
parent21c59b99a1c75d58d8aab760105b0535cc04c6f1 (diff)
downloadserd-45358052fb4fa254f06d0d704a27c5ed9608cc58.tar.gz
serd-45358052fb4fa254f06d0d704a27c5ed9608cc58.tar.bz2
serd-45358052fb4fa254f06d0d704a27c5ed9608cc58.zip
Remove serd_uri_to_path()
-rw-r--r--NEWS1
-rw-r--r--serd/serd.h11
-rw-r--r--src/serdi.c10
-rw-r--r--src/uri.c23
-rw-r--r--tests/serd_test.c29
5 files changed, 9 insertions, 65 deletions
diff --git a/NEWS b/NEWS
index 5e6c9eb4..1d4ac879 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ serd (1.0.1) unstable;
* Add SerdBuffer for mutable buffers to keep SerdChunk const-correct
* Make nodes opaque
* Make serd_strtod API const-correct
+ * Remove half-baked serd_uri_to_path()
* Remove useless character counting from API
* Rename SerdChunk to SerdStringView
* Use char* for strings in public API
diff --git a/serd/serd.h b/serd/serd.h
index fc1ac5ff..4f0d8a6b 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -380,17 +380,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 38646a67..47118e8f 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -33,6 +33,7 @@
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#define SERDI_ERROR(msg) fprintf(stderr, "serdi: " msg)
@@ -236,11 +237,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;
}
@@ -331,6 +336,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 726b0f54..66ef0b6a 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -25,29 +25,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 330ca985..f0541593 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -337,34 +337,6 @@ test_strerror(void)
}
static void
-test_uri_to_path(void)
-{
- 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"));
-}
-
-static void
test_uri_parsing(void)
{
test_file_uri(NULL, "C:/My 100%", true,
@@ -670,7 +642,6 @@ main(void)
test_blob_to_node();
test_strlen();
test_strerror();
- test_uri_to_path();
test_uri_parsing();
test_node_equals();
test_node_from_string();