aboutsummaryrefslogtreecommitdiffstats
path: root/include/serd
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-04-29 18:29:03 +0200
committerDavid Robillard <d@drobilla.net>2023-12-02 16:27:02 -0500
commit5c02da92038072f28408854e862fc2d4edf765d4 (patch)
tree34577415801279981b626b18c1dc69dc79afea7f /include/serd
parent672e90382da08efa8f593fdc9081e31d0e548fa0 (diff)
downloadserd-5c02da92038072f28408854e862fc2d4edf765d4.tar.gz
serd-5c02da92038072f28408854e862fc2d4edf765d4.tar.bz2
serd-5c02da92038072f28408854e862fc2d4edf765d4.zip
Simplify node construction API
Diffstat (limited to 'include/serd')
-rw-r--r--include/serd/env.h23
-rw-r--r--include/serd/node.h42
-rw-r--r--include/serd/writer.h11
3 files changed, 37 insertions, 39 deletions
diff --git a/include/serd/env.h b/include/serd/env.h
index 7a03e80d..db2c1150 100644
--- a/include/serd/env.h
+++ b/include/serd/env.h
@@ -9,7 +9,6 @@
#include "serd/sink.h"
#include "serd/status.h"
#include "serd/string_view.h"
-#include "serd/uri.h"
#include <stdbool.h>
@@ -26,21 +25,19 @@ typedef struct SerdEnvImpl SerdEnv;
/// Create a new environment
SERD_API SerdEnv* SERD_ALLOCATED
-serd_env_new(const SerdNode* SERD_NULLABLE base_uri);
+serd_env_new(SerdStringView base_uri);
/// Free `env`
SERD_API void
serd_env_free(SerdEnv* SERD_NULLABLE env);
/// Get the current base URI
-SERD_API const SerdNode* SERD_NULLABLE
-serd_env_base_uri(const SerdEnv* SERD_NONNULL env,
- SerdURIView* SERD_NULLABLE out);
+SERD_PURE_API const SerdNode* SERD_NULLABLE
+serd_env_base_uri(const SerdEnv* SERD_NULLABLE env);
/// Set the current base URI
SERD_API SerdStatus
-serd_env_set_base_uri(SerdEnv* SERD_NONNULL env,
- const SerdNode* SERD_NULLABLE uri);
+serd_env_set_base_uri(SerdEnv* SERD_NONNULL env, SerdStringView uri);
/**
Set a namespace prefix.
@@ -50,15 +47,9 @@ serd_env_set_base_uri(SerdEnv* SERD_NONNULL env,
expand to "http://www.w3.org/2001/XMLSchema#decimal".
*/
SERD_API SerdStatus
-serd_env_set_prefix(SerdEnv* SERD_NONNULL env,
- const SerdNode* SERD_NONNULL name,
- const SerdNode* SERD_NONNULL uri);
-
-/// Set a namespace prefix
-SERD_API SerdStatus
-serd_env_set_prefix_from_strings(SerdEnv* SERD_NONNULL env,
- const char* SERD_NONNULL name,
- const char* SERD_NONNULL uri);
+serd_env_set_prefix(SerdEnv* SERD_NONNULL env,
+ SerdStringView name,
+ SerdStringView uri);
/// Qualify `uri` into a CURIE if possible
SERD_API bool
diff --git a/include/serd/node.h b/include/serd/node.h
index 4aa4ec0a..cbf5efcc 100644
--- a/include/serd/node.h
+++ b/include/serd/node.h
@@ -100,29 +100,40 @@ typedef uint32_t SerdNodeFlags;
*/
/**
- Create a new node from `str`.
+ Create a new simple "token" node.
+
+ A "token" is a node that isn't a typed or tagged literal. This can be used
+ to create URIs, blank nodes, CURIEs, and simple string literals.
*/
SERD_API SerdNode* SERD_ALLOCATED
-serd_new_string(SerdNodeType type, const char* SERD_NULLABLE str);
+serd_new_token(SerdNodeType type, SerdStringView string);
/**
- Create a new node from a prefix of `str`.
+ Create a new string literal node.
*/
SERD_API SerdNode* SERD_ALLOCATED
-serd_new_substring(SerdNodeType type,
- const char* SERD_NULLABLE str,
- size_t len);
+serd_new_string(SerdStringView string);
/**
Create a new literal node from `str`.
- Either `datatype` or `lang` can be given, but not both, unless `datatype` is
- rdf:langString in which case it is ignored.
+ Either `datatype_uri` or `lang` can be given, but not both, unless
+ `datatype_uri` is rdf:langString in which case it is ignored.
*/
SERD_API SerdNode* SERD_ALLOCATED
-serd_new_literal(const char* SERD_NONNULL str,
- const char* SERD_NULLABLE datatype,
- const char* SERD_NULLABLE lang);
+serd_new_literal(SerdStringView string,
+ SerdStringView datatype_uri,
+ SerdStringView lang);
+
+/**
+ Create a new node from a blank node label.
+*/
+SERD_API SerdNode* SERD_ALLOCATED
+serd_new_blank(SerdStringView string);
+
+/// Create a new CURIE node
+SERD_API SerdNode* SERD_ALLOCATED
+serd_new_curie(SerdStringView string);
/**
Create a new URI node from a parsed URI.
@@ -134,7 +145,7 @@ serd_new_parsed_uri(SerdURIView uri);
Create a new URI node from a string.
*/
SERD_API SerdNode* SERD_ALLOCATED
-serd_new_uri(const char* SERD_NONNULL str);
+serd_new_uri(SerdStringView string);
/**
Create a new file URI node from a file system path and optional hostname.
@@ -143,12 +154,9 @@ serd_new_uri(const char* SERD_NONNULL str);
percent encoded as necessary.
If `path` is relative, `hostname` is ignored.
- If `out` is not NULL, it will be set to the parsed URI.
*/
SERD_API SerdNode* SERD_ALLOCATED
-serd_new_file_uri(const char* SERD_NONNULL path,
- const char* SERD_NULLABLE hostname,
- SerdURIView* SERD_NULLABLE out);
+serd_new_file_uri(SerdStringView path, SerdStringView hostname);
/**
Create a new node by serialising `d` into an xsd:decimal string.
@@ -237,7 +245,7 @@ serd_node_string_view(const SerdNode* SERD_NONNULL node);
idea to keep the value if you will be using it several times in the same
scope.
*/
-SERD_API SerdURIView
+SERD_PURE_API SerdURIView
serd_node_uri_view(const SerdNode* SERD_NONNULL node);
/**
diff --git a/include/serd/writer.h b/include/serd/writer.h
index 3327c1b9..976ed5b7 100644
--- a/include/serd/writer.h
+++ b/include/serd/writer.h
@@ -48,12 +48,11 @@ typedef uint32_t SerdWriterFlags;
/// Create a new RDF writer
SERD_API SerdWriter* SERD_ALLOCATED
-serd_writer_new(SerdSyntax syntax,
- SerdWriterFlags flags,
- SerdEnv* SERD_NONNULL env,
- const SerdNode* SERD_NULLABLE base_uri,
- SerdSink SERD_NONNULL ssink,
- void* SERD_NULLABLE stream);
+serd_writer_new(SerdSyntax syntax,
+ SerdWriterFlags flags,
+ SerdEnv* SERD_NONNULL env,
+ SerdSink SERD_NONNULL ssink,
+ void* SERD_NULLABLE stream);
/// Free `writer`
SERD_API void