From 4ac6d94d9a8826e09b81c6505408bed44d11e567 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 21 Jun 2020 18:19:48 +0200 Subject: Add serd_node_from_syntax() and serd_node_to_syntax() --- include/serd/serd.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'include/serd') 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 @@ -1665,6 +1665,54 @@ void 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 -- cgit v1.2.1