diff options
author | David Robillard <d@drobilla.net> | 2016-07-10 19:07:14 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2016-07-10 19:07:14 -0400 |
commit | 1e8c93c6e760c4453c4fd1f471feebd7886692d3 (patch) | |
tree | 0a7b77f7f27db3ceb401658cf18c883352dc7308 /src/node.c | |
parent | af9356818981e83d5eb9430d4717b19c7316c154 (diff) | |
download | serd-1e8c93c6e760c4453c4fd1f471feebd7886692d3.tar.gz serd-1e8c93c6e760c4453c4fd1f471feebd7886692d3.tar.bz2 serd-1e8c93c6e760c4453c4fd1f471feebd7886692d3.zip |
Add serd_node_new_relative_uri()
Diffstat (limited to 'src/node.c')
-rw-r--r-- | src/node.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -212,6 +212,32 @@ serd_node_new_uri(const SerdURI* uri, const SerdURI* base, SerdURI* out) return node; } +SERD_API +SerdNode +serd_node_new_relative_uri(const SerdURI* uri, + const SerdURI* base, + const SerdURI* root, + SerdURI* out) +{ + const size_t uri_len = serd_uri_string_length(uri); + const size_t base_len = serd_uri_string_length(base); + uint8_t* buf = (uint8_t*)malloc(uri_len + base_len + 1); + SerdNode node = { buf, 0, 0, 0, SERD_URI }; + uint8_t* ptr = buf; + const size_t actual_len = serd_uri_serialise_relative( + uri, base, root, string_sink, &ptr); + + buf[actual_len] = '\0'; + node.n_bytes = actual_len; + node.n_chars = serd_strlen(buf, NULL, NULL); + + if (out) { + serd_uri_parse(buf, out); // TODO: cleverly avoid double parse + } + + return node; +} + static inline unsigned serd_digits(double abs) { |