From f4365012b555699b916dbeec4d81425bf663579c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 8 Mar 2012 15:57:20 +0000 Subject: Add serd_writer_get_env(). Add serd_node_new_uri_from_path() and serd_file_uri_parse() and implement proper URI to/from path hex escaping, etc. Add serd_uri_serialise_relative() for making URIs relative to a base where possible (by chopping a common prefix and adding dot segments). Make URIs serialised by the writer properly escape characters. git-svn-id: http://svn.drobilla.net/serd/trunk@330 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- serd/serd.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'serd') diff --git a/serd/serd.h b/serd/serd.h index ba4e6fb5..3a2f9e3b 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -244,7 +244,7 @@ typedef enum { SERD_STYLE_ASCII = 1 << 1, /**< Escape all non-ASCII characters. */ SERD_STYLE_RESOLVED = 1 << 2, /**< Resolve URIs against base URI. */ SERD_STYLE_CURIED = 1 << 3, /**< Shorten URIs into CURIEs. */ - SERD_STYLE_BULK = 1 << 4, /**< Write output in pages. */ + SERD_STYLE_BULK = 1 << 4 /**< Write output in pages. */ } SerdStyle; /** @@ -305,11 +305,28 @@ static const SerdURI SERD_URI_NULL = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}}; /** Return the local path for @c uri, or NULL if @c uri is not a file URI. + Note this (inappropriately named) function only removes the file scheme if + necessary, and returns @c 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 uint8_t* serd_uri_to_path(const uint8_t* 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. + @return The path component of the URI. + + Both the returned path and @c hostname (if applicable) are owned by the + caller and must be freed with free(). +*/ +SERD_API +uint8_t* +serd_file_uri_parse(const uint8_t* uri, uint8_t** hostname); + /** Return true iff @c utf8 starts with a valid URI scheme. */ @@ -343,6 +360,16 @@ SERD_API size_t serd_uri_serialise(const SerdURI* uri, SerdSink sink, void* stream); +/** + Serialise @c uri relative to @c base with a series of calls to @c sink. +*/ +SERD_API +size_t +serd_uri_serialise_relative(const SerdURI* uri, + const SerdURI* base, + SerdSink sink, + void* stream); + /** @} @name Node @@ -394,6 +421,17 @@ serd_node_new_uri_from_string(const uint8_t* str, const SerdURI* base, SerdURI* out); +/** + Create a new file URI node from a file system path. + If @c path is relative, @c hostname is ignored. + If @c out is not NULL, it will be set to the parsed URI. +*/ +SERD_API +SerdNode +serd_node_new_uri_from_path(const uint8_t* path, + const uint8_t* hostname, + SerdURI* out); + /** Create a new node by serialising @c uri into a new string. @@ -439,7 +477,6 @@ serd_node_new_integer(int64_t i); This function can be used to make a serialisable node out of arbitrary binary data, which can be decoded using serd_base64_decode(). - @param buf Raw binary input data. @param size Size of @c buf. @param wrap_lines Wrap lines at 76 characters to conform to RFC 2045. @@ -692,6 +729,13 @@ SERD_API void serd_writer_free(SerdWriter* writer); +/** + Return the env used by @c writer. +*/ +SERD_API +SerdEnv* +serd_writer_get_env(SerdWriter* writer); + /** A convenience sink function for writing to a FILE*. -- cgit v1.2.1