aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-01-20 19:08:09 +0000
committerDavid Robillard <d@drobilla.net>2011-01-20 19:08:09 +0000
commit57683c8352e4a545171f28047617df88a6d4c917 (patch)
treee46f7493647a9d95a627d403edcbe6cdf7d4e8da
parentf0c50e7461641d060c783e1f0fb1b74b3c175054 (diff)
downloadserd-57683c8352e4a545171f28047617df88a6d4c917.tar.gz
serd-57683c8352e4a545171f28047617df88a6d4c917.tar.bz2
serd-57683c8352e4a545171f28047617df88a6d4c917.zip
Add serd_string_free to API.
git-svn-id: http://svn.drobilla.net/serd/trunk@13 490d8e77-9747-427b-9fa3-0b8f29cee8a0
-rw-r--r--serd/serd.h83
-rw-r--r--src/namespaces.c6
-rw-r--r--src/serdi.c6
-rw-r--r--src/string.c7
4 files changed, 59 insertions, 43 deletions
diff --git a/serd/serd.h b/serd/serd.h
index 98aea4b5..d59e3002 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -70,7 +70,8 @@ typedef enum {
LITERAL = 4 ///< Literal string (with optional lang or datatype)
} SerdNodeType;
-/** @name URIs
+/** @name URI
+ * Support for parsing and resolving URIs.
* @{
*/
@@ -123,8 +124,8 @@ size_t
serd_uri_serialise(const SerdURI* uri, SerdSink sink, void* stream);
/** @} */
-
/** @name String
+ * @brief A measured UTF-8 string.
* @{
*/
@@ -145,27 +146,50 @@ SERD_API
SerdString*
serd_string_copy(const SerdString* str);
+/** Free @a str. */
+SERD_API
+void
+serd_string_free(SerdString* str);
+
/** Serialise @a uri to a string. */
SERD_API
SerdString*
serd_string_new_from_uri(const SerdURI* uri,
SerdURI* out);
+/** @} */
+/** @name Namespaces
+ * @brief A dictionary of namespaces (names associated with URI strings)
+ * @{
+ */
-/** Write a node to @a file. */
+/** Create a new namespaces dictionary. */
SERD_API
-bool
-serd_write_node(FILE* file,
- const SerdURI* base_uri,
- SerdNamespaces ns,
- SerdNodeType type,
- const SerdString* str,
- const SerdString* datatype,
- const SerdString* lang);
+SerdNamespaces
+serd_namespaces_new();
-/** @} */
+/** Free @a ns. */
+SERD_API
+void
+serd_namespaces_free(SerdNamespaces ns);
+/** Add namespace @a uri to @a ns using prefix @a name. */
+SERD_API
+void
+serd_namespaces_add(SerdNamespaces ns,
+ const SerdString* name,
+ const SerdString* uri);
+/** Expand @a qname. */
+SERD_API
+bool
+serd_namespaces_expand(SerdNamespaces ns,
+ const SerdString* qname,
+ SerdChunk* uri_prefix,
+ SerdChunk* uri_suffix);
+
+/** @} */
/** @name Reader
+ * @brief Reader for RDF syntax.
* @{
*/
@@ -212,36 +236,21 @@ void
serd_reader_free(SerdReader reader);
/** @} */
-
-
-/** @name Namespaces
+/** @name Writer
+ * @brief Writer of RDF syntax.
* @{
*/
-/** Create a new namespaces dictionary. */
-SERD_API
-SerdNamespaces
-serd_namespaces_new();
-
-/** Free @a ns. */
-SERD_API
-void
-serd_namespaces_free(SerdNamespaces ns);
-
-/** Add namespace @a uri to @a ns using prefix @a name. */
-SERD_API
-void
-serd_namespaces_add(SerdNamespaces ns,
- const SerdString* name,
- const SerdString* uri);
-
-/** Expand @a qname. */
+/** Write a node to @a file. */
SERD_API
bool
-serd_namespaces_expand(SerdNamespaces ns,
- const SerdString* qname,
- SerdChunk* uri_prefix,
- SerdChunk* uri_suffix);
+serd_write_node(FILE* file,
+ const SerdURI* base_uri,
+ SerdNamespaces ns,
+ SerdNodeType type,
+ const SerdString* str,
+ const SerdString* datatype,
+ const SerdString* lang);
/** @} */
diff --git a/src/namespaces.c b/src/namespaces.c
index b14d74c5..6c400a3c 100644
--- a/src/namespaces.c
+++ b/src/namespaces.c
@@ -47,8 +47,8 @@ void
serd_namespaces_free(SerdNamespaces ns)
{
for (size_t i = 0; i < ns->n_namespaces; ++i) {
- free(ns->namespaces[i].name);
- free(ns->namespaces[i].uri);
+ serd_string_free(ns->namespaces[i].name);
+ serd_string_free(ns->namespaces[i].uri);
}
free(ns->namespaces);
free(ns);
@@ -80,7 +80,7 @@ serd_namespaces_add(SerdNamespaces ns,
assert(uri);
SerdNamespace* const record = serd_namespaces_find(ns, name->buf, name->n_chars);
if (record) {
- free(record->uri);
+ serd_string_free(record->uri);
record->uri = serd_string_copy(uri);
} else {
++ns->n_namespaces;
diff --git a/src/serdi.c b/src/serdi.c
index 548f88e7..13fdb2af 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -60,7 +60,7 @@ event_base(void* handle,
}
// Replace the old base URI
- free(state->base_uri_str);
+ serd_string_free(state->base_uri_str);
state->base_uri_str = base_uri_str;
state->base_uri = base_uri;
@@ -85,7 +85,7 @@ event_prefix(void* handle,
SerdURI new_abs_uri;
SerdString* abs_uri_string = serd_string_new_from_uri(&abs_uri, &new_abs_uri);
serd_namespaces_add(state->ns, name, abs_uri_string);
- free(abs_uri_string);
+ serd_string_free(abs_uri_string);
} else {
serd_namespaces_add(state->ns, name, uri_string);
}
@@ -155,7 +155,7 @@ main(int argc, char** argv)
serd_reader_free(reader);
fclose(in_fd);
serd_namespaces_free(state.ns);
- free(state.base_uri_str);
+ serd_string_free(state.base_uri_str);
if (success) {
return 0;
diff --git a/src/string.c b/src/string.c
index 301a98cc..0f5d2430 100644
--- a/src/string.c
+++ b/src/string.c
@@ -63,3 +63,10 @@ serd_string_copy(const SerdString* s)
}
return NULL;
}
+
+SERD_API
+void
+serd_string_free(SerdString* str)
+{
+ free(str);
+}