From 7994fd5ebcfc07e83d7f46e974466a7d32211ac6 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 4 Feb 2018 15:33:36 +0100 Subject: Use opaque node API --- src/env.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src/env.c') diff --git a/src/env.c b/src/env.c index 34e8cad9..292f047c 100644 --- a/src/env.c +++ b/src/env.c @@ -96,7 +96,7 @@ serd_env_find(const SerdEnv* env, for (size_t i = 0; i < env->n_prefixes; ++i) { const SerdNode* const prefix_name = &env->prefixes[i].name; if (prefix_name->n_bytes == name_len) { - if (!memcmp(prefix_name->buf, name, name_len)) { + if (!memcmp(serd_node_get_string(prefix_name), name, name_len)) { return &env->prefixes[i]; } } @@ -109,7 +109,8 @@ serd_env_add(SerdEnv* env, const SerdNode* name, const SerdNode* uri) { - SerdPrefix* const prefix = serd_env_find(env, name->buf, name->n_bytes); + const char* name_str = serd_node_get_string(name); + SerdPrefix* const prefix = serd_env_find(env, name_str, name->n_bytes); if (prefix) { SerdNode old_prefix_uri = prefix->uri; prefix->uri = serd_node_copy(uri); @@ -129,7 +130,7 @@ serd_env_set_prefix(SerdEnv* env, { if (!name->buf || uri->type != SERD_URI) { return SERD_ERR_BAD_ARG; - } else if (serd_uri_string_has_scheme(uri->buf)) { + } else if (serd_uri_string_has_scheme(serd_node_get_string(uri))) { // Set prefix to absolute URI serd_env_add(env, name, uri); } else { @@ -165,9 +166,12 @@ serd_env_qualify(const SerdEnv* env, for (size_t i = 0; i < env->n_prefixes; ++i) { const SerdNode* const prefix_uri = &env->prefixes[i].uri; if (uri->n_bytes >= prefix_uri->n_bytes) { - if (!strncmp(uri->buf, prefix_uri->buf, prefix_uri->n_bytes)) { - *prefix = env->prefixes[i].name; - suffix->buf = uri->buf + prefix_uri->n_bytes; + const char* prefix_str = serd_node_get_string(prefix_uri); + const char* uri_str = serd_node_get_string(uri); + + if (!strncmp(uri_str, prefix_str, prefix_uri->n_bytes)) { + *prefix = env->prefixes[i].name; + suffix->buf = uri_str + prefix_uri->n_bytes; suffix->len = uri->n_bytes - prefix_uri->n_bytes; return true; } @@ -182,16 +186,16 @@ serd_env_expand(const SerdEnv* env, SerdStringView* uri_prefix, SerdStringView* uri_suffix) { - const char* const colon = (const char*)memchr( - curie->buf, ':', curie->n_bytes + 1); + const char* const str = serd_node_get_string(curie); + const char* const colon = (const char*)memchr(str, ':', curie->n_bytes + 1); if (curie->type != SERD_CURIE || !colon) { return SERD_ERR_BAD_ARG; } - const size_t name_len = (size_t)(colon - curie->buf); - const SerdPrefix* const prefix = serd_env_find(env, curie->buf, name_len); + const size_t name_len = (size_t)(colon - str); + const SerdPrefix* const prefix = serd_env_find(env, str, name_len); if (prefix) { - uri_prefix->buf = prefix->uri.buf; + uri_prefix->buf = serd_node_get_string(&prefix->uri); uri_prefix->len = prefix->uri.n_bytes; uri_suffix->buf = colon + 1; uri_suffix->len = curie->n_bytes - name_len - 1; -- cgit v1.2.1