5.11 Environment

typedef struct SerdEnvImpl SerdEnv

Lexical environment for relative URIs or CURIEs (base URI and namespaces)

SerdEnv *serd_env_new(const SerdWorld *world, SerdStringView base_uri)

Create a new environment.

SerdEnv *serd_env_copy(SerdAllocator *allocator, const SerdEnv *env)

Copy an environment.

bool serd_env_equals(const SerdEnv *a, const SerdEnv *b)

Return true iff a is equal to b

void serd_env_free(SerdEnv *env)

Free env

const SerdNode *serd_env_base_uri(const SerdEnv *env)

Get the current base URI.

SerdStatus serd_env_set_base_uri(SerdEnv *env, SerdStringView uri)

Set the current base URI.

SerdStatus serd_env_set_prefix(SerdEnv *env, SerdStringView name, SerdStringView uri)

Set a namespace prefix.

A namespace prefix is used to expand CURIE nodes, for example, with the prefix “xsd” set to “http://www.w3.org/2001/XMLSchema#”, “xsd:decimal” will expand to “http://www.w3.org/2001/XMLSchema#decimal”.

SerdNode *serd_env_expand(const SerdEnv *env, const SerdNode *node)

Expand node, which must be a CURIE or URI, to a full URI.

Returns null if node can not be expanded.

void serd_env_write_prefixes(const SerdEnv *env, const SerdSink *sink)

Write all prefixes in env to sink

SerdNode *serd_node_from_syntax(SerdWorld *world, const char *str, SerdSyntax syntax, SerdEnv *env)

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 SerdSyntax.SERD_TURTLE, can be used to round-trip any node to a string and back.

Parameters
  • world – The world.

  • str – String representation of a node.

  • 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.

  • env – Environment of str. This must define any abbreviations needed to parse the string.

Returns

A newly allocated node that must be freed with serd_node_free() using the world allocator.

char *serd_node_to_syntax(SerdWorld *world, const SerdNode *node, SerdSyntax syntax, const SerdEnv *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.

Parameters
  • world – World used to allocate internal components and the returned string.

  • node – Node to write as a string.

  • 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.

  • env – Environment for the output string. This can be used to abbreviate things nicely by setting namespace prefixes.

Returns

A newly allocated string that must be freed with serd_free() using the world allocator.