aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-01-24 23:27:15 +0000
committerDavid Robillard <d@drobilla.net>2011-01-24 23:27:15 +0000
commite4daedb841acef2a4839a33e7c17ee8ea5fa6913 (patch)
treed24a5a955c3be4b5f2cc938ea5c090c9e80de06c /src
parent6903e56e2443a1a5b023d688cb7fd54e3580316d (diff)
downloadserd-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')
-rw-r--r--src/env.c38
-rw-r--r--src/reader.c7
-rw-r--r--src/serd_internal.h43
-rw-r--r--src/serdi.c18
-rw-r--r--src/string.c91
5 files changed, 55 insertions, 142 deletions
diff --git a/src/env.c b/src/env.c
index 87356ad6..99bf77af 100644
--- a/src/env.c
+++ b/src/env.c
@@ -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;
diff --git a/src/reader.c b/src/reader.c
index 35067403..773dd99b 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -60,6 +60,13 @@ typedef struct {
const Node* predicate;
} ReadContext;
+/** Measured UTF-8 string. */
+typedef struct {
+ size_t n_bytes; ///< Size in bytes including trailing null byte
+ size_t n_chars; ///< Length in characters
+ uint8_t buf[]; ///< Buffer
+} SerdString;
+
static const Node INTERNAL_NODE_NULL = { 0, 0, 0, 0 };
struct SerdReaderImpl {
diff --git a/src/serd_internal.h b/src/serd_internal.h
index 1b601e12..7adf1567 100644
--- a/src/serd_internal.h
+++ b/src/serd_internal.h
@@ -99,27 +99,26 @@ is_digit(const uint8_t c)
return in_range(c, '0', '9');
}
-/** Measured UTF-8 string. */
-typedef struct {
- size_t n_bytes; ///< Size in bytes including trailing null byte
- size_t n_chars; ///< Length in characters
- uint8_t buf[]; ///< Buffer
-} SerdString;
-
-#if 0
-/** Create a new UTF-8 string from @a utf8. */
-SerdString*
-serd_string_new(const uint8_t* utf8);
-
-/** Copy @a string. */
-SerdString*
-serd_string_copy(const SerdString* str);
-#endif
-
-void
-serd_string_free(SerdString* str);
-
-SerdString*
-serd_string_new_from_node(const SerdNode* node);
+/** UTF-8 strlen.
+ * @return Lengh of @a utf8 in characters.
+ * @param utf8 A null-terminated UTF-8 string.
+ * @param out_n_bytes (Output) Set to the size of @a utf8 in bytes.
+ */
+static inline size_t
+serd_strlen(const uint8_t* utf8, size_t* out_n_bytes)
+{
+ size_t n_chars = 0;
+ size_t i = 0;
+ for (; utf8[i]; ++i) {
+ if ((utf8[i] & 0xC0) != 0x80) {
+ // Does not start with `10', start of a new character
+ ++n_chars;
+ }
+ }
+ if (out_n_bytes) {
+ *out_n_bytes = i + 1;
+ }
+ return n_chars;
+}
#endif // SERD_INTERNAL_H
diff --git a/src/serdi.c b/src/serdi.c
index 810de74c..451905b8 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -96,24 +96,6 @@ copy_string(const uint8_t* str, size_t* n_bytes)
return ret;
}
-#if 0
-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
-}
-#endif
-
static bool
event_base(void* handle,
const SerdNode* uri_node)
diff --git a/src/string.c b/src/string.c
deleted file mode 100644
index 77346676..00000000
--- a/src/string.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/* Serd, an RDF serialisation library.
- * Copyright 2011 David Robillard <d@drobilla.net>
- *
- * Serd is free software: you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Serd is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <assert.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "serd_internal.h"
-
-#if 0
-static inline size_t
-utf8_strlen(const uint8_t* utf8, size_t* out_n_bytes)
-{
- size_t n_chars = 0;
- size_t i = 0;
- for (; utf8[i]; ++i) {
- if ((utf8[i] & 0xC0) != 0x80) {
- // Does not start with `10', start of a new character
- ++n_chars;
- }
- }
- if (out_n_bytes) {
- *out_n_bytes = i + 1;
- }
- return n_chars;
-}
-#endif
-
-static SerdString*
-serd_string_new_measured(const uint8_t* utf8, size_t n_bytes, size_t n_chars)
-{
- SerdString* const str = malloc(sizeof(SerdString) + n_bytes);
- str->n_bytes = n_bytes;
- str->n_chars = n_chars;
- memcpy(str->buf, utf8, n_bytes);
- return str;
-}
-
-#if 0
-SERD_API
-SerdString*
-serd_string_new(const uint8_t* utf8)
-{
- size_t n_bytes;
- size_t n_chars = utf8_strlen(utf8, &n_bytes);
- return serd_string_new_measured(utf8, n_bytes, n_chars);
-}
-#endif
-
-SERD_API
-SerdString*
-serd_string_new_from_node(const SerdNode* node)
-{
- return serd_string_new_measured(node->buf, node->n_bytes, node->n_chars);
-}
-
-#if 0
-SERD_API
-SerdString*
-serd_string_copy(const SerdString* s)
-{
- if (s) {
- SerdString* const copy = malloc(sizeof(SerdString) + s->n_bytes);
- memcpy(copy, s, sizeof(SerdString) + s->n_bytes);
- return copy;
- }
- return NULL;
-}
-#endif
-
-SERD_API
-void
-serd_string_free(SerdString* str)
-{
- free(str);
-}