diff options
author | David Robillard <d@drobilla.net> | 2021-02-20 20:10:57 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-03-08 23:23:06 -0500 |
commit | 1c1c060d7a449952051b2dd78176e48db53df1c4 (patch) | |
tree | 3f1a487c3fbdf87fa812c99bd5380325310e7b9f /src | |
parent | dd63c46261f36de5c6dbd951ae1c535128f5cf8c (diff) | |
download | serd-1c1c060d7a449952051b2dd78176e48db53df1c4.tar.gz serd-1c1c060d7a449952051b2dd78176e48db53df1c4.tar.bz2 serd-1c1c060d7a449952051b2dd78176e48db53df1c4.zip |
WIP: Make serd_env_expand() always return a node if it is not relative
The old interface was potentially faster, because it avoided unnecessary
copies, but was annoying to use and problematic because nodes that don't need
expansion were indistinguishable from nodes that failed to expand (like those
that use undefined namespace prefixes).
In the grand scheme of things, the potential performance improvement isn't
worth it, and unexpected unexpanded nodes causes deep nightmarish problems, so
just make serd_env_expand() copy the input if it doesn't need expansion to make
the API simpler and safer.
Diffstat (limited to 'src')
-rw-r--r-- | src/env.c | 31 | ||||
-rw-r--r-- | src/uri.c | 3 |
2 files changed, 25 insertions, 9 deletions
@@ -278,15 +278,34 @@ expand_literal(const SerdEnv* env, const SerdNode* node) assert(serd_node_type(node) == SERD_LITERAL); const SerdNode* const datatype = serd_node_datatype(node); - if (datatype && serd_node_type(datatype) == SERD_CURIE) { + if (!datatype) { + return serd_node_copy(node); + } + + if (serd_node_type(datatype) == SERD_CURIE) { SerdStringView prefix; SerdStringView suffix; - if (!serd_env_expand_in_place(env, datatype, &prefix, &suffix)) { - return serd_new_typed_literal_expanded( - serd_node_string_view(node), serd_node_flags(node), SERD_URI, prefix, suffix); + if (serd_env_expand_in_place(env, datatype, &prefix, &suffix)) { + return NULL; + } + + return serd_new_typed_literal_expanded(serd_node_string_view(node), + serd_node_flags(node), + SERD_URI, + prefix, + suffix); + } + + if (serd_node_type(datatype) == SERD_URI) { + const SerdURIView datatype_uri = serd_parse_uri(serd_node_string(datatype)); + + const SerdURIView abs_datatype_uri = + serd_resolve_uri(datatype_uri, env->base_uri); + + if (!abs_datatype_uri.scheme.len) { + return NULL; } - } else if (datatype && serd_node_type(datatype) == SERD_URI) { return serd_new_typed_literal_uri( serd_node_string_view(node), serd_node_flags(node), @@ -336,7 +355,7 @@ serd_env_expand(const SerdEnv* env, const SerdNode* node) case SERD_CURIE: return expand_curie(env, node); case SERD_BLANK: - return NULL; + return serd_node_copy(node); } } @@ -283,9 +283,6 @@ serd_resolve_uri(const SerdURIView r, const SerdURIView base) SerdURIView t = SERD_URI_NULL; - t.path_prefix.buf = NULL; - t.path_prefix.len = 0; - if (r.authority.len) { t.authority = r.authority; t.path = r.path; |