diff options
author | David Robillard <d@drobilla.net> | 2011-02-16 17:03:27 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-02-16 17:03:27 +0000 |
commit | 0e7dfee8bae6655b316f1d0cabbad7df4dba6105 (patch) | |
tree | cc568baf815586293145caa774ad443d8b4ff612 /src | |
parent | ebbaf807a95ad9fb80e0bfcfdab629a257c5836d (diff) | |
download | serd-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')
-rw-r--r-- | src/env.c | 36 | ||||
-rw-r--r-- | src/serdi.c | 2 |
2 files changed, 38 insertions, 0 deletions
@@ -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); + } +} diff --git a/src/serdi.c b/src/serdi.c index 5d7244b2..7736f773 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -237,6 +237,8 @@ main(int argc, char** argv) ? SERD_STYLE_ASCII : SERD_STYLE_ABBREVIATED; + output_style |= SERD_STYLE_RESOLVED; + const SerdNode base_uri_node = { SERD_URI, base_uri_n_bytes, base_uri_n_bytes - 1, |