aboutsummaryrefslogtreecommitdiffstats
path: root/src/env.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-02-16 17:03:27 +0000
committerDavid Robillard <d@drobilla.net>2011-02-16 17:03:27 +0000
commit0e7dfee8bae6655b316f1d0cabbad7df4dba6105 (patch)
treecc568baf815586293145caa774ad443d8b4ff612 /src/env.c
parentebbaf807a95ad9fb80e0bfcfdab629a257c5836d (diff)
downloadserd-0e7dfee8bae6655b316f1d0cabbad7df4dba6105.tar.gz
serd-0e7dfee8bae6655b316f1d0cabbad7df4dba6105.tar.bz2
serd-0e7dfee8bae6655b316f1d0cabbad7df4dba6105.zip
Add SERD_STYLE_RESOLVED option for resolving (expanding) relative URIs in output.
Add serd_env_qualify and serd_env_foreach. git-svn-id: http://svn.drobilla.net/serd/trunk@101 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/env.c')
-rw-r--r--src/env.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/env.c b/src/env.c
index 3d64d2b1..9d3b3ca4 100644
--- a/src/env.c
+++ b/src/env.c
@@ -93,6 +93,29 @@ serd_env_add(SerdEnv env,
SERD_API
bool
+serd_env_qualify(const SerdEnv env,
+ const SerdNode* uri,
+ SerdNode* prefix_name,
+ SerdChunk* suffix)
+{
+ for (size_t i = 0; i < env->n_prefixes; ++i) {
+ const SerdNode* const prefix_uri = &env->prefixes[i].uri;
+ if (uri->n_bytes >= prefix_uri->n_bytes) {
+ if (!strncmp((const char*)uri->buf,
+ (const char*)prefix_uri->buf,
+ prefix_uri->n_bytes)) {
+ *prefix_name = env->prefixes[i].name;
+ suffix->buf = uri->buf + prefix_uri->n_bytes;
+ suffix->len = uri->n_bytes - prefix_uri->n_bytes;
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+SERD_API
+bool
serd_env_expand(const SerdEnv env,
const SerdNode* qname,
SerdChunk* uri_prefix,
@@ -114,3 +137,16 @@ serd_env_expand(const SerdEnv env,
}
return false;
}
+
+SERD_API
+void
+serd_env_foreach(const SerdEnv env,
+ SerdPrefixSink func,
+ void* handle)
+{
+ for (size_t i = 0; i < env->n_prefixes; ++i) {
+ func(handle,
+ &env->prefixes[i].name,
+ &env->prefixes[i].uri);
+ }
+}