diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sord.c | 20 | ||||
-rw-r--r-- | src/sord_test.c | 18 |
2 files changed, 38 insertions, 0 deletions
@@ -959,6 +959,7 @@ sord_new_uri_counted(SordWorld* world, const uint8_t* str, size_t n_bytes, size_t n_chars, bool copy) { if (!serd_uri_string_has_scheme(str)) { + fprintf(stderr, "Attempt to map invalid URI `%s'.\n", str); return NULL; // Can't intern relative URIs } @@ -985,6 +986,25 @@ sord_new_uri(SordWorld* world, const uint8_t* str) return sord_new_uri_counted(world, str, node.n_bytes, node.n_chars, true); } +SordNode* +sord_new_relative_uri(SordWorld* world, + const uint8_t* str, + const uint8_t* base_str) +{ + if (serd_uri_string_has_scheme(str)) { + return sord_new_uri(world, str); + } + SerdURI buri = SERD_URI_NULL; + SerdNode base = serd_node_new_uri_from_string(base_str, NULL, &buri); + SerdNode node = serd_node_new_uri_from_string(str, &buri, NULL); + + SordNode* ret = sord_new_uri_counted( + world, node.buf, node.n_bytes, node.n_chars, false); + + serd_node_free(&base); + return ret; +} + static SordNode* sord_new_blank_counted(SordWorld* world, const uint8_t* str, size_t n_bytes, size_t n_chars) diff --git a/src/sord_test.c b/src/sord_test.c index 15d4ad6..9d5f008 100644 --- a/src/sord_test.c +++ b/src/sord_test.c @@ -437,6 +437,24 @@ main(int argc, char** argv) goto fail; } + // Check relative URI construction + SordNode* reluri = sord_new_relative_uri( + world, USTR("a/b"), USTR("http://example.org/")); + if (strcmp((const char*)sord_node_get_string(reluri), + "http://example.org/a/b")) { + fprintf(stderr, "Fail: Bad relative URI constructed: <%s>\n", + sord_node_get_string(reluri)); + goto fail; + } + SordNode* reluri2 = sord_new_relative_uri( + world, USTR("http://drobilla.net/"), USTR("http://example.org/")); + if (strcmp((const char*)sord_node_get_string(reluri2), + "http://drobilla.net/")) { + fprintf(stderr, "Fail: Bad relative URI constructed: <%s>\n", + sord_node_get_string(reluri)); + goto fail; + } + // Check comparison with NULL sord_node_free(world, uri_id); sord_node_free(world, blank_id); |