aboutsummaryrefslogtreecommitdiffstats
path: root/src/serd_internal.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-07-22 16:57:46 +0200
committerDavid Robillard <d@drobilla.net>2018-07-22 16:57:46 +0200
commit8b8890dd104066c190497792e427ad2a9a7f918a (patch)
tree26b553712fcb6fca01fc1199f97cd7e189a31488 /src/serd_internal.h
parentade6c7579fae302d64681555a77dbf78fcacd682 (diff)
downloadserd-8b8890dd104066c190497792e427ad2a9a7f918a.tar.gz
serd-8b8890dd104066c190497792e427ad2a9a7f918a.tar.bz2
serd-8b8890dd104066c190497792e427ad2a9a7f918a.zip
Inline serd_byte_source_advance
Diffstat (limited to 'src/serd_internal.h')
-rw-r--r--src/serd_internal.h36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/serd_internal.h b/src/serd_internal.h
index 18cc74bd..fecd2b6a 100644
--- a/src/serd_internal.h
+++ b/src/serd_internal.h
@@ -118,6 +118,9 @@ serd_byte_source_close(SerdByteSource* source);
SerdStatus
serd_byte_source_prepare(SerdByteSource* source);
+SerdStatus
+serd_byte_source_page(SerdByteSource* source);
+
static inline uint8_t
serd_byte_source_peek(SerdByteSource* source)
{
@@ -125,8 +128,37 @@ serd_byte_source_peek(SerdByteSource* source)
return source->read_buf[source->read_head];
}
-SerdStatus
-serd_byte_source_advance(SerdByteSource* source);
+static inline SerdStatus
+serd_byte_source_advance(SerdByteSource* source)
+{
+ SerdStatus st = SERD_SUCCESS;
+
+ switch (serd_byte_source_peek(source)) {
+ case '\0': break;
+ case '\n': ++source->cur.line; source->cur.col = 0; break;
+ default: ++source->cur.col;
+ }
+
+ if (source->from_stream) {
+ source->eof = false;
+ if (source->page_size > 1) {
+ if (++source->read_head == source->page_size) {
+ st = serd_byte_source_page(source);
+ }
+ } else {
+ if (!source->read_func(&source->read_byte, 1, 1, source->stream)) {
+ st = source->error_func(source->stream) ? SERD_ERR_UNKNOWN
+ : SERD_FAILURE;
+ }
+ }
+ } else if (source->eof) {
+ st = SERD_FAILURE; // Can't read past end of string
+ } else {
+ ++source->read_head; // Move to next character in string
+ }
+
+ return st;
+}
/* Stack */