aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-03-16 16:21:20 -0400
committerDavid Robillard <d@drobilla.net>2018-05-27 18:18:30 +0200
commit8ce3b77e73a6c172dc0954b3f5aa0e37a10850d0 (patch)
tree9d894ecb157e9c977657dc3dd4d9ca06b3c3e9b0
parent88ea0c449a8daa8951eca0ae69fd376f86122982 (diff)
downloadserd-8ce3b77e73a6c172dc0954b3f5aa0e37a10850d0.tar.gz
serd-8ce3b77e73a6c172dc0954b3f5aa0e37a10850d0.tar.bz2
serd-8ce3b77e73a6c172dc0954b3f5aa0e37a10850d0.zip
Use char* for strings in public API
The constant casting just makes user code a mess, for no benefit.
-rw-r--r--NEWS1
-rw-r--r--serd/serd.h90
-rw-r--r--src/byte_source.c8
-rw-r--r--src/env.c16
-rw-r--r--src/n3.c2
-rw-r--r--src/node.c57
-rw-r--r--src/reader.c50
-rw-r--r--src/reader.h2
-rw-r--r--src/serd_internal.h48
-rw-r--r--src/serdi.c26
-rw-r--r--src/string.c38
-rw-r--r--src/uri.c64
-rw-r--r--src/writer.c27
-rw-r--r--tests/serd_test.c123
14 files changed, 275 insertions, 277 deletions
diff --git a/NEWS b/NEWS
index 446387d6..2e94537f 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ serd (1.0.0) unstable;
* Use SerdBuffer for mutable buffers instead of abusing SerdChunk
* Add serd_node_new_relative_uri()
* Fix construction and comparison of URIs with UTF-8 characters
+ * Use char* for strings in public API
* Remove useless character counting
* Report I/O errors with message and return appropriate status code
* Report missing statement separator errors
diff --git a/serd/serd.h b/serd/serd.h
index d289ee72..d3c6cdeb 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -215,7 +215,7 @@ typedef uint32_t SerdNodeFlags;
A syntactic RDF node.
*/
typedef struct {
- const uint8_t* buf; /**< Value string */
+ const char* buf; /**< Value string */
size_t n_bytes; /**< Size in bytes (not including null) */
SerdNodeFlags flags; /**< Node flags (e.g. string properties) */
SerdType type; /**< Node type */
@@ -225,8 +225,8 @@ typedef struct {
An unterminated string fragment.
*/
typedef struct {
- const uint8_t* buf; /**< Start of chunk */
- size_t len; /**< Length of chunk in bytes */
+ const char* buf; /**< Start of chunk */
+ size_t len; /**< Length of chunk in bytes */
} SerdChunk;
/**
@@ -241,12 +241,12 @@ typedef struct {
An error description.
*/
typedef struct {
- SerdStatus status; /**< Error code */
- const uint8_t* filename; /**< File where error was encountered, or NULL */
- unsigned line; /**< Line where error was encountered, or 0 */
- unsigned col; /**< Column where error was encountered */
- const char* fmt; /**< Message format string (printf style) */
- va_list* args; /**< Arguments for fmt */
+ SerdStatus status; /**< Error code */
+ const char* filename; /**< File where error was encountered, or NULL */
+ unsigned line; /**< Line where error was encountered, or 0 */
+ unsigned col; /**< Column where error was encountered */
+ const char* fmt; /**< Message format string (printf style) */
+ va_list* args; /**< Arguments for fmt */
} SerdError;
/**
@@ -290,7 +290,7 @@ typedef enum {
Return a string describing a status code.
*/
SERD_API
-const uint8_t*
+const char*
serd_strerror(SerdStatus status);
/**
@@ -301,7 +301,7 @@ serd_strerror(SerdStatus status);
*/
SERD_API
size_t
-serd_strlen(const uint8_t* str, SerdNodeFlags* flags);
+serd_strlen(const char* str, SerdNodeFlags* flags);
/**
Parse a string to a double.
@@ -326,7 +326,7 @@ serd_strtod(const char* str, char** endptr);
*/
SERD_API
void*
-serd_base64_decode(const uint8_t* str, size_t len, size_t* size);
+serd_base64_decode(const char* str, size_t len, size_t* size);
/**
@}
@@ -346,8 +346,8 @@ static const SerdURI SERD_URI_NULL = {
a path, use serd_file_uri_parse().
*/
SERD_API
-const uint8_t*
-serd_uri_to_path(const uint8_t* uri);
+const char*
+serd_uri_to_path(const char* uri);
/**
Get the unescaped path and hostname from a file URI.
@@ -358,22 +358,22 @@ serd_uri_to_path(const uint8_t* uri);
The returned path and `*hostname` must be freed with free().
*/
SERD_API
-uint8_t*
-serd_file_uri_parse(const uint8_t* uri, uint8_t** hostname);
+char*
+serd_file_uri_parse(const char* uri, char** hostname);
/**
Return true iff `utf8` starts with a valid URI scheme.
*/
SERD_API
bool
-serd_uri_string_has_scheme(const uint8_t* utf8);
+serd_uri_string_has_scheme(const char* utf8);
/**
Parse `utf8`, writing result to `out`.
*/
SERD_API
SerdStatus
-serd_uri_parse(const uint8_t* utf8, SerdURI* out);
+serd_uri_parse(const char* utf8, SerdURI* out);
/**
Set target `t` to reference `r` resolved against `base`.
@@ -452,7 +452,7 @@ static const SerdNode SERD_NODE_NULL = { NULL, 0, 0, SERD_NOTHING };
*/
SERD_API
SerdNode
-serd_node_from_string(SerdType type, const uint8_t* str);
+serd_node_from_string(SerdType type, const char* str);
/**
Make a (shallow) node from a prefix of `str`.
@@ -462,7 +462,7 @@ serd_node_from_string(SerdType type, const uint8_t* str);
*/
SERD_API
SerdNode
-serd_node_from_substring(SerdType type, const uint8_t* str, size_t len);
+serd_node_from_substring(SerdType type, const char* str, size_t len);
/**
Make a deep copy of `node`.
@@ -494,7 +494,7 @@ serd_node_new_uri_from_node(const SerdNode* uri_node,
*/
SERD_API
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);
@@ -510,10 +510,10 @@ serd_node_new_uri_from_string(const uint8_t* str,
*/
SERD_API
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);
/**
Create a new node by serialising `uri` into a new string.
@@ -703,9 +703,9 @@ serd_env_set_prefix(SerdEnv* env,
*/
SERD_API
SerdStatus
-serd_env_set_prefix_from_strings(SerdEnv* env,
- const uint8_t* name,
- const uint8_t* uri);
+serd_env_set_prefix_from_strings(SerdEnv* env,
+ const char* name,
+ const char* uri);
/**
Qualify `uri` into a CURIE if possible.
@@ -809,8 +809,8 @@ serd_reader_get_handle(const SerdReader* reader);
*/
SERD_API
void
-serd_reader_add_blank_prefix(SerdReader* reader,
- const uint8_t* prefix);
+serd_reader_add_blank_prefix(SerdReader* reader,
+ const char* prefix);
/**
Set the URI of the default graph.
@@ -829,8 +829,8 @@ serd_reader_set_default_graph(SerdReader* reader,
*/
SERD_API
SerdStatus
-serd_reader_read_file(SerdReader* reader,
- const uint8_t* uri);
+serd_reader_read_file(SerdReader* reader,
+ const char* uri);
/**
Start an incremental read from a file handle.
@@ -842,10 +842,10 @@ serd_reader_read_file(SerdReader* reader,
*/
SERD_API
SerdStatus
-serd_reader_start_stream(SerdReader* reader,
- FILE* file,
- const uint8_t* name,
- bool bulk);
+serd_reader_start_stream(SerdReader* reader,
+ FILE* file,
+ const char* name,
+ bool bulk);
/**
Start an incremental read from a user-specified source.
@@ -859,7 +859,7 @@ serd_reader_start_source_stream(SerdReader* reader,
SerdSource read_func,
SerdStreamErrorFunc error_func,
void* stream,
- const uint8_t* name,
+ const char* name,
size_t page_size);
/**
@@ -886,9 +886,9 @@ serd_reader_end_stream(SerdReader* reader);
*/
SERD_API
SerdStatus
-serd_reader_read_file_handle(SerdReader* reader,
- FILE* file,
- const uint8_t* name);
+serd_reader_read_file_handle(SerdReader* reader,
+ FILE* file,
+ const char* name);
/**
Read a user-specified byte source.
@@ -899,7 +899,7 @@ serd_reader_read_source(SerdReader* reader,
SerdSource source,
SerdStreamErrorFunc error,
void* stream,
- const uint8_t* name,
+ const char* name,
size_t page_size);
/**
@@ -907,7 +907,7 @@ serd_reader_read_source(SerdReader* reader,
*/
SERD_API
SerdStatus
-serd_reader_read_string(SerdReader* reader, const uint8_t* utf8);
+serd_reader_read_string(SerdReader* reader, const char* utf8);
/**
Free `reader`.
@@ -977,7 +977,7 @@ serd_buffer_sink(const void* buf, size_t len, void* stream);
terminated (by this function) and owned by the caller.
*/
SERD_API
-uint8_t*
+char*
serd_buffer_sink_finish(SerdBuffer* stream);
/**
@@ -997,8 +997,8 @@ serd_writer_set_error_sink(SerdWriter* writer,
*/
SERD_API
void
-serd_writer_chop_blank_prefix(SerdWriter* writer,
- const uint8_t* prefix);
+serd_writer_chop_blank_prefix(SerdWriter* writer,
+ const char* prefix);
/**
Set the current output base URI (and emit directive if applicable).
diff --git a/src/byte_source.c b/src/byte_source.c
index e2bcf196..74ce14a4 100644
--- a/src/byte_source.c
+++ b/src/byte_source.c
@@ -38,7 +38,7 @@ serd_byte_source_open_source(SerdByteSource* source,
SerdSource read_func,
SerdStreamErrorFunc error_func,
void* stream,
- const uint8_t* name,
+ const char* name,
size_t page_size)
{
const Cursor cur = { name, 1, 1 };
@@ -52,7 +52,7 @@ serd_byte_source_open_source(SerdByteSource* source,
source->read_func = read_func;
if (page_size > 1) {
- source->file_buf = (uint8_t*)serd_bufalloc(page_size);
+ source->file_buf = (char*)serd_bufalloc(page_size);
source->read_buf = source->file_buf;
memset(source->file_buf, '\0', page_size);
} else {
@@ -78,9 +78,9 @@ serd_byte_source_prepare(SerdByteSource* source)
}
SerdStatus
-serd_byte_source_open_string(SerdByteSource* source, const uint8_t* utf8)
+serd_byte_source_open_string(SerdByteSource* source, const char* utf8)
{
- const Cursor cur = { (const uint8_t*)"(string)", 1, 1 };
+ const Cursor cur = { "(string)", 1, 1 };
memset(source, '\0', sizeof(*source));
source->cur = cur;
diff --git a/src/env.c b/src/env.c
index cf1c3538..7831daf7 100644
--- a/src/env.c
+++ b/src/env.c
@@ -92,7 +92,7 @@ serd_env_set_base_uri(SerdEnv* env,
static inline SerdPrefix*
serd_env_find(const SerdEnv* env,
- const uint8_t* name,
+ const char* name,
size_t name_len)
{
for (size_t i = 0; i < env->n_prefixes; ++i) {
@@ -150,9 +150,9 @@ serd_env_set_prefix(SerdEnv* env,
SERD_API
SerdStatus
-serd_env_set_prefix_from_strings(SerdEnv* env,
- const uint8_t* name,
- const uint8_t* uri)
+serd_env_set_prefix_from_strings(SerdEnv* env,
+ const char* name,
+ const char* uri)
{
const SerdNode name_node = serd_node_from_string(SERD_LITERAL, name);
const SerdNode uri_node = serd_node_from_string(SERD_URI, uri);
@@ -161,7 +161,7 @@ serd_env_set_prefix_from_strings(SerdEnv* env,
}
static inline bool
-is_nameChar(const uint8_t c)
+is_nameChar(const char c)
{
return is_alpha(c) || is_digit(c) || c == '_';
}
@@ -171,7 +171,7 @@ is_nameChar(const uint8_t c)
TODO: This is more strict than it should be.
*/
static inline bool
-is_name(const uint8_t* buf, size_t len)
+is_name(const char* buf, size_t len)
{
for (size_t i = 0; i < len; ++i) {
if (!is_nameChar(buf[i])) {
@@ -213,7 +213,7 @@ serd_env_expand(const SerdEnv* env,
SerdChunk* uri_prefix,
SerdChunk* uri_suffix)
{
- const uint8_t* const colon = (const uint8_t*)memchr(
+ const char* const colon = (const char*)memchr(
curie->buf, ':', curie->n_bytes + 1);
if (curie->type != SERD_CURIE || !colon) {
return SERD_ERR_BAD_ARG;
@@ -244,7 +244,7 @@ serd_env_expand_node(const SerdEnv* env,
return SERD_NODE_NULL;
}
const size_t len = prefix.len + suffix.len;
- uint8_t* buf = (uint8_t*)malloc(len + 1);
+ char* buf = (char*)malloc(len + 1);
SerdNode ret = { buf, len, 0, SERD_URI };
snprintf((char*)buf, ret.n_bytes + 1, "%s%s", prefix.buf, suffix.buf);
return ret;
diff --git a/src/n3.c b/src/n3.c
index bb8d4d9d..51b06d91 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -847,7 +847,7 @@ read_BLANK_NODE_LABEL(SerdReader* reader, bool* ate_dot)
eat_byte_safe(reader, '_');
eat_byte_check(reader, ':');
Ref ref = push_node(reader, SERD_BLANK,
- reader->bprefix ? (char*)reader->bprefix : "",
+ reader->bprefix ? reader->bprefix : "",
reader->bprefix_len);
uint8_t c = peek_byte(reader); // First: (PN_CHARS | '_' | [0-9])
diff --git a/src/node.c b/src/node.c
index 1ea6bd5b..7a520886 100644
--- a/src/node.c
+++ b/src/node.c
@@ -33,7 +33,7 @@
SERD_API
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;
@@ -47,7 +47,7 @@ serd_node_from_string(SerdType type, const uint8_t* str)
SERD_API
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;
@@ -68,7 +68,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;
@@ -106,7 +106,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;
@@ -125,7 +125,7 @@ serd_node_new_uri_from_node(const SerdNode* uri_node,
SERD_API
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)
{
@@ -140,7 +140,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;
@@ -160,23 +160,22 @@ is_uri_path_char(const uint8_t c)
SERD_API
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 };
@@ -196,11 +195,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);
}
SERD_API
@@ -213,9 +212,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';
@@ -235,11 +234,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);
@@ -271,7 +270,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
@@ -322,7 +321,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;
@@ -368,7 +367,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 / 57) : 0);
uint8_t* str = (uint8_t*)calloc(1, len + 2);
- 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);
@@ -389,7 +388,7 @@ void
serd_node_free(SerdNode* node)
{
if (node && node->buf) {
- free((uint8_t*)node->buf);
+ free((char*)node->buf);
node->buf = NULL;
}
}
diff --git a/src/reader.c b/src/reader.c
index 4266e128..142622e4 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -76,7 +76,7 @@ Ref
push_node_padded(SerdReader* reader, size_t maxlen,
SerdType type, const char* str, size_t n_bytes)
{
- void* mem = serd_stack_push_aligned(
+ char* mem = (char*)serd_stack_push_aligned(
&reader->stack, sizeof(SerdNode) + maxlen + 1, sizeof(SerdNode));
SerdNode* const node = (SerdNode*)mem;
@@ -85,15 +85,15 @@ push_node_padded(SerdReader* reader, size_t maxlen,
node->type = type;
node->buf = NULL;
- uint8_t* buf = (uint8_t*)(node + 1);
+ char* buf = (char*)(node + 1);
memcpy(buf, str, n_bytes + 1);
#ifdef SERD_STACK_CHECK
reader->allocs = realloc(
reader->allocs, sizeof(reader->allocs) * (++reader->n_allocs));
- reader->allocs[reader->n_allocs - 1] = ((uint8_t*)mem - reader->stack.buf);
+ reader->allocs[reader->n_allocs - 1] = (mem - reader->stack.buf);
#endif
- return (uint8_t*)node - reader->stack.buf;
+ return (char*)node - reader->stack.buf;
}
Ref
@@ -107,7 +107,7 @@ deref(SerdReader* reader, const Ref ref)
{
if (ref) {
SerdNode* node = (SerdNode*)(reader->stack.buf + ref);
- node->buf = (uint8_t*)node + sizeof(SerdNode);
+ node->buf = (char*)node + sizeof(SerdNode);
return node;
}
return NULL;
@@ -123,8 +123,8 @@ pop_node(SerdReader* reader, Ref ref)
--reader->n_allocs;
#endif
SerdNode* const node = deref(reader, ref);
- uint8_t* const top = reader->stack.buf + reader->stack.size;
- serd_stack_pop_aligned(&reader->stack, top - (uint8_t*)node);
+ char* const top = reader->stack.buf + reader->stack.size;
+ serd_stack_pop_aligned(&reader->stack, top - (char*)node);
}
return 0;
}
@@ -238,15 +238,15 @@ serd_reader_get_handle(const SerdReader* reader)
SERD_API
void
-serd_reader_add_blank_prefix(SerdReader* reader,
- const uint8_t* prefix)
+serd_reader_add_blank_prefix(SerdReader* reader,
+ const char* prefix)
{
free(reader->bprefix);
reader->bprefix_len = 0;
reader->bprefix = NULL;
if (prefix) {
- reader->bprefix_len = strlen((const char*)prefix);
- reader->bprefix = (uint8_t*)malloc(reader->bprefix_len + 1);
+ reader->bprefix_len = strlen(prefix);
+ reader->bprefix = (char*)malloc(reader->bprefix_len + 1);
memcpy(reader->bprefix, prefix, reader->bprefix_len + 1);
}
}
@@ -262,15 +262,15 @@ serd_reader_set_default_graph(SerdReader* reader,
SERD_API
SerdStatus
-serd_reader_read_file(SerdReader* reader,
- const uint8_t* uri)
+serd_reader_read_file(SerdReader* reader,
+ const char* uri)
{
- uint8_t* const path = serd_file_uri_parse(uri, NULL);
+ char* const path = serd_file_uri_parse(uri, NULL);
if (!path) {
return SERD_ERR_BAD_ARG;
}
- FILE* fd = serd_fopen((const char*)path, "rb");
+ FILE* fd = serd_fopen(path, "rb");
if (!fd) {
free(path);
return SERD_ERR_UNKNOWN;
@@ -301,10 +301,10 @@ skip_bom(SerdReader* me)
SERD_API
SerdStatus
-serd_reader_start_stream(SerdReader* reader,
- FILE* file,
- const uint8_t* name,
- bool bulk)
+serd_reader_start_stream(SerdReader* reader,
+ FILE* file,
+ const char* name,
+ bool bulk)
{
return serd_reader_start_source_stream(
reader,
@@ -321,7 +321,7 @@ serd_reader_start_source_stream(SerdReader* reader,
SerdSource read_func,
SerdStreamErrorFunc error_func,
void* stream,
- const uint8_t* name,
+ const char* name,
size_t page_size)
{
return serd_byte_source_open_source(
@@ -369,9 +369,9 @@ serd_reader_end_stream(SerdReader* reader)
SERD_API
SerdStatus
-serd_reader_read_file_handle(SerdReader* reader,
- FILE* file,
- const uint8_t* name)
+serd_reader_read_file_handle(SerdReader* reader,
+ FILE* file,
+ const char* name)
{
return serd_reader_read_source(
reader, (SerdSource)fread, (SerdStreamErrorFunc)ferror,
@@ -384,7 +384,7 @@ serd_reader_read_source(SerdReader* reader,
SerdSource source,
SerdStreamErrorFunc error,
void* stream,
- const uint8_t* name,
+ const char* name,
size_t page_size)
{
SerdStatus st = serd_reader_start_source_stream(
@@ -403,7 +403,7 @@ serd_reader_read_source(SerdReader* reader,
SERD_API
SerdStatus
-serd_reader_read_string(SerdReader* reader, const uint8_t* utf8)
+serd_reader_read_string(SerdReader* reader, const char* utf8)
{
serd_byte_source_open_string(&reader->source, utf8);
diff --git a/src/reader.h b/src/reader.h
index 7dc981af..18b587c8 100644
--- a/src/reader.h
+++ b/src/reader.h
@@ -66,7 +66,7 @@ static inline SerdStatus
push_byte(SerdReader* reader, Ref ref, const uint8_t c)
{
SERD_STACK_ASSERT_TOP(reader, ref);
- uint8_t* const s = serd_stack_push(&reader->stack, 1);
+ char* const s = serd_stack_push(&reader->stack, 1);
SerdNode* const node = (SerdNode*)(reader->stack.buf + ref);
++node->n_bytes;
*(s - 1) = c;
diff --git a/src/serd_internal.h b/src/serd_internal.h
index 46b88c83..d678627f 100644
--- a/src/serd_internal.h
+++ b/src/serd_internal.h
@@ -76,9 +76,9 @@ serd_bufalloc(size_t size)
/* Byte source */
typedef struct {
- const uint8_t* filename;
- unsigned line;
- unsigned col;
+ const char* filename;
+ unsigned line;
+ unsigned col;
} Cursor;
typedef struct {
@@ -87,10 +87,10 @@ typedef struct {
void* stream; ///< Stream (e.g. FILE)
size_t page_size; ///< Number of bytes to read at a time
Cursor cur; ///< Cursor for error reporting
- uint8_t* file_buf; ///< Buffer iff reading pages from a file
- const uint8_t* read_buf; ///< Pointer to file_buf or read_byte
+ char* file_buf; ///< Buffer iff reading pages from a file
+ const char* read_buf; ///< Pointer to file_buf or read_byte
size_t read_head; ///< Offset into read_buf
- uint8_t read_byte; ///< 1-byte 'buffer' used when not paging
+ char read_byte; ///< 1-byte 'buffer' used when not paging
bool from_stream; ///< True iff reading from `stream`
bool prepared; ///< True iff prepared for reading
bool eof; ///< True iff end of file reached
@@ -102,14 +102,14 @@ serd_byte_source_open_file(SerdByteSource* source,
bool bulk);
SerdStatus
-serd_byte_source_open_string(SerdByteSource* source, const uint8_t* utf8);
+serd_byte_source_open_string(SerdByteSource* source, const char* utf8);
SerdStatus
serd_byte_source_open_source(SerdByteSource* source,
SerdSource read_func,
SerdStreamErrorFunc error_func,
void* stream,
- const uint8_t* name,
+ const char* name,
size_t page_size);
SerdStatus
@@ -132,7 +132,7 @@ serd_byte_source_advance(SerdByteSource* source);
/** A dynamic stack in memory. */
typedef struct {
- uint8_t* buf; ///< Stack memory
+ char* buf; ///< Stack memory
size_t buf_size; ///< Allocated size of buf (>= size)
size_t size; ///< Conceptual size of stack in buf
} SerdStack;
@@ -144,7 +144,7 @@ static inline SerdStack
serd_stack_new(size_t size)
{
SerdStack stack;
- stack.buf = (uint8_t*)malloc(size);
+ stack.buf = (char*)malloc(size);
stack.buf_size = size;
stack.size = SERD_STACK_BOTTOM;
return stack;
@@ -165,15 +165,15 @@ serd_stack_free(SerdStack* stack)
stack->size = 0;
}
-static inline uint8_t*
+static inline char*
serd_stack_push(SerdStack* stack, size_t n_bytes)
{
const size_t new_size = stack->size + n_bytes;
if (stack->buf_size < new_size) {
stack->buf_size += (stack->buf_size >> 1); // *= 1.5
- stack->buf = (uint8_t*)realloc(stack->buf, stack->buf_size);
+ stack->buf = (char*)realloc(stack->buf, stack->buf_size);
}
- uint8_t* const ret = (stack->buf + stack->size);
+ char* const ret = (stack->buf + stack->size);
stack->size = new_size;
return ret;
}
@@ -222,7 +222,7 @@ serd_stack_pop_aligned(SerdStack* stack, size_t n_bytes)
typedef struct SerdByteSinkImpl {
SerdSink sink;
void* stream;
- uint8_t* buf;
+ char* buf;
size_t size;
size_t block_size;
} SerdByteSink;
@@ -236,7 +236,7 @@ serd_byte_sink_new(SerdSink sink, void* stream, size_t block_size)
bsink.size = 0;
bsink.block_size = block_size;
bsink.buf = ((block_size > 1)
- ? (uint8_t*)serd_bufalloc(block_size)
+ ? (char*)serd_bufalloc(block_size)
: NULL);
return bsink;
}
@@ -275,7 +275,7 @@ serd_byte_sink_write(const void* buf, size_t len, SerdByteSink* bsink)
// Write as much as possible into the remaining buffer space
memcpy(bsink->buf + bsink->size, buf, n);
bsink->size += n;
- buf = (const uint8_t*)buf + n;
+ buf = (const char*)buf + n;
len -= n;
// Flush page if buffer is full
@@ -291,21 +291,21 @@ serd_byte_sink_write(const void* buf, size_t len, SerdByteSink* bsink)
/** Return true if `c` lies within [`min`...`max`] (inclusive) */
static inline bool
-in_range(const uint8_t c, const uint8_t min, const uint8_t max)
+in_range(const char c, const char min, const char max)
{
return (c >= min && c <= max);
}
/** RFC2234: ALPHA ::= %x41-5A / %x61-7A ; A-Z / a-z */
static inline bool
-is_alpha(const uint8_t c)
+is_alpha(const char c)
{
return in_range(c, 'A', 'Z') || in_range(c, 'a', 'z');
}
/** RFC2234: DIGIT ::= %x30-39 ; 0-9 */
static inline bool
-is_digit(const uint8_t c)
+is_digit(const char c)
{
return in_range(c, '0', '9');
}
@@ -336,13 +336,13 @@ is_space(const char c)
}
static inline bool
-is_base64(const uint8_t c)
+is_base64(const char c)
{
return is_alpha(c) || is_digit(c) || c == '+' || c == '/' || c == '=';
}
static inline bool
-is_windows_path(const uint8_t* path)
+is_windows_path(const char* path)
{
return is_alpha(path[0]) && (path[1] == ':' || path[1] == '|')
&& (path[2] == '/' || path[2] == '\\');
@@ -351,7 +351,7 @@ is_windows_path(const uint8_t* path)
/* String utilities */
size_t
-serd_substrlen(const uint8_t* str,
+serd_substrlen(const char* str,
const size_t len,
SerdNodeFlags* flags);
@@ -420,7 +420,7 @@ uri_path_len(const SerdURI* uri)
return uri->path_base.len + uri->path.len;
}
-static inline uint8_t
+static inline char
uri_path_at(const SerdURI* uri, size_t i)
{
if (i < uri->path_base.len) {
@@ -525,7 +525,7 @@ struct SerdReaderImpl {
unsigned next_id;
SerdStatus status;
uint8_t* buf;
- uint8_t* bprefix;
+ char* bprefix;
size_t bprefix_len;
bool strict; ///< True iff strict parsing
bool seen_genid;
diff --git a/src/serdi.c b/src/serdi.c
index 16767ffd..419d3d06 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -130,14 +130,14 @@ main(int argc, char** argv)
bool full_uris = false;
bool lax = false;
bool quiet = false;
- const uint8_t* in_name = NULL;
- const uint8_t* add_prefix = NULL;
- const uint8_t* chop_prefix = NULL;
- const uint8_t* root_uri = NULL;
+ const char* in_name = NULL;
+ const char* add_prefix = NULL;
+ const char* chop_prefix = NULL;
+ const char* root_uri = NULL;
int a = 1;
for (; a < argc && argv[a][0] == '-'; ++a) {
if (argv[a][1] == '\0') {
- in_name = (const uint8_t*)"(stdin)";
+ in_name = (const char*)"(stdin)";
in_fd = stdin;
break;
} else if (argv[a][1] == 'a') {
@@ -157,7 +157,7 @@ main(int argc, char** argv)
} else if (argv[a][1] == 'v') {
return print_version();
} else if (argv[a][1] == 's') {
- in_name = (const uint8_t*)"(string)";
+ in_name = (const char*)"(string)";
from_file = false;
++a;
break;
@@ -177,17 +177,17 @@ main(int argc, char** argv)
if (++a == argc) {
return missing_arg(argv[0], 'p');
}
- add_prefix = (const uint8_t*)argv[a];
+ add_prefix = (const char*)argv[a];
} else if (argv[a][1] == 'c') {
if (++a == argc) {
return missing_arg(argv[0], 'c');
}
- chop_prefix = (const uint8_t*)argv[a];
+ chop_prefix = (const char*)argv[a];
} else if (argv[a][1] == 'r') {
if (++a == argc) {
return missing_arg(argv[0], 'r');
}
- root_uri = (const uint8_t*)argv[a];
+ root_uri = (const char*)argv[a];
} else {
SERDI_ERRORF("invalid option -- '%s'\n", argv[a] + 1);
return print_usage(argv[0], true);
@@ -199,18 +199,18 @@ main(int argc, char** argv)
return 1;
}
- const uint8_t* input = (const uint8_t*)argv[a++];
+ const char* input = (const char*)argv[a++];
if (from_file) {
in_name = in_name ? in_name : input;
if (!in_fd) {
input = serd_uri_to_path(in_name);
- if (!input || !(in_fd = serd_fopen((const char*)input, "rb"))) {
+ if (!input || !(in_fd = serd_fopen(input, "rb"))) {
return 1;
}
}
}
- if (!input_syntax && !(input_syntax = guess_syntax((const char*)in_name))) {
+ if (!input_syntax && !(input_syntax = guess_syntax(in_name))) {
input_syntax = SERD_TRIG;
}
@@ -225,7 +225,7 @@ main(int argc, char** argv)
SerdNode base = SERD_NODE_NULL;
if (a < argc) { // Base URI given on command line
base = serd_node_new_uri_from_string(
- (const uint8_t*)argv[a], NULL, &base_uri);
+ (const char*)argv[a], NULL, &base_uri);
} else if (from_file && in_fd != stdin) { // Use input file URI
base = serd_node_new_file_uri(input, NULL, &base_uri, true);
}
diff --git a/src/string.c b/src/string.c
index ee2ac290..81c6ae07 100644
--- a/src/string.c
+++ b/src/string.c
@@ -19,21 +19,21 @@
#include <math.h>
SERD_API
-const uint8_t*
+const char*
serd_strerror(SerdStatus status)
{
switch (status) {
- case SERD_SUCCESS: return (const uint8_t*)"Success";
- case SERD_FAILURE: return (const uint8_t*)"Non-fatal failure";
- case SERD_ERR_UNKNOWN: return (const uint8_t*)"Unknown error";
- case SERD_ERR_BAD_SYNTAX: return (const uint8_t*)"Invalid syntax";
- case SERD_ERR_BAD_ARG: return (const uint8_t*)"Invalid argument";
- case SERD_ERR_NOT_FOUND: return (const uint8_t*)"Not found";
- case SERD_ERR_ID_CLASH: return (const uint8_t*)"Blank node ID clash";
- case SERD_ERR_BAD_CURIE: return (const uint8_t*)"Invalid CURIE";
- case SERD_ERR_INTERNAL: return (const uint8_t*)"Internal error";
+ case SERD_SUCCESS: return "Success";
+ case SERD_FAILURE: return "Non-fatal failure";
+ case SERD_ERR_UNKNOWN: return "Unknown error";
+ case SERD_ERR_BAD_SYNTAX: return "Invalid syntax";
+ case SERD_ERR_BAD_ARG: return "Invalid argument";
+ case SERD_ERR_NOT_FOUND: return "Not found";
+ case SERD_ERR_ID_CLASH: return "Blank node ID clash";
+ case SERD_ERR_BAD_CURIE: return "Invalid CURIE";
+ case SERD_ERR_INTERNAL: return "Internal error";
}
- return (const uint8_t*)"Unknown error"; // never reached
+ return "Unknown error"; // never reached
}
static inline void
@@ -49,7 +49,7 @@ serd_update_flags(const uint8_t c, SerdNodeFlags* const flags)
}
size_t
-serd_substrlen(const uint8_t* const str,
+serd_substrlen(const char* const str,
const size_t len,
SerdNodeFlags* const flags)
{
@@ -61,12 +61,12 @@ serd_substrlen(const uint8_t* const str,
}
return i;
}
- return strlen((const char*)str);
+ return strlen(str);
}
SERD_API
size_t
-serd_strlen(const uint8_t* str, SerdNodeFlags* flags)
+serd_strlen(const char* str, SerdNodeFlags* flags)
{
if (flags) {
size_t i = 0;
@@ -76,7 +76,7 @@ serd_strlen(const uint8_t* str, SerdNodeFlags* flags)
}
return i;
}
- return strlen((const char*)str);
+ return strlen(str);
}
static inline double
@@ -163,16 +163,18 @@ decode_chunk(const uint8_t in[4], uint8_t out[3])
SERD_API
void*
-serd_base64_decode(const uint8_t* str, size_t len, size_t* size)
+serd_base64_decode(const char* str, size_t len, size_t* size)
{
+ const uint8_t* ustr = (const uint8_t*)str;
+
void* buf = malloc((len * 3) / 4 + 2);
*size = 0;
for (size_t i = 0, j = 0; i < len; j += 3) {
uint8_t in[] = "====";
size_t n_in = 0;
for (; i < len && n_in < 4; ++n_in) {
- for (; i < len && !is_base64(str[i]); ++i) {} // Skip junk
- in[n_in] = str[i++];
+ for (; i < len && !is_base64(ustr[i]); ++i) {} // Skip junk
+ in[n_in] = ustr[i++];
}
if (n_in > 1) {
*size += decode_chunk(in, (uint8_t*)buf + j);
diff --git a/src/uri.c b/src/uri.c
index b13a1e6f..46a55675 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -22,17 +22,17 @@
// #define URI_DEBUG 1
SERD_API
-const uint8_t*
-serd_uri_to_path(const uint8_t* uri)
+const char*
+serd_uri_to_path(const char* uri)
{
- const uint8_t* path = uri;
+ const char* path = uri;
if (!is_windows_path(uri) && serd_uri_string_has_scheme(uri)) {
- if (strncmp((const char*)uri, "file:", 5)) {
+ if (strncmp(uri, "file:", 5)) {
fprintf(stderr, "Non-file URI `%s'\n", uri);
return NULL;
- } else if (!strncmp((const char*)uri, "file://localhost/", 17)) {
+ } else if (!strncmp(uri, "file://localhost/", 17)) {
path = uri + 16;
- } else if (!strncmp((const char*)uri, "file://", 7)) {
+ } else if (!strncmp(uri, "file://", 7)) {
path = uri + 7;
} else {
fprintf(stderr, "Invalid file URI `%s'\n", uri);
@@ -46,23 +46,23 @@ serd_uri_to_path(const uint8_t* uri)
}
SERD_API
-uint8_t*
-serd_file_uri_parse(const uint8_t* uri, uint8_t** hostname)
+char*
+serd_file_uri_parse(const char* uri, char** hostname)
{
- const uint8_t* path = uri;
+ const char* path = uri;
if (hostname) {
*hostname = NULL;
}
- if (!strncmp((const char*)uri, "file://", 7)) {
- const uint8_t* auth = uri + 7;
+ if (!strncmp(uri, "file://", 7)) {
+ const char* auth = uri + 7;
if (*auth == '/') { // No hostname
path = auth;
} else { // Has hostname
- if (!(path = (const uint8_t*)strchr((const char*)auth, '/'))) {
+ if (!(path = strchr(auth, '/'))) {
return NULL;
}
if (hostname) {
- *hostname = (uint8_t*)calloc(1, path - auth + 1);
+ *hostname = (char*)calloc(1, path - auth + 1);
memcpy(*hostname, auth, path - auth);
}
}
@@ -73,16 +73,16 @@ serd_file_uri_parse(const uint8_t* uri, uint8_t** hostname)
}
SerdBuffer buffer = { NULL, 0 };
- for (const uint8_t* s = path; *s; ++s) {
+ for (const char* s = path; *s; ++s) {
if (*s == '%') {
if (*(s + 1) == '%') {
serd_buffer_sink("%", 1, &buffer);
++s;
} else if (is_hexdig(*(s + 1)) && is_hexdig(*(s + 2))) {
- const uint8_t code[3] = { *(s + 1), *(s + 2), 0 };
+ const char code[3] = { *(s + 1), *(s + 2), 0 };
uint32_t num;
sscanf((const char*)code, "%X", &num);
- const uint8_t c = num;
+ const char c = num;
serd_buffer_sink(&c, 1, &buffer);
s += 2;
} else {
@@ -97,14 +97,14 @@ serd_file_uri_parse(const uint8_t* uri, uint8_t** hostname)
SERD_API
bool
-serd_uri_string_has_scheme(const uint8_t* utf8)
+serd_uri_string_has_scheme(const char* utf8)
{
// RFC3986: scheme ::= ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
if (!utf8 || !is_alpha(utf8[0])) {
return false; // Invalid scheme initial character, URI is relative
}
- for (uint8_t c; (c = *++utf8) != '\0';) {
+ for (char c; (c = *++utf8) != '\0';) {
if (!is_uri_scheme_char(c)) {
return false;
} else if (c == ':') {
@@ -137,11 +137,11 @@ serd_uri_dump(const SerdURI* uri, FILE* file)
SERD_API
SerdStatus
-serd_uri_parse(const uint8_t* utf8, SerdURI* out)
+serd_uri_parse(const char* utf8, SerdURI* out)
{
*out = SERD_URI_NULL;
- const uint8_t* ptr = utf8;
+ const char* ptr = utf8;
/* See http://tools.ietf.org/html/rfc3986#section-3
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
@@ -149,7 +149,7 @@ serd_uri_parse(const uint8_t* utf8, SerdURI* out)
/* S3.1: scheme ::= ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) */
if (is_alpha(*ptr)) {
- for (uint8_t c = *++ptr; true; c = *++ptr) {
+ for (char c = *++ptr; true; c = *++ptr) {
switch (c) {
case '\0': case '/': case '?': case '#':
ptr = utf8;
@@ -176,7 +176,7 @@ maybe_authority:
if (*ptr == '/' && *(ptr + 1) == '/') {
ptr += 2;
out->authority.buf = ptr;
- for (uint8_t c; (c = *ptr) != '\0'; ++ptr) {
+ for (char c; (c = *ptr) != '\0'; ++ptr) {
switch (c) {
case '/': goto path;
case '?': goto query;
@@ -199,7 +199,7 @@ path:
}
out->path.buf = ptr;
out->path.len = 0;
- for (uint8_t c; (c = *ptr) != '\0'; ++ptr) {
+ for (char c; (c = *ptr) != '\0'; ++ptr) {
switch (c) {
case '?': goto query;
case '#': goto fragment;
@@ -215,7 +215,7 @@ path:
query:
if (*ptr == '?') {
out->query.buf = ++ptr;
- for (uint8_t c; (c = *ptr) != '\0'; ++ptr) {
+ for (char c; (c = *ptr) != '\0'; ++ptr) {
switch (c) {
case '#':
goto fragment;
@@ -253,11 +253,11 @@ end:
@param up Set to the number of up-references (e.g. "../") trimmed
@return A pointer to the new start of `path`
*/
-static const uint8_t*
-remove_dot_segments(const uint8_t* path, size_t len, size_t* up)
+static const char*
+remove_dot_segments(const char* path, size_t len, size_t* up)
{
- const uint8_t* begin = path;
- const uint8_t* const end = path + len;
+ const char* begin = path;
+ const char* const end = path + len;
*up = 0;
while (begin < end) {
@@ -317,13 +317,13 @@ remove_dot_segments(const uint8_t* path, size_t len, size_t* up)
static void
merge(SerdChunk* base, SerdChunk* path)
{
- size_t up;
- const uint8_t* begin = remove_dot_segments(path->buf, path->len, &up);
- const uint8_t* end = path->buf + path->len;
+ size_t up;
+ const char* begin = remove_dot_segments(path->buf, path->len, &up);
+ const char* end = path->buf + path->len;
if (base->len) {
// Find the up'th last slash
- const uint8_t* base_last = (base->buf + base->len - 1);
+ const char* base_last = (base->buf + base->len - 1);
++up;
do {
if (*base_last == '/') {
diff --git a/src/writer.c b/src/writer.c
index cecaacf5..e7ec0e09 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -146,7 +146,7 @@ static void
copy_node(SerdNode* dst, const SerdNode* src)
{
if (src) {
- dst->buf = (uint8_t*)realloc((char*)dst->buf, src->n_bytes + 1);
+ dst->buf = (char*)realloc((char*)dst->buf, src->n_bytes + 1);
dst->n_bytes = src->n_bytes;
dst->flags = src->flags;
dst->type = src->type;
@@ -207,7 +207,7 @@ uri_must_escape(const uint8_t c)
}
static size_t
-write_uri(SerdWriter* writer, const uint8_t* utf8, size_t n_bytes)
+write_uri(SerdWriter* writer, const char* utf8, size_t n_bytes)
{
size_t len = 0;
for (size_t i = 0; i < n_bytes;) {
@@ -226,7 +226,7 @@ write_uri(SerdWriter* writer, const uint8_t* utf8, size_t n_bytes)
// Write UTF-8 character
size_t size = 0;
- len += write_character(writer, utf8 + i, &size);
+ len += write_character(writer, (const uint8_t*)utf8 + i, &size);
i += size;
if (size == 0) {
// Corrupt input, scan to start of next character
@@ -237,7 +237,7 @@ write_uri(SerdWriter* writer, const uint8_t* utf8, size_t n_bytes)
}
static bool
-lname_must_escape(const uint8_t c)
+lname_must_escape(const char c)
{
/* This arbitrary list of characters, most of which have nothing to do with
Turtle, must be handled as special cases here because the RDF and SPARQL
@@ -258,7 +258,7 @@ lname_must_escape(const uint8_t c)
}
static size_t
-write_lname(SerdWriter* writer, const uint8_t* utf8, size_t n_bytes)
+write_lname(SerdWriter* writer, const char* utf8, size_t n_bytes)
{
size_t len = 0;
for (size_t i = 0; i < n_bytes; ++i) {
@@ -284,7 +284,7 @@ write_lname(SerdWriter* writer, const uint8_t* utf8, size_t n_bytes)
static size_t
write_text(SerdWriter* writer, TextContext ctx,
- const uint8_t* utf8, size_t n_bytes)
+ const char* utf8, size_t n_bytes)
{
size_t len = 0;
for (size_t i = 0; i < n_bytes;) {
@@ -338,7 +338,8 @@ write_text(SerdWriter* writer, TextContext ctx,
// Write UTF-8 character
size_t size = 0;
- len += write_character(writer, utf8 + i - 1, &size);
+ len += write_character(writer, (const uint8_t*)utf8 + i - 1, &size);
+
if (size == 0) {
// Corrupt input, scan to start of next character
for (; i < n_bytes && (utf8[i] & 0x80); ++i) {}
@@ -352,7 +353,7 @@ write_text(SerdWriter* writer, TextContext ctx,
static size_t
uri_sink(const void* buf, size_t len, void* stream)
{
- return write_uri((SerdWriter*)stream, (const uint8_t*)buf, len);
+ return write_uri((SerdWriter*)stream, (const char*)buf, len);
}
static void
@@ -871,14 +872,14 @@ serd_writer_set_error_sink(SerdWriter* writer,
SERD_API
void
-serd_writer_chop_blank_prefix(SerdWriter* writer,
- const uint8_t* prefix)
+serd_writer_chop_blank_prefix(SerdWriter* writer,
+ const char* prefix)
{
free(writer->bprefix);
writer->bprefix_len = 0;
writer->bprefix = NULL;
if (prefix) {
- writer->bprefix_len = strlen((const char*)prefix);
+ writer->bprefix_len = strlen(prefix);
writer->bprefix = (uint8_t*)malloc(writer->bprefix_len + 1);
memcpy(writer->bprefix, prefix, writer->bprefix_len + 1);
}
@@ -985,9 +986,9 @@ serd_buffer_sink(const void* buf, size_t len, void* stream)
}
SERD_API
-uint8_t*
+char*
serd_buffer_sink_finish(SerdBuffer* stream)
{
serd_buffer_sink("", 1, stream);
- return (uint8_t*)stream->buf;
+ return (char*)stream->buf;
}
diff --git a/tests/serd_test.c b/tests/serd_test.c
index 71801c1b..b3270cde 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -25,8 +25,6 @@
#include "test_utils.h"
-#define USTR(s) ((const uint8_t*)(s))
-
#ifndef INFINITY
# define INFINITY (DBL_MAX + DBL_MAX)
#endif
@@ -89,11 +87,9 @@ check_file_uri(const char* hostname,
expected_path = path;
}
- SerdNode node = serd_node_new_file_uri(
- USTR(path), USTR(hostname), 0, escape);
-
- uint8_t* out_hostname = NULL;
- uint8_t* out_path = serd_file_uri_parse(node.buf, &out_hostname);
+ SerdNode node = serd_node_new_file_uri(path, hostname, 0, escape);
+ char* out_hostname = NULL;
+ char* out_path = serd_file_uri_parse(node.buf, &out_hostname);
int ret = 0;
if (strcmp((const char*)node.buf, expected_uri)) {
ret = FAILF("Bad URI %s != %s\n", node.buf, expected_uri);
@@ -156,13 +152,13 @@ main(void)
for (unsigned i = 0; i < sizeof(dbl_test_nums) / sizeof(double); ++i) {
SerdNode node = serd_node_new_decimal(dbl_test_nums[i], 8);
const bool pass = (node.buf && dbl_test_strs[i])
- ? !strcmp((const char*)node.buf, (const char*)dbl_test_strs[i])
- : ((const char*)node.buf == dbl_test_strs[i]);
+ ? !strcmp(node.buf, dbl_test_strs[i])
+ : (node.buf == dbl_test_strs[i]);
if (!pass) {
FAILF("Serialised `%s' != %s\n",
node.buf, dbl_test_strs[i]);
}
- const size_t len = node.buf ? strlen((const char*)node.buf) : 0;
+ const size_t len = node.buf ? strlen(node.buf) : 0;
if (node.n_bytes != len) {
FAILF("Length %zu != %zu\n",
node.n_bytes, len);
@@ -186,7 +182,7 @@ main(void)
FAILF("Serialised `%s' != %s\n",
node.buf, int_test_strs[i]);
}
- const size_t len = strlen((const char*)node.buf);
+ const size_t len = strlen(node.buf);
if (node.n_bytes != len) {
FAILF("Length %zu,%zu != %zu\n",
node.n_bytes, len);
@@ -225,7 +221,7 @@ main(void)
const uint8_t str[] = { '"', '5', 0xE2, 0x82, 0xAC, '"', '\n', 0 };
SerdNodeFlags flags;
- size_t n_bytes = serd_strlen(str, &flags);
+ size_t n_bytes = serd_strlen((const char*)str, &flags);
if (n_bytes != 7 || flags != (SERD_HAS_QUOTE|SERD_HAS_NEWLINE)) {
FAILF("Bad serd_strlen(%s) n_bytes=%zu flags=%u\n",
str, n_bytes, flags);
@@ -233,8 +229,8 @@ main(void)
// Test serd_strerror
- const uint8_t* msg = NULL;
- if (strcmp((const char*)(msg = serd_strerror(SERD_SUCCESS)), "Success")) {
+ const char* msg = NULL;
+ if (strcmp((msg = serd_strerror(SERD_SUCCESS)), "Success")) {
FAILF("Bad message `%s' for SERD_SUCCESS\n", msg);
}
for (int i = SERD_FAILURE; i <= SERD_ERR_INTERNAL; ++i) {
@@ -247,36 +243,36 @@ main(void)
// Test serd_uri_to_path
- const uint8_t* uri = (const uint8_t*)"file:///home/user/foo.ttl";
- if (strcmp((const char*)serd_uri_to_path(uri), "/home/user/foo.ttl")) {
+ const char* uri = "file:///home/user/foo.ttl";
+ if (strcmp(serd_uri_to_path(uri), "/home/user/foo.ttl")) {
FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri);
}
- uri = (const uint8_t*)"file://localhost/home/user/foo.ttl";
- if (strcmp((const char*)serd_uri_to_path(uri), "/home/user/foo.ttl")) {
+ uri = "file://localhost/home/user/foo.ttl";
+ if (strcmp(serd_uri_to_path(uri), "/home/user/foo.ttl")) {
FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri);
}
- uri = (const uint8_t*)"file:illegal/file/uri";
+ uri = "file:illegal/file/uri";
if (serd_uri_to_path(uri)) {
FAILF("Converted invalid URI `%s' to path `%s'\n",
uri, serd_uri_to_path(uri));
}
- uri = (const uint8_t*)"file:///c:/awful/system";
+ uri = "file:///c:/awful/system";
if (strcmp((const char*)serd_uri_to_path(uri), "c:/awful/system")) {
FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri);
}
- uri = (const uint8_t*)"file:///c:awful/system";
+ uri = "file:///c:awful/system";
if (strcmp((const char*)serd_uri_to_path(uri), "/c:awful/system")) {
FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri);
}
- uri = (const uint8_t*)"file:///0/1";
+ uri = "file:///0/1";
if (strcmp((const char*)serd_uri_to_path(uri), "/0/1")) {
FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri);
}
- uri = (const uint8_t*)"C:\\Windows\\Sucks";
+ uri = "C:\\Windows\\Sucks";
if (strcmp((const char*)serd_uri_to_path(uri), "C:\\Windows\\Sucks")) {
FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri);
}
- uri = (const uint8_t*)"C|/Windows/Sucks";
+ uri = "C|/Windows/Sucks";
if (strcmp((const char*)serd_uri_to_path(uri), "C|/Windows/Sucks")) {
FAILF("Bad path %s for %s\n", serd_uri_to_path(uri), uri);
}
@@ -300,9 +296,8 @@ main(void)
}
// Test tolerance of parsing junk URI escapes
-
- uint8_t* out_path = serd_file_uri_parse(USTR("file:///foo/%0Xbar"), NULL);
- if (strcmp((const char*)out_path, "/foo/bar")) {
+ char* out_path = serd_file_uri_parse("file:///foo/%0Xbar", NULL);
+ if (strcmp(out_path, "/foo/bar")) {
FAILF("bad tolerance of junk escape: `%s'\n", out_path);
}
free(out_path);
@@ -310,13 +305,13 @@ main(void)
// Test serd_node_equals
const uint8_t replacement_char_str[] = { 0xEF, 0xBF, 0xBD, 0 };
- SerdNode lhs = serd_node_from_string(SERD_LITERAL, replacement_char_str);
- SerdNode rhs = serd_node_from_string(SERD_LITERAL, USTR("123"));
+ SerdNode lhs = serd_node_from_string(SERD_LITERAL, (const char*)replacement_char_str);
+ SerdNode rhs = serd_node_from_string(SERD_LITERAL, "123");
if (serd_node_equals(&lhs, &rhs)) {
FAILF("%s == %s\n", lhs.buf, rhs.buf);
}
- SerdNode qnode = serd_node_from_string(SERD_CURIE, USTR("foo:bar"));
+ SerdNode qnode = serd_node_from_string(SERD_CURIE, "foo:bar");
if (serd_node_equals(&lhs, &qnode)) {
FAILF("%s == %s\n", lhs.buf, qnode.buf);
}
@@ -332,7 +327,7 @@ main(void)
// Test serd_node_from_string
- SerdNode node = serd_node_from_string(SERD_LITERAL, (const uint8_t*)"hello\"");
+ SerdNode node = serd_node_from_string(SERD_LITERAL, "hello\"");
if (node.n_bytes != 6 || node.flags != SERD_HAS_QUOTE
|| strcmp((const char*)node.buf, "hello\"")) {
FAILF("Bad node %s %zu %d %d\n",
@@ -351,14 +346,14 @@ main(void)
FAIL("Successfully created node from NULL substring\n");
}
- SerdNode a_b = serd_node_from_substring(SERD_LITERAL, USTR("a\"bc"), 3);
+ SerdNode a_b = serd_node_from_substring(SERD_LITERAL, "a\"bc", 3);
if (a_b.n_bytes != 3 || a_b.flags != SERD_HAS_QUOTE
|| strncmp((const char*)a_b.buf, "a\"b", 3)) {
FAILF("Bad node %s %zu %d %d\n",
a_b.buf, a_b.n_bytes, a_b.flags, a_b.type);
}
- a_b = serd_node_from_substring(SERD_LITERAL, USTR("a\"bc"), 10);
+ a_b = serd_node_from_substring(SERD_LITERAL, "a\"bc", 10);
if (a_b.n_bytes != 4 || a_b.flags != SERD_HAS_QUOTE
|| strncmp((const char*)a_b.buf, "a\"bc", 4)) {
FAILF("Bad node %s %zu %zu %d %d\n",
@@ -373,10 +368,10 @@ main(void)
}
SerdURI base_uri;
- SerdNode base = serd_node_new_uri_from_string(USTR("http://example.org/"),
+ SerdNode base = serd_node_new_uri_from_string("http://example.org/",
NULL, &base_uri);
SerdNode nil = serd_node_new_uri_from_string(NULL, &base_uri, NULL);
- SerdNode nil2 = serd_node_new_uri_from_string(USTR(""), &base_uri, NULL);
+ SerdNode nil2 = serd_node_new_uri_from_string("", &base_uri, NULL);
if (nil.type != SERD_URI || strcmp((const char*)nil.buf, (const char*)base.buf) ||
nil2.type != SERD_URI || strcmp((const char*)nil2.buf, (const char*)base.buf)) {
FAILF("URI %s != base %s\n", nil.buf, base.buf);
@@ -385,7 +380,7 @@ main(void)
serd_node_free(&nil2);
// Test serd_node_new_relative_uri
- SerdNode abs = serd_node_from_string(SERD_URI, USTR("http://example.org/foo/bar"));
+ SerdNode abs = serd_node_from_string(SERD_URI, "http://example.org/foo/bar");
SerdURI abs_uri;
serd_uri_parse(abs.buf, &abs_uri);
@@ -400,11 +395,11 @@ main(void)
// Test SerdEnv
- SerdNode u = serd_node_from_string(SERD_URI, USTR("http://example.org/foo"));
- SerdNode b = serd_node_from_string(SERD_CURIE, USTR("invalid"));
- SerdNode c = serd_node_from_string(SERD_CURIE, USTR("eg.2:b"));
+ SerdNode u = serd_node_from_string(SERD_URI, "http://example.org/foo");
+ SerdNode b = serd_node_from_string(SERD_CURIE, "invalid");
+ SerdNode c = serd_node_from_string(SERD_CURIE, "eg.2:b");
SerdEnv* env = serd_env_new(NULL);
- serd_env_set_prefix_from_strings(env, USTR("eg.2"), USTR("http://example.org/"));
+ serd_env_set_prefix_from_strings(env, "eg.2", "http://example.org/");
if (!serd_env_set_base_uri(env, NULL)) {
FAIL("Successfully set NULL base URI\n");
@@ -434,7 +429,7 @@ main(void)
}
serd_node_free(&xu);
- SerdNode badpre = serd_node_from_string(SERD_CURIE, USTR("hm:what"));
+ SerdNode badpre = serd_node_from_string(SERD_CURIE, "hm:what");
SerdNode xbadpre = serd_env_expand_node(env, &badpre);
if (!serd_node_equals(&xbadpre, &SERD_NODE_NULL)) {
FAILF("Expanded invalid curie %s\n", badpre.buf);
@@ -450,19 +445,19 @@ main(void)
FAIL("Set NULL prefix\n");
}
- const SerdNode lit = serd_node_from_string(SERD_LITERAL, USTR("hello"));
+ const SerdNode lit = serd_node_from_string(SERD_LITERAL, "hello");
if (!serd_env_set_prefix(env, &b, &lit)) {
FAIL("Set prefix to literal\n");
}
int n_prefixes = 0;
- serd_env_set_prefix_from_strings(env, USTR("eg.2"), USTR("http://example.org/"));
+ serd_env_set_prefix_from_strings(env, "eg.2", "http://example.org/");
serd_env_foreach(env, count_prefixes, &n_prefixes);
if (n_prefixes != 1) {
FAILF("Bad prefix count %d\n", n_prefixes);
}
- SerdNode shorter_uri = serd_node_from_string(SERD_URI, USTR("urn:foo"));
+ SerdNode shorter_uri = serd_node_from_string(SERD_URI, "urn:foo");
SerdNode prefix_name;
if (serd_env_qualify(env, &shorter_uri, &prefix_name, &suffix)) {
FAILF("Qualified %s\n", shorter_uri.buf);
@@ -482,7 +477,7 @@ main(void)
FAIL("Failed to create writer\n");
}
- serd_writer_chop_blank_prefix(writer, USTR("tmp"));
+ serd_writer_chop_blank_prefix(writer, "tmp");
serd_writer_chop_blank_prefix(writer, NULL);
if (!serd_writer_set_base_uri(writer, &lit)) {
@@ -495,10 +490,10 @@ main(void)
FAIL("Writer has incorrect env\n");
}
- uint8_t buf[] = { 0x80, 0, 0, 0, 0 };
- SerdNode s = serd_node_from_string(SERD_URI, USTR(""));
- SerdNode p = serd_node_from_string(SERD_URI, USTR("http://example.org/pred"));
- SerdNode o = serd_node_from_string(SERD_LITERAL, buf);
+ uint8_t buf[] = { 0xEF, 0xBF, 0xBD, 0 };
+ SerdNode s = serd_node_from_string(SERD_URI, "");
+ SerdNode p = serd_node_from_string(SERD_URI, "http://example.org/pred");
+ SerdNode o = serd_node_from_string(SERD_LITERAL, (char*)buf);
// Write 3 invalid statements (should write nothing)
const SerdNode* junk[][5] = { { &s, &p, NULL, NULL, NULL },
@@ -519,8 +514,8 @@ main(void)
}
}
- const SerdNode t = serd_node_from_string(SERD_URI, USTR("urn:Type"));
- const SerdNode l = serd_node_from_string(SERD_LITERAL, USTR("en"));
+ const SerdNode t = serd_node_from_string(SERD_URI, "urn:Type");
+ const SerdNode l = serd_node_from_string(SERD_LITERAL, "en");
const SerdNode* good[][5] = { { &s, &p, &o, NULL, NULL },
{ &s, &p, &o, &SERD_NODE_NULL, &SERD_NODE_NULL },
{ &s, &p, &o, &t, NULL },
@@ -540,9 +535,9 @@ main(void)
}
// Write statements with bad UTF-8 (should be replaced)
- const uint8_t bad_str[] = { 0xFF, 0x90, 'h', 'i', 0 };
- SerdNode bad_lit = serd_node_from_string(SERD_LITERAL, bad_str);
- SerdNode bad_uri = serd_node_from_string(SERD_URI, bad_str);
+ const char bad_str[] = { (char)0xFF, (char)0x90, 'h', 'i', 0 };
+ SerdNode bad_lit = serd_node_from_string(SERD_LITERAL, bad_str);
+ SerdNode bad_uri = serd_node_from_string(SERD_URI, bad_str);
if (serd_writer_write_statement(writer, 0, NULL,
&s, &p, &bad_lit, NULL, NULL)) {
FAIL("Failed to write junk UTF-8 literal\n");
@@ -552,7 +547,7 @@ main(void)
}
// Write 1 valid statement
- o = serd_node_from_string(SERD_LITERAL, USTR("hello"));
+ o = serd_node_from_string(SERD_LITERAL, "hello");
if (serd_writer_write_statement(writer, 0, NULL,
&s, &p, &o, NULL, NULL)) {
FAIL("Failed to write valid statement\n");
@@ -565,13 +560,13 @@ main(void)
writer = serd_writer_new(
SERD_TURTLE, (SerdStyle)0, env, NULL, serd_buffer_sink, &buffer);
- o = serd_node_from_string(SERD_URI, USTR("http://example.org/base"));
+ o = serd_node_from_string(SERD_URI, "http://example.org/base");
if (serd_writer_set_base_uri(writer, &o)) {
FAIL("Failed to write to chunk sink\n");
}
serd_writer_free(writer);
- uint8_t* out = serd_buffer_sink_finish(&buffer);
+ char* out = serd_buffer_sink_finish(&buffer);
if (strcmp((const char*)out, "@base <http://example.org/base> .\n")) {
FAILF("Incorrect buffer output:\n%s\n", buffer.buf);
@@ -593,20 +588,20 @@ main(void)
FAIL("Corrupt reader handle\n");
}
- SerdNode g = serd_node_from_string(SERD_URI, USTR("http://example.org/"));
+ SerdNode g = serd_node_from_string(SERD_URI, "http://example.org/");
serd_reader_set_default_graph(reader, &g);
- serd_reader_add_blank_prefix(reader, USTR("tmp"));
+ serd_reader_add_blank_prefix(reader, "tmp");
serd_reader_add_blank_prefix(reader, NULL);
- if (!serd_reader_read_file(reader, USTR("http://notafile"))) {
+ if (!serd_reader_read_file(reader, "http://notafile")) {
FAIL("Apparently read an http URI\n");
- } else if (!serd_reader_read_file(reader, USTR("file:///better/not/exist"))) {
+ } else if (!serd_reader_read_file(reader, "file:///better/not/exist")) {
FAIL("Apparently read a non-existent file\n");
- } else if (!serd_reader_read_file(reader, USTR("file://"))) {
+ } else if (!serd_reader_read_file(reader, "file://")) {
FAIL("Apparently read a file with no path\n");
}
- const SerdStatus st = serd_reader_read_file(reader, USTR(path));
+ const SerdStatus st = serd_reader_read_file(reader, path);
if (st) {
FAILF("Error reading file (%s)\n", serd_strerror(st));
} else if (rt->n_statements != 13) {
@@ -616,7 +611,7 @@ main(void)
FAILF("Bad graph %p\n", rt->graph);
}
- if (!serd_reader_read_string(reader, USTR("This isn't Turtle at all."))) {
+ if (!serd_reader_read_string(reader, "This isn't Turtle at all.")) {
FAIL("Parsed invalid string successfully.\n");
}