diff options
author | David Robillard <d@drobilla.net> | 2019-10-27 19:29:30 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-10-27 22:40:45 +0100 |
commit | cd6d4569c1c8819cc8e54eefdc0ac389d8efb4ea (patch) | |
tree | 9be604e9ceb648652b1b4dd28202b7bf896817d2 /src/reader.h | |
parent | 9c3aa95c0ed18ecc20517458bf1c0e4180e8b2e2 (diff) | |
download | serd-cd6d4569c1c8819cc8e54eefdc0ac389d8efb4ea.tar.gz serd-cd6d4569c1c8819cc8e54eefdc0ac389d8efb4ea.tar.bz2 serd-cd6d4569c1c8819cc8e54eefdc0ac389d8efb4ea.zip |
Use int as internal character type so it can represent EOF
Diffstat (limited to 'src/reader.h')
-rw-r--r-- | src/reader.h | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/reader.h b/src/reader.h index f6cbc7ad..f7cdba02 100644 --- a/src/reader.h +++ b/src/reader.h @@ -16,16 +16,21 @@ #include "serd_internal.h" -static inline uint8_t +#include <assert.h> +#include <stdio.h> + +static inline int peek_byte(SerdReader* reader) { - return serd_byte_source_peek(&reader->source); + SerdByteSource* source = &reader->source; + + return source->eof ? EOF : (int)source->read_buf[source->read_head]; } -static inline uint8_t +static inline int eat_byte(SerdReader* reader) { - const uint8_t c = peek_byte(reader); + const int c = peek_byte(reader); const SerdStatus st = serd_byte_source_advance(&reader->source); if (st) { reader->status = st; @@ -33,20 +38,20 @@ eat_byte(SerdReader* reader) return c; } -static inline uint8_t -eat_byte_safe(SerdReader* reader, const uint8_t byte) +static inline int +eat_byte_safe(SerdReader* reader, const int byte) { (void)byte; - const uint8_t c = eat_byte(reader); + const int c = eat_byte(reader); assert(c == byte); return c; } -static inline uint8_t -eat_byte_check(SerdReader* reader, const uint8_t byte) +static inline int +eat_byte_check(SerdReader* reader, const int byte) { - const uint8_t c = peek_byte(reader); + const int c = peek_byte(reader); if (c != byte) { return r_err(reader, SERD_ERR_BAD_SYNTAX, "expected `%c', not `%c'\n", byte, c); @@ -65,16 +70,18 @@ eat_string(SerdReader* reader, const char* str, unsigned n) } static inline SerdStatus -push_byte(SerdReader* reader, Ref ref, const uint8_t c) +push_byte(SerdReader* reader, Ref ref, const int c) { + assert(c != EOF); SERD_STACK_ASSERT_TOP(reader, ref); + uint8_t* const s = serd_stack_push(&reader->stack, 1); SerdNode* const node = (SerdNode*)(reader->stack.buf + ref); ++node->n_bytes; if (!(c & 0x80)) { // Starts with 0 bit, start of new character ++node->n_chars; } - *(s - 1) = c; + *(s - 1) = (uint8_t)c; *s = '\0'; return SERD_SUCCESS; } |