aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-27 18:16:08 +0200
committerDavid Robillard <d@drobilla.net>2018-05-27 18:16:08 +0200
commita0c483d9f1f3955499560ef1536fdb760df274fb (patch)
treefa46603a7180e17a3d4e78ea088969d48babc79c
parent120b99b1cb02f153ec6f4071a8071ac08cb9d074 (diff)
downloadserd-a0c483d9f1f3955499560ef1536fdb760df274fb.tar.gz
serd-a0c483d9f1f3955499560ef1536fdb760df274fb.tar.bz2
serd-a0c483d9f1f3955499560ef1536fdb760df274fb.zip
Clarify errors returned by serd_env_expand()
-rw-r--r--NEWS3
-rw-r--r--serd/serd.h5
-rw-r--r--src/env.c6
-rw-r--r--src/writer.c10
4 files changed, 15 insertions, 9 deletions
diff --git a/NEWS b/NEWS
index 101aaeea..b54e8bd4 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,6 @@
serd (0.29.3) unstable;
+ * Clarify errors returned by serd_env_expand()
* Fix reported error when reading statements with only a blank node
* Fix parsing local names that end with escaped dots
* Add serdi option to write ASCII output
@@ -13,7 +14,7 @@ serd (0.29.3) unstable;
* Fix building with MSVC
* Clean up testing code
- -- David Robillard <d@drobilla.net> Thu, 08 Mar 2018 15:42:51 -0500
+ -- David Robillard <d@drobilla.net> Sun, 27 May 2018 17:51:33 +0200
serd (0.28.0) stable;
diff --git a/serd/serd.h b/serd/serd.h
index 762c58a4..b3056239 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -713,6 +713,9 @@ serd_env_qualify(const SerdEnv* env,
/**
Expand `curie`.
+
+ Errors: SERD_ERR_BAD_ARG if `curie` is not valid, or SERD_ERR_BAD_CURIE if
+ prefix is not defined in `env`.
*/
SERD_API
SerdStatus
@@ -723,6 +726,8 @@ serd_env_expand(const SerdEnv* env,
/**
Expand `node`, which must be a CURIE or URI, to a full URI.
+
+ Returns null if `node` can not be expanded.
*/
SERD_API
SerdNode
diff --git a/src/env.c b/src/env.c
index adda27ba..d969d3df 100644
--- a/src/env.c
+++ b/src/env.c
@@ -215,8 +215,8 @@ serd_env_expand(const SerdEnv* env,
{
const uint8_t* const colon = (const uint8_t*)memchr(
curie->buf, ':', curie->n_bytes + 1);
- if (!colon) {
- return SERD_ERR_BAD_ARG; // Invalid CURIE
+ if (curie->type != SERD_CURIE || !colon) {
+ return SERD_ERR_BAD_ARG;
}
const size_t name_len = colon - curie->buf;
@@ -228,7 +228,7 @@ serd_env_expand(const SerdEnv* env,
uri_suffix->len = curie->n_bytes - (colon - curie->buf) - 1;
return SERD_SUCCESS;
}
- return SERD_ERR_NOT_FOUND;
+ return SERD_ERR_BAD_CURIE;
}
SERD_API
diff --git a/src/writer.c b/src/writer.c
index 58cf17ee..603ca65e 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -525,14 +525,14 @@ write_curie(SerdWriter* const writer,
const Field field,
const SerdStatementFlags flags)
{
- SerdChunk prefix;
- SerdChunk suffix;
+ SerdChunk prefix;
+ SerdChunk suffix;
+ SerdStatus st;
switch (writer->syntax) {
case SERD_NTRIPLES:
case SERD_NQUADS:
- if (serd_env_expand(writer->env, node, &prefix, &suffix)) {
- w_err(writer, SERD_ERR_BAD_CURIE,
- "undefined namespace prefix `%s'\n", node->buf);
+ if ((st = serd_env_expand(writer->env, node, &prefix, &suffix))) {
+ w_err(writer, st, "undefined namespace prefix `%s'\n", node->buf);
return false;
}
write_sep(writer, SEP_URI_BEGIN);