aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-03-02 08:49:23 +0000
committerDavid Robillard <d@drobilla.net>2011-03-02 08:49:23 +0000
commitbb14fdecabb00dbda2740343f22ecb817dc52f47 (patch)
treefce60a5bb52ff4a770c7945a4f05f696dd771b1c
parent5b72a58a2f0dc020bee2bba6b3b19d0a278dfd21 (diff)
downloadserd-bb14fdecabb00dbda2740343f22ecb817dc52f47.tar.gz
serd-bb14fdecabb00dbda2740343f22ecb817dc52f47.tar.bz2
serd-bb14fdecabb00dbda2740343f22ecb817dc52f47.zip
Fix parsing several files/strings with the same parser.
Add serd_read_state_expand. git-svn-id: http://svn.drobilla.net/serd/trunk@114 490d8e77-9747-427b-9fa3-0b8f29cee8a0
-rw-r--r--serd/serd.h10
-rw-r--r--src/reader.c26
2 files changed, 36 insertions, 0 deletions
diff --git a/serd/serd.h b/serd/serd.h
index a56ab971..56511b12 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -511,6 +511,16 @@ void
serd_read_state_free(SerdReadState state);
/**
+ Expand @a node to a full URI.
+
+ @param node A CURIE or URI node to expand and/or resolve.
+*/
+SERD_API
+SerdNode
+serd_read_state_expand(SerdReadState state,
+ const SerdNode* node);
+
+/**
Get the current base URI.
*/
SERD_API
diff --git a/src/reader.c b/src/reader.c
index b19ffcdc..904422b0 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -1429,6 +1429,7 @@ serd_reader_read_file(SerdReader me, FILE* file, const uint8_t* name)
me->read_head = 0;
me->cur = cur;
me->from_file = true;
+ me->eof = false;
/* Read into the second page of the buffer. Occasionally peek_string
will move the read_head to before this point when readahead causes
@@ -1455,6 +1456,7 @@ serd_reader_read_string(SerdReader me, const uint8_t* utf8)
me->read_head = 0;
me->cur = cur;
me->from_file = false;
+ me->eof = false;
const bool ret = read_turtleDoc(me);
@@ -1485,6 +1487,30 @@ serd_read_state_free(SerdReadState state)
SERD_API
SerdNode
+serd_read_state_expand(SerdReadState state,
+ const SerdNode* node)
+{
+ if (node->type == SERD_CURIE) {
+ SerdChunk prefix;
+ SerdChunk suffix;
+ serd_env_expand(state->env, node, &prefix, &suffix);
+ SerdNode ret = { SERD_URI,
+ prefix.len + suffix.len + 1,
+ prefix.len + suffix.len, // FIXME: UTF-8
+ NULL };
+ ret.buf = malloc(ret.n_bytes);
+ snprintf((char*)ret.buf, ret.n_bytes, "%s%s", prefix.buf, suffix.buf);
+ return ret;
+ } else if (node->type == SERD_URI) {
+ SerdURI ignored;
+ return serd_node_new_uri_from_node(node, &state->base_uri, &ignored);
+ } else {
+ return SERD_NODE_NULL;
+ }
+}
+
+SERD_API
+SerdNode
serd_read_state_get_base_uri(SerdReadState state,
SerdURI* out)
{