diff options
author | David Robillard <d@drobilla.net> | 2011-01-24 23:27:15 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-01-24 23:27:15 +0000 |
commit | e4daedb841acef2a4839a33e7c17ee8ea5fa6913 (patch) | |
tree | d24a5a955c3be4b5f2cc938ea5c090c9e80de06c /src/env.c | |
parent | 6903e56e2443a1a5b023d688cb7fd54e3580316d (diff) | |
download | serd-e4daedb841acef2a4839a33e7c17ee8ea5fa6913.tar.gz serd-e4daedb841acef2a4839a33e7c17ee8ea5fa6913.tar.bz2 serd-e4daedb841acef2a4839a33e7c17ee8ea5fa6913.zip |
Remove SerdString cruft.
git-svn-id: http://svn.drobilla.net/serd/trunk@54 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/env.c')
-rw-r--r-- | src/env.c | 38 |
1 files changed, 27 insertions, 11 deletions
@@ -23,8 +23,8 @@ #include "serd_internal.h" typedef struct { - SerdString* name; - SerdString* uri; + SerdNode name; + SerdNode uri; } SerdPrefix; struct SerdEnvImpl { @@ -32,6 +32,22 @@ struct SerdEnvImpl { size_t n_prefixes; }; +static SerdNode +serd_node_copy(const SerdNode* node) +{ + SerdNode copy = *node; + uint8_t* buf = malloc(copy.n_bytes); + memcpy(buf, node->buf, copy.n_bytes); + copy.buf = buf; + return copy; +} + +static void +serd_node_free(SerdNode* node) +{ + free((uint8_t*)node->buf); // FIXME: const cast +} + SERD_API SerdEnv serd_env_new() @@ -47,8 +63,8 @@ void serd_env_free(SerdEnv env) { for (size_t i = 0; i < env->n_prefixes; ++i) { - serd_string_free(env->prefixes[i].name); - serd_string_free(env->prefixes[i].uri); + serd_node_free(&env->prefixes[i].name); + serd_node_free(&env->prefixes[i].uri); } free(env->prefixes); free(env); @@ -60,7 +76,7 @@ serd_env_find(SerdEnv env, size_t name_len) { for (size_t i = 0; i < env->n_prefixes; ++i) { - const SerdString* prefix_name = env->prefixes[i].name; + const SerdNode* const prefix_name = &env->prefixes[i].name; if (prefix_name->n_bytes == name_len + 1) { if (!memcmp(prefix_name->buf, name, name_len)) { return &env->prefixes[i]; @@ -79,13 +95,13 @@ serd_env_add(SerdEnv env, assert(name && uri); SerdPrefix* const prefix = serd_env_find(env, name->buf, name->n_chars); if (prefix) { - serd_string_free(prefix->uri); - prefix->uri = serd_string_new_from_node(uri); + serd_node_free(&prefix->uri); + prefix->uri = serd_node_copy(uri); } else { env->prefixes = realloc(env->prefixes, (++env->n_prefixes) * sizeof(SerdPrefix)); - env->prefixes[env->n_prefixes - 1].name = serd_string_new_from_node(name); - env->prefixes[env->n_prefixes - 1].uri = serd_string_new_from_node(uri); + env->prefixes[env->n_prefixes - 1].name = serd_node_copy(name); + env->prefixes[env->n_prefixes - 1].uri = serd_node_copy(uri); } } @@ -104,8 +120,8 @@ serd_env_expand(const SerdEnv env, const size_t name_len = colon - qname->buf; const SerdPrefix* const prefix = serd_env_find(env, qname->buf, name_len); if (prefix) { - uri_prefix->buf = prefix->uri->buf; - uri_prefix->len = prefix->uri->n_bytes - 1; + uri_prefix->buf = prefix->uri.buf; + uri_prefix->len = prefix->uri.n_bytes - 1; uri_suffix->buf = colon + 1; uri_suffix->len = qname->n_bytes - (colon - qname->buf) - 2; return true; |