aboutsummaryrefslogtreecommitdiffstats
path: root/src/node.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-03-16 16:21:20 -0400
committerDavid Robillard <d@drobilla.net>2018-11-25 09:21:03 +0100
commit5e60861c65b84ef7569a26920a7ff2401c1e14d0 (patch)
tree7db2d30adf9044bd56c245b13dc730d5e4005043 /src/node.c
parentd70d76deeb5735f97bb90792d5200ee812fb50b0 (diff)
downloadserd-5e60861c65b84ef7569a26920a7ff2401c1e14d0.tar.gz
serd-5e60861c65b84ef7569a26920a7ff2401c1e14d0.tar.bz2
serd-5e60861c65b84ef7569a26920a7ff2401c1e14d0.zip
Use char* for strings in public API
The constant casting just makes user code a mess, for no benefit.
Diffstat (limited to 'src/node.c')
-rw-r--r--src/node.c57
1 files changed, 28 insertions, 29 deletions
diff --git a/src/node.c b/src/node.c
index 0ae750eb..ebd6b3ad 100644
--- a/src/node.c
+++ b/src/node.c
@@ -32,7 +32,7 @@
#endif
SerdNode
-serd_node_from_string(SerdType type, const uint8_t* str)
+serd_node_from_string(SerdType type, const char* str)
{
if (!str) {
return SERD_NODE_NULL;
@@ -45,7 +45,7 @@ serd_node_from_string(SerdType type, const uint8_t* str)
}
SerdNode
-serd_node_from_substring(SerdType type, const uint8_t* str, const size_t len)
+serd_node_from_substring(SerdType type, const char* str, const size_t len)
{
if (!str) {
return SERD_NODE_NULL;
@@ -65,7 +65,7 @@ serd_node_copy(const SerdNode* node)
}
SerdNode copy = *node;
- uint8_t* buf = (uint8_t*)malloc(copy.n_bytes + 1);
+ char* buf = (char*)malloc(copy.n_bytes + 1);
memcpy(buf, node->buf, copy.n_bytes + 1);
copy.buf = buf;
return copy;
@@ -102,7 +102,7 @@ serd_uri_string_length(const SerdURI* uri)
static size_t
string_sink(const void* buf, size_t len, void* stream)
{
- uint8_t** ptr = (uint8_t**)stream;
+ char** ptr = (char**)stream;
memcpy(*ptr, buf, len);
*ptr += len;
return len;
@@ -119,7 +119,7 @@ serd_node_new_uri_from_node(const SerdNode* uri_node,
}
SerdNode
-serd_node_new_uri_from_string(const uint8_t* str,
+serd_node_new_uri_from_string(const char* str,
const SerdURI* base,
SerdURI* out)
{
@@ -134,7 +134,7 @@ serd_node_new_uri_from_string(const uint8_t* str,
}
static inline bool
-is_uri_path_char(const uint8_t c)
+is_uri_path_char(const char c)
{
if (is_alpha(c) || is_digit(c)) {
return true;
@@ -153,23 +153,22 @@ is_uri_path_char(const uint8_t c)
}
SerdNode
-serd_node_new_file_uri(const uint8_t* path,
- const uint8_t* hostname,
- SerdURI* out,
- bool escape)
+serd_node_new_file_uri(const char* path,
+ const char* hostname,
+ SerdURI* out,
+ bool escape)
{
- const size_t path_len = strlen((const char*)path);
- const size_t hostname_len = hostname ? strlen((const char*)hostname) : 0;
+ const size_t path_len = strlen(path);
+ const size_t hostname_len = hostname ? strlen(hostname) : 0;
const bool evil = is_windows_path(path);
size_t uri_len = 0;
- uint8_t* uri = NULL;
+ char* uri = NULL;
if (path[0] == '/' || is_windows_path(path)) {
uri_len = strlen("file://") + hostname_len + evil;
- uri = (uint8_t*)malloc(uri_len + 1);
- snprintf((char*)uri, uri_len + 1, "file://%s%s",
- hostname ? (const char*)hostname : "",
- evil ? "/" : "");
+ uri = (char*)malloc(uri_len + 1);
+ snprintf(uri, uri_len + 1, "file://%s%s",
+ hostname ? hostname : "", evil ? "/" : "");
}
SerdBuffer buffer = { uri, uri_len };
@@ -189,11 +188,11 @@ serd_node_new_file_uri(const uint8_t* path,
serd_buffer_sink_finish(&buffer);
if (out) {
- serd_uri_parse((const uint8_t*)buffer.buf, out);
+ serd_uri_parse((const char*)buffer.buf, out);
}
return serd_node_from_substring(
- SERD_URI, (const uint8_t*)buffer.buf, buffer.len);
+ SERD_URI, (const char*)buffer.buf, buffer.len);
}
SerdNode
@@ -205,9 +204,9 @@ serd_node_new_uri(const SerdURI* uri, const SerdURI* base, SerdURI* out)
}
const size_t len = serd_uri_string_length(&abs_uri);
- uint8_t* buf = (uint8_t*)malloc(len + 1);
+ char* buf = (char*)malloc(len + 1);
SerdNode node = { buf, len, 0, SERD_URI };
- uint8_t* ptr = buf;
+ char* ptr = buf;
const size_t actual_len = serd_uri_serialise(&abs_uri, string_sink, &ptr);
buf[actual_len] = '\0';
@@ -226,11 +225,11 @@ serd_node_new_relative_uri(const SerdURI* uri,
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);
+ const size_t uri_len = serd_uri_string_length(uri);
+ const size_t base_len = serd_uri_string_length(base);
+ char* buf = (char*)malloc(uri_len + base_len + 1);
SerdNode node = { buf, 0, 0, SERD_URI };
- uint8_t* ptr = buf;
+ char* ptr = buf;
const size_t actual_len = serd_uri_serialise_relative(
uri, base, root, string_sink, &ptr);
@@ -261,7 +260,7 @@ serd_node_new_decimal(double d, unsigned frac_digits)
const double abs_d = fabs(d);
const unsigned int_digits = serd_digits(abs_d);
char* buf = (char*)calloc(int_digits + frac_digits + 3, 1);
- SerdNode node = { (const uint8_t*)buf, 0, 0, SERD_LITERAL };
+ SerdNode node = { buf, 0, 0, SERD_LITERAL };
const double int_part = floor(abs_d);
// Point s to decimal point location
@@ -311,7 +310,7 @@ serd_node_new_integer(int64_t i)
int64_t abs_i = (i < 0) ? -i : i;
const unsigned digits = serd_digits(abs_i);
char* buf = (char*)calloc(digits + 2, 1);
- SerdNode node = { (const uint8_t*)buf, 0, 0, SERD_LITERAL };
+ SerdNode node = { (const char*)buf, 0, 0, SERD_LITERAL };
// Point s to the end
char* s = buf + digits - 1;
@@ -356,7 +355,7 @@ serd_node_new_blob(const void* buf, size_t size, bool wrap_lines)
{
const size_t len = (size + 2) / 3 * 4 + (wrap_lines * ((size - 1) / 57));
uint8_t* str = (uint8_t*)calloc(len + 2, 1);
- SerdNode node = { str, len, 0, SERD_LITERAL };
+ SerdNode node = { (const char*)str, len, 0, SERD_LITERAL };
for (size_t i = 0, j = 0; i < size; i += 3, j += 4) {
uint8_t in[4] = { 0, 0, 0, 0 };
size_t n_in = MIN(3, size - i);
@@ -376,7 +375,7 @@ void
serd_node_free(SerdNode* node)
{
if (node && node->buf) {
- free((uint8_t*)node->buf);
+ free((char*)node->buf);
node->buf = NULL;
}
}