aboutsummaryrefslogtreecommitdiffstats
path: root/include/serd
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-06-21 18:19:48 +0200
committerDavid Robillard <d@drobilla.net>2022-01-14 19:37:51 -0500
commit4ac6d94d9a8826e09b81c6505408bed44d11e567 (patch)
treec14d3545d56c1e10be516db1838c1811bc83bcc9 /include/serd
parent4436f80225c441a878c4baf856d21dee0394c8dc (diff)
downloadserd-4ac6d94d9a8826e09b81c6505408bed44d11e567.tar.gz
serd-4ac6d94d9a8826e09b81c6505408bed44d11e567.tar.bz2
serd-4ac6d94d9a8826e09b81c6505408bed44d11e567.zip
Add serd_node_from_syntax() and serd_node_to_syntax()
Diffstat (limited to 'include/serd')
-rw-r--r--include/serd/serd.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 05c1ed8c..4067fa3f 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -1666,6 +1666,54 @@ serd_env_write_prefixes(const SerdEnv* SERD_NONNULL env,
const SerdSink* SERD_NONNULL sink);
/**
+ Create a node from a string representation in `syntax`.
+
+ The string should be a node as if written as an object in the given syntax,
+ without any extra quoting or punctuation, which is the format returned by
+ serd_node_to_syntax(). These two functions, when used with #SERD_TURTLE,
+ can be used to round-trip any node to a string and back.
+
+ @param str String representation of a node.
+
+ @param syntax Syntax to use. Should be either SERD_TURTLE or SERD_NTRIPLES
+ (the others are redundant). Note that namespaced (CURIE) nodes and relative
+ URIs can not be expressed in NTriples.
+
+ @param env Environment of `str`. This must define any abbreviations needed
+ to parse the string.
+
+ @return A newly allocated node that must be freed with serd_node_free().
+*/
+SERD_API
+SerdNode* SERD_ALLOCATED
+serd_node_from_syntax(const char* SERD_NONNULL str,
+ SerdSyntax syntax,
+ SerdEnv* SERD_NULLABLE env);
+
+/**
+ Return a string representation of `node` in `syntax`.
+
+ The returned string represents that node as if written as an object in the
+ given syntax, without any extra quoting or punctuation.
+
+ @param node Node to write as a string.
+
+ @param syntax Syntax to use. Should be either SERD_TURTLE or SERD_NTRIPLES
+ (the others are redundant). Note that namespaced (CURIE) nodes and relative
+ URIs can not be expressed in NTriples.
+
+ @param env Environment for the output string. This can be used to
+ abbreviate things nicely by setting namespace prefixes.
+
+ @return A newly allocated string that must be freed with serd_free().
+*/
+SERD_API
+char* SERD_ALLOCATED
+serd_node_to_syntax(const SerdNode* SERD_NONNULL node,
+ SerdSyntax syntax,
+ const SerdEnv* SERD_NULLABLE env);
+
+/**
@}
@defgroup serd_byte_source Byte Source
@{