aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-07-11 16:42:00 -0400
committerDavid Robillard <d@drobilla.net>2022-01-14 01:13:45 -0500
commit6c31c9d159424d1a6ba2e64b8d271743b9710f32 (patch)
treed1563a23b0e3252b290b4307aaa6421c79aa936c
parentc857c0ae873ea7558e8d702ae4c588a21c220409 (diff)
downloadserd-6c31c9d159424d1a6ba2e64b8d271743b9710f32.tar.gz
serd-6c31c9d159424d1a6ba2e64b8d271743b9710f32.tar.bz2
serd-6c31c9d159424d1a6ba2e64b8d271743b9710f32.zip
Make serd_env_expand_in_place() take a string view instead of a node
-rw-r--r--src/env.c14
-rw-r--r--src/env.h2
-rw-r--r--src/writer.c3
3 files changed, 11 insertions, 8 deletions
diff --git a/src/env.c b/src/env.c
index 3ebcf646..dccff337 100644
--- a/src/env.c
+++ b/src/env.c
@@ -257,13 +257,14 @@ serd_env_qualify(const SerdEnv* const env, const SerdNode* const uri)
SerdStatus
serd_env_expand_in_place(const SerdEnv* const env,
- const SerdNode* const curie,
+ const SerdStringView curie,
SerdStringView* const uri_prefix,
SerdStringView* const uri_suffix)
{
- const char* const str = serd_node_string(curie);
- const char* const colon = (const char*)memchr(str, ':', curie->length + 1);
- if (curie->type != SERD_CURIE || !colon) {
+ const char* const str = curie.buf;
+ const char* const colon =
+ str ? (const char*)memchr(str, ':', curie.len + 1) : NULL;
+ if (!colon) {
return SERD_ERR_BAD_ARG;
}
@@ -273,7 +274,7 @@ serd_env_expand_in_place(const SerdEnv* const env,
uri_prefix->buf = serd_node_string(prefix->uri);
uri_prefix->len = prefix->uri ? prefix->uri->length : 0;
uri_suffix->buf = colon + 1;
- uri_suffix->len = curie->length - name_len - 1;
+ uri_suffix->len = curie.len - name_len - 1;
return SERD_SUCCESS;
}
return SERD_ERR_BAD_CURIE;
@@ -294,7 +295,8 @@ expand_curie(const SerdEnv* env, const SerdNode* node)
SerdStringView prefix;
SerdStringView suffix;
- if (serd_env_expand_in_place(env, node, &prefix, &suffix)) {
+ if (serd_env_expand_in_place(
+ env, serd_node_string_view(node), &prefix, &suffix)) {
return NULL;
}
diff --git a/src/env.h b/src/env.h
index 50ae82eb..c3fd5dc9 100644
--- a/src/env.h
+++ b/src/env.h
@@ -36,7 +36,7 @@ serd_env_qualify_in_place(const SerdEnv* env,
*/
SerdStatus
serd_env_expand_in_place(const SerdEnv* env,
- const SerdNode* curie,
+ SerdStringView curie,
SerdStringView* uri_prefix,
SerdStringView* uri_suffix);
diff --git a/src/writer.c b/src/writer.c
index a0e5f3a3..c86b066d 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -857,7 +857,8 @@ write_curie(SerdWriter* const writer, const SerdNode* const node)
SerdStatus st = SERD_SUCCESS;
if (writer->syntax == SERD_NTRIPLES || writer->syntax == SERD_NQUADS) {
- if ((st = serd_env_expand_in_place(writer->env, node, &prefix, &suffix))) {
+ const SerdStringView curie = serd_node_string_view(node);
+ if ((st = serd_env_expand_in_place(writer->env, curie, &prefix, &suffix))) {
return w_err(writer,
st,
"undefined namespace prefix in `%s'",