From 4bc530b356ed4b390816669725e684d038e48aa0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 11 May 2018 18:11:44 +0200 Subject: Clean up node construction API --- serd/serd.h | 97 +++++++++++++++++++++++++------------------------------------ 1 file changed, 40 insertions(+), 57 deletions(-) (limited to 'serd/serd.h') diff --git a/serd/serd.h b/serd/serd.h index 0f937b24..89f612a3 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -439,18 +439,11 @@ serd_uri_serialise_relative(const SerdURI* uri, */ /** - Create a new node from `str`. + Create a new plain literal string node from `str`. */ SERD_API SerdNode* -serd_node_new_string(SerdType type, const char* str); - -/** - Create a new node from a prefix of `str`. -*/ -SERD_API -SerdNode* -serd_node_new_substring(SerdType type, const char* str, size_t len); +serd_node_new_string(const char* str); /** Create a new literal node from `str`. @@ -466,14 +459,18 @@ serd_node_new_literal(const char* str, /** Create a new blank node. - - Note this function measures `str`, which is a common bottleneck. - Use sord_node_from_serd_node() instead if `str` is already measured. */ SERD_API SerdNode* serd_node_new_blank(const char* str); +/** + Create a new CURIE node. +*/ +SERD_API +SerdNode* +serd_node_new_curie(const char* str); + /** Return a deep copy of `node`. */ @@ -489,72 +486,60 @@ bool serd_node_equals(const SerdNode* a, const SerdNode* b); /** - Simple wrapper for serd_node_new_uri() to resolve a URI node. + Create a new URI from a string. */ SERD_API SerdNode* -serd_node_new_uri_from_node(const SerdNode* uri_node, - const SerdURI* base, - SerdURI* out); +serd_node_new_uri(const char* str); /** - Simple wrapper for serd_node_new_uri() to resolve a URI string. + Create a new URI from a string, resolved against a base URI. */ SERD_API SerdNode* -serd_node_new_uri_from_string(const char* str, - const SerdURI* base, - SerdURI* out); +serd_node_new_resolved_uri(const char* str, const SerdNode* base); /** - Create a new file URI node from a file system path and optional hostname. + Resolve `node` against `base`. - Backslashes in Windows paths will be converted and '%' will always be - percent encoded. If `escape` is true, all other invalid characters will be - percent encoded as well. - - If `path` is relative, `hostname` is ignored. - If `out` is not NULL, it will be set to the parsed URI. + If `node` is not a relative URI, an equivalent new node is returned. */ SERD_API SerdNode* -serd_node_new_file_uri(const char* path, - const char* hostname, - SerdURI* out, - bool escape); +serd_node_resolve(const SerdNode* node, const SerdNode* base); /** - Create a new node by serialising `uri` into a new string. - - @param uri The URI to serialise. + Create a new file URI node from a file system path and optional hostname. - @param base Base URI to resolve `uri` against (or NULL for no resolution). + Backslashes in Windows paths will be converted and '%' will always be + percent encoded. If `escape` is true, all other invalid characters will be + percent encoded as well. - @param out Set to the parsing of the new URI (i.e. points only to - memory owned by the new returned node). + If `path` is relative, `hostname` is ignored. + If `out` is not NULL, it will be set to the parsed URI. */ SERD_API SerdNode* -serd_node_new_uri(const SerdURI* uri, const SerdURI* base, SerdURI* out); +serd_node_new_file_uri(const char* path, const char* hostname, bool escape); /** - Create a new node by serialising `uri` into a new relative URI. + Create a new URI from a string, relative to a base URI. - @param uri The URI to serialise. + @param str URI string. - @param base Base URI to make `uri` relative to, if possible. + @param base Base URI to make `str` relative to, if possible. - @param root Root URI for resolution (see serd_uri_serialise_relative()). + @param root Optional root URI for resolution. - @param out Set to the parsing of the new URI (i.e. points only to - memory owned by the new returned node). + The URI is made relative iff if it a child of `base` and `root`. The + optional `root` parameter must be a prefix of `base` and can be used keep + up-references ("../") within a certain namespace. */ SERD_API SerdNode* -serd_node_new_relative_uri(const SerdURI* uri, - const SerdURI* base, - const SerdURI* root, - SerdURI* out); +serd_node_new_relative_uri(const char* str, + const SerdNode* base, + const SerdNode* root); /** Create a new node by serialising `d` into an xsd:decimal string. @@ -772,8 +757,7 @@ serd_env_free(SerdEnv* env); */ SERD_API const SerdNode* -serd_env_get_base_uri(const SerdEnv* env, - SerdURI* out); +serd_env_get_base_uri(const SerdEnv* env); /** Set the current base URI. @@ -986,13 +970,12 @@ serd_reader_free(SerdReader* reader); */ SERD_API SerdWriter* -serd_writer_new(SerdWorld* world, - SerdSyntax syntax, - SerdStyle style, - SerdEnv* env, - const SerdURI* base_uri, - SerdSink ssink, - void* stream); +serd_writer_new(SerdWorld* world, + SerdSyntax syntax, + SerdStyle style, + SerdEnv* env, + SerdSink ssink, + void* stream); /** Free `writer`. -- cgit v1.2.1