aboutsummaryrefslogtreecommitdiffstats
path: root/src/serd_internal.h
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/serd_internal.h
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/serd_internal.h')
-rw-r--r--src/serd_internal.h48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/serd_internal.h b/src/serd_internal.h
index 57862f3d..99a76a53 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
@@ -162,7 +162,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;
@@ -174,7 +174,7 @@ static inline SerdStack
serd_stack_new(size_t size)
{
SerdStack stack;
- stack.buf = (uint8_t*)calloc(size, 1);
+ stack.buf = (char*)calloc(size, 1);
stack.buf_size = size;
stack.size = SERD_STACK_BOTTOM;
return stack;
@@ -195,15 +195,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;
}
@@ -252,7 +252,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;
@@ -266,7 +266,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;
}
@@ -305,7 +305,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
@@ -321,21 +321,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');
}
@@ -366,13 +366,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] == '\\');
@@ -381,7 +381,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);
@@ -450,7 +450,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) {
@@ -578,7 +578,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;