summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-02-10 22:30:43 +0000
committerDavid Robillard <d@drobilla.net>2011-02-10 22:30:43 +0000
commitef59f62b1b85e6992ac196ce9346165675604a94 (patch)
tree94183ba28108e7a9ffa67c9c306ae4539ad029fc /src
parent2d284c02f95fcd897a6cdaab5c704d1af7a6097b (diff)
downloadsord-ef59f62b1b85e6992ac196ce9346165675604a94.tar.gz
sord-ef59f62b1b85e6992ac196ce9346165675604a94.tar.bz2
sord-ef59f62b1b85e6992ac196ce9346165675604a94.zip
Update for new Serd API.
git-svn-id: http://svn.drobilla.net/sord/trunk@24 3d64ff67-21c5-427c-a301-fe4f08042e5a
Diffstat (limited to 'src')
-rw-r--r--src/syntax.c69
1 files changed, 30 insertions, 39 deletions
diff --git a/src/syntax.c b/src/syntax.c
index eef1c99..911f70a 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -49,24 +49,21 @@ static bool
event_base(void* handle,
const SerdNode* uri_node)
{
- ReadState* const state = (ReadState*)handle;
- SerdNode base_uri_node = *uri_node;
- SerdURI base_uri;
- if (!serd_uri_parse(uri_node->buf, &base_uri)) {
- return false;
- }
+ ReadState* const state = (ReadState*)handle;
- SerdURI abs_base_uri;
- if (!serd_uri_resolve(&base_uri, &state->base_uri, &abs_base_uri)) {
- fprintf(stderr, "error: failed to resolve new base URI\n");
- return false;
+ // Resolve base URI and create a new node and URI for it
+ SerdURI base_uri;
+ SerdNode base_uri_node = serd_node_new_uri_from_node(
+ uri_node, &state->base_uri, &base_uri);
+
+ if (base_uri_node.buf) {
+ // Replace the current base URI
+ serd_node_free(&state->base_uri_node);
+ state->base_uri_node = base_uri_node;
+ state->base_uri = base_uri;
+ return true;
}
- base_uri_node = serd_node_new_uri(&abs_base_uri, &base_uri);
-
- serd_node_free(&state->base_uri_node);
- state->base_uri_node = base_uri_node;
- state->base_uri = base_uri;
- return true;
+ return false;
}
static bool
@@ -75,21 +72,22 @@ event_prefix(void* handle,
const SerdNode* uri_node)
{
ReadState* const state = (ReadState*)handle;
- if (!serd_uri_string_has_scheme(uri_node->buf)) {
- SerdURI uri;
- if (!serd_uri_parse(uri_node->buf, &uri)) {
- return false;
- }
- SerdURI abs_uri;
- if (!serd_uri_resolve(&uri, &state->base_uri, &abs_uri)) {
+ if (serd_uri_string_has_scheme(uri_node->buf)) {
+ // Set prefix to absolute URI
+ serd_env_add(state->env, name, uri_node);
+ } else {
+ // Resolve relative URI and create a new node and URI for it
+ SerdURI abs_uri;
+ SerdNode abs_uri_node = serd_node_new_uri_from_node(
+ uri_node, &state->base_uri, &abs_uri);
+
+ if (!abs_uri_node.buf) {
return false;
}
- SerdURI base_uri;
- SerdNode base_uri_node = serd_node_new_uri(&abs_uri, &base_uri);
- serd_env_add(state->env, name, &base_uri_node);
- serd_node_free(&base_uri_node);
- } else {
- serd_env_add(state->env, name, uri_node);
+
+ // Set prefix to resolved (absolute) URI
+ serd_env_add(state->env, name, &abs_uri_node);
+ serd_node_free(&abs_uri_node);
}
return true;
}
@@ -103,16 +101,9 @@ sord_node_from_serd_node(ReadState* state, const SerdNode* sn)
case SERD_LITERAL:
return sord_get_literal(state->sord, true, NULL, sn->buf, NULL);
case SERD_URI: {
- SerdURI uri;
- if (!serd_uri_parse(sn->buf, &uri)) {
- return NULL;
- }
- SerdURI abs_uri;
- if (!serd_uri_resolve(&uri, &state->base_uri, &abs_uri)) {
- return false;
- }
- SerdURI ignored;
- SerdNode abs_uri_node = serd_node_new_uri(&abs_uri, &ignored);
+ SerdURI abs_uri;
+ SerdNode abs_uri_node = serd_node_new_uri_from_node(
+ sn, &state->base_uri, &abs_uri);
SordID ret = sord_get_uri(state->sord, true, abs_uri_node.buf);
serd_node_free(&abs_uri_node);
return ret;