aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--serd/serd.h10
-rw-r--r--src/reader.c27
-rw-r--r--src/uri.c26
3 files changed, 35 insertions, 28 deletions
diff --git a/serd/serd.h b/serd/serd.h
index bd5b50eb..5af0331a 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -116,8 +116,7 @@ typedef enum {
SERD_EMPTY_O = 1 << 2, /**< Empty blank node object */
SERD_ANON_S_BEGIN = 1 << 3, /**< Start of anonymous subject */
SERD_ANON_O_BEGIN = 1 << 4, /**< Start of anonymous object */
- SERD_ANON_CONT = 1 << 5, /**< Continuation of anonymous node */
- SERD_ANON_END = 1 << 6, /**< End of anonymous node */
+ SERD_ANON_CONT = 1 << 5 /**< Continuation of anonymous node */
} SerdStatementFlag;
/**
@@ -262,6 +261,13 @@ serd_strlen(const uint8_t* str, size_t* n_bytes, SerdNodeFlags* flags);
static const SerdURI SERD_URI_NULL = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}};
/**
+ Return the local path for @a uri, or NULL if @a uri is not a file URI.
+*/
+SERD_API
+const uint8_t*
+serd_uri_to_path(const uint8_t* uri);
+
+/**
Return true iff @a utf8 starts with a valid URI scheme.
*/
SERD_API
diff --git a/src/reader.c b/src/reader.c
index bdd0ba06..67f53513 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -1492,37 +1492,12 @@ serd_reader_add_blank_prefix(SerdReader* reader,
}
}
-static const uint8_t*
-file_uri_to_path(const uint8_t* uri)
-{
- const uint8_t* filename = 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, "Unsupported URI scheme `%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://", 7)) {
- filename = uri + 7;
-#endif
- } else {
- filename = uri + 5;
- }
- } else {
- filename = uri;
- }
- return filename;
-}
-
SERD_API
SerdStatus
serd_reader_read_file(SerdReader* reader,
const uint8_t* uri)
{
- const uint8_t* path = file_uri_to_path(uri);
+ const uint8_t* path = serd_uri_to_path(uri);
if (!path) {
return SERD_ERR_BAD_ARG;
}
diff --git a/src/uri.c b/src/uri.c
index 4f1ef3a5..921de4b7 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -25,6 +25,32 @@
// #define URI_DEBUG 1
SERD_API
+const uint8_t*
+serd_uri_to_path(const uint8_t* uri)
+{
+ const uint8_t* filename = 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, "Unsupported URI scheme `%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://", 7)) {
+ filename = uri + 7;
+#endif
+ } else {
+ filename = uri + 5;
+ }
+ } else {
+ filename = uri;
+ }
+ return filename;
+}
+
+SERD_API
bool
serd_uri_string_has_scheme(const uint8_t* utf8)
{