From 8a13a270d9150e0cd14a049c76c601d09ee539bf Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 21 Jun 2020 18:19:48 +0200 Subject: WIP: Add serd_node_from_syntax() and serd_node_to_syntax() --- include/serd/serd.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'include/serd/serd.h') diff --git a/include/serd/serd.h b/include/serd/serd.h index f3402dd1..3c75518e 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -714,6 +714,44 @@ serd_write_uri(SerdURIView uri, @{ */ +/** + 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. + + @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); + +/** + 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 serialise. + + @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. + + @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); + /** Create a new "simple" node that is just a string. -- cgit v1.2.1