diff options
author | David Robillard <d@drobilla.net> | 2018-05-11 18:11:44 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-12-19 20:52:36 -0500 |
commit | 8e04e69b5a724af9ce16c1178022afc8fdf38d69 (patch) | |
tree | 5627e3421d0bc02ee53449095b2b72aa6888a533 /serd | |
parent | 2370d86f35ff41ae94c5c45deef1e6a6dac0052c (diff) | |
download | serd-8e04e69b5a724af9ce16c1178022afc8fdf38d69.tar.gz serd-8e04e69b5a724af9ce16c1178022afc8fdf38d69.tar.bz2 serd-8e04e69b5a724af9ce16c1178022afc8fdf38d69.zip |
Clean up node construction API
Diffstat (limited to 'serd')
-rw-r--r-- | serd/serd.h | 106 |
1 files changed, 54 insertions, 52 deletions
diff --git a/serd/serd.h b/serd/serd.h index 37a90750..5f1c4929 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -460,18 +460,30 @@ serd_uri_serialise_relative(const SerdURI* uri, */ /** - Create a new node from `str`. + Create a new "simple" node that is just a string. + + This can be used to create blank, CURIE, or URI nodes from an already + measured string or slice of a buffer, which avoids a strlen compared to the + friendly constructors. This may not be used for literals since those must + be measured to set the SERD_HAS_NEWLINE and SERD_HAS_QUOTE flags. */ SERD_API SerdNode* -serd_node_new_string(SerdType type, const char* str); +serd_node_new_simple_node(SerdType type, const char* str, size_t len); /** - Create a new node from a prefix of `str`. + Create a new plain literal string node from `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 plain literal string node from a prefix of `str`. +*/ +SERD_API +SerdNode* +serd_node_new_substring(const char* str, size_t len); /** Create a new literal node from `str`. @@ -487,15 +499,19 @@ 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`. */ SERD_API @@ -510,72 +526,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. @@ -793,8 +797,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. @@ -991,13 +994,12 @@ serd_reader_free(SerdReader* reader); */ SERD_API SerdWriter* -serd_writer_new(SerdWorld* world, - SerdSyntax syntax, - SerdStyle style, - SerdEnv* env, - const SerdURI* base_uri, - SerdWriteFunc ssink, - void* stream); +serd_writer_new(SerdWorld* world, + SerdSyntax syntax, + SerdStyle style, + SerdEnv* env, + SerdWriteFunc ssink, + void* stream); /** Free `writer`. |